issueWidgetQueries.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {useEffect, useState} from 'react';
  2. import {Client, ResponseMeta} from 'sentry/api';
  3. import MemberListStore from 'sentry/stores/memberListStore';
  4. import {Group, Organization, PageFilters} from 'sentry/types';
  5. import getDynamicText from 'sentry/utils/getDynamicText';
  6. import {IssuesConfig} from '../datasetConfig/issues';
  7. import {DashboardFilters, Widget} from '../types';
  8. import GenericWidgetQueries, {
  9. GenericWidgetQueriesChildrenProps,
  10. OnDataFetchedProps,
  11. } from './genericWidgetQueries';
  12. type Props = {
  13. api: Client;
  14. children: (props: GenericWidgetQueriesChildrenProps) => JSX.Element;
  15. organization: Organization;
  16. selection: PageFilters;
  17. widget: Widget;
  18. cursor?: string;
  19. dashboardFilters?: DashboardFilters;
  20. limit?: number;
  21. onDataFetched?: (results: OnDataFetchedProps) => void;
  22. };
  23. function IssueWidgetQueries({
  24. children,
  25. api,
  26. organization,
  27. selection,
  28. widget,
  29. cursor,
  30. limit,
  31. dashboardFilters,
  32. onDataFetched,
  33. }: Props) {
  34. const [memberListStoreLoaded, setMemberListStoreLoaded] = useState(false);
  35. useEffect(() => {
  36. setMemberListStoreLoaded(!MemberListStore.state.loading);
  37. const unlistener = MemberListStore.listen(() => {
  38. setMemberListStoreLoaded(!MemberListStore.state.loading);
  39. }, undefined);
  40. return () => unlistener();
  41. }, []);
  42. const config = IssuesConfig;
  43. const afterFetchTableData = (_rawResult: Group[], response?: ResponseMeta) => {
  44. return {totalIssuesCount: response?.getResponseHeader('X-Hits') ?? undefined};
  45. };
  46. return getDynamicText({
  47. value: (
  48. <GenericWidgetQueries<never, Group[]>
  49. config={config}
  50. api={api}
  51. organization={organization}
  52. selection={selection}
  53. widget={widget}
  54. cursor={cursor}
  55. limit={limit}
  56. dashboardFilters={dashboardFilters}
  57. onDataFetched={onDataFetched}
  58. afterFetchTableData={afterFetchTableData}
  59. >
  60. {({loading, ...rest}) =>
  61. children({
  62. loading: loading || !memberListStoreLoaded,
  63. ...rest,
  64. })
  65. }
  66. </GenericWidgetQueries>
  67. ),
  68. fixed: <div />,
  69. });
  70. }
  71. export default IssueWidgetQueries;