diff --git a/.changeset/tile-description-editor.md b/.changeset/tile-description-editor.md new file mode 100644 index 0000000000..52b6172d58 --- /dev/null +++ b/.changeset/tile-description-editor.md @@ -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. diff --git a/packages/api/src/routers/external-api/v2/utils/__tests__/dashboards.test.ts b/packages/api/src/routers/external-api/v2/utils/__tests__/dashboards.test.ts index 11ad83d8cc..2dca4ef17e 100644 --- a/packages/api/src/routers/external-api/v2/utils/__tests__/dashboards.test.ts +++ b/packages/api/src/routers/external-api/v2/utils/__tests__/dashboards.test.ts @@ -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, @@ -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'); }); diff --git a/packages/api/src/routers/external-api/v2/utils/alertChartConfig.ts b/packages/api/src/routers/external-api/v2/utils/alertChartConfig.ts index ee794963da..a0975d3e90 100644 --- a/packages/api/src/routers/external-api/v2/utils/alertChartConfig.ts +++ b/packages/api/src/routers/external-api/v2/utils/alertChartConfig.ts @@ -98,6 +98,8 @@ export const EXTERNAL_TO_INTERNAL_KEY: Record = { */ export const EVALUATION_INERT_CONFIG_KEYS: ReadonlySet = new Set([ 'markdown', + // Tile tooltip text; the alert task never reads it. + 'description', // Only meaningful together with `filters`, which is itself lossy. 'filtersLogicalOperator', 'groupByColumnsOnLeft', diff --git a/packages/api/src/routers/external-api/v2/utils/dashboards.ts b/packages/api/src/routers/external-api/v2/utils/dashboards.ts index bbf6405c56..7c43f3e6c1 100644 --- a/packages/api/src/routers/external-api/v2/utils/dashboards.ts +++ b/packages/api/src/routers/external-api/v2/utils/dashboards.ts @@ -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 } + : {}), }; } @@ -733,6 +735,7 @@ export function convertToInternalTileConfig( ): DashboardDocument['tiles'][number] { const externalConfig = externalTile.config; const name = externalTile.name || ''; + const description = externalTile.description || undefined; let internalConfig: SavedChartConfig; @@ -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, @@ -775,6 +779,7 @@ export function convertToInternalTileConfig( ? DisplayType.Bar : DisplayType.Pie, name, + description, connection: externalConfig.connectionId, sqlTemplate: externalConfig.sqlTemplate, source: externalConfig.sourceId, @@ -827,6 +832,7 @@ export function convertToInternalTileConfig( seriesReturnType: externalConfig.asRatio ? 'ratio' : undefined, seriesLimit: externalConfig.seriesLimit, name, + description, } satisfies BuilderSavedChartConfig; break; case 'table': @@ -849,6 +855,7 @@ export function convertToInternalTileConfig( where: '', seriesReturnType: externalConfig.asRatio ? 'ratio' : undefined, name, + description, } satisfies BuilderSavedChartConfig; break; case 'number': @@ -881,6 +888,7 @@ export function convertToInternalTileConfig( // palette token, so it passes through directly. backgroundChart: externalConfig.backgroundChart, name, + description, } satisfies BuilderSavedChartConfig; break; case 'pie': @@ -896,6 +904,7 @@ export function convertToInternalTileConfig( where: '', seriesLimit: externalConfig.limit, name, + description, } satisfies BuilderSavedChartConfig; break; case 'heatmap': { @@ -910,6 +919,7 @@ export function convertToInternalTileConfig( source: externalConfig.sourceId, where: '', name, + description, } satisfies BuilderSavedChartConfig; break; } @@ -973,6 +983,7 @@ export function convertToInternalTileConfig( where: externalConfig.where, whereLanguage: externalConfig.whereLanguage ?? 'lucene', name, + description, } satisfies BuilderSavedChartConfig; break; } @@ -982,6 +993,7 @@ export function convertToInternalTileConfig( displayType: DisplayType.Search, source: externalConfig.sourceId, name, + description, whereLanguage: externalConfig.whereLanguage ?? 'lucene', } satisfies BuilderSavedChartConfig; break; @@ -991,6 +1003,7 @@ export function convertToInternalTileConfig( displayType: DisplayType.EventPatterns, source: externalConfig.sourceId, name, + description, whereLanguage: externalConfig.whereLanguage ?? 'lucene', } satisfies BuilderSavedChartConfig; break; @@ -1002,6 +1015,7 @@ export function convertToInternalTileConfig( where: '', select: [], name, + description, } satisfies BuilderSavedChartConfig; break; default: @@ -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, @@ -1037,7 +1051,6 @@ export function convertToInternalTileConfig( h, ...(containerId !== undefined ? { containerId } : {}), ...(tabId !== undefined ? { tabId } : {}), - ...(description ? { description } : {}), config: strippedConfig, }; } diff --git a/packages/api/src/utils/externalApi.ts b/packages/api/src/utils/externalApi.ts index 0f0721e11e..187abd7a24 100644 --- a/packages/api/src/utils/externalApi.ts +++ b/packages/api/src/utils/externalApi.ts @@ -53,7 +53,19 @@ const pickIfTruthy = (obj: T, keys: K[]): Partial => { 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'); @@ -208,6 +220,7 @@ export function translateExternalChartToTileConfig( ['groupBy', 'orderBy', 'markdown', 'seriesReturnType', 'numberFormat'], ), name, + ...(description ? { description } : {}), source: sourceId, displayType, select, diff --git a/packages/api/src/utils/zod.ts b/packages/api/src/utils/zod.ts index ca469a7e45..0ead1cf350 100644 --- a/packages/api/src/utils/zod.ts +++ b/packages/api/src/utils/zod.ts @@ -26,6 +26,7 @@ import { SearchConditionLanguageSchema as whereLanguageSchema, StaticListDashboardFilterSchema, tagsSchema, + TILE_DESCRIPTION_MAX_LENGTH, validateAlertChannelSelection, validateAlertScheduleOffsetMinutes, validateAlertThresholdMax, @@ -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) { diff --git a/packages/app/src/DBDashboardPage.tsx b/packages/app/src/DBDashboardPage.tsx index 3f32c8adab..2768782fff 100644 --- a/packages/app/src/DBDashboardPage.tsx +++ b/packages/app/src/DBDashboardPage.tsx @@ -1175,18 +1175,23 @@ const Tile = ({ chart.config.name ? ( {chart.config.name} - {chart.description && ( - + {chart.config.description && ( + )} ) : 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) diff --git a/packages/app/src/components/ChartEditor/__tests__/utils.test.ts b/packages/app/src/components/ChartEditor/__tests__/utils.test.ts index aa6c554dfa..2b7d556950 100644 --- a/packages/app/src/components/ChartEditor/__tests__/utils.test.ts +++ b/packages/app/src/components/ChartEditor/__tests__/utils.test.ts @@ -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', diff --git a/packages/app/src/components/ChartEditor/utils.ts b/packages/app/src/components/ChartEditor/utils.ts index d028efd563..8cc970be58 100644 --- a/packages/app/src/components/ChartEditor/utils.ts +++ b/packages/app/src/components/ChartEditor/utils.ts @@ -264,6 +264,7 @@ export function convertFormStateToSavedChartConfig( configType: 'promql', ...pick(form, [ 'name', + 'description', 'displayType', 'numberFormat', 'color', @@ -291,6 +292,7 @@ export function convertFormStateToSavedChartConfig( configType: 'sql', ...pick(form, [ 'name', + 'description', 'displayType', 'numberFormat', 'color', diff --git a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx index 0cc4e83795..9d01c71dbb 100644 --- a/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx @@ -29,6 +29,7 @@ import { PromqlHeatmapMode, SavedChartConfig, SourceKind, + TILE_DESCRIPTION_MAX_LENGTH, TSource, } from '@hyperdx/common-utils/dist/types'; import { getAlertVariableWarning } from '@hyperdx/common-utils/dist/variables'; @@ -1121,17 +1122,54 @@ export default function EditTimeChartForm({
- - Chart Name - - + gap="sm" + direction={{ base: 'column', lg: 'row' }} + align={{ base: 'stretch', lg: 'center' }} + > + + + Chart Name + + + + {isDashboardForm && ( + + + Description + + ( +