Skip to content

Commit 9e980a9

Browse files
committed
setup snuba query details
1 parent 6138b2d commit 9e980a9

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

static/app/types/workflowEngine/dataConditions.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@ interface SnubaQuery {
55
dataset: string;
66
id: string;
77
query: string;
8+
/**
9+
* Time window in seconds
10+
*/
811
timeWindow: number;
912
environment?: string;
1013
}
1114

1215
interface QueryObject {
1316
id: string;
1417
snubaQuery: SnubaQuery;
15-
sourceId: string;
16-
type: 'snuba_query_subscription';
18+
status: number;
19+
subscription: string;
1720
}
1821

19-
export interface DataSource {
22+
export interface SnubaQueryDataSource {
2023
id: string;
24+
organizationId: string;
2125
queryObj: QueryObject;
22-
status: number;
23-
subscription?: string;
26+
sourceId: string;
27+
type: 'snuba_query_subscription';
2428
}
2529

30+
export type DataSource = SnubaQueryDataSource;
31+
2632
export enum DataConditionType {
2733
// operators
2834
EQUAL = 'eq',
@@ -75,11 +81,17 @@ export enum DataConditionGroupLogicType {
7581
NONE = 'none',
7682
}
7783

84+
export const enum DetectorPriorityLevel {
85+
HIGH = 75,
86+
MEDIUM = 50,
87+
LOW = 25,
88+
}
89+
7890
export interface NewDataCondition {
79-
comparison: any;
91+
comparison: string | number;
8092
comparison_type: DataConditionType;
8193
condition_group?: DataConditionGroup;
82-
condition_result?: any;
94+
condition_result?: DetectorPriorityLevel;
8395
}
8496

8597
export interface DataCondition extends Readonly<NewDataCondition> {

static/app/views/detectors/components/detailsPanel.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,46 @@ import {Flex} from 'sentry/components/container/flex';
44
import {Container} from 'sentry/components/workflowEngine/ui/container';
55
import {t} from 'sentry/locale';
66
import {space} from 'sentry/styles/space';
7+
import type {SnubaQueryDataSource} from 'sentry/types/workflowEngine/dataConditions';
8+
import type {Detector} from 'sentry/types/workflowEngine/detectors';
9+
import {getExactDuration} from 'sentry/utils/duration/getExactDuration';
10+
11+
interface DetailsPanelProps {
12+
detector: Detector;
13+
}
14+
15+
function SnubaQueryDetails({dataSource}: {dataSource: SnubaQueryDataSource}) {
16+
return (
17+
<Container>
18+
<Flex column gap={space(0.5)}>
19+
<Heading>{t('Query:')}</Heading>
20+
<Query>
21+
<Label>{t('visualize:')}</Label>{' '}
22+
<Value>{dataSource.queryObj.snubaQuery.aggregate}</Value>
23+
<Label>{t('where:')}</Label>{' '}
24+
<Value>{dataSource.queryObj.snubaQuery.query}</Value>
25+
</Query>
26+
</Flex>
27+
<Flex gap={space(0.5)}>
28+
<Heading>{t('Threshold:')}</Heading>
29+
<Value>{getExactDuration(dataSource.queryObj.snubaQuery.timeWindow, true)}</Value>
30+
</Flex>
31+
</Container>
32+
);
33+
}
34+
35+
function DetailsPanel({detector}: DetailsPanelProps) {
36+
if (detector.dataSources[0]?.type === 'snuba_query_subscription') {
37+
return <SnubaQueryDetails dataSource={detector.dataSources[0]} />;
38+
}
739

8-
// TODO: Make component flexible for different alert types
9-
function DetailsPanel() {
1040
return (
1141
<Container>
1242
<Flex column gap={space(0.5)}>
1343
<Heading>{t('Query:')}</Heading>
1444
<Query>
15-
<Label>{t('visualize:')}</Label> <Value>{t('p75')}</Value>
16-
<Label>{t('where:')}</Label> <Value>{t('device.name is "Chrome"')}</Value>
17-
<Label>{t('grouped by:')}</Label> <Value>{t('release')}</Value>
45+
<Label>{t('visualize:')}</Label> <Value>placeholder</Value>
46+
<Label>{t('where:')}</Label> <Value>placeholder</Value>
1847
</Query>
1948
</Flex>
2049
<Heading>{t('Threshold:')}</Heading>

static/app/views/detectors/detail.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const priorities: Priority[] = [
4242
{sensitivity: 'high', threshold: 10},
4343
];
4444

45-
function getEnvironmentFromDetector(detector: Detector) {
45+
function getDetectorEnvironment(detector: Detector) {
4646
return detector.dataSources.find(ds => ds.queryObj.snubaQuery.environment)?.queryObj
4747
.snubaQuery.environment;
4848
}
@@ -75,7 +75,7 @@ export default function DetectorDetail() {
7575
crumb={{label: t('Monitors'), to: makeMonitorBasePathname(organization.slug)}}
7676
>
7777
<ActionsProvider actions={<Actions detector={detector} />}>
78-
<DetailLayout project={{slug: 'project-slug', platform: 'javascript-astro'}}>
78+
<DetailLayout project={project}>
7979
<DetailLayout.Main>
8080
{/* TODO: Add chart here */}
8181
<Section title={t('Ongoing Issues')}>
@@ -88,7 +88,7 @@ export default function DetectorDetail() {
8888
</DetailLayout.Main>
8989
<DetailLayout.Sidebar>
9090
<Section title={t('Detect')}>
91-
<DetailsPanel />
91+
<DetailsPanel detector={detector} />
9292
</Section>
9393
<Section title={t('Assign')}>
9494
{t('Assign to %s', 'admin@sentry.io')}
@@ -122,7 +122,7 @@ export default function DetectorDetail() {
122122
/>
123123
<KeyValueTableRow
124124
keyName={t('Environment')}
125-
value={getEnvironmentFromDetector(detector)}
125+
value={getDetectorEnvironment(detector)}
126126
/>
127127
</KeyValueTable>
128128
</Section>

0 commit comments

Comments
 (0)