Skip to content

Commit 6dcd370

Browse files
authored
Merge branch 'main' into fix/implicit-search-fixedstring-hastoken
2 parents 9613c2f + bd0da16 commit 6dcd370

11 files changed

Lines changed: 391 additions & 110 deletions

File tree

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+
feat: Edit heatmap value and count inline in the chart editor

‎packages/app/src/components/ChartDisplaySettingsDrawer.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { shouldFillNullsWithZero } from '@/ChartUtils';
2727
import { MAX_RENDERED_TIME_CHART_SERIES } from '@/defaults';
2828
import { FormatTime } from '@/useFormatTime';
2929

30+
import { HeatmapScaleControl } from './DBHeatmapChart/HeatmapScaleControl';
3031
import { BackgroundChartInput } from './BackgroundChartInput';
3132
import {
3233
attachLocalIds,
@@ -35,6 +36,7 @@ import {
3536
stripLocalIds,
3637
} from './ColorRulesEditor';
3738
import { ColorSwatchInput } from './ColorSwatchInput';
39+
import type { HeatmapScaleType } from './DBHeatmapChart';
3840
import { CheckBoxControlled, TextInputControlled } from './InputControlled';
3941
import { DEFAULT_NUMBER_FORMAT, NumberFormatForm } from './NumberFormat';
4042

@@ -61,6 +63,8 @@ export type ChartConfigDisplaySettings = Pick<
6163
// PromQL-only: Handlebars template over each series' Prometheus label set
6264
// that renders the legend/tooltip name.
6365
legendTemplate?: string;
66+
// Heatmaps only; stored on the heatmap's select[0].
67+
heatmapScaleType?: HeatmapScaleType;
6468
};
6569

6670
/**
@@ -113,6 +117,7 @@ function applyDefaultSettings(
113117
? attachLocalIds(settings.colorRules)
114118
: undefined,
115119
backgroundChart: settings.backgroundChart,
120+
heatmapScaleType: settings.heatmapScaleType ?? 'log',
116121
};
117122
}
118123

@@ -243,6 +248,8 @@ export default function ChartDisplaySettingsDrawer({
243248
? 'Available on PromQL range queries.'
244249
: 'Available on query-builder number tiles.';
245250

251+
const showHeatmapScale = displayType === DisplayType.Heatmap;
252+
246253
return (
247254
<Drawer
248255
title="Display Settings"
@@ -322,6 +329,22 @@ export default function ChartDisplaySettingsDrawer({
322329
</>
323330
)}
324331

332+
{showHeatmapScale && (
333+
<>
334+
<Controller
335+
control={control}
336+
name="heatmapScaleType"
337+
render={({ field: { onChange, value } }) => (
338+
<HeatmapScaleControl
339+
value={value ?? 'log'}
340+
onChange={onChange}
341+
/>
342+
)}
343+
/>
344+
<Divider />
345+
</>
346+
)}
347+
325348
{showLegendTemplate && (
326349
<>
327350
<Box>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ type ChartEditorControlsProps = {
8383
chartConfigForExplanations?: ChartConfigWithOptTimestamp;
8484
onSubmit: (suppressErrorNotification?: boolean) => void;
8585
openDisplaySettings: () => void;
86-
openHeatmapSettings: () => void;
8786
};
8887

8988
export function ChartEditorControls({
@@ -117,7 +116,6 @@ export function ChartEditorControls({
117116
chartConfigForExplanations,
118117
onSubmit,
119118
openDisplaySettings,
120-
openHeatmapSettings,
121119
}: ChartEditorControlsProps) {
122120
// Formulas (HDX-5080): derived series computed from the chart's series via
123121
// letter-ref arithmetic expressions. Metric and event (log/trace) sources,
@@ -224,12 +222,15 @@ export function ChartEditorControls({
224222
</Flex>
225223
{displayType === DisplayType.Heatmap && Array.isArray(select) ? (
226224
<HeatmapSeriesEditor
225+
key={fields[0]?.id}
227226
control={control}
228227
setValue={setValue}
228+
errors={errors}
229229
tableSource={tableSource}
230230
dateRange={dateRange}
231+
parentRef={parentRef}
231232
onSubmit={onSubmit}
232-
onOpenDisplaySettings={openHeatmapSettings}
233+
onOpenDisplaySettings={openDisplaySettings}
233234
/>
234235
) : displayType === DisplayType.EventPatterns ? (
235236
<Flex gap="xs" direction="column">

‎packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx‎

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,8 @@ import {
7171
isStringSelectDisplayType,
7272
validateChartForm,
7373
} from '@/components/ChartEditor/utils';
74-
import {
75-
HEATMAP_DURATION_NUMBER_FORMAT,
76-
type HeatmapScaleType,
77-
} from '@/components/DBHeatmapChart';
74+
import { HEATMAP_DURATION_NUMBER_FORMAT } from '@/components/DBHeatmapChart';
7875
import { ErrorBoundary } from '@/components/Error/ErrorBoundary';
79-
import HeatmapSettingsDrawer, {
80-
HeatmapSettingsValues,
81-
} from '@/components/HeatmapSettingsDrawer';
8276
import { InputControlled } from '@/components/InputControlled';
8377
import SaveToDashboardModal from '@/components/SaveToDashboardModal';
8478
import { getStoredLanguage } from '@/components/SearchInput/SearchWhereInput';
@@ -349,6 +343,7 @@ export default function EditTimeChartForm({
349343
colorRules,
350344
backgroundChart,
351345
legendTemplate,
346+
heatmapScaleType,
352347
] = useWatch({
353348
control,
354349
name: [
@@ -364,6 +359,7 @@ export default function EditTimeChartForm({
364359
'colorRules',
365360
'backgroundChart',
366361
'legendTemplate',
362+
'series.0.heatmapScaleType',
367363
],
368364
});
369365

@@ -395,6 +391,7 @@ export default function EditTimeChartForm({
395391
colorRules,
396392
backgroundChart,
397393
legendTemplate,
394+
heatmapScaleType,
398395
}),
399396
[
400397
alignDateRangeToGranularity,
@@ -409,6 +406,7 @@ export default function EditTimeChartForm({
409406
colorRules,
410407
backgroundChart,
411408
legendTemplate,
409+
heatmapScaleType,
412410
],
413411
);
414412

@@ -417,11 +415,6 @@ export default function EditTimeChartForm({
417415
{ open: openDisplaySettings, close: closeDisplaySettings },
418416
] = useDisclosure(false);
419417

420-
const [
421-
heatmapSettingsOpened,
422-
{ open: openHeatmapSettings, close: closeHeatmapSettings },
423-
] = useDisclosure(false);
424-
425418
// Only update this on submit, otherwise we'll have issues
426419
// with using the source value from the last submit
427420
// (ex. ignoring local custom source updates)
@@ -890,6 +883,7 @@ export default function EditTimeChartForm({
890883
colorRules,
891884
backgroundChart,
892885
legendTemplate,
886+
heatmapScaleType,
893887
}: ChartConfigDisplaySettings,
894888
isDirty: boolean,
895889
) => {
@@ -916,6 +910,9 @@ export default function EditTimeChartForm({
916910
if (configType === 'promql') {
917911
setValue('legendTemplate', legendTemplate ?? '');
918912
}
913+
if (displayType === DisplayType.Heatmap) {
914+
setValue('series.0.heatmapScaleType', heatmapScaleType);
915+
}
919916
// Display settings live in a separate drawer form, so RHF can't track
920917
// them. Latch dirty state only when the drawer reports actual changes.
921918
if (isDirty) {
@@ -924,44 +921,7 @@ export default function EditTimeChartForm({
924921
}
925922
onSubmit();
926923
},
927-
[setValue, onDirtyChange, onSubmit, configType],
928-
);
929-
930-
const handleUpdateHeatmapSettings = useCallback(
931-
(data: HeatmapSettingsValues) => {
932-
setValue('series.0.valueExpression', data.value);
933-
setValue('series.0.countExpression', data.count || 'count()');
934-
setValue('series.0.heatmapScaleType', data.scaleType);
935-
// Heatmap settings are applied outside RHF's change tracking.
936-
subFormDirtyRef.current = true;
937-
onDirtyChange?.(true);
938-
onSubmit();
939-
closeHeatmapSettings();
940-
},
941-
[setValue, onDirtyChange, onSubmit, closeHeatmapSettings],
942-
);
943-
944-
const heatmapValueExpression = useWatch({
945-
control,
946-
name: 'series.0.valueExpression',
947-
});
948-
const heatmapCountExpression = useWatch({
949-
control,
950-
name: 'series.0.countExpression',
951-
});
952-
const heatmapScaleType: HeatmapScaleType =
953-
useWatch({
954-
control,
955-
name: 'series.0.heatmapScaleType',
956-
}) ?? 'log';
957-
958-
const heatmapSettingsDefaults = useMemo(
959-
() => ({
960-
value: heatmapValueExpression || '',
961-
count: heatmapCountExpression || 'count()',
962-
scaleType: heatmapScaleType,
963-
}),
964-
[heatmapValueExpression, heatmapCountExpression, heatmapScaleType],
924+
[setValue, onDirtyChange, onSubmit, configType, displayType],
965925
);
966926

967927
const tableConnection = useMemo(
@@ -1152,7 +1112,6 @@ export default function EditTimeChartForm({
11521112
chartConfigForExplanations={chartConfigForExplanations}
11531113
onSubmit={onSubmit}
11541114
openDisplaySettings={openDisplaySettings}
1155-
openHeatmapSettings={openHeatmapSettings}
11561115
/>
11571116
)}
11581117
<ChartActionBar
@@ -1221,17 +1180,10 @@ export default function EditTimeChartForm({
12211180
})}
12221181
onChange={handleUpdateDisplaySettings}
12231182
onClose={closeDisplaySettings}
1224-
isPerSeriesNumberFormatAllowed={configType !== 'sql'}
1225-
/>
1226-
<HeatmapSettingsDrawer
1227-
opened={heatmapSettingsOpened}
1228-
onClose={closeHeatmapSettings}
1229-
connection={tableConnection}
1230-
sourceId={tableSource?.id}
1231-
dateRange={dateRange}
1232-
parentRef={parentRef}
1233-
defaultValues={heatmapSettingsDefaults}
1234-
onSubmit={handleUpdateHeatmapSettings}
1183+
// Heatmaps format with the chart-level number format only.
1184+
isPerSeriesNumberFormatAllowed={
1185+
configType !== 'sql' && displayType !== DisplayType.Heatmap
1186+
}
12351187
/>
12361188
</div>
12371189
);

‎packages/app/src/components/DBEditTimeChartForm/HeatmapSeriesEditor.tsx‎

Lines changed: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,122 @@
11
import { useMemo } from 'react';
2-
import { Control, UseFormSetValue } from 'react-hook-form';
2+
import { Control, FieldErrors, UseFormSetValue } from 'react-hook-form';
33
import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata';
44
import { TSource } from '@hyperdx/common-utils/dist/types';
5-
import { Button, Divider, Flex } from '@mantine/core';
5+
import { Button, Divider, Flex, Stack, Text, Tooltip } from '@mantine/core';
6+
import { IconHelpCircle } from '@tabler/icons-react';
67

78
import { ChartEditorFormState } from '@/components/ChartEditor/types';
9+
import { EDITOR_INPUT_HEIGHTS } from '@/components/editorInputHeights';
810
import SearchWhereInput from '@/components/SearchInput/SearchWhereInput';
11+
import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEditor';
912

1013
type HeatmapSeriesEditorProps = {
1114
control: Control<ChartEditorFormState>;
1215
setValue: UseFormSetValue<ChartEditorFormState>;
16+
errors: FieldErrors<ChartEditorFormState>;
1317
tableSource?: TSource;
1418
dateRange?: [Date, Date];
19+
parentRef: HTMLElement | null;
1520
onSubmit: () => void;
1621
onOpenDisplaySettings: () => void;
1722
};
1823

24+
function InlineLabel({ label, tooltip }: { label: string; tooltip: string }) {
25+
return (
26+
<Flex h={`${EDITOR_INPUT_HEIGHTS.sm}px`} align="center" gap={4}>
27+
<Text size="sm" style={{ whiteSpace: 'nowrap' }}>
28+
{label}
29+
</Text>
30+
<Tooltip label={tooltip}>
31+
<IconHelpCircle size={16} opacity={0.5} />
32+
</Tooltip>
33+
</Flex>
34+
);
35+
}
36+
1937
export function HeatmapSeriesEditor({
2038
control,
2139
setValue,
40+
errors,
2241
tableSource,
2342
dateRange,
43+
parentRef,
2444
onSubmit,
2545
onOpenDisplaySettings,
2646
}: HeatmapSeriesEditorProps) {
2747
const connection = useMemo(() => tcFromSource(tableSource), [tableSource]);
2848

2949
return (
30-
<Flex direction="column" gap="sm">
31-
<SearchWhereInput
32-
tableConnection={connection}
33-
sourceId={tableSource?.id}
34-
dateRange={dateRange}
35-
control={control}
36-
name="where"
37-
onSubmit={onSubmit}
38-
onLanguageChange={(lang: 'sql' | 'lucene') =>
39-
setValue('whereLanguage', lang)
40-
}
41-
enableVariables
42-
/>
43-
<Divider />
50+
<Flex direction="column">
51+
<Stack gap="sm">
52+
<div
53+
className="gap-2"
54+
style={{
55+
display: 'grid',
56+
gridTemplateColumns: 'auto 1fr auto 1fr',
57+
alignItems: 'start',
58+
}}
59+
>
60+
<InlineLabel
61+
label="Value"
62+
tooltip="The y axis: the value each event is bucketed by."
63+
/>
64+
<div data-testid="heatmap-value-input">
65+
<SQLInlineEditorControlled
66+
parentRef={parentRef}
67+
tableConnection={connection}
68+
sourceId={tableSource?.id}
69+
dateRange={dateRange}
70+
control={control}
71+
name="series.0.valueExpression"
72+
placeholder="SQL expression, e.g. Duration"
73+
onSubmit={onSubmit}
74+
error={
75+
Array.isArray(errors.series)
76+
? errors.series[0]?.valueExpression?.message
77+
: undefined
78+
}
79+
enableVariables
80+
/>
81+
</div>
82+
<InlineLabel
83+
label="Count"
84+
tooltip="The color intensity: how much each bucket holds."
85+
/>
86+
<div data-testid="heatmap-count-input">
87+
<SQLInlineEditorControlled
88+
parentRef={parentRef}
89+
tableConnection={connection}
90+
sourceId={tableSource?.id}
91+
dateRange={dateRange}
92+
control={control}
93+
name="series.0.countExpression"
94+
placeholder="SQL expression, e.g. count()"
95+
onSubmit={onSubmit}
96+
enableVariables
97+
/>
98+
</div>
99+
</div>
100+
<SearchWhereInput
101+
tableConnection={connection}
102+
sourceId={tableSource?.id}
103+
dateRange={dateRange}
104+
control={control}
105+
name="where"
106+
onSubmit={onSubmit}
107+
onLanguageChange={(lang: 'sql' | 'lucene') =>
108+
setValue('whereLanguage', lang)
109+
}
110+
enableVariables
111+
/>
112+
</Stack>
113+
<Divider my="sm" />
44114
<Flex justify="flex-end">
45115
<Button
46116
onClick={onOpenDisplaySettings}
47117
size="compact-sm"
48118
variant="secondary"
119+
data-testid="display-settings-button"
49120
>
50121
Display Settings
51122
</Button>

0 commit comments

Comments
 (0)