1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import {EventQuery} from 'sentry/actionCreators/events';
- import {LocationQuery} from 'sentry/utils/discover/eventView';
- import GenericDiscoverQuery, {
- DiscoverQueryProps,
- GenericChildrenProps,
- } from 'sentry/utils/discover/genericDiscoverQuery';
- import withApi from 'sentry/utils/withApi';
- /**
- * An individual row in a Segment explorer result
- */
- export type TableDataRow = {
- aggregate: number;
- comparison: number;
- count: number;
- frequency: number;
- sumdelta: number;
- tags_key: string;
- tags_value: string;
- };
- export type TableData = {
- data: TableDataRow[];
- meta: {};
- };
- /**
- * A Segment Explorer result including rows and metadata.
- */
- type ChildrenProps = Omit<GenericChildrenProps<TableData>, 'tableData'> & {
- tableData: TableData | null;
- };
- type QueryProps = DiscoverQueryProps & {
- aggregateColumn: string;
- children: (props: ChildrenProps) => React.ReactNode;
- allTagKeys?: boolean;
- sort?: string | string[];
- tagKey?: string;
- };
- type FacetQuery = LocationQuery &
- EventQuery & {
- aggregateColumn?: string;
- allTagKeys?: boolean;
- sort?: string | string[];
- tagKey?: string;
- };
- export function getRequestFunction(_props: QueryProps) {
- const {aggregateColumn} = _props;
- function getTagExplorerRequestPayload(props: DiscoverQueryProps) {
- const {eventView} = props;
- const apiPayload: FacetQuery = eventView.getEventsAPIPayload(props.location);
- apiPayload.aggregateColumn = aggregateColumn;
- apiPayload.sort = _props.sort ? _props.sort : apiPayload.sort;
- if (_props.allTagKeys) {
- apiPayload.allTagKeys = _props.allTagKeys;
- }
- if (_props.tagKey) {
- apiPayload.tagKey = _props.tagKey;
- }
- return apiPayload;
- }
- return getTagExplorerRequestPayload;
- }
- function shouldRefetchData(prevProps: QueryProps, nextProps: QueryProps) {
- return (
- prevProps.aggregateColumn !== nextProps.aggregateColumn ||
- prevProps.sort !== nextProps.sort ||
- prevProps.allTagKeys !== nextProps.allTagKeys ||
- prevProps.tagKey !== nextProps.tagKey
- );
- }
- function SegmentExplorerQuery(props: QueryProps) {
- return (
- <GenericDiscoverQuery<TableData, QueryProps>
- route="events-facets-performance"
- getRequestPayload={getRequestFunction(props)}
- shouldRefetchData={shouldRefetchData}
- {...props}
- />
- );
- }
- export default withApi(SegmentExplorerQuery);
|