Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/save-temporary-dashboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

feat: save a temporary dashboard with its content intact
148 changes: 97 additions & 51 deletions packages/app/src/DBDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ import {
useCreateDashboard,
useDashboards,
useDeleteDashboard,
withoutAlert,
} from '@/dashboard';
import { useAlertAnnotations } from '@/hooks/useAlertAnnotations';
import { getMinGranularitySeconds } from '@/hooks/useChartConfig';
Expand Down Expand Up @@ -416,6 +417,41 @@ const whereLanguageParser = parseAsString.withDefault(
typeof window !== 'undefined' ? (getStoredLanguage() ?? 'lucene') : 'lucene',
);

function toWhereLanguage(value: string | null): SearchConditionLanguage {
return value === 'sql' || value === 'lucene'
? value
: (getStoredLanguage() ?? 'lucene');
}

// Shared by "Save query" and saving a temporary dashboard so both persist a
// view the same way.
function toViewDefaults({
where,
whereLanguage,
rangeSeconds,
filterValues,
}: {
where: string;
whereLanguage: SearchConditionLanguage;
rangeSeconds: number | null;
filterValues: Dashboard['savedFilterValues'] | null;
}): Pick<
Dashboard,
'savedQuery' | 'savedQueryLanguage' | 'savedFilterValues' | 'savedDateRange'
> {
const savedQuery = where || null;
return {
savedQuery,
savedQueryLanguage: savedQuery ? whereLanguage || 'lucene' : null,
savedFilterValues: filterValues ?? [],
// The time input shows absolute text even for relative picks, so a saved
// range can only be its duration.
savedDateRange: rangeSeconds
? { type: 'relative', value: rangeSeconds }
: undefined,
};
}

/**
* A tile that cannot draw its chart yet, explaining why in its place. Keeps the
* chrome identical to a rendered tile so the toolbar stays usable.
Expand Down Expand Up @@ -2219,46 +2255,27 @@ function DBDashboardPage({
// Sync changes to the URL params into the form
useEffect(() => {
setValue('where', where);
setValue(
'whereLanguage',
whereLanguage === 'sql' || whereLanguage === 'lucene'
? whereLanguage
: (getStoredLanguage() ?? 'lucene'),
);
setValue('whereLanguage', toWhereLanguage(whereLanguage));
}, [setValue, where, whereLanguage]);

const handleSaveQuery = useCallback(() => {
if (!dashboard || isLocalDashboard) return;

// Execute the query first (updates URL)
// Apply the draft query/time input so what's saved is what's shown.
onSubmit();

// Then save to database (reads from form values which were just submitted to URL)
const formValues = getValues();
const currentWhere = formValues.where || null;
const currentWhereLanguage = currentWhere
? formValues.whereLanguage || 'lucene'
: null;
const currentFilterValues = filterValueEntries?.length
? filterValueEntries
: [];

const currentRelativeDateRange = timeRangeInputToSeconds(
displayedTimeInputValue,
timeZone,
);
const { savedDateRange, ...defaults } = toViewDefaults({
where: formValues.where,
whereLanguage: formValues.whereLanguage,
rangeSeconds: timeRangeInputToSeconds(displayedTimeInputValue, timeZone),
filterValues: filterValueEntries,
});

setDashboard(
produce(dashboard, draft => {
draft.savedQuery = currentWhere;
draft.savedQueryLanguage = currentWhereLanguage;
draft.savedFilterValues = currentFilterValues;
// Only supporting relative date range saving ATM
if (currentRelativeDateRange) {
draft.savedDateRange = {
type: 'relative',
value: currentRelativeDateRange,
};
Object.assign(draft, defaults);
if (savedDateRange) {
draft.savedDateRange = savedDateRange;
}
}),
() => {
Expand All @@ -2275,11 +2292,11 @@ function DBDashboardPage({
dashboard,
isLocalDashboard,
setDashboard,
getValues,
filterValueEntries,
onSubmit,
timeZone,
getValues,
displayedTimeInputValue,
timeZone,
filterValueEntries,
]);
const handleRemoveSavedQuery = useCallback(() => {
if (!dashboard || isLocalDashboard) return;
Expand Down Expand Up @@ -2565,14 +2582,7 @@ function DBDashboardPage({
...dashboard,
tiles: [
...dashboard.tiles,
{
...chart,
id: makeId(),
config: {
...chart.config,
alert: undefined,
},
},
{ ...withoutAlert(chart), id: makeId() },
],
});
}
Expand Down Expand Up @@ -2929,25 +2939,60 @@ function DBDashboardPage({

const createDashboard = useCreateDashboard();
const onCreateDashboard = useCallback(() => {
if (!dashboard) return;

Comment thread
pulpdrew marked this conversation as resolved.
Resolved
// The new /dashboards/{id} page drops this page's URL state, so the view
// only survives as saved defaults.
// Reads the applied URL state rather than calling onSubmit(): its queued
// URL update would cancel the navigation to the new dashboard.
const [start, end] = searchedTimeRange;
const viewDefaults = toViewDefaults({
where,
whereLanguage: toWhereLanguage(whereLanguage),
rangeSeconds: (end.getTime() - start.getTime()) / 1000,

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 — Saving a temporary dashboard always stores a default time range, even an odd one from a zoomed or absolute view

rangeSeconds comes from searchedTimeRange, which is always set, so every dashboard saved from a temporary one gets a savedDateRange. With the new hasSavedDefaults, that makes the menu say 'Update Default Query & Filters' and show 'Remove' even when the user never set a default. It also turns a chart drag-zoom (say 7m12.3s) into a permanent default of 'last 432.3s'. Fix: save a range only when the displayed input is a relative preset (for example, check displayedTimeInputValue against RELATIVE_TIME_OPTIONS in components/TimePicker/utils.ts). Otherwise leave savedDateRange unset.

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

filterValues: filterValueEntries,
});

createDashboard.mutate(
{
name: 'My Dashboard',
tiles: [],
tags: [],
name: dashboard.name?.trim() ? dashboard.name : 'My New Dashboard',
tiles: dashboard.tiles.map(withoutAlert),
tags: dashboard.tags ?? [],
filters: dashboard.filters,
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
containers: dashboard.containers,
...viewDefaults,
},
{
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
onSuccess: data => {
router.push(`/dashboards/${data.id}`);
},
onError: e => {
notifications.show({
color: 'red',
title: 'Unable to save dashboard',
message: e.message.slice(0, 100),
autoClose: 5000,
});
},
},
);
}, [createDashboard, router]);
}, [
createDashboard,
router,
dashboard,
searchedTimeRange,
where,
whereLanguage,
filterValueEntries,
]);

const [isSaving, setIsSaving] = useState(false);

const hasTiles = dashboard && dashboard.tiles.length > 0;
const hasSavedQueryAndFilterDefaults = Boolean(
dashboard?.savedQuery || dashboard?.savedFilterValues?.length,
const hasSavedDefaults = Boolean(
dashboard?.savedQuery ||
dashboard?.savedFilterValues?.length ||
dashboard?.savedDateRange,
);

const dashboardMeta =
Expand Down Expand Up @@ -3179,11 +3224,11 @@ function DBDashboardPage({
leftSection={<IconDeviceFloppy size={16} />}
onClick={handleSaveQuery}
>
{hasSavedQueryAndFilterDefaults
{hasSavedDefaults
? 'Update Default Query & Filters'
: 'Save Query & Filters as Default'}
</Menu.Item>
{hasSavedQueryAndFilterDefaults && (
{hasSavedDefaults && (
<Menu.Item
data-testid="remove-default-query-filters-menu-item"
leftSection={<IconX size={16} />}
Expand Down Expand Up @@ -3359,15 +3404,16 @@ function DBDashboardPage({
<Paper mt="xs" mb="md" p="md" data-testid="temporary-dashboard-banner">
<Flex justify="space-between" align="center">
<Text size="sm">
This is a temporary dashboard and can not be saved.
This is currently an unsaved, temporary dashboard.
</Text>
<Button
variant="primary"
fw={400}
onClick={onCreateDashboard}
loading={createDashboard.isPending || createDashboard.isSuccess}
data-testid="create-dashboard-button"
>
Create New Saved Dashboard
Save dashboard
</Button>
</Flex>
</Paper>
Expand Down
6 changes: 6 additions & 0 deletions packages/app/src/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export type Tile = {
tabId?: string;
};

// Copied tiles must not carry alerts: saving a dashboard creates every tile's
// alert server-side, without the user seeing an alert editor.
export function withoutAlert(tile: Tile): Tile {
return { ...tile, config: { ...tile.config, alert: undefined } };
}

export type Dashboard = {
id: string;
name: string;
Expand Down
79 changes: 74 additions & 5 deletions packages/app/tests/e2e/features/temporary-dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DashboardPage } from '../page-objects/DashboardPage';
import { DashboardsListPage } from '../page-objects/DashboardsListPage';
import { expect, test } from '../utils/base-test';
import { DEFAULT_LOGS_SOURCE_NAME } from '../utils/constants';

test.describe('Temporary Dashboard', { tag: ['@dashboard'] }, () => {
let dashboardPage: DashboardPage;
Expand All @@ -24,8 +25,9 @@ test.describe('Temporary Dashboard', { tag: ['@dashboard'] }, () => {
await test.step('Verify the temporary dashboard banner is visible', async () => {
await expect(dashboardPage.temporaryDashboardBanner).toBeVisible();
await expect(dashboardPage.temporaryDashboardBanner).toContainText(
'This is a temporary dashboard and can not be saved.',
'This is currently an unsaved, temporary dashboard.',
);
await expect(dashboardPage.createButton).toHaveText('Save dashboard');
});
},
);
Expand Down Expand Up @@ -79,20 +81,57 @@ test.describe('Temporary Dashboard', { tag: ['@dashboard'] }, () => {
);

test(
'should convert temporary dashboard to saved dashboard',
'should carry tiles, title, filters, and saved filters into the saved dashboard',
{ tag: '@full-stack' },
async ({ page }) => {
const uniqueName = `Saved From Temp ${Date.now()}`;
const savedQuery = 'SeverityText:error';

await dashboardPage.goto();

await test.step('Verify the temporary dashboard banner is visible', async () => {
await expect(dashboardPage.temporaryDashboardBanner).toBeVisible();
});

await test.step('Click Create New Saved Dashboard', async () => {
await dashboardPage.createButton.click();
await test.step('Rename the temporary dashboard', async () => {
await dashboardPage.renameDashboard('My New Dashboard', uniqueName);
});

await test.step('Add a tile', async () => {
await dashboardPage.addTile();
await dashboardPage.chartEditor.createBasicChart('Temp tile');
await expect(dashboardPage.getTiles()).toHaveCount(1, {
timeout: 10000,
});
});

await test.step('Add a dashboard filter', async () => {
await dashboardPage.openEditFiltersModal();
await expect(dashboardPage.emptyFiltersList).toBeVisible();
await dashboardPage.addFilterToDashboard(
'Service',
DEFAULT_LOGS_SOURCE_NAME,
'ServiceName',
);
await expect(
dashboardPage.getFilterItemByName('Service'),
).toBeVisible();
await dashboardPage.closeFiltersModal();
});

await test.step('Verify navigation to a saved dashboard', async () => {
await test.step('Select a filter value and enter a search query', async () => {
await dashboardPage.clickFilterOption('Service', 'accounting');
await expect(
dashboardPage
.getFilterSelectByName('Service')
.locator('..')
.getByText('accounting'),
).toBeVisible();
await dashboardPage.setGlobalFilter(savedQuery);
});

await test.step('Save the temporary dashboard', async () => {
await dashboardPage.createButton.click();
await expect(page).toHaveURL(/\/dashboards\/.+/, { timeout: 10000 });
});

Expand All @@ -104,6 +143,36 @@ test.describe('Temporary Dashboard', { tag: ['@dashboard'] }, () => {
.getByRole('link', { name: 'Dashboards' }),
).toBeVisible();
});

await test.step('Verify the title carried over', async () => {
await expect(dashboardPage.dashboardName).toHaveValue(uniqueName, {
timeout: 10000,
});
});

await test.step('Verify the tile carried over', async () => {
await expect(dashboardPage.getTiles()).toHaveCount(1, {
timeout: 10000,
});
});

await test.step('Verify the filter carried over', async () => {
await expect(
dashboardPage.getFilterSelectByName('Service'),
).toBeVisible({ timeout: 10000 });
});

await test.step('Verify the saved query and filter value carried over', async () => {
await expect(dashboardPage.searchInput).toHaveValue(savedQuery, {
timeout: 10000,
});
await expect(
dashboardPage
.getFilterSelectByName('Service')
.locator('..')
.getByText('accounting'),
).toBeVisible({ timeout: 10000 });
});
},
);
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
});
9 changes: 8 additions & 1 deletion packages/app/tests/e2e/page-objects/DashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,14 @@
* Edit dashboard name
*/
async editDashboardName(newName: string) {
await this.renameDashboard('My Dashboard', newName);
// The default name depends on how the dashboard was created: the list-page
// "Saved Dashboard" action names it "My Dashboard", while saving a
// temporary dashboard carries its name over ("My New Dashboard" by
// default). Read whatever is there rather than assuming one.
const nameInput = this.page.getByTestId('dashboard-name-input');
await expect(nameInput).not.toHaveValue('', { timeout: 10000 });
const currentName = await nameInput.inputValue();
await this.renameDashboard(currentName, newName);
}

/**
Expand All @@ -279,7 +286,7 @@
// The document title comes from the saved dashboard, so it only changes
// once the rename has persisted.
const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), {

Check failure on line 289 in packages/app/tests/e2e/page-objects/DashboardPage.ts

View workflow job for this annotation

GitHub Actions / e2e-tests / E2E Tests - Shard 2

[chromium] › tests/e2e/features/dashboard.spec.ts:1358:7 › Dashboard › should enter and exit read-only live kiosk mode @dashboard @full-stack @dashboard

6) [chromium] › tests/e2e/features/dashboard.spec.ts:1358:7 › Dashboard › should enter and exit read-only live kiosk mode @dashboard @full-stack @dashboard › Create and name a new dashboard Error: expect(page).toHaveTitle(expected) failed Expected pattern: /^Kiosk Dashboard 1795118437072 - / Received string: "My New Dashboard - ClickStack" Timeout: 10000ms Call log: - Expect "toHaveTitle" with timeout 10000ms 14 × unexpected value "My New Dashboard - ClickStack" at page-objects/DashboardPage.ts:289 287 | // once the rename has persisted. 288 | const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); > 289 | await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), { | ^ 290 | timeout: 10000, 291 | }); 292 | } at DashboardPage.renameDashboard (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:289:29) at DashboardPage.editDashboardName (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:271:5) at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard.spec.ts:1368:9 at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard.spec.ts:1366:7

Check failure on line 289 in packages/app/tests/e2e/page-objects/DashboardPage.ts

View workflow job for this annotation

GitHub Actions / e2e-tests / E2E Tests - Shard 2

[chromium] › tests/e2e/features/dashboard.spec.ts:48:7 › Dashboard › should persist dashboard across page reloads @dashboard

4) [chromium] › tests/e2e/features/dashboard.spec.ts:48:7 › Dashboard › should persist dashboard across page reloads @dashboard › Create and name a new dashboard Error: expect(page).toHaveTitle(expected) failed Expected pattern: /^Test Dashboard 1795118402203 - / Received string: "My New Dashboard - ClickStack" Timeout: 10000ms Call log: - Expect "toHaveTitle" with timeout 10000ms 14 × unexpected value "My New Dashboard - ClickStack" at page-objects/DashboardPage.ts:289 287 | // once the rename has persisted. 288 | const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); > 289 | await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), { | ^ 290 | timeout: 10000, 291 | }); 292 | } at DashboardPage.renameDashboard (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:289:29) at DashboardPage.editDashboardName (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:271:5) at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard.spec.ts:57:7 at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard.spec.ts:51:5

Check failure on line 289 in packages/app/tests/e2e/page-objects/DashboardPage.ts

View workflow job for this annotation

GitHub Actions / e2e-tests / E2E Tests - Shard 2

[chromium] › tests/e2e/features/dashboard-table-linking.spec.ts:446:9 › Dashboard Table Linking › Dashboard mode (ID): selecting a dashboard from dropdown navigates to that dashboard id @dashboard @full-stack

2) [chromium] › tests/e2e/features/dashboard-table-linking.spec.ts:446:9 › Dashboard Table Linking › Dashboard mode (ID): selecting a dashboard from dropdown navigates to that dashboard id @dashboard @full-stack › Create the target dashboard Error: expect(page).toHaveTitle(expected) failed Expected pattern: /^E2E ID Target Dashboard 1795118361601 - / Received string: "My New Dashboard - ClickStack" Timeout: 10000ms Call log: - Expect "toHaveTitle" with timeout 10000ms 14 × unexpected value "My New Dashboard - ClickStack" at page-objects/DashboardPage.ts:289 287 | // once the rename has persisted. 288 | const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); > 289 | await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), { | ^ 290 | timeout: 10000, 291 | }); 292 | } at DashboardPage.renameDashboard (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:289:29) at DashboardPage.editDashboardName (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:271:5) at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard-table-linking.spec.ts:454:9 at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard-table-linking.spec.ts:453:7

Check failure on line 289 in packages/app/tests/e2e/page-objects/DashboardPage.ts

View workflow job for this annotation

GitHub Actions / e2e-tests / E2E Tests - Shard 2

[chromium] › tests/e2e/features/dashboard-table-linking.spec.ts:233:9 › Dashboard Table Linking › Dashboard mode: valid link navigates to target dashboard with rendered WHERE @dashboard @full-stack

1) [chromium] › tests/e2e/features/dashboard-table-linking.spec.ts:233:9 › Dashboard Table Linking › Dashboard mode: valid link navigates to target dashboard with rendered WHERE @dashboard @full-stack › Create the target dashboard (must exist before opening drawer) Error: expect(page).toHaveTitle(expected) failed Expected pattern: /^E2E Target Dashboard 1795118357028 - / Received string: "My New Dashboard - ClickStack" Timeout: 10000ms Call log: - Expect "toHaveTitle" with timeout 10000ms 14 × unexpected value "My New Dashboard - ClickStack" at page-objects/DashboardPage.ts:289 287 | // once the rename has persisted. 288 | const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); > 289 | await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), { | ^ 290 | timeout: 10000, 291 | }); 292 | } at DashboardPage.renameDashboard (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:289:29) at DashboardPage.editDashboardName (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:271:5) at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard-table-linking.spec.ts:242:9 at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/dashboard-table-linking.spec.ts:240:7

Check failure on line 289 in packages/app/tests/e2e/page-objects/DashboardPage.ts

View workflow job for this annotation

GitHub Actions / e2e-tests / E2E Tests - Shard 3

[chromium] › tests/e2e/features/heatmap-series.spec.ts:96:7 › Heatmap modes › series heatmap with a group by renders and persists @full-stack @dashboard

1) [chromium] › tests/e2e/features/heatmap-series.spec.ts:96:7 › Heatmap modes › series heatmap with a group by renders and persists @full-stack @dashboard › Create a series heatmap on the log source Error: expect(page).toHaveTitle(expected) failed Expected pattern: /^E2E Series Heatmap 1795118383616 - / Received string: "My New Dashboard - ClickStack" Timeout: 10000ms Call log: - Expect "toHaveTitle" with timeout 10000ms 14 × unexpected value "My New Dashboard - ClickStack" at page-objects/DashboardPage.ts:289 287 | // once the rename has persisted. 288 | const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); > 289 | await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), { | ^ 290 | timeout: 10000, 291 | }); 292 | } at DashboardPage.renameDashboard (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:289:29) at DashboardPage.editDashboardName (/home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/page-objects/DashboardPage.ts:271:5) at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/heatmap-series.spec.ts:122:7 at /home/runner/work/ClickStack/ClickStack/packages/app/tests/e2e/features/heatmap-series.spec.ts:119:5
timeout: 10000,
});
}
Expand Down
Loading