Skip to content

Commit b1e200f

Browse files
authored
Merge branch 'main' into drew/lint-restore
2 parents 84062ec + 61db3e8 commit b1e200f

File tree

8 files changed

+222
-163
lines changed

8 files changed

+222
-163
lines changed

.changeset/two-rocks-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
refactor: Create TileAlertEditor component

packages/app/src/components/Alerts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const WebhookChannelForm = <T extends object>(
6363

6464
return (
6565
<div>
66-
<Group gap="md" justify="space-between">
66+
<Group gap="md" justify="space-between" align="flex-start">
6767
<Select
6868
data-testid="select-webhook"
6969
comboboxProps={{

packages/app/src/components/ChartEditor/RawSqlChartEditor.tsx

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -133,38 +133,49 @@ export default function RawSqlChartEditor({
133133
}, [sources, connection]);
134134

135135
return (
136-
<Stack>
137-
<Group align="center" gap={0}>
138-
<Text pe="md" size="sm">
139-
Connection
140-
</Text>
141-
<ConnectionSelectControlled
142-
control={control}
143-
name="connection"
144-
size="xs"
145-
/>
146-
<Group align="center" gap={8} mx="md">
147-
<Text size="sm" ps="md">
148-
Source
136+
<Stack gap="xs">
137+
<Group align="center" gap={0} justify="space-between">
138+
<Group align="center" gap={0}>
139+
<Text pe="md" size="sm">
140+
Connection
149141
</Text>
150-
{isDashboardForm && (
151-
<Tooltip
152-
label="Optional. Required to apply dashboard filters to this chart."
153-
pe="md"
154-
>
155-
<IconHelpCircle size={14} className="cursor-pointer" />
156-
</Tooltip>
157-
)}
142+
<ConnectionSelectControlled
143+
control={control}
144+
name="connection"
145+
size="xs"
146+
/>
147+
<Group align="center" gap={8} mx="md">
148+
<Text size="sm" ps="md">
149+
Source
150+
</Text>
151+
{isDashboardForm && (
152+
<Tooltip
153+
label="Optional. Required to apply dashboard filters to this chart."
154+
pe="md"
155+
>
156+
<IconHelpCircle size={14} className="cursor-pointer" />
157+
</Tooltip>
158+
)}
159+
</Group>
160+
<SourceSelectControlled
161+
control={control}
162+
name="source"
163+
connectionId={connection}
164+
size="xs"
165+
clearable
166+
placeholder="None"
167+
sourceSchemaPreview={sourceSchemaPreview}
168+
/>
169+
</Group>
170+
<Group gap="xs">
171+
<Button
172+
onClick={onOpenDisplaySettings}
173+
size="compact-sm"
174+
variant="secondary"
175+
>
176+
Display Settings
177+
</Button>
158178
</Group>
159-
<SourceSelectControlled
160-
control={control}
161-
name="source"
162-
connectionId={connection}
163-
size="xs"
164-
clearable
165-
placeholder="None"
166-
sourceSchemaPreview={sourceSchemaPreview}
167-
/>
168179
</Group>
169180
<RawSqlChartInstructions displayType={displayType ?? DisplayType.Table} />
170181
<Box style={{ position: 'relative' }}>
@@ -179,15 +190,6 @@ export default function RawSqlChartEditor({
179190
/>
180191
<div className={resizeStyles.resizeYHandle} onMouseDown={startResize} />
181192
</Box>
182-
<Group justify="flex-end">
183-
<Button
184-
onClick={onOpenDisplaySettings}
185-
size="compact-sm"
186-
variant="secondary"
187-
>
188-
Display Settings
189-
</Button>
190-
</Group>
191193
</Stack>
192194
);
193195
}

packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx

Lines changed: 15 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {
44
FieldErrors,
55
UseFormClearErrors,
66
UseFormSetValue,
7-
useWatch,
87
} from 'react-hook-form';
9-
import { NativeSelect, NumberInput } from 'react-hook-form-mantine';
108
import { TableConnection } from '@hyperdx/common-utils/dist/core/metadata';
119
import { isBuilderChartConfig } from '@hyperdx/common-utils/dist/guards';
1210
import {
@@ -15,20 +13,9 @@ import {
1513
SourceKind,
1614
TSource,
1715
} from '@hyperdx/common-utils/dist/types';
18-
import {
19-
Button,
20-
Divider,
21-
Flex,
22-
Group,
23-
Paper,
24-
Stack,
25-
Switch,
26-
Text,
27-
} from '@mantine/core';
16+
import { Box, Button, Divider, Flex, Group, Switch, Text } from '@mantine/core';
2817
import { IconBell, IconCirclePlus } from '@tabler/icons-react';
2918

30-
import { AlertChannelForm } from '@/components/Alerts';
31-
import { AlertScheduleFields } from '@/components/AlertScheduleFields';
3219
import {
3320
ChartEditorFormState,
3421
SavedChartConfigWithSelectArray,
@@ -39,16 +26,10 @@ import SourceSchemaPreview from '@/components/SourceSchemaPreview';
3926
import { SourceSelectControlled } from '@/components/SourceSelect';
4027
import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEditor';
4128
import { IS_LOCAL_MODE } from '@/config';
42-
import { optionsToSelectData } from '@/utils';
43-
import {
44-
ALERT_CHANNEL_OPTIONS,
45-
DEFAULT_TILE_ALERT,
46-
intervalToMinutes,
47-
TILE_ALERT_INTERVAL_OPTIONS,
48-
TILE_ALERT_THRESHOLD_TYPE_OPTIONS,
49-
} from '@/utils/alerts';
29+
import { DEFAULT_TILE_ALERT } from '@/utils/alerts';
5030

5131
import { ChartSeriesEditor } from './ChartSeriesEditor';
32+
import { TileAlertEditor } from './TileAlertEditor';
5233

5334
type ChartEditorControlsProps = {
5435
control: Control<ChartEditorFormState>;
@@ -103,18 +84,6 @@ export function ChartEditorControls({
10384
onSubmit,
10485
openDisplaySettings,
10586
}: ChartEditorControlsProps) {
106-
const alertChannelType = useWatch({ control, name: 'alert.channel.type' });
107-
const alertScheduleOffsetMinutes = useWatch({
108-
control,
109-
name: 'alert.scheduleOffsetMinutes',
110-
});
111-
const maxAlertScheduleOffsetMinutes = alert?.interval
112-
? Math.max(intervalToMinutes(alert.interval) - 1, 0)
113-
: 0;
114-
const alertIntervalLabel = alert?.interval
115-
? TILE_ALERT_INTERVAL_OPTIONS[alert.interval]
116-
: undefined;
117-
11887
return (
11988
<>
12089
<Flex mb="md" align="center" justify="space-between">
@@ -274,20 +243,19 @@ export function ChartEditorControls({
274243
/>
275244
)}
276245
{(displayType === DisplayType.Line ||
246+
displayType === DisplayType.StackedBar ||
277247
displayType === DisplayType.Number) &&
278248
dashboardId &&
249+
!alert &&
279250
!IS_LOCAL_MODE && (
280251
<Button
281252
variant="subtle"
282253
data-testid="alert-button"
283254
size="sm"
284-
color={alert ? 'red' : 'gray'}
285-
onClick={() =>
286-
setValue('alert', alert ? undefined : DEFAULT_TILE_ALERT)
287-
}
255+
onClick={() => setValue('alert', DEFAULT_TILE_ALERT)}
288256
>
289257
<IconBell size={14} className="me-2" />
290-
{!alert ? 'Add Alert' : 'Remove Alert'}
258+
Add Alert
291259
</Button>
292260
)}
293261
</Group>
@@ -334,76 +302,14 @@ export function ChartEditorControls({
334302
</Flex>
335303
)}
336304
{alert && !isRawSqlInput && (
337-
<Paper my="sm">
338-
<Stack gap="xs" data-testid="alert-details">
339-
<Paper px="md" py="sm" radius="xs">
340-
<Text size="xxs" opacity={0.5} mb={4}>
341-
Trigger
342-
</Text>
343-
<Group gap="xs">
344-
<Text size="sm" opacity={0.7}>
345-
Alert when the value
346-
</Text>
347-
<NativeSelect
348-
data={optionsToSelectData(TILE_ALERT_THRESHOLD_TYPE_OPTIONS)}
349-
size="xs"
350-
name={`alert.thresholdType`}
351-
control={control}
352-
/>
353-
<NumberInput
354-
size="xs"
355-
w={80}
356-
control={control}
357-
name={`alert.threshold`}
358-
/>
359-
over
360-
<NativeSelect
361-
data={optionsToSelectData(TILE_ALERT_INTERVAL_OPTIONS)}
362-
size="xs"
363-
name={`alert.interval`}
364-
control={control}
365-
/>
366-
<Text size="sm" opacity={0.7}>
367-
window via
368-
</Text>
369-
<NativeSelect
370-
data={optionsToSelectData(ALERT_CHANNEL_OPTIONS)}
371-
size="xs"
372-
name={`alert.channel.type`}
373-
control={control}
374-
/>
375-
</Group>
376-
{alert?.createdBy && (
377-
<Text size="xs" opacity={0.6} mt="xs">
378-
Created by {alert.createdBy.name || alert.createdBy.email}
379-
</Text>
380-
)}
381-
<AlertScheduleFields
382-
control={control}
383-
setValue={setValue}
384-
scheduleOffsetName="alert.scheduleOffsetMinutes"
385-
scheduleStartAtName="alert.scheduleStartAt"
386-
scheduleOffsetMinutes={alertScheduleOffsetMinutes}
387-
maxScheduleOffsetMinutes={maxAlertScheduleOffsetMinutes}
388-
offsetWindowLabel={
389-
alertIntervalLabel
390-
? `from each ${alertIntervalLabel} window`
391-
: 'from each alert window'
392-
}
393-
/>
394-
</Paper>
395-
<Paper px="md" py="sm" radius="xs">
396-
<Text size="xxs" opacity={0.5} mb={4}>
397-
Send to
398-
</Text>
399-
<AlertChannelForm
400-
control={control}
401-
type={alertChannelType}
402-
namePrefix="alert."
403-
/>
404-
</Paper>
405-
</Stack>
406-
</Paper>
305+
<Box mt="sm">
306+
<TileAlertEditor
307+
control={control}
308+
setValue={setValue}
309+
alert={alert}
310+
onRemove={() => setValue('alert', undefined)}
311+
/>
312+
</Box>
407313
)}
408314
</>
409315
);

0 commit comments

Comments
 (0)