issueWidgetQueries.tsx 2.2 KB

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