issueWidgetQueries.tsx 2.3 KB

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