Skip to content

Commit ab146bb

Browse files
feat(delta): add clear selection button for heatmap
Co-authored-by: Alex Fedotyev <alex-fedotyev@users.noreply.github.com>
1 parent c9d1dda commit ab146bb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/app/src/components/DBDeltaChart.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import {
55
Filter,
66
} from '@hyperdx/common-utils/dist/types';
77
import {
8+
ActionIcon,
89
Box,
910
Code,
1011
Container,
1112
Divider,
1213
Flex,
1314
Pagination,
1415
Text,
16+
Tooltip,
1517
} from '@mantine/core';
1618
import { useElementSize } from '@mantine/hooks';
19+
import { IconX } from '@tabler/icons-react';
1720

1821
import { isAggregateFunction } from '@/ChartUtils';
1922
import { useQueriedChartConfig } from '@/hooks/useChartConfig';
@@ -52,6 +55,7 @@ export default function DBDeltaChart({
5255
yMin: rawYMin,
5356
yMax: rawYMax,
5457
onAddFilter,
58+
onClearSelection,
5559
spanIdExpression,
5660
legendPrefix,
5761
}: {
@@ -62,6 +66,7 @@ export default function DBDeltaChart({
6266
yMin?: number | null;
6367
yMax?: number | null;
6468
onAddFilter?: AddFilterFn;
69+
onClearSelection?: () => void;
6570
spanIdExpression?: string;
6671
legendPrefix?: React.ReactNode;
6772
}) {
@@ -516,6 +521,18 @@ export default function DBDeltaChart({
516521
Background
517522
</Text>
518523
</Flex>
524+
{onClearSelection && (
525+
<Tooltip label="Clear selection">
526+
<ActionIcon
527+
variant="secondary"
528+
size="xs"
529+
aria-label="Clear heatmap selection"
530+
onClick={onClearSelection}
531+
>
532+
<IconX size={14} />
533+
</ActionIcon>
534+
</Tooltip>
535+
)}
519536
</>
520537
) : (
521538
<>

packages/app/src/components/Search/DBSearchHeatmapChart.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,20 @@ export function DBSearchHeatmapChart({
7979
const [settingsOpened, settingsHandlers] = useDisclosure(false);
8080
const { colorScheme } = useMantineColorScheme();
8181
const palette = colorScheme === 'light' ? lightPalette : darkPalette;
82+
const clearSelection = useCallback(() => {
83+
setFields({ xMin: null, xMax: null, yMin: null, yMax: null });
84+
}, [setFields]);
8285

8386
// After applying a filter, clear the heatmap selection so the delta chart
8487
// resets instead of staying in comparison mode.
8588
const handleAddFilterAndClearSelection = useCallback<
8689
NonNullable<AddFilterFn>
8790
>(
8891
(property, value, action) => {
89-
setFields({ xMin: null, xMax: null, yMin: null, yMax: null });
92+
clearSelection();
9093
onAddFilter?.(property, value, action);
9194
},
92-
[onAddFilter, setFields],
95+
[clearSelection, onAddFilter],
9396
);
9497

9598
return (
@@ -180,6 +183,7 @@ export function DBSearchHeatmapChart({
180183
onAddFilter={
181184
onAddFilter ? handleAddFilterAndClearSelection : undefined
182185
}
186+
onClearSelection={clearSelection}
183187
spanIdExpression={source.spanIdExpression}
184188
legendPrefix={<ColorLegend colors={palette} />}
185189
/>

0 commit comments

Comments
 (0)