Repository navigation
fix(app): open the alert panel from a dashboard tile's alert button #3680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7585904
5fffdb9
6ea34c9
bf47224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { | |
| displayTypeSupportsBuilderAlerts, | ||
| displayTypeSupportsRawSqlAlerts, | ||
| isTimeSeriesDisplayType, | ||
| savedChartConfigSupportsAlerts, | ||
| } from '@hyperdx/common-utils/dist/core/utils'; | ||
| import { | ||
| displayTypeRequiresSource, | ||
|
|
@@ -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'; | ||
|
|
@@ -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; | ||
| }; | ||
|
|
@@ -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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| if (!opensOnNewAlert) return savedFormValue; | ||
| return { | ||
| ...savedFormValue, | ||
| alert: { | ||
| ...DEFAULT_TILE_ALERT, | ||
| ...(savedFormValue.name && { displayName: savedFormValue.name }), | ||
| }, | ||
| }; | ||
| }, [savedFormValue, opensOnNewAlert]); | ||
|
|
||
| const { | ||
| control, | ||
|
|
@@ -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) { | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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, | ||
|
|
@@ -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} | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| onOpen={snapshotAlert} | ||
| onCancel={cancelAlertChanges} | ||
| actions={ | ||
|
|
||
There was a problem hiding this comment.
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 asdefaultValues/values, so RHF treats the draft as the saved state. When the user closes the panel,cancelAlertChanges(true)setsalertto undefined. From then on_getDirty()sees a difference from the defaults, so the next field edit, even one that is reverted, makesisDirtytrue. Closing the editor (EditTileModal.handleClose) then asks to discard changes on a tile the user never changed. Fix: keepsavedFormValueas the form's defaults and add the draft after mount withsetValue('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
There was a problem hiding this comment.
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 onmaintoo. I also tried the suggestedsetValue('alert', …)after mount: same result. Closing the draft panel with no other edit leavesisDirtyfalse, sincecancelAlertChangessets the value withoutshouldDirty. Leaving it as is.