Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tile-alert-opens-alert-panel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/app': patch
---

fix: the alert button on a dashboard tile opens the tile editor with the alert
panel showing, on the tile's alert or on a new one, instead of an editor where
"Add alert" had to be clicked again
26 changes: 21 additions & 5 deletions packages/app/src/DBDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ const Tile = ({
dateRange,
onDuplicateClick,
onEditClick,
onAlertClick,
onDeleteClick,
onUpdateChart,
onMoveToGroup,
Expand Down Expand Up @@ -520,7 +521,7 @@ const Tile = ({
dateRange: [Date, Date];
onDuplicateClick: () => void;
onEditClick: () => void;
onAddAlertClick?: () => void;
onAlertClick: () => void;
onDeleteClick: () => void;
onUpdateChart?: (chart: Tile) => void;
onMoveToGroup?: (containerId: string | undefined, tabId?: string) => void;
Expand Down Expand Up @@ -1050,7 +1051,7 @@ const Tile = ({
data-testid={`tile-alerts-button-${chart.id}`}
variant="subtle"
size="sm"
onClick={onEditClick}
onClick={onAlertClick}
>
<IconBell size={16} />
</ActionIcon>
Expand All @@ -1064,7 +1065,7 @@ const Tile = ({
data-testid={`tile-alerts-button-${chart.id}`}
variant="subtle"
size="sm"
onClick={onEditClick}
onClick={onAlertClick}
mr={4}
>
<IconBellPlus size={16} />
Expand Down Expand Up @@ -1147,6 +1148,7 @@ const Tile = ({
onDeleteClick,
onDuplicateClick,
onEditClick,
onAlertClick,
onMoveToGroup,
openFullscreen,
readOnly,
Expand Down Expand Up @@ -1179,7 +1181,7 @@ const Tile = ({
leftSection={
alert ? <IconBell size={14} /> : <IconBellPlus size={14} />
}
onClick={onEditClick}
onClick={onAlertClick}
>
{alertTooltip}
</Menu.Item>
Expand Down Expand Up @@ -1230,6 +1232,7 @@ const Tile = ({
onDeleteClick,
onDuplicateClick,
onEditClick,
onAlertClick,
onMoveToGroup,
openFullscreen,
readOnly,
Expand Down Expand Up @@ -1694,6 +1697,7 @@ const Tile = ({
const EditTileModal = ({
dashboardId,
chart,
defaultAlertPanelOpened,
onClose,
onSave,
isSaving,
Expand All @@ -1704,6 +1708,7 @@ const EditTileModal = ({
}: {
dashboardId?: string;
chart: Tile | undefined;
defaultAlertPanelOpened?: boolean;
onClose: () => void;
dateRange: [Date, Date];
isSaving?: boolean;
Expand Down Expand Up @@ -1790,6 +1795,7 @@ const EditTileModal = ({
onDirtyChange={setHasUnsavedChanges}
isDashboardForm
autoRun
defaultAlertPanelOpened={defaultAlertPanelOpened}
/>
</SqlVariablesProvider>
</IsolatedChartSyncProvider>
Expand Down Expand Up @@ -2336,6 +2342,7 @@ function DBDashboardPage({
}, [dashboard, isLocalDashboard, setDashboard]);

const [editedTile, setEditedTile] = useState<undefined | Tile>();
const [isEditingTileAlert, setIsEditingTileAlert] = useState(false);

const containers = useMemo(
() => dashboard?.containers ?? [],
Expand Down Expand Up @@ -2541,7 +2548,14 @@ function DBDashboardPage({
chart={resolvedChart}
referenceVariableNames={referenceVariableNamesByTileId.get(chart.id)}
dateRange={searchedTimeRange}
onEditClick={() => setEditedTile(chart)}
onEditClick={() => {
setIsEditingTileAlert(false);
setEditedTile(chart);
}}
onAlertClick={() => {
setIsEditingTileAlert(true);
setEditedTile(chart);
}}
readOnly={isKioskMode}
isLive={isRefreshEnabled}
granularity={
Expand Down Expand Up @@ -2846,6 +2860,7 @@ function DBDashboardPage({
return !t.containerId;
});
const pos = calculateNextTilePosition(targetTiles, newW);
setIsEditingTileAlert(false);
setEditedTile({
id: makeId(),
x: pos.x,
Expand Down Expand Up @@ -3371,6 +3386,7 @@ function DBDashboardPage({
<EditTileModal
dashboardId={dashboardId}
chart={editedTile}
defaultAlertPanelOpened={isEditingTileAlert}
onClose={() => {
if (!isSaving) setEditedTile(undefined);
}}
Expand Down
5 changes: 4 additions & 1 deletion packages/app/src/components/AlertPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@ const AlertPanelContext = createContext<
/** Lays out its children beside the alert panel. */
export function AlertPanelLayout({
defaultOpened = false,
defaultIsDraft = false,
actions,
onOpen,
onCancel,
children,
...props
}: BoxProps & {
defaultOpened?: boolean;
/** Whether the panel opens on a new alert, which closing it discards. */
defaultIsDraft?: boolean;
/**
* The alert's primary action. The alert form places it under its inputs
* with `AlertPanelActions`, so it reads as part of the alert rather than
Expand All @@ -153,7 +156,7 @@ export function AlertPanelLayout({
children: ReactNode;
}) {
const [opened, setOpened] = useState(defaultOpened);
const [isDraft, setIsDraft] = useState(false);
const [isDraft, setIsDraft] = useState(defaultIsDraft);
const [target, setTarget] = useState<HTMLElement | null>(null);
const [hasContent, setHasContent] = useState(false);
const [root, setRoot] = useState<HTMLDivElement | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
displayTypeSupportsBuilderAlerts,
displayTypeSupportsRawSqlAlerts,
isTimeSeriesDisplayType,
savedChartConfigSupportsAlerts,
} from '@hyperdx/common-utils/dist/core/utils';
import {
displayTypeRequiresSource,
Expand Down Expand Up @@ -104,15 +105,22 @@ import {
useResolvedReference,
useSourceVariableDeclarations,
} from '@/components/sourceSelectUtils';
import { IS_EXEMPLARS_ENABLED, IS_PROMQL_ENABLED } from '@/config';
import {
IS_EXEMPLARS_ENABLED,
IS_LOCAL_MODE,
IS_PROMQL_ENABLED,
} from '@/config';
import HDXMarkdownChart from '@/HDXMarkdownChart';
import {
getDurationMsExpression,
getFirstSeriesNumberFormat,
useSource,
useSources,
} from '@/source';
import { normalizeNoOpAlertScheduleFields } from '@/utils/alerts';
import {
DEFAULT_TILE_ALERT,
normalizeNoOpAlertScheduleFields,
} from '@/utils/alerts';

import { AlertPanelPrimaryAction } from './AlertPanelPrimaryAction';
import { ChartActionBar, DashboardFiltersToggleProps } from './ChartActionBar';
Expand Down Expand Up @@ -174,6 +182,11 @@ type EditTimeChartFormProps = {
isSavingAlert?: boolean;
/** Hides the alert editor's remove control, for surfaces that require one. */
isAlertRequired?: boolean;
/**
* Opens with the alert panel showing, as the alert button does: on the
* chart's alert, or on a new draft where the editor offers alerts.
*/
defaultAlertPanelOpened?: boolean;
/** Whether to offer "Save to dashboard". Defaults to "outside a dashboard". */
showSaveToDashboard?: boolean;
};
Expand Down Expand Up @@ -275,12 +288,32 @@ export default function EditTimeChartForm({
saveAlertLabel,
isSavingAlert,
isAlertRequired = false,
defaultAlertPanelOpened = false,
showSaveToDashboard,
}: EditTimeChartFormProps) {
const formValue: ChartEditorFormState = useMemo(
const savedFormValue = useMemo(
() => convertSavedChartConfigToFormState(chartConfig),
[chartConfig],
);
// Opened from a tile's alert button, a chart without an alert starts on a
// new one where the editor offers alerts, as if Add alert were clicked.
const opensOnNewAlert =
defaultAlertPanelOpened &&
chartConfig.alert == null &&
(enableAlerts ?? dashboardId != null) &&
getFormReferenceVariables(savedFormValue).length === 0 &&
!IS_LOCAL_MODE &&
savedChartConfigSupportsAlerts(chartConfig);
const formValue: ChartEditorFormState = useMemo(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Putting the draft alert into the form's defaultValues makes discarding it look like an unsaved edit

formValue (with the draft alert) is passed as defaultValues/values, so RHF treats the draft as the saved state. When the user closes the panel, cancelAlertChanges(true) sets alert to undefined. From then on _getDirty() sees a difference from the defaults, so the next field edit, even one that is reverted, makes isDirty true. Closing the editor (EditTileModal.handleClose) then asks to discard changes on a tile the user never changed. Fix: keep savedFormValue as the form's defaults and add the draft after mount with setValue('alert', …) (the path the Add alert button already uses), so the defaults still match the saved tile.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and the draft in the defaults doesn't change when the discard prompt shows. With the bell unused and no alert on the tile, typing a character into Chart Name and deleting it already ends on onDirtyChange(true), so an edited-then-reverted field prompts on main too. I also tried the suggested setValue('alert', …) after mount: same result. Closing the draft panel with no other edit leaves isDirty false, since cancelAlertChanges sets the value without shouldDirty. Leaving it as is.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — The draft alert is put into the form's defaultValues, so discarding it makes an untouched tile count as edited

formValue, including the seeded alert, is passed as defaultValues/values to useForm. When the user closes the panel, cancelAlertChanges(true) sets alert to undefined, so the form no longer matches its defaults. The next dirty recompute (any field change, even one typed and then reverted) reports isDirty, and EditTileModal (DBDashboardPage.tsx:1737) then asks 'You have unsaved changes…' for a tile the user never changed. The Add alert button path doesn't have this problem because its defaults contain no alert. Fix: keep defaultValues equal to savedFormValue and seed the draft once on mount with setValue('alert', …), the same way onAddAlert does it. Add a test that closes the draft and checks that onDirtyChange is not reported as true.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same finding as the thread above, and my answer there still holds: an edited-then-reverted field ends on onDirtyChange(true) on main too, with no alert involved, and seeding with setValue('alert', …) after mount gave the same result when I tried it. Closing the draft with no other edit leaves isDirty false. Leaving it as is.

if (!opensOnNewAlert) return savedFormValue;
return {
...savedFormValue,
alert: {
...DEFAULT_TILE_ALERT,
...(savedFormValue.name && { displayName: savedFormValue.name }),
},
};
}, [savedFormValue, opensOnNewAlert]);

const {
control,
Expand Down Expand Up @@ -778,9 +811,12 @@ export default function EditTimeChartForm({
],
);

// Until the chart has run, a new alert from a tile's alert button doesn't
// stop it running: the alert has no webhook yet.
const ignoresNewAlert = opensOnNewAlert && queriedConfig == null;
const onSubmit = useCallback(
(suppressErrorNotification: boolean = false) => {
handleSubmit(form => {
const runChart = (form: ChartEditorFormState) => {
const { errors, config } = validateAndNormalize(form);
if (errors.length > 0) {
if (!suppressErrorNotification) {
Expand Down Expand Up @@ -817,11 +853,25 @@ export default function EditTimeChartForm({
isRawSqlChart ? undefined : tableSource,
);
}
})();
};
handleSubmit(
runChart,
// The resolver only checks the alert. The chart runs without it, and
// the alert's errors are neither shown nor focused.
ignoresNewAlert

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — The first-run bypass ignores every resolver error, not just alert errors

The onInvalid callback drops the errors argument and runs the chart whenever ignoresNewAlert is true. It rests on the comment's claim that the resolver checks only the alert, but chartFormResolver runs the whole zSavedChartConfig. If any non-alert field fails, the chart still runs and that error stays set in the form without being reported. Fix: only take the bypass when Object.keys(errors) is exactly ['alert']; otherwise fall through to the normal invalid handling.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

? () => {
clearErrors('alert');
runChart({ ...getValues(), alert: undefined });
}
: undefined,
)();
},
[
validateAndNormalize,
handleSubmit,
ignoresNewAlert,
clearErrors,
getValues,
setChartConfig,
setQueriedConfigAndSource,
tableSource,
Expand Down Expand Up @@ -1283,10 +1333,11 @@ export default function EditTimeChartForm({

return (
// The panel opens on request, except where the alert is what is being
// edited (the inline-alert modal).
// edited (the inline-alert modal) or what the editor was opened for.
<AlertPanelLayout
data-testid={dataTestId}
defaultOpened={isAlertRequired}
defaultOpened={isAlertRequired || defaultAlertPanelOpened}
defaultIsDraft={opensOnNewAlert}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
onOpen={snapshotAlert}
onCancel={cancelAlertChanges}
actions={
Expand Down
Loading
Loading