getMetricDatasetQueryExtras.tsx 986 B

123456789101112131415161718192021222324252627282930313233
  1. import {Location} from 'history';
  2. import {Organization} from 'sentry/types';
  3. import {hasOnDemandMetricAlertFeature} from 'sentry/utils/onDemandMetrics/features';
  4. import {decodeScalar} from 'sentry/utils/queryString';
  5. import {getMEPAlertsDataset} from 'sentry/views/alerts/wizard/options';
  6. import {MetricRule} from '../types';
  7. export function getMetricDatasetQueryExtras({
  8. organization,
  9. location,
  10. dataset,
  11. newAlertOrQuery,
  12. }: {
  13. dataset: MetricRule['dataset'];
  14. newAlertOrQuery: boolean;
  15. organization: Organization;
  16. location?: Location;
  17. }) {
  18. const hasMetricDataset =
  19. hasOnDemandMetricAlertFeature(organization) ||
  20. organization.features.includes('mep-rollout-flag');
  21. const disableMetricDataset =
  22. decodeScalar(location?.query?.disableMetricDataset) === 'true';
  23. const queryExtras: Record<string, string> =
  24. hasMetricDataset && !disableMetricDataset
  25. ? {dataset: getMEPAlertsDataset(dataset, newAlertOrQuery)}
  26. : {};
  27. return queryExtras;
  28. }