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 @@ -487,6 +487,7 @@ const Tile = ({
dateRange,
onDuplicateClick,
onEditClick,
onAlertClick,
onDeleteClick,
onUpdateChart,
onMoveToGroup,
Expand Down Expand Up @@ -519,7 +520,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 @@ -1049,7 +1050,7 @@ const Tile = ({
data-testid={`tile-alerts-button-${chart.id}`}
variant="subtle"
size="sm"
onClick={onEditClick}
onClick={onAlertClick}
>
<IconBell size={16} />
</ActionIcon>
Expand All @@ -1063,7 +1064,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 @@ -1146,6 +1147,7 @@ const Tile = ({
onDeleteClick,
onDuplicateClick,
onEditClick,
onAlertClick,
onMoveToGroup,
openFullscreen,
readOnly,
Expand Down Expand Up @@ -1178,7 +1180,7 @@ const Tile = ({
leftSection={
alert ? <IconBell size={14} /> : <IconBellPlus size={14} />
}
onClick={onEditClick}
onClick={onAlertClick}
>
{alertTooltip}
</Menu.Item>
Expand Down Expand Up @@ -1229,6 +1231,7 @@ const Tile = ({
onDeleteClick,
onDuplicateClick,
onEditClick,
onAlertClick,
onMoveToGroup,
openFullscreen,
readOnly,
Expand Down Expand Up @@ -1693,6 +1696,7 @@ const Tile = ({
const EditTileModal = ({
dashboardId,
chart,
defaultAlertPanelOpened,
onClose,
onSave,
isSaving,
Expand All @@ -1703,6 +1707,7 @@ const EditTileModal = ({
}: {
dashboardId?: string;
chart: Tile | undefined;
defaultAlertPanelOpened?: boolean;
onClose: () => void;
dateRange: [Date, Date];
isSaving?: boolean;
Expand Down Expand Up @@ -1789,6 +1794,7 @@ const EditTileModal = ({
onDirtyChange={setHasUnsavedChanges}
isDashboardForm
autoRun
defaultAlertPanelOpened={defaultAlertPanelOpened}
/>
</SqlVariablesProvider>
</IsolatedChartSyncProvider>
Expand Down Expand Up @@ -2320,6 +2326,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 @@ -2525,7 +2532,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 @@ -2830,6 +2844,7 @@ function DBDashboardPage({
return !t.containerId;
});
const pos = calculateNextTilePosition(targetTiles, newW);
setIsEditingTileAlert(false);
setEditedTile({
id: makeId(),
x: pos.x,
Expand Down Expand Up @@ -3364,6 +3379,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 @@ -103,15 +104,18 @@ import {
useResolvedReference,
useSourceVariableDeclarations,
} from '@/components/sourceSelectUtils';
import { IS_PROMQL_ENABLED } from '@/config';
import { 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 @@ -173,6 +177,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 @@ -274,12 +283,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.

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

const {
control,
Expand Down Expand Up @@ -759,9 +788,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 @@ -798,11 +830,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
? () => {
clearErrors('alert');
runChart({ ...getValues(), alert: undefined });
}
: undefined,
)();
},
[
validateAndNormalize,
handleSubmit,
ignoresNewAlert,
clearErrors,
getValues,
setChartConfig,
setQueriedConfigAndSource,
tableSource,
Expand Down Expand Up @@ -1260,10 +1306,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}
onOpen={snapshotAlert}
onCancel={cancelAlertChanges}
actions={
Expand Down
Loading
Loading