widgetCardChartContainer.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {DataZoomComponentOption, LegendComponentOption} from 'echarts';
  4. import type {Location} from 'history';
  5. import type {Client} from 'sentry/api';
  6. import TransparentLoadingMask from 'sentry/components/charts/transparentLoadingMask';
  7. import LoadingIndicator from 'sentry/components/loadingIndicator';
  8. import type {PageFilters} from 'sentry/types/core';
  9. import type {EChartEventHandler, Series} from 'sentry/types/echarts';
  10. import type {Organization} from 'sentry/types/organization';
  11. import type {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery';
  12. import type {AggregationOutputType} from 'sentry/utils/discover/fields';
  13. import {useLocation} from 'sentry/utils/useLocation';
  14. import useRouter from 'sentry/utils/useRouter';
  15. import type {DashboardFilters, Widget} from '../types';
  16. import {WidgetType} from '../types';
  17. import type {AugmentedEChartDataZoomHandler} from './chart';
  18. import WidgetCardChart from './chart';
  19. import {IssueWidgetCard} from './issueWidgetCard';
  20. import IssueWidgetQueries from './issueWidgetQueries';
  21. import ReleaseWidgetQueries from './releaseWidgetQueries';
  22. import WidgetQueries from './widgetQueries';
  23. type Props = {
  24. api: Client;
  25. location: Location;
  26. organization: Organization;
  27. selection: PageFilters;
  28. widget: Widget;
  29. chartGroup?: string;
  30. chartZoomOptions?: DataZoomComponentOption;
  31. dashboardFilters?: DashboardFilters;
  32. expandNumbers?: boolean;
  33. isMobile?: boolean;
  34. legendOptions?: LegendComponentOption;
  35. noPadding?: boolean;
  36. onDataFetched?: (results: {
  37. pageLinks?: string;
  38. tableResults?: TableDataWithTitle[];
  39. timeseriesResults?: Series[];
  40. timeseriesResultsTypes?: Record<string, AggregationOutputType>;
  41. totalIssuesCount?: string;
  42. }) => void;
  43. onLegendSelectChanged?: EChartEventHandler<{
  44. name: string;
  45. selected: Record<string, boolean>;
  46. type: 'legendselectchanged';
  47. }>;
  48. onWidgetSplitDecision?: (splitDecision: WidgetType) => void;
  49. onZoom?: AugmentedEChartDataZoomHandler;
  50. renderErrorMessage?: (errorMessage?: string) => React.ReactNode;
  51. shouldResize?: boolean;
  52. showSlider?: boolean;
  53. tableItemLimit?: number;
  54. windowWidth?: number;
  55. };
  56. export function WidgetCardChartContainer({
  57. api,
  58. organization,
  59. selection,
  60. widget,
  61. dashboardFilters,
  62. isMobile,
  63. renderErrorMessage,
  64. tableItemLimit,
  65. windowWidth,
  66. onZoom,
  67. onLegendSelectChanged,
  68. legendOptions,
  69. expandNumbers,
  70. onDataFetched,
  71. showSlider,
  72. noPadding,
  73. chartZoomOptions,
  74. onWidgetSplitDecision,
  75. chartGroup,
  76. shouldResize,
  77. }: Props) {
  78. const location = useLocation();
  79. const router = useRouter();
  80. if (widget.widgetType === WidgetType.ISSUE) {
  81. return (
  82. <IssueWidgetQueries
  83. api={api}
  84. organization={organization}
  85. widget={widget}
  86. selection={selection}
  87. limit={tableItemLimit}
  88. onDataFetched={onDataFetched}
  89. dashboardFilters={dashboardFilters}
  90. >
  91. {({tableResults, errorMessage, loading}) => {
  92. return (
  93. <Fragment>
  94. {typeof renderErrorMessage === 'function'
  95. ? renderErrorMessage(errorMessage)
  96. : null}
  97. <LoadingScreen loading={loading} />
  98. <IssueWidgetCard
  99. transformedResults={tableResults?.[0].data ?? []}
  100. loading={loading}
  101. errorMessage={errorMessage}
  102. widget={widget}
  103. location={location}
  104. selection={selection}
  105. />
  106. </Fragment>
  107. );
  108. }}
  109. </IssueWidgetQueries>
  110. );
  111. }
  112. if (widget.widgetType === WidgetType.RELEASE) {
  113. return (
  114. <ReleaseWidgetQueries
  115. api={api}
  116. organization={organization}
  117. widget={widget}
  118. selection={selection}
  119. limit={widget.limit ?? tableItemLimit}
  120. onDataFetched={onDataFetched}
  121. dashboardFilters={dashboardFilters}
  122. >
  123. {({tableResults, timeseriesResults, errorMessage, loading}) => {
  124. return (
  125. <Fragment>
  126. {typeof renderErrorMessage === 'function'
  127. ? renderErrorMessage(errorMessage)
  128. : null}
  129. <WidgetCardChart
  130. timeseriesResults={timeseriesResults}
  131. tableResults={tableResults}
  132. errorMessage={errorMessage}
  133. loading={loading}
  134. location={location}
  135. widget={widget}
  136. selection={selection}
  137. router={router}
  138. organization={organization}
  139. isMobile={isMobile}
  140. windowWidth={windowWidth}
  141. expandNumbers={expandNumbers}
  142. onZoom={onZoom}
  143. showSlider={showSlider}
  144. noPadding={noPadding}
  145. chartZoomOptions={chartZoomOptions}
  146. chartGroup={chartGroup}
  147. shouldResize={shouldResize}
  148. />
  149. </Fragment>
  150. );
  151. }}
  152. </ReleaseWidgetQueries>
  153. );
  154. }
  155. return (
  156. <WidgetQueries
  157. api={api}
  158. organization={organization}
  159. widget={widget}
  160. selection={selection}
  161. limit={tableItemLimit}
  162. onDataFetched={onDataFetched}
  163. dashboardFilters={dashboardFilters}
  164. onWidgetSplitDecision={onWidgetSplitDecision}
  165. >
  166. {({
  167. tableResults,
  168. timeseriesResults,
  169. errorMessage,
  170. loading,
  171. timeseriesResultsTypes,
  172. }) => {
  173. return (
  174. <Fragment>
  175. {typeof renderErrorMessage === 'function'
  176. ? renderErrorMessage(errorMessage)
  177. : null}
  178. <WidgetCardChart
  179. timeseriesResults={timeseriesResults}
  180. tableResults={tableResults}
  181. errorMessage={errorMessage}
  182. loading={loading}
  183. location={location}
  184. widget={widget}
  185. selection={selection}
  186. router={router}
  187. organization={organization}
  188. isMobile={isMobile}
  189. windowWidth={windowWidth}
  190. onZoom={onZoom}
  191. onLegendSelectChanged={onLegendSelectChanged}
  192. legendOptions={legendOptions}
  193. expandNumbers={expandNumbers}
  194. showSlider={showSlider}
  195. noPadding={noPadding}
  196. chartZoomOptions={chartZoomOptions}
  197. timeseriesResultsTypes={timeseriesResultsTypes}
  198. chartGroup={chartGroup}
  199. shouldResize={shouldResize}
  200. />
  201. </Fragment>
  202. );
  203. }}
  204. </WidgetQueries>
  205. );
  206. }
  207. export default WidgetCardChartContainer;
  208. const StyledTransparentLoadingMask = styled(props => (
  209. <TransparentLoadingMask {...props} maskBackgroundColor="transparent" />
  210. ))`
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. `;
  215. export function LoadingScreen({loading}: {loading: boolean}) {
  216. if (!loading) {
  217. return null;
  218. }
  219. return (
  220. <StyledTransparentLoadingMask visible={loading}>
  221. <LoadingIndicator mini />
  222. </StyledTransparentLoadingMask>
  223. );
  224. }