index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {t} from 'sentry/locale';
  2. import type {TagCollection} from 'sentry/types/group';
  3. import type {Organization} from 'sentry/types/organization';
  4. import type {QueryFieldValue} from 'sentry/utils/discover/fields';
  5. import type {UseApiQueryResult} from 'sentry/utils/queryClient';
  6. import type RequestError from 'sentry/utils/requestError/requestError';
  7. import {getDatasetConfig} from 'sentry/views/dashboards/datasetConfig/base';
  8. import type {ValidateWidgetResponse} from 'sentry/views/dashboards/types';
  9. import type {DataSet} from '../../utils';
  10. import {DATA_SET_TO_WIDGET_TYPE} from '../../widgetBuilder';
  11. import {BuildStep} from '../buildStep';
  12. import {GroupBySelector} from './groupBySelector';
  13. interface Props {
  14. columns: QueryFieldValue[];
  15. dataSet: DataSet;
  16. onGroupByChange: (newFields: QueryFieldValue[]) => void;
  17. organization: Organization;
  18. tags: TagCollection;
  19. validatedWidgetResponse: UseApiQueryResult<ValidateWidgetResponse, RequestError>;
  20. }
  21. export function GroupByStep({
  22. dataSet,
  23. columns,
  24. onGroupByChange,
  25. organization,
  26. tags,
  27. validatedWidgetResponse,
  28. }: Props) {
  29. const datasetConfig = getDatasetConfig(DATA_SET_TO_WIDGET_TYPE[dataSet]);
  30. const groupByOptions = datasetConfig.getGroupByFieldOptions
  31. ? datasetConfig.getGroupByFieldOptions(organization, tags)
  32. : {};
  33. return (
  34. <BuildStep
  35. title={t('Group your results')}
  36. description={t('This is how you can group your data result by field or tag.')}
  37. >
  38. <GroupBySelector
  39. columns={columns}
  40. fieldOptions={groupByOptions}
  41. onChange={onGroupByChange}
  42. validatedWidgetResponse={validatedWidgetResponse}
  43. />
  44. </BuildStep>
  45. );
  46. }