widgetCardDataLoader.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import {Fragment} from 'react';
  2. import type {PageFilters} from 'sentry/types/core';
  3. import type {Series} from 'sentry/types/echarts';
  4. import type {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery';
  5. import type {AggregationOutputType} from 'sentry/utils/discover/fields';
  6. import useApi from 'sentry/utils/useApi';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import type {DashboardFilters, Widget} from '../types';
  9. import {WidgetType} from '../types';
  10. import IssueWidgetQueries from './issueWidgetQueries';
  11. import ReleaseWidgetQueries from './releaseWidgetQueries';
  12. import WidgetQueries from './widgetQueries';
  13. type Results = {
  14. loading: boolean;
  15. errorMessage?: string;
  16. pageLinks?: string;
  17. tableResults?: TableDataWithTitle[];
  18. timeseriesResults?: Series[];
  19. timeseriesResultsTypes?: Record<string, AggregationOutputType>;
  20. totalIssuesCount?: string;
  21. };
  22. type Props = {
  23. children: (props: Results) => React.ReactNode;
  24. selection: PageFilters;
  25. widget: Widget;
  26. dashboardFilters?: DashboardFilters;
  27. onDataFetched?: (
  28. results: Pick<
  29. Results,
  30. | 'pageLinks'
  31. | 'tableResults'
  32. | 'timeseriesResults'
  33. | 'timeseriesResultsTypes'
  34. | 'totalIssuesCount'
  35. >
  36. ) => void;
  37. onWidgetSplitDecision?: (splitDecision: WidgetType) => void;
  38. tableItemLimit?: number;
  39. };
  40. export function WidgetCardDataLoader({
  41. children,
  42. widget,
  43. selection,
  44. dashboardFilters,
  45. tableItemLimit,
  46. onDataFetched,
  47. onWidgetSplitDecision,
  48. }: Props) {
  49. const api = useApi();
  50. const organization = useOrganization();
  51. if (widget.widgetType === WidgetType.ISSUE) {
  52. return (
  53. <IssueWidgetQueries
  54. api={api}
  55. organization={organization}
  56. widget={widget}
  57. selection={selection}
  58. limit={tableItemLimit}
  59. onDataFetched={onDataFetched}
  60. dashboardFilters={dashboardFilters}
  61. >
  62. {({tableResults, errorMessage, loading}) => (
  63. <Fragment>{children({tableResults, errorMessage, loading})}</Fragment>
  64. )}
  65. </IssueWidgetQueries>
  66. );
  67. }
  68. if (widget.widgetType === WidgetType.RELEASE) {
  69. return (
  70. <ReleaseWidgetQueries
  71. api={api}
  72. organization={organization}
  73. widget={widget}
  74. selection={selection}
  75. limit={widget.limit ?? tableItemLimit}
  76. onDataFetched={onDataFetched}
  77. dashboardFilters={dashboardFilters}
  78. >
  79. {({tableResults, timeseriesResults, errorMessage, loading}) => (
  80. <Fragment>
  81. {children({tableResults, timeseriesResults, errorMessage, loading})}
  82. </Fragment>
  83. )}
  84. </ReleaseWidgetQueries>
  85. );
  86. }
  87. return (
  88. <WidgetQueries
  89. api={api}
  90. organization={organization}
  91. widget={widget}
  92. selection={selection}
  93. limit={tableItemLimit}
  94. onDataFetched={onDataFetched}
  95. dashboardFilters={dashboardFilters}
  96. onWidgetSplitDecision={onWidgetSplitDecision}
  97. >
  98. {({
  99. tableResults,
  100. timeseriesResults,
  101. errorMessage,
  102. loading,
  103. timeseriesResultsTypes,
  104. }) => (
  105. <Fragment>
  106. {children({
  107. tableResults,
  108. timeseriesResults,
  109. errorMessage,
  110. loading,
  111. timeseriesResultsTypes,
  112. })}
  113. </Fragment>
  114. )}
  115. </WidgetQueries>
  116. );
  117. }