issueWidgetQueries.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. skipDashboardFilterParens // Issue widgets do not support parens in search
  61. >
  62. {({loading, ...rest}) =>
  63. children({
  64. loading: loading || !memberListStoreLoaded,
  65. ...rest,
  66. })
  67. }
  68. </GenericWidgetQueries>
  69. ),
  70. fixed: <div />,
  71. });
  72. }
  73. export default IssueWidgetQueries;