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 @@ -446,6 +446,7 @@ const Tile = ({
dateRange,
onDuplicateClick,
onEditClick,
onAlertClick,
onDeleteClick,
onUpdateChart,
onMoveToGroup,
Expand Down Expand Up @@ -477,7 +478,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 @@ -983,7 +984,7 @@ const Tile = ({
data-testid={`tile-alerts-button-${chart.id}`}
variant="subtle"
size="sm"
onClick={onEditClick}
onClick={onAlertClick}
>
<IconBell size={16} />
</ActionIcon>
Expand All @@ -997,7 +998,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 @@ -1080,6 +1081,7 @@ const Tile = ({
onDeleteClick,
onDuplicateClick,
onEditClick,
onAlertClick,
onMoveToGroup,
openFullscreen,
readOnly,
Expand Down Expand Up @@ -1119,7 +1121,7 @@ const Tile = ({
leftSection={
alert ? <IconBell size={14} /> : <IconBellPlus size={14} />
}
onClick={onEditClick}
onClick={onAlertClick}
>
{alertTooltip}
</Menu.Item>
Expand Down Expand Up @@ -1170,6 +1172,7 @@ const Tile = ({
onDeleteClick,
onDuplicateClick,
onEditClick,
onAlertClick,
onMoveToGroup,
openFullscreen,
readOnly,
Expand Down Expand Up @@ -1618,6 +1621,7 @@ const Tile = ({
const EditTileModal = ({
dashboardId,
chart,
defaultAlertPanelOpened,
onClose,
onSave,
isSaving,
Expand All @@ -1628,6 +1632,7 @@ const EditTileModal = ({
}: {
dashboardId?: string;
chart: Tile | undefined;
defaultAlertPanelOpened?: boolean;
onClose: () => void;
dateRange: [Date, Date];
isSaving?: boolean;
Expand Down Expand Up @@ -1714,6 +1719,7 @@ const EditTileModal = ({
onDirtyChange={setHasUnsavedChanges}
isDashboardForm
autoRun
defaultAlertPanelOpened={defaultAlertPanelOpened}
/>
</SqlVariablesProvider>
</IsolatedChartSyncProvider>
Expand Down Expand Up @@ -2233,6 +2239,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 @@ -2434,7 +2441,14 @@ function DBDashboardPage({
key={chart.id}
chart={chart}
dateRange={searchedTimeRange}
onEditClick={() => setEditedTile(chart)}
onEditClick={() => {
setIsEditingTileAlert(false);
setEditedTile(chart);
}}
onAlertClick={() => {
setIsEditingTileAlert(true);
setEditedTile(chart);
}}
readOnly={isKioskMode}
isLive={isRefreshEnabled}
granularity={
Expand Down Expand Up @@ -2737,6 +2751,7 @@ function DBDashboardPage({
return !t.containerId;
});
const pos = calculateNextTilePosition(targetTiles, newW);
setIsEditingTileAlert(false);
setEditedTile({
id: makeId(),
x: pos.x,
Expand Down Expand Up @@ -3233,6 +3248,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 @@ -16,6 +16,7 @@ import {
displayTypeSupportsBuilderAlerts,
displayTypeSupportsRawSqlAlerts,
isTimeSeriesDisplayType,
savedChartConfigSupportsAlerts,
} from '@hyperdx/common-utils/dist/core/utils';
import {
displayTypeRequiresSource,
Expand Down Expand Up @@ -90,15 +91,18 @@ import {
firstSourceItemValue,
useFilteredSortedSourceItems,
} 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 @@ -158,6 +162,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 @@ -241,13 +250,29 @@ export default function EditTimeChartForm({
saveAlertLabel,
isSavingAlert,
isAlertRequired = false,
defaultAlertPanelOpened = false,
showSaveToDashboard,
}: EditTimeChartFormProps) {
const alertsEnabled = enableAlerts ?? dashboardId != null;
const formValue: ChartEditorFormState = 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 &&
alertsEnabled &&
!IS_LOCAL_MODE &&
savedChartConfigSupportsAlerts(chartConfig);
const formValue: ChartEditorFormState = useMemo(() => {
const value = convertSavedChartConfigToFormState(chartConfig);
if (!opensOnNewAlert) return value;
return {
...value,
alert: {
...DEFAULT_TILE_ALERT,
...(value.name && { displayName: value.name }),
},
};
}, [chartConfig, opensOnNewAlert]);

const {
control,
Expand Down Expand Up @@ -630,9 +655,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 @@ -661,11 +689,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 @@ -1110,10 +1152,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