123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import {Fragment} from 'react';
- import type {PageFilters} from 'sentry/types/core';
- import type {Series} from 'sentry/types/echarts';
- import type {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery';
- import type {AggregationOutputType} from 'sentry/utils/discover/fields';
- import useApi from 'sentry/utils/useApi';
- import useOrganization from 'sentry/utils/useOrganization';
- import type {DashboardFilters, Widget} from '../types';
- import {WidgetType} from '../types';
- import IssueWidgetQueries from './issueWidgetQueries';
- import ReleaseWidgetQueries from './releaseWidgetQueries';
- import WidgetQueries from './widgetQueries';
- type Results = {
- loading: boolean;
- errorMessage?: string;
- pageLinks?: string;
- tableResults?: TableDataWithTitle[];
- timeseriesResults?: Series[];
- timeseriesResultsTypes?: Record<string, AggregationOutputType>;
- totalIssuesCount?: string;
- };
- type Props = {
- children: (props: Results) => React.ReactNode;
- selection: PageFilters;
- widget: Widget;
- dashboardFilters?: DashboardFilters;
- onDataFetched?: (
- results: Pick<
- Results,
- | 'pageLinks'
- | 'tableResults'
- | 'timeseriesResults'
- | 'timeseriesResultsTypes'
- | 'totalIssuesCount'
- >
- ) => void;
- onWidgetSplitDecision?: (splitDecision: WidgetType) => void;
- tableItemLimit?: number;
- };
- export function WidgetCardDataLoader({
- children,
- widget,
- selection,
- dashboardFilters,
- tableItemLimit,
- onDataFetched,
- onWidgetSplitDecision,
- }: Props) {
- const api = useApi();
- const organization = useOrganization();
- if (widget.widgetType === WidgetType.ISSUE) {
- return (
- <IssueWidgetQueries
- api={api}
- organization={organization}
- widget={widget}
- selection={selection}
- limit={tableItemLimit}
- onDataFetched={onDataFetched}
- dashboardFilters={dashboardFilters}
- >
- {({tableResults, errorMessage, loading}) => (
- <Fragment>{children({tableResults, errorMessage, loading})}</Fragment>
- )}
- </IssueWidgetQueries>
- );
- }
- if (widget.widgetType === WidgetType.RELEASE) {
- return (
- <ReleaseWidgetQueries
- api={api}
- organization={organization}
- widget={widget}
- selection={selection}
- limit={widget.limit ?? tableItemLimit}
- onDataFetched={onDataFetched}
- dashboardFilters={dashboardFilters}
- >
- {({tableResults, timeseriesResults, errorMessage, loading}) => (
- <Fragment>
- {children({tableResults, timeseriesResults, errorMessage, loading})}
- </Fragment>
- )}
- </ReleaseWidgetQueries>
- );
- }
- return (
- <WidgetQueries
- api={api}
- organization={organization}
- widget={widget}
- selection={selection}
- limit={tableItemLimit}
- onDataFetched={onDataFetched}
- dashboardFilters={dashboardFilters}
- onWidgetSplitDecision={onWidgetSplitDecision}
- >
- {({
- tableResults,
- timeseriesResults,
- errorMessage,
- loading,
- timeseriesResultsTypes,
- }) => (
- <Fragment>
- {children({
- tableResults,
- timeseriesResults,
- errorMessage,
- loading,
- timeseriesResultsTypes,
- })}
- </Fragment>
- )}
- </WidgetQueries>
- );
- }
|