Skip to content

Commit 772cadf

Browse files
committed
feat(aci): Setup detector details
1 parent 4091ded commit 772cadf

File tree

6 files changed

+97
-17
lines changed

6 files changed

+97
-17
lines changed

static/app/types/workflowEngine/dataConditions.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ interface SnubaQuery {
99
environment?: string;
1010
}
1111

12-
export interface DataSource {
12+
interface QueryObject {
1313
id: string;
1414
snubaQuery: SnubaQuery;
15+
sourceId: string;
16+
type: 'snuba_query_subscription';
17+
}
18+
19+
export interface DataSource {
20+
id: string;
21+
queryObj: QueryObject;
1522
status: number;
1623
subscription?: string;
1724
}

static/app/types/workflowEngine/detectors.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export type DetectorType =
1212
| 'uptime';
1313

1414
interface NewDetector {
15+
conditionGroup: DataConditionGroup;
1516
config: Record<string, unknown>;
16-
dataCondition: DataConditionGroup;
17-
dataSource: DataSource;
17+
dataSources: DataSource[];
1818
disabled: boolean;
1919
name: string;
2020
projectId: string;
@@ -23,9 +23,10 @@ interface NewDetector {
2323
}
2424

2525
export interface Detector extends Readonly<NewDetector> {
26+
readonly connectedWorkflows: string[];
2627
readonly createdBy: string;
27-
readonly dateCreated: Date;
28-
readonly dateUpdated: Date;
28+
readonly dateCreated: string;
29+
readonly dateUpdated: string;
2930
readonly id: string;
30-
readonly lastTriggered: Date;
31+
readonly lastTriggered: string;
3132
}

static/app/utils/useParams.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type ParamKeys =
1818
| 'codeId'
1919
| 'dataExportId'
2020
| 'dashboardId'
21+
| 'detectorId'
2122
| 'docIntegrationSlug'
2223
| 'eventId'
2324
| 'fineTuneType'

static/app/views/detectors/detail.tsx

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {Button} from 'sentry/components/core/button';
66
import {LinkButton} from 'sentry/components/core/button/linkButton';
77
import {DateTime} from 'sentry/components/dateTime';
88
import {KeyValueTable, KeyValueTableRow} from 'sentry/components/keyValueTable';
9+
import LoadingError from 'sentry/components/loadingError';
10+
import LoadingIndicator from 'sentry/components/loadingIndicator';
911
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
1012
import TimeSince from 'sentry/components/timeSince';
1113
import {ActionsProvider} from 'sentry/components/workflowEngine/layout/actions';
@@ -16,12 +18,19 @@ import {useWorkflowEngineFeatureGate} from 'sentry/components/workflowEngine/use
1618
import {IconArrow, IconEdit} from 'sentry/icons';
1719
import {t} from 'sentry/locale';
1820
import {space} from 'sentry/styles/space';
21+
import type {Detector} from 'sentry/types/workflowEngine/detectors';
1922
import getDuration from 'sentry/utils/duration/getDuration';
2023
import useOrganization from 'sentry/utils/useOrganization';
24+
import {useParams} from 'sentry/utils/useParams';
25+
import useProjects from 'sentry/utils/useProjects';
2126
import {ConnectedAutomationsList} from 'sentry/views/detectors/components/connectedAutomationList';
2227
import DetailsPanel from 'sentry/views/detectors/components/detailsPanel';
2328
import IssuesList from 'sentry/views/detectors/components/issuesList';
24-
import {makeMonitorBasePathname} from 'sentry/views/detectors/pathnames';
29+
import {useDetector} from 'sentry/views/detectors/hooks';
30+
import {
31+
makeMonitorBasePathname,
32+
makeMonitorDetailsPathname,
33+
} from 'sentry/views/detectors/pathnames';
2534

2635
type Priority = {
2736
sensitivity: string;
@@ -33,16 +42,43 @@ const priorities: Priority[] = [
3342
{sensitivity: 'high', threshold: 10},
3443
];
3544

45+
function getEnvironmentFromDetector(detector: Detector) {
46+
return detector.dataSources.find(ds => ds.queryObj.snubaQuery.environment)?.queryObj
47+
.snubaQuery.environment;
48+
}
49+
3650
export default function DetectorDetail() {
3751
const organization = useOrganization();
3852
useWorkflowEngineFeatureGate({redirect: true});
53+
const params = useParams<{detectorId: string}>();
54+
const {projects} = useProjects();
55+
56+
const {
57+
data: detector,
58+
isPending,
59+
isError,
60+
refetch,
61+
} = useDetector({
62+
// TODO: Remove hardcoded project slug or move to project url
63+
projectSlug: 'sentry',
64+
detectorId: params.detectorId,
65+
});
66+
const project = projects.find(p => p.id === detector?.projectId);
67+
68+
if (isPending) {
69+
return <LoadingIndicator />;
70+
}
71+
72+
if (isError || !project) {
73+
return <LoadingError onRetry={refetch} />;
74+
}
3975

4076
return (
41-
<SentryDocumentTitle title={'/endpoint'} noSuffix>
77+
<SentryDocumentTitle title={detector.name} noSuffix>
4278
<BreadcrumbsProvider
4379
crumb={{label: t('Monitors'), to: makeMonitorBasePathname(organization.slug)}}
4480
>
45-
<ActionsProvider actions={<Actions />}>
81+
<ActionsProvider actions={<Actions detector={detector} />}>
4682
<DetailLayout project={{slug: 'project-slug', platform: 'javascript-astro'}}>
4783
<DetailLayout.Main>
4884
{/* TODO: Add chart here */}
@@ -81,15 +117,17 @@ export default function DetectorDetail() {
81117
<KeyValueTable>
82118
<KeyValueTableRow
83119
keyName={t('Date created')}
84-
value={<DateTime date={new Date()} dateOnly year />}
120+
value={<DateTime date={detector.dateCreated} dateOnly year />}
85121
/>
86-
<KeyValueTableRow keyName={t('Created by')} value="Jane Doe" />
122+
<KeyValueTableRow keyName={t('Created by')} value="placeholder" />
87123
<KeyValueTableRow
88124
keyName={t('Last modified')}
89-
value={<TimeSince date={new Date()} />}
125+
value={<TimeSince date={detector.dateUpdated} />}
126+
/>
127+
<KeyValueTableRow
128+
keyName={t('Environment')}
129+
value={getEnvironmentFromDetector(detector)}
90130
/>
91-
<KeyValueTableRow keyName={t('Team')} value="Platform" />
92-
<KeyValueTableRow keyName={t('Environment')} value="prod" />
93131
</KeyValueTable>
94132
</Section>
95133
</DetailLayout.Sidebar>
@@ -100,7 +138,8 @@ export default function DetectorDetail() {
100138
);
101139
}
102140

103-
function Actions() {
141+
function Actions({detector}: {detector: Detector}) {
142+
const organization = useOrganization();
104143
const disable = () => {
105144
window.alert('disable');
106145
};
@@ -109,7 +148,12 @@ function Actions() {
109148
<Button onClick={disable} size="sm">
110149
{t('Disable')}
111150
</Button>
112-
<LinkButton to="edit" priority="primary" icon={<IconEdit />} size="sm">
151+
<LinkButton
152+
to={`${makeMonitorDetailsPathname(organization.slug, detector.id)}edit/`}
153+
priority="primary"
154+
icon={<IconEdit />}
155+
size="sm"
156+
>
113157
{t('Edit')}
114158
</LinkButton>
115159
</Fragment>

static/app/views/detectors/hooks.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type {Detector} from 'sentry/types/workflowEngine/detectors';
2+
import type {ApiQueryKey} from 'sentry/utils/queryClient';
3+
import {useApiQuery} from 'sentry/utils/queryClient';
4+
import useOrganization from 'sentry/utils/useOrganization';
5+
6+
function getDetectorQueryKey(
7+
organizationSlug: string,
8+
projectSlug: string,
9+
detectorId: string
10+
): ApiQueryKey {
11+
return [`/projects/${organizationSlug}/${projectSlug}/detectors/${detectorId}/`];
12+
}
13+
14+
interface UseDetectorOptions {
15+
detectorId: string;
16+
projectSlug: string;
17+
}
18+
19+
export function useDetector({projectSlug, detectorId}: UseDetectorOptions) {
20+
const organization = useOrganization();
21+
return useApiQuery<Detector>(
22+
getDetectorQueryKey(organization.slug, projectSlug, detectorId),
23+
{
24+
staleTime: 0,
25+
}
26+
);
27+
}

static/app/views/detectors/routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const detectorRoutes = (
1111
component={make(() => import('sentry/views/detectors/new-settings'))}
1212
/>
1313
</Route>
14-
<Route path=":monitorId/">
14+
<Route path=":detectorId/">
1515
<IndexRoute component={make(() => import('sentry/views/detectors/detail'))} />
1616
<Route path="edit/" component={make(() => import('sentry/views/detectors/edit'))} />
1717
</Route>

0 commit comments

Comments
 (0)