Skip to content

Commit 20b3832

Browse files
authored
feat(aci): Hide transactions dataset option (#101497)
Hides the transactions dataset option except for editing existing transaction alerts
1 parent b7f489c commit 20b3832

File tree

3 files changed

+122
-6
lines changed

3 files changed

+122
-6
lines changed

static/app/views/detectors/components/forms/metric/metric.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ import {
1919
DataConditionType,
2020
DetectorPriorityLevel,
2121
} from 'sentry/types/workflowEngine/dataConditions';
22-
import type {Detector, MetricDetectorConfig} from 'sentry/types/workflowEngine/detectors';
22+
import type {
23+
Detector,
24+
MetricDetector,
25+
MetricDetectorConfig,
26+
} from 'sentry/types/workflowEngine/detectors';
2327
import {generateFieldAsString} from 'sentry/utils/discover/fields';
2428
import useOrganization from 'sentry/utils/useOrganization';
2529
import {
2630
AlertRuleSensitivity,
2731
AlertRuleThresholdType,
32+
Dataset,
2833
} from 'sentry/views/alerts/rules/metric/types';
2934
import {hasLogAlerts} from 'sentry/views/alerts/wizard/utils';
3035
import {TransactionsDatasetWarning} from 'sentry/views/detectors/components/details/metric/transactionsDatasetWarning';
3136
import {AutomateSection} from 'sentry/views/detectors/components/forms/automateSection';
3237
import {AssignSection} from 'sentry/views/detectors/components/forms/common/assignSection';
38+
import {useDetectorFormContext} from 'sentry/views/detectors/components/forms/context';
3339
import {EditDetectorLayout} from 'sentry/views/detectors/components/forms/editDetectorLayout';
3440
import type {MetricDetectorFormData} from 'sentry/views/detectors/components/forms/metric/metricFormData';
3541
import {
@@ -48,6 +54,7 @@ import {SectionLabel} from 'sentry/views/detectors/components/forms/sectionLabel
4854
import {getDatasetConfig} from 'sentry/views/detectors/datasetConfig/getDatasetConfig';
4955
import {DetectorDataset} from 'sentry/views/detectors/datasetConfig/types';
5056
import {getStaticDetectorThresholdSuffix} from 'sentry/views/detectors/utils/metricDetectorSuffix';
57+
import {deprecateTransactionAlerts} from 'sentry/views/insights/common/utils/hasEAPAlerts';
5158

5259
function MetricDetectorForm() {
5360
return (
@@ -212,16 +219,29 @@ function IntervalPicker() {
212219
function useDatasetChoices() {
213220
const organization = useOrganization();
214221

222+
const {detector} = useDetectorFormContext();
223+
const savedDataset = (detector as MetricDetector | undefined)?.dataSources[0]?.queryObj
224+
?.snubaQuery?.dataset;
225+
const isExistingTransactionsDetector =
226+
Boolean(detector) &&
227+
[Dataset.TRANSACTIONS, Dataset.GENERIC_METRICS].includes(savedDataset as Dataset);
228+
const shouldHideTransactionsDataset =
229+
!isExistingTransactionsDetector && deprecateTransactionAlerts(organization);
230+
215231
return useMemo(() => {
216232
const datasetChoices: Array<SelectValue<DetectorDataset>> = [
217233
{
218234
value: DetectorDataset.ERRORS,
219235
label: t('Errors'),
220236
},
221-
{
222-
value: DetectorDataset.TRANSACTIONS,
223-
label: t('Transactions'),
224-
},
237+
...(shouldHideTransactionsDataset
238+
? []
239+
: [
240+
{
241+
value: DetectorDataset.TRANSACTIONS,
242+
label: t('Transactions'),
243+
},
244+
]),
225245
...(organization.features.includes('visibility-explore-view')
226246
? [{value: DetectorDataset.SPANS, label: t('Spans')}]
227247
: []),
@@ -238,7 +258,7 @@ function useDatasetChoices() {
238258
];
239259

240260
return datasetChoices;
241-
}, [organization]);
261+
}, [organization, shouldHideTransactionsDataset]);
242262
}
243263

244264
function DetectSection() {

static/app/views/detectors/edit.spec.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,5 +741,73 @@ describe('DetectorEdit', () => {
741741
});
742742
});
743743
});
744+
745+
it('shows transactions dataset when editing existing transactions detector even with deprecation flag enabled', async () => {
746+
const organizationWithDeprecation = OrganizationFixture({
747+
features: [
748+
'workflow-engine-ui',
749+
'visibility-explore-view',
750+
'discover-saved-queries-deprecation',
751+
],
752+
});
753+
754+
const existingTransactionsDetector = MetricDetectorFixture({
755+
id: '123',
756+
name: 'Transactions Detector',
757+
dataSources: [
758+
SnubaQueryDataSourceFixture({
759+
queryObj: {
760+
id: '1',
761+
status: 1,
762+
subscription: '1',
763+
snubaQuery: {
764+
aggregate: 'count()',
765+
dataset: Dataset.GENERIC_METRICS,
766+
id: '',
767+
query: '',
768+
timeWindow: 60,
769+
eventTypes: [EventTypes.TRANSACTION],
770+
},
771+
},
772+
}),
773+
],
774+
});
775+
776+
MockApiClient.addMockResponse({
777+
url: `/organizations/${organizationWithDeprecation.slug}/detectors/123/`,
778+
body: existingTransactionsDetector,
779+
});
780+
781+
const editRouterConfig = {
782+
route: '/organizations/:orgId/issues/monitors/:detectorId/edit/',
783+
location: {
784+
pathname: `/organizations/${organizationWithDeprecation.slug}/issues/monitors/123/edit/`,
785+
},
786+
};
787+
788+
render(<DetectorEdit />, {
789+
organization: organizationWithDeprecation,
790+
initialRouterConfig: editRouterConfig,
791+
});
792+
793+
// Wait for the detector to load
794+
expect(
795+
await screen.findByRole('link', {name: 'Transactions Detector'})
796+
).toBeInTheDocument();
797+
798+
// Open dataset dropdown
799+
const datasetField = screen.getByLabelText('Dataset');
800+
await userEvent.click(datasetField);
801+
802+
// Verify transactions option IS available when editing existing transactions detector
803+
expect(
804+
screen.getByRole('menuitemradio', {name: 'Transactions'})
805+
).toBeInTheDocument();
806+
807+
// Verify other datasets are also available
808+
expect(screen.getByRole('menuitemradio', {name: 'Errors'})).toBeInTheDocument();
809+
expect(screen.getByRole('menuitemradio', {name: 'Spans'})).toBeInTheDocument();
810+
expect(screen.getByRole('menuitemradio', {name: 'Releases'})).toBeInTheDocument();
811+
});
744812
});
745813
});

static/app/views/detectors/new-setting.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,34 @@ describe('DetectorEdit', () => {
346346
})
347347
);
348348
});
349+
350+
it('hides transactions dataset when deprecateTransactionAlerts feature flag is enabled for new detectors', async () => {
351+
const organizationWithDeprecation = OrganizationFixture({
352+
features: [
353+
'workflow-engine-ui',
354+
'visibility-explore-view',
355+
'discover-saved-queries-deprecation',
356+
],
357+
});
358+
359+
render(<DetectorNewSettings />, {
360+
organization: organizationWithDeprecation,
361+
initialRouterConfig: metricRouterConfig,
362+
});
363+
364+
// Open dataset dropdown
365+
await userEvent.click(screen.getByText('Spans'));
366+
367+
// Verify transactions option is not available for new detectors
368+
expect(
369+
screen.queryByRole('menuitemradio', {name: 'Transactions'})
370+
).not.toBeInTheDocument();
371+
372+
// Verify other datasets are still available
373+
expect(screen.getByRole('menuitemradio', {name: 'Errors'})).toBeInTheDocument();
374+
expect(screen.getByRole('menuitemradio', {name: 'Spans'})).toBeInTheDocument();
375+
expect(screen.getByRole('menuitemradio', {name: 'Releases'})).toBeInTheDocument();
376+
});
349377
});
350378

351379
describe('Uptime Detector', () => {

0 commit comments

Comments
 (0)