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
9 changes: 9 additions & 0 deletions .changeset/tile-description-editor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@hyperdx/common-utils': patch
'@hyperdx/api': patch
'@hyperdx/app': patch
---

Add a description field to the tile editor. The description is now stored on the
tile's chart config next to its name, and is kept for series tiles in the
external Dashboards API.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import { DashboardDocument } from '@/models/dashboard';
import {
collectTileContainerRefIssues,
ConfigTile,
convertExternalTilesToInternal,
convertToExternalDashboard,
convertToInternalTileConfig,
} from '@/routers/external-api/v2/utils/dashboards';
import { externalDashboardSelectItemSchema } from '@/utils/zod';
import {
externalDashboardSelectItemSchema,
ExternalDashboardTileWithId,
} from '@/utils/zod';

function makeMarkdownTile(
markdown?: string,
Expand Down Expand Up @@ -97,15 +101,62 @@ describe('tile description', () => {
const internal = convertToInternalTileConfig(
makeMarkdownTile('# Hello', { description: 'What this tile shows.' }),
);
expect(internal.description).toBe('What this tile shows.');
expect(internal.config.description).toBe('What this tile shows.');
expect(internal).not.toHaveProperty('description');

const ext = convertToExternalDashboard(makeDoc({ tiles: [internal] }));
expect(ext.tiles[0].description).toBe('What this tile shows.');
});

describe.each([
['a series tile', 'series'],
['a config tile', 'config'],
] as const)(
'through convertExternalTilesToInternal for %s',
(_label, kind) => {
const makeTile = (
overrides: { description?: string } = {},
): ExternalDashboardTileWithId => ({
id: 'test-id',
x: 0,
y: 0,
w: 12,
h: 4,
name: 'Tile',
...(kind === 'series'
? {
series: [
{
type: 'time',
sourceId: new mongoose.Types.ObjectId().toString(),
aggFn: 'count',
where: '',
groupBy: [],
displayType: 'line',
},
],
}
: { config: { displayType: 'markdown', markdown: '# Hello' } }),
...overrides,
});

it('keeps the description', () => {
const [internal] = convertExternalTilesToInternal([
makeTile({ description: 'What this tile shows.' }),
]);
expect(internal.config.description).toBe('What this tile shows.');
});

it('omits the description when unset', () => {
const [internal] = convertExternalTilesToInternal([makeTile()]);
expect(internal.config).not.toHaveProperty('description');
});
},
);

it('omits the field when unset', () => {
const internal = convertToInternalTileConfig(makeMarkdownTile('# Hello'));
expect(internal).not.toHaveProperty('description');
expect(internal.config).not.toHaveProperty('description');
const ext = convertToExternalDashboard(makeDoc({ tiles: [internal] }));
expect(ext.tiles[0]).not.toHaveProperty('description');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export const EXTERNAL_TO_INTERNAL_KEY: Record<string, string> = {
*/
export const EVALUATION_INERT_CONFIG_KEYS: ReadonlySet<string> = new Set([
'markdown',
// Tile tooltip text; the alert task never reads it.
'description',
// Only meaningful together with `filters`, which is itself lossy.
'filtersLogicalOperator',
'groupByColumnsOnLeft',
Expand Down
19 changes: 16 additions & 3 deletions packages/api/src/routers/external-api/v2/utils/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ function convertTileToExternalChart(
config: convertToExternalTileChartConfig(tile.config) ?? defaultTileConfig,
...(containerId !== undefined ? { containerId } : {}),
...(tabId !== undefined ? { tabId } : {}),
...(tile.description ? { description: tile.description } : {}),
...(tile.config.description
? { description: tile.config.description }
: {}),
Comment thread
karl-power marked this conversation as resolved.
Resolved
};
}

Expand Down Expand Up @@ -733,6 +735,7 @@ export function convertToInternalTileConfig(
): DashboardDocument['tiles'][number] {
const externalConfig = externalTile.config;
const name = externalTile.name || '';
const description = externalTile.description || undefined;
Comment thread
karl-power marked this conversation as resolved.
Resolved

let internalConfig: SavedChartConfig;

Expand All @@ -755,6 +758,7 @@ export function convertToInternalTileConfig(
TIME_SERIES_DISPLAY_TYPE_BY_NAME[externalConfig.displayType],
fillNulls: externalConfig.fillNulls === false ? false : undefined,
name,
description,
connection: externalConfig.connectionId,
sqlTemplate: externalConfig.sqlTemplate,
source: externalConfig.sourceId,
Expand All @@ -775,6 +779,7 @@ export function convertToInternalTileConfig(
? DisplayType.Bar
: DisplayType.Pie,
name,
description,
connection: externalConfig.connectionId,
sqlTemplate: externalConfig.sqlTemplate,
source: externalConfig.sourceId,
Expand Down Expand Up @@ -827,6 +832,7 @@ export function convertToInternalTileConfig(
seriesReturnType: externalConfig.asRatio ? 'ratio' : undefined,
seriesLimit: externalConfig.seriesLimit,
name,
description,
} satisfies BuilderSavedChartConfig;
break;
case 'table':
Expand All @@ -849,6 +855,7 @@ export function convertToInternalTileConfig(
where: '',
seriesReturnType: externalConfig.asRatio ? 'ratio' : undefined,
name,
description,
} satisfies BuilderSavedChartConfig;
break;
case 'number':
Expand Down Expand Up @@ -881,6 +888,7 @@ export function convertToInternalTileConfig(
// palette token, so it passes through directly.
backgroundChart: externalConfig.backgroundChart,
name,
description,
} satisfies BuilderSavedChartConfig;
break;
case 'pie':
Expand All @@ -896,6 +904,7 @@ export function convertToInternalTileConfig(
where: '',
seriesLimit: externalConfig.limit,
name,
description,
} satisfies BuilderSavedChartConfig;
break;
case 'heatmap': {
Expand All @@ -910,6 +919,7 @@ export function convertToInternalTileConfig(
source: externalConfig.sourceId,
where: '',
name,
description,
} satisfies BuilderSavedChartConfig;
break;
}
Expand Down Expand Up @@ -973,6 +983,7 @@ export function convertToInternalTileConfig(
where: externalConfig.where,
whereLanguage: externalConfig.whereLanguage ?? 'lucene',
name,
description,
} satisfies BuilderSavedChartConfig;
break;
}
Expand All @@ -982,6 +993,7 @@ export function convertToInternalTileConfig(
displayType: DisplayType.Search,
source: externalConfig.sourceId,
name,
description,
whereLanguage: externalConfig.whereLanguage ?? 'lucene',
} satisfies BuilderSavedChartConfig;
break;
Expand All @@ -991,6 +1003,7 @@ export function convertToInternalTileConfig(
displayType: DisplayType.EventPatterns,
source: externalConfig.sourceId,
name,
description,
whereLanguage: externalConfig.whereLanguage ?? 'lucene',
} satisfies BuilderSavedChartConfig;
break;
Expand All @@ -1002,6 +1015,7 @@ export function convertToInternalTileConfig(
where: '',
select: [],
name,
description,
} satisfies BuilderSavedChartConfig;
break;
default:
Expand All @@ -1028,7 +1042,7 @@ export function convertToInternalTileConfig(
// name on `config`, not at the top level (`strippedConfig` carries it).
// Stripping the top-level `name` brings the runtime shape back in line
// with `DashboardDocument['tiles'][number]`.
const { id, x, y, w, h, containerId, tabId, description } = externalTile;
const { id, x, y, w, h, containerId, tabId } = externalTile;
return {
id,
x,
Expand All @@ -1037,7 +1051,6 @@ export function convertToInternalTileConfig(
h,
...(containerId !== undefined ? { containerId } : {}),
...(tabId !== undefined ? { tabId } : {}),
...(description ? { description } : {}),
config: strippedConfig,
};
}
Expand Down
15 changes: 14 additions & 1 deletion packages/api/src/utils/externalApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@ const pickIfTruthy = <T, K extends keyof T>(obj: T, keys: K[]): Partial<T> => {
export function translateExternalChartToTileConfig(
chart: SeriesTile,
): DashboardDocument['tiles'][number] {
const { id, name, x, y, w, h, series, asRatio, containerId, tabId } = chart;
const {
id,
name,
description,
x,
y,
w,
h,
series,
asRatio,
containerId,
tabId,
} = chart;

if (series.length === 0) {
throw new Error('Chart must have at least one series');
Expand Down Expand Up @@ -208,6 +220,7 @@ export function translateExternalChartToTileConfig(
['groupBy', 'orderBy', 'markdown', 'seriesReturnType', 'numberFormat'],
),
name,
...(description ? { description } : {}),
source: sourceId,
displayType,
select,
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/utils/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
SearchConditionLanguageSchema as whereLanguageSchema,
StaticListDashboardFilterSchema,
tagsSchema,
TILE_DESCRIPTION_MAX_LENGTH,
validateAlertChannelSelection,
validateAlertScheduleOffsetMinutes,
validateAlertThresholdMax,
Expand Down Expand Up @@ -808,7 +809,7 @@ export const externalDashboardTileSchema = z
// valid container id from the editor always fits.
containerId: z.string().min(1).max(DASHBOARD_CONTAINER_ID_MAX).optional(),
tabId: z.string().min(1).max(DASHBOARD_CONTAINER_ID_MAX).optional(),
description: z.string().max(1024).optional(),
description: z.string().max(TILE_DESCRIPTION_MAX_LENGTH).optional(),
})
.superRefine((data, ctx) => {
if (data.series && data.config) {
Expand Down
13 changes: 9 additions & 4 deletions packages/app/src/DBDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,18 +1175,23 @@ const Tile = ({
chart.config.name ? (
<Group gap={4} wrap="nowrap">
<Text size="sm">{chart.config.name}</Text>
{chart.description && (
<Tooltip label={chart.description} multiline maw={360} withArrow>
{chart.config.description && (
<Tooltip
label={chart.config.description}
multiline
maw={360}
withArrow
>
<IconInfoCircle
size={14}
aria-label={chart.description}
aria-label={chart.config.description}
data-testid={`tile-description-${chart.id}`}
/>
</Tooltip>
)}
</Group>
) : undefined,
[chart.config.name, chart.description, chart.id],
[chart.config.name, chart.config.description, chart.id],
);

// Render chart content (used in both tile and fullscreen views)
Expand Down
27 changes: 27 additions & 0 deletions packages/app/src/components/ChartEditor/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ describe('convertFormStateToSavedChartConfig', () => {
expect(result).toMatchObject({ alternateRowBackground: true });
});

it.each(['sql', 'promql'] as const)(
'persists description for a %s config',
configType => {
const form: ChartEditorFormState = {
configType,
displayType: DisplayType.Table,
sqlTemplate: 'SELECT 1',
promqlExpression: 'up',
connection: 'conn-1',
description: 'What this tile shows.',
series: [],
};
const result = convertFormStateToSavedChartConfig(form, undefined);
expect(result).toMatchObject({ description: 'What this tile shows.' });
},
);

it('persists description for a builder config', () => {
const form: ChartEditorFormState = {
displayType: DisplayType.Line,
description: 'What this tile shows.',
series: [seriesItem],
};
const result = convertFormStateToSavedChartConfig(form, logSource);
expect(result).toMatchObject({ description: 'What this tile shows.' });
});

it('persists backgroundChart for a promql+number config', () => {
const form: ChartEditorFormState = {
configType: 'promql',
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/components/ChartEditor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export function convertFormStateToSavedChartConfig(
configType: 'promql',
...pick(form, [
'name',
'description',
'displayType',
'numberFormat',
'color',
Expand Down Expand Up @@ -291,6 +292,7 @@ export function convertFormStateToSavedChartConfig(
configType: 'sql',
...pick(form, [
'name',
'description',
'displayType',
'numberFormat',
'color',
Expand Down
Loading
Loading