From 7fe1bb271e27e03fa16476ec492a6f2134a5c520 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:07:57 +0000 Subject: [PATCH 01/15] =?UTF-8?q?feat(spec):=20report=20chart=20showEmptyG?= =?UTF-8?q?roups=20=E2=80=94=20show=20declared=20options=20with=20no=20rec?= =?UTF-8?q?ords?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01L9qibyFBwGSJLARjP5asi3 Co-Authored-By: Claude --- packages/spec/src/ui/report.test.ts | 23 +++++++++++++++++++++++ packages/spec/src/ui/report.zod.ts | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/packages/spec/src/ui/report.test.ts b/packages/spec/src/ui/report.test.ts index 3c0d98a76f2..cf704891ba1 100644 --- a/packages/spec/src/ui/report.test.ts +++ b/packages/spec/src/ui/report.test.ts @@ -581,6 +581,29 @@ describe('ReportChartSchema', () => { expect(r.success).toBe(false); expect(r.error?.issues.map((i) => i.path.join('.'))).toContain('seriesBy'); }); + + // objectstack#36722 — "show groups with no records". Optional with NO + // default: an existing report parses to exactly the bytes it parsed to + // before, so the switch is off by being absent. + it('`showEmptyGroups` is optional and off by default — absent stays absent', () => { + const parsed = ReportChartSchema.parse({ type: 'bar', xAxis: 'stage', yAxis: 'count' }); + expect('showEmptyGroups' in parsed).toBe(false); + const on = ReportChartSchema.safeParse({ type: 'bar', xAxis: 'stage', yAxis: 'count', showEmptyGroups: true }); + expect(on.success).toBe(true); + expect(on.data?.showEmptyGroups).toBe(true); + const report = ReportSchema.parse({ + name: 'deals_by_stage', label: 'Deals by stage', type: 'summary', + dataset: 'deals', rows: ['stage'], values: ['count'], + chart: { type: 'bar', xAxis: 'stage', yAxis: 'count', showEmptyGroups: true }, + }); + expect(report.chart?.showEmptyGroups).toBe(true); + }); + + it('refuses a non-boolean `showEmptyGroups`', () => { + const r = ReportChartSchema.safeParse({ type: 'bar', xAxis: 'stage', yAxis: 'count', showEmptyGroups: 'yes' }); + expect(r.success).toBe(false); + expect(r.error?.issues.map((i) => i.path.join('.'))).toContain('showEmptyGroups'); + }); }); /** diff --git a/packages/spec/src/ui/report.zod.ts b/packages/spec/src/ui/report.zod.ts index 907535ac7b8..78be5e89715 100644 --- a/packages/spec/src/ui/report.zod.ts +++ b/packages/spec/src/ui/report.zod.ts @@ -56,6 +56,26 @@ export const ReportChartSchema = lazySchema(() => ChartConfigSchema.extend({ + '(bound-dataset dimension, not a raw field); with it set, `series[].name` names a value of this dimension. ' + 'Refused on a single-series type (' + SINGLE_SERIES_CHART_TYPES.join('/') + ') and when it names the xAxis dimension', ), + /** + * Show the groups that hold no records. A grouped query answers one row per + * value that HOLDS rows, so a stage with no deals is absent from a + * "deals by stage" chart rather than reading as zero. With this on, the + * report renderer adds every DECLARED option of the `xAxis` dimension's + * field that the answer left out, valued the way the analytics + * executor values any empty group (`emptyGroupValueFor`: `0` for count and + * sum, empty for avg/min/max). + * + * Only a dimension whose field declares its options is filled (a select or + * similar); a free-text or lookup dimension has no known set of values. Not + * filled when the answer is truncated or ordered by a measure, where an added + * group would compete for a place it did not earn. A date axis needs no + * switch: the executor already fills every bucket of the report's period. + * Omitted = off, and the chart draws exactly the groups the query returned. + */ + showEmptyGroups: z.boolean().optional().describe( + 'Show the declared options of the xAxis dimension field that have no records, valued 0 for a count or sum ' + + '(left empty for avg/min/max). Only a field that declares its options is filled; omitted = off', + ), })); /** From 6daf8734898b3f872c081749cf4b26b1cd93bbc5 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:14:04 +0000 Subject: [PATCH 02/15] chore(spec): regenerate report reference, authorable surface and liveness counts for showEmptyGroups Claude-Session: https://claude.ai/code/session_01L9qibyFBwGSJLARjP5asi3 Co-Authored-By: Claude --- content/docs/references/ui/report.mdx | 2 ++ packages/spec/authorable-surface/ui.json | 1 + packages/spec/liveness/state-counts/report.md | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/content/docs/references/ui/report.mdx b/content/docs/references/ui/report.mdx index 268e0047c17..6983b6f0902 100644 --- a/content/docs/references/ui/report.mdx +++ b/content/docs/references/ui/report.mdx @@ -106,6 +106,7 @@ const result = JoinedReportBlockSchema.parse(data); | **interaction** | `{ tooltips?: boolean; brush?: boolean }` | optional | Interaction toggles: `{ tooltips?, brush? }` | | **aria** | `never` | optional | [REMOVED] `ChartConfig.aria` — authored as `dashboard.widgets[].chartConfig.aria`, `report.chart.aria` and `report.blocks[].chart.aria` — was removed in @objectstack/spec 17 (ADR-0049 D2). No chart renderer ever applied it: the chart implementation declares no `aria` prop, the presentation lowering names it nowhere, and the react `` block never published it, so ARIA attributes declared here parsed and then silently did not reach the DOM. Delete the key. The accessible name that IS applied on this same chart config is its sibling `description`, which the chart renderer lowers onto the chart graphic as `role="img"` plus `aria-label`. The shared `AriaProps` shape is NOT gone — `ariaLabel` / `ariaDescribedBy` / `role` stay live in the `aria` block on `page.aria`, `page.components[].aria` and the list view `aria`. Run `os migrate meta --from 17` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. | | **seriesBy** | `string` | optional | Dataset dimension name that splits the yAxis measure into one series per value of it (bound-dataset dimension, not a raw field); with it set, `series[].name` names a value of this dimension. Refused on a single-series type (pie/donut/funnel/treemap/sankey) and when it names the xAxis dimension | +| **showEmptyGroups** | `boolean` | optional | Show the declared options of the xAxis dimension field that have no records, valued 0 for a count or sum (left empty for avg/min/max). Only a field that declares its options is filled; omitted = off | ### Nested Shape: `Report.dateRange` @@ -177,6 +178,7 @@ const result = JoinedReportBlockSchema.parse(data); | **interaction** | `{ tooltips?: boolean; brush?: boolean }` | optional | Interaction toggles: `{ tooltips?, brush? }` | | **aria** | `never` | optional | [REMOVED] `ChartConfig.aria` — authored as `dashboard.widgets[].chartConfig.aria`, `report.chart.aria` and `report.blocks[].chart.aria` — was removed in @objectstack/spec 17 (ADR-0049 D2). No chart renderer ever applied it: the chart implementation declares no `aria` prop, the presentation lowering names it nowhere, and the react `` block never published it, so ARIA attributes declared here parsed and then silently did not reach the DOM. Delete the key. The accessible name that IS applied on this same chart config is its sibling `description`, which the chart renderer lowers onto the chart graphic as `role="img"` plus `aria-label`. The shared `AriaProps` shape is NOT gone — `ariaLabel` / `ariaDescribedBy` / `role` stay live in the `aria` block on `page.aria`, `page.components[].aria` and the list view `aria`. Run `os migrate meta --from 17` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. | | **seriesBy** | `string` | optional | Dataset dimension name that splits the yAxis measure into one series per value of it (bound-dataset dimension, not a raw field); with it set, `series[].name` names a value of this dimension. Refused on a single-series type (pie/donut/funnel/treemap/sankey) and when it names the xAxis dimension | +| **showEmptyGroups** | `boolean` | optional | Show the declared options of the xAxis dimension field that have no records, valued 0 for a count or sum (left empty for avg/min/max). Only a field that declares its options is filled; omitted = off | ### Allowed Values: `ReportChart.type` diff --git a/packages/spec/authorable-surface/ui.json b/packages/spec/authorable-surface/ui.json index e8e047df488..693b1270fad 100644 --- a/packages/spec/authorable-surface/ui.json +++ b/packages/spec/authorable-surface/ui.json @@ -1345,6 +1345,7 @@ "ui/ReportChart:series", "ui/ReportChart:seriesBy", "ui/ReportChart:showDataLabels", + "ui/ReportChart:showEmptyGroups", "ui/ReportChart:showLegend", "ui/ReportChart:subtitle", "ui/ReportChart:title", diff --git a/packages/spec/liveness/state-counts/report.md b/packages/spec/liveness/state-counts/report.md index c4b052c5696..64bb0385abe 100644 --- a/packages/spec/liveness/state-counts/report.md +++ b/packages/spec/liveness/state-counts/report.md @@ -12,4 +12,4 @@ committed anywhere: `check:liveness` sums the shards when it reads them. | Type | live | exp | elsewhere | dead | planned | classified | |---|---|---|---|---|---|---| -| `report` | 40 | 0 | 0 | 1 | 2 | 43 | +| `report` | 41 | 0 | 0 | 1 | 2 | 44 | From ff36e96efde7584850f3c8861a8619edfa0715ed Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:16:32 +0000 Subject: [PATCH 03/15] feat(plugin-report): fill a report chart's empty declared options under chart.showEmptyGroups Claude-Session: https://claude.ai/code/session_01L9qibyFBwGSJLARjP5asi3 Co-Authored-By: Claude --- .../src/DatasetReportRenderer.tsx | 46 ++++++- .../plugin-report/src/emptyOptionGroups.ts | 117 ++++++++++++++++++ 2 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 ui/packages/plugin-report/src/emptyOptionGroups.ts diff --git a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx index a9457d15563..7bccee58eb4 100644 --- a/ui/packages/plugin-report/src/DatasetReportRenderer.tsx +++ b/ui/packages/plugin-report/src/DatasetReportRenderer.tsx @@ -147,6 +147,7 @@ import { import { builtinAggregateLabels, useSafeFieldLabel, useSafeTranslate, useDisplayLocale, useObjectTranslation, pickLocalized } from '@object-ui/i18n'; import { useDataInvalidation, classifyLoadError } from '@object-ui/react'; import { mergeFilters } from './mergeFilters'; +import { fillEmptyOptionGroups } from './emptyOptionGroups'; import { measureDrillScope, sharedMeasureDrillScope, scopeDrillFilter, type MeasureDrillScope } from './measureDrillScope'; import { useDatasetDimensionMeta, type DatasetDimensionMeta } from './useDatasetDimensionLabels'; import { @@ -1757,8 +1758,17 @@ function DatasetReportChart({ // component). Mirrors `DatasetWidget`'s own call exactly. (Since // objectui#12243 the tables above read the same hook, for the declared order.) const dimensionMeta = useDatasetDimensionMeta(state.object, state.dimensionFields, chartDimensions); - const { categoryColors, dimensionLabels, categoryOrder, seriesOrder } = React.useMemo(() => { - if (!dimensionMeta) return { categoryColors: null, dimensionLabels: null, categoryOrder: null, seriesOrder: null }; + const { categoryColors, dimensionLabels, categoryOrder, seriesOrder, xOptions, xLocalizedOptions } = React.useMemo(() => { + if (!dimensionMeta) { + return { + categoryColors: null, + dimensionLabels: null, + categoryOrder: null, + seriesOrder: null, + xOptions: undefined, + xLocalizedOptions: undefined, + }; + } const { metaByPath, relabel } = dimensionMeta; // Colours and declared order read `option.label`, so they are fed the // LOCALIZED options — the same "translate the options, then render them" @@ -1784,6 +1794,10 @@ function DatasetReportChart({ dimensionLabels: deriveDimensionLabelMaps(metaByPath, relabel, fieldOptionLabel), categoryOrder: buildCategoryOrder(firstDimOptions), seriesOrder: buildCategoryOrder(secondDimOptions), + // The x-axis field's declared options, authored and translated, for the + // `showEmptyGroups` fill (objectstack#36722). + xOptions: firstDimMeta?.options as unknown, + xLocalizedOptions: firstDimOptions, }; }, [dimensionMeta, fieldOptionLabel]); @@ -1954,8 +1968,30 @@ function DatasetReportChart({ // undeclared values next in the dataset's order, the empty bucket last. A // report whose `order` reaches this chart's selection keeps the server's // order. No drill reads these rows by index, so the reordered copy is safe. - const displayRows = relabelDimensions(state.rows, dimensionLabels); - const categoryRank = scopeOrder(order, queryDimensions, queryMeasures) ? null : buildCategoryRank(categoryOrder); + // + // objectstack#36722 — `chart.showEmptyGroups`: the declared options of the + // x-axis field that no row carries are added BEFORE the relabelling, carrying + // their stored value as an unresolved server row would, so they take the + // label, the declared position and the option colour every real group takes. + // Their measure cells read the executor's empty-group value for the column's + // aggregate (`fillEmptyOptionGroups`). Not filled under an order that reaches + // this selection: the server placed every row, and an added group has no + // position in an order it was never part of. A field with no declared options + // has no known set of values and is never filled; a date axis needs no fill + // here, the executor already answers every bucket of the report's period. + const chartOrder = scopeOrder(order, queryDimensions, queryMeasures); + const chartRows = chart.showEmptyGroups === true && !chartOrder + ? fillEmptyOptionGroups(state.rows, { + xAxis, + ...(seriesBy ? { seriesBy } : {}), + measures: compareTo && !seriesBy ? [yAxis, compareKey] : [yAxis], + aggregate: measureField(yAxis)?.aggregate, + options: xOptions, + localizedOptions: xLocalizedOptions, + }) + : state.rows; + const displayRows = relabelDimensions(chartRows, dimensionLabels); + const categoryRank = chartOrder ? null : buildCategoryRank(categoryOrder); const plotLayout = arrangeByDeclaredOptions( displayRows, [xAxis], @@ -2025,6 +2061,8 @@ function DatasetReportChart({ }); if (at < 0) return; const index = plotLayout ? plotLayout[at] : at; + // A group `showEmptyGroups` added counted no record: it opens no list. + if (index >= state.rows.length) return; const groupKey: Record = {}; for (const dim of queryDimensions) groupKey[dim] = displayRows[index]?.[dim]; emitBucketDrill({ diff --git a/ui/packages/plugin-report/src/emptyOptionGroups.ts b/ui/packages/plugin-report/src/emptyOptionGroups.ts new file mode 100644 index 00000000000..bb7e253dad2 --- /dev/null +++ b/ui/packages/plugin-report/src/emptyOptionGroups.ts @@ -0,0 +1,117 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `ReportChartSchema.showEmptyGroups` (objectstack#36722) — the chart's + * "show the groups that hold no records" switch. + * + * A grouped dataset query answers one row per value that HOLDS rows, so a + * select option no record carries is absent from the answer: a "deals by + * stage" bar chart has no bar for an empty stage, and the stage reads as not + * existing rather than as zero. With the switch on, the report chart adds the + * x-axis field's DECLARED options the answer left out. + * + * **Values come from the executor's own table.** An added row's measure cell + * is `emptyGroupValueFor(aggregate)` from `@objectstack/spec/data` — the one + * kind→identity mapping the analytics executor fills its own empty groups + * with — so a count or sum reads `0` and an avg/min/max stays empty (there is + * nothing to average). ⛔ No second empty-value table, and no `?? 0`: a column + * whose aggregate the answer does not state gets no value either. + * + * **Rows, not cells.** The added rows carry the option's STORED value, as an + * unresolved server row would, so the chart's relabelling, declared order and + * option colours treat them exactly like a real group. With a `seriesBy` + * split, an added option gets one row per series value the answer holds, so + * every series reads the empty value at that category. + * + * **Presence** is judged by every spelling a row can carry for an option: its + * stored value, its authored label (the server resolves dimension labels, + * ADR-0021) and its localized label. + * + * Added rows are APPENDED after the answer's own rows, so every index below + * `rows.length` still addresses the answer (the drill reads those by index). + * Returns the input array itself when nothing is missing. + */ +import { emptyGroupValueFor } from '@objectstack/spec/data'; + +type Row = Record; + +export interface EmptyOptionGroupFill { + /** The chart's category dimension. */ + xAxis: string; + /** The `seriesBy` split dimension, when one is authored. */ + seriesBy?: string; + /** The measure columns the added rows carry: the plotted one, and its `__compare` twin when compared. */ + measures: string[]; + /** The aggregate the plotted measure's answer column states (`fields[].aggregate`). */ + aggregate: unknown; + /** The x-axis field's declared options, as authored. */ + options: unknown; + /** The same options with translated labels (`localizeFieldOptions`), when a translator ran. */ + localizedOptions?: unknown; +} + +/** An option's stored value plus every label it can arrive under. */ +function optionSpellings(opt: unknown): { value: unknown; keys: string[] } | null { + if (typeof opt === 'string' || typeof opt === 'number' || typeof opt === 'boolean') { + return { value: opt, keys: [String(opt)] }; + } + if (opt && typeof opt === 'object') { + const o = opt as { value?: unknown; label?: unknown }; + if (o.value == null) return null; + const keys = [String(o.value)]; + if (typeof o.label === 'string') keys.push(o.label); + return { value: o.value, keys }; + } + return null; +} + +/** + * The answer's rows plus one row (one per series value with a split) for each + * declared option no row carries. See the module header for the rules. + */ +export function fillEmptyOptionGroups(rows: readonly Row[], fill: EmptyOptionGroupFill): Row[] { + const input = rows as Row[]; + if (!Array.isArray(fill.options) || fill.options.length === 0) return input; + const localized = Array.isArray(fill.localizedOptions) ? fill.localizedOptions : []; + + const present = new Set(); + for (const row of rows) { + const v = row[fill.xAxis]; + if (v != null) present.add(String(v)); + } + + // Series values the answer holds, in arrival order — the null group included, + // since it is a series the chart draws. + const seriesValues: unknown[] = []; + if (fill.seriesBy) { + const seen = new Set(); + for (const row of rows) { + if (!(fill.seriesBy in row)) continue; + const v = row[fill.seriesBy]; + const key = v == null ? 'n' : `s:${String(v)}`; + if (seen.has(key)) continue; + seen.add(key); + seriesValues.push(v ?? null); + } + } + + const empty = emptyGroupValueFor(typeof fill.aggregate === 'string' ? fill.aggregate : undefined); + const added: Row[] = []; + fill.options.forEach((opt, i) => { + const spelled = optionSpellings(opt); + if (!spelled) return; + const translated = optionSpellings(localized[i]); + const keys = translated ? [...spelled.keys, ...translated.keys] : spelled.keys; + if (keys.some((k) => present.has(k))) return; + // A duplicate declaration of the same value adds it once. + for (const k of keys) present.add(k); + const base: Row = { [fill.xAxis]: spelled.value }; + if (empty !== undefined) for (const m of fill.measures) base[m] = empty; + if (fill.seriesBy && seriesValues.length > 0) { + for (const s of seriesValues) added.push({ ...base, [fill.seriesBy]: s }); + } else { + added.push(base); + } + }); + return added.length > 0 ? [...rows, ...added] : input; +} From fc0f8eac2b859f8b983b8dd427df73d2e902c5fe Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:20:32 +0000 Subject: [PATCH 04/15] test(plugin-report): pin chart.showEmptyGroups fill, its controls and the date-axis no-op Claude-Session: https://claude.ai/code/session_01L9qibyFBwGSJLARjP5asi3 Co-Authored-By: Claude --- ...setReportRenderer.dateRange-25873.test.tsx | 60 +++++++ .../__tests__/DatasetReportRenderer.test.tsx | 162 +++++++++++++++++- .../src/__tests__/emptyOptionGroups.test.ts | 66 +++++++ 3 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 ui/packages/plugin-report/src/__tests__/emptyOptionGroups.test.ts diff --git a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.dateRange-25873.test.tsx b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.dateRange-25873.test.tsx index 85e8bbcecff..a05ba3c0e09 100644 --- a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.dateRange-25873.test.tsx +++ b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.dateRange-25873.test.tsx @@ -14,6 +14,7 @@ import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/re import '@testing-library/jest-dom'; import { SchemaRendererProvider } from '@object-ui/react'; import { I18nProvider } from '@object-ui/i18n'; +import { ComponentRegistry } from '@object-ui/core'; import { DatasetReportRenderer } from '../DatasetReportRenderer'; // Radix Select opens on pointer events the DOM environment does not implement; @@ -294,3 +295,62 @@ describe('DatasetReportRenderer reads the date dimension as the report\'s reader expect(src.selections[0].timeDimensions).toEqual([{ dimension: 'bare_date', dateRange: 'last_90_days' }]); }); }); + +/** + * objectstack#36722 — `chart.showEmptyGroups` and a date axis. The executor + * already answers every bucket of the report's period, the empty ones at 0 + * (`fillEmptyTimeBuckets`, pinned in service-analytics + * `dataset-time-bucket-zero-fill.test.ts`), so the switch adds nothing there: + * with it on or off the report posts the same window and plots the same + * buckets. A date dimension declares no options, so the chart's fill never + * runs on it. + */ +describe('a date axis over the report period is the same with chart.showEmptyGroups on or off (objectstack#36722)', () => { + // The answer as the executor gives it for a three-month window with an + // empty middle month: the bucket is there, at 0. + const MONTHS = [ + { close_date: '2026-09', amount: 4 }, + { close_date: '2026-10', amount: 0 }, + { close_date: '2026-11', amount: 7 }, + ]; + + it('posts the same selection and plots the same buckets', async () => { + const runs: Array<{ selections: unknown[]; data: unknown }> = []; + for (const showEmptyGroups of [false, true]) { + let data: unknown; + ComponentRegistry.register('chart', (props: { schema: { data?: unknown } }) => { + data = props.schema.data; + return null; + }); + const selections: unknown[] = []; + const src = { + selections, + queryDataset: vi.fn(async (_dataset: string, selection: unknown) => { + selections.push(selection); + return { + rows: MONTHS, + fields: [{ name: 'close_date', type: 'date' }, { name: 'amount', type: 'number', aggregate: 'sum' }], + }; + }), + }; + const { apiFetch } = makeApiFetch([{ name: 'close_date', type: 'date' }]); + const { unmount } = renderReport( + { + ...BASE, + rows: ['close_date'], + chart: { type: 'line', xAxis: 'close_date', yAxis: 'amount', ...(showEmptyGroups ? { showEmptyGroups } : {}) }, + dateRange: { dimension: 'close_date', defaultRange: 'last_90_days' }, + }, + src as unknown as ReturnType, + apiFetch, + ); + await waitFor(() => expect(Array.isArray(data) && (data as unknown[]).length).toBe(3)); + runs.push({ selections: [...selections], data }); + unmount(); + } + expect(runs[1].selections).toEqual(runs[0].selections); + expect(runs[0].selections.every((s) => JSON.stringify((s as { timeDimensions?: unknown }).timeDimensions) === JSON.stringify([{ dimension: 'close_date', dateRange: 'last_90_days' }]))).toBe(true); + expect(runs[1].data).toEqual(runs[0].data); + expect(runs[1].data).toEqual(MONTHS); + }); +}); diff --git a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.test.tsx b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.test.tsx index 5574d2d0565..907caf9776a 100644 --- a/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.test.tsx +++ b/ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.test.tsx @@ -19,10 +19,11 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react'; import '@testing-library/jest-dom'; import { I18nProvider } from '@object-ui/i18n'; +import { ComponentRegistry } from '@object-ui/core'; import { DatasetReportRenderer, isDatasetReport } from '../DatasetReportRenderer'; type MockRows = Array>; -type MockField = { name: string; type?: string; label?: string; format?: string; currency?: string }; +type MockField = { name: string; type?: string; label?: string; format?: string; currency?: string; aggregate?: string }; type MockResult = { rows: MockRows; fields?: MockField[]; @@ -1466,3 +1467,162 @@ describe('DatasetReportRenderer — drilling a relationship-path dimension (obje warn.mockRestore(); }); }); + +/** + * objectstack#36722 — `chart.showEmptyGroups`: the report chart adds the x-axis + * field's DECLARED options the dataset answer left out, valued by the + * executor's empty-group table (`emptyGroupValueFor`): `0` for count and sum, + * empty for avg. The answer below is server-resolved to the authored label + * (ADR-0021) and holds two of the four declared stages. + * + * DIRECTIONS, written before the ablation: with the call site's fill removed + * (the chart plots `state.rows` as before), every "adds" case goes RED and the + * three controls stay GREEN on both sides, on purpose. + */ +describe('DatasetReportRenderer — chart.showEmptyGroups (objectstack#36722)', () => { + const STAGES = [ + { value: 'prospecting', label: 'Prospecting' }, + { value: 'qualification', label: 'Qualification' }, + { value: 'proposal', label: 'Proposal' }, + { value: 'closed_won', label: 'Closed Won' }, + ]; + let chartSchema: { data?: Array> } | null = null; + let chartClick: ((ev: Record) => void) | undefined; + + beforeEach(() => { + chartSchema = null; + chartClick = undefined; + metaDocs.deal = { + name: 'deal', + fields: { stage: { type: 'select', options: STAGES }, region: { type: 'text' }, owner: { type: 'select', options: [{ value: 'amy', label: 'Amy' }, { value: 'bo', label: 'Bo' }] } }, + }; + ComponentRegistry.register('chart', (props: { schema: { data?: Array> }; onChartClick?: (ev: Record) => void }) => { + chartSchema = props.schema; + chartClick = props.onChartClick; + return null; + }); + }); + + const answer = (aggregate: string | undefined, extra: Partial = {}): MockResult => ({ + rows: [ + { stage: 'Closed Won', deals: 3 }, + { stage: 'Qualification', deals: 5 }, + ], + fields: [ + { name: 'stage', type: 'string', label: 'Stage' }, + { name: 'deals', type: 'number', label: 'Deals', ...(aggregate ? { aggregate } : {}) }, + ], + object: 'deal', + dimensionFields: { stage: 'stage' }, + drillRawRows: [{ stage: 'closed_won' }, { stage: 'qualification' }], + drillScopes: { deals: {} }, + ...extra, + }); + const report = (chart: Record, extra: Record = {}) => ({ + name: 'deals_by_stage', + type: 'summary', + dataset: 'deal_metrics', + rows: ['stage'], + values: ['deals'], + chart: { type: 'bar', xAxis: 'stage', yAxis: 'deals', ...chart }, + ...extra, + }); + /** The plotted categories once the option metadata has landed (the declared order moves them). */ + const plotted = async (key = 'stage') => { + await waitFor(() => expect(chartSchema?.data?.[0]?.[key]).toBe('Qualification')); + return chartSchema!.data!; + }; + + it('adds the empty declared options in their declared place, at 0 for a count', async () => { + render(); + await waitFor(() => expect(chartSchema?.data?.map((r) => r.stage)).toEqual(['Prospecting', 'Qualification', 'Proposal', 'Closed Won'])); + expect(chartSchema!.data).toEqual([ + { stage: 'Prospecting', deals: 0 }, + { stage: 'Qualification', deals: 5 }, + { stage: 'Proposal', deals: 0 }, + { stage: 'Closed Won', deals: 3 }, + ]); + }); + + it('a sum reads 0 too; an avg is left empty (nothing to average)', async () => { + const { unmount } = render(); + await waitFor(() => expect(chartSchema?.data).toHaveLength(4)); + expect(chartSchema!.data!.find((r) => r.stage === 'Proposal')).toEqual({ stage: 'Proposal', deals: 0 }); + unmount(); + chartSchema = null; + render(); + await waitFor(() => expect(chartSchema?.data).toHaveLength(4)); + const proposal = chartSchema!.data!.find((r) => r.stage === 'Proposal')!; + expect(proposal).toEqual({ stage: 'Proposal' }); + expect('deals' in proposal).toBe(false); + }); + + it('with a seriesBy split, an added stage reads 0 in every series', async () => { + const src = makeSource({ + deal_metrics: answer('count', { + rows: [ + { stage: 'Closed Won', owner: 'Amy', deals: 3 }, + { stage: 'Qualification', owner: 'Bo', deals: 5 }, + ], + dimensionFields: { stage: 'stage', owner: 'owner' }, + }), + }); + render(); + await waitFor(() => expect(chartSchema?.data).toHaveLength(4)); + const prospecting = chartSchema!.data!.find((r) => r.stage === 'Prospecting')!; + expect(Object.values(prospecting).filter((v) => typeof v === 'number')).toEqual([0, 0]); + }); + + it('a mark on an added stage opens no list; a real one still drills', async () => { + const onDrill = vi.fn(); + render(); + await waitFor(() => expect(chartSchema?.data).toHaveLength(4)); + await waitFor(() => expect(chartClick).toBeTypeOf('function')); + chartClick!({ category: 'Proposal', series: 'deals' }); + expect(onDrill).not.toHaveBeenCalled(); + chartClick!({ category: 'Qualification', series: 'deals' }); + await waitFor(() => expect(onDrill).toHaveBeenCalledTimes(1)); + }); + + it('CONTROL — switch off (absent): only the groups the answer holds', async () => { + render(); + expect((await plotted()).map((r) => r.stage)).toEqual(['Qualification', 'Closed Won']); + }); + + it('CONTROL — an order reaching the chart (a measure): not filled, the server placed every row', async () => { + const src = makeSource({ deal_metrics: answer('count') }); + render(); + await waitFor(() => expect(chartSchema?.data).toBeDefined()); + // The option read lands, and still nothing is added. + await waitFor(() => expect(probedObjects()).toContain('deal')); + await new Promise((r) => setTimeout(r, 20)); + expect(chartSchema!.data!.map((r) => r.stage)).toEqual(['Closed Won', 'Qualification']); + const chartCall = src.calls.find((c) => c.selection.dimensions?.length === 1); + expect(chartCall?.selection.order).toEqual({ deals: 'desc' }); + }); + + it('CONTROL — a field with no declared options (text): nothing to fill', async () => { + const src = makeSource({ + deal_metrics: answer('count', { + rows: [{ region: 'North', deals: 2 }], + fields: [{ name: 'region', type: 'string' }, { name: 'deals', type: 'number', aggregate: 'count' }], + dimensionFields: { region: 'region' }, + }), + }); + render(); + await waitFor(() => expect(probedObjects()).toContain('deal')); + await new Promise((r) => setTimeout(r, 20)); + expect(chartSchema!.data).toEqual([{ region: 'North', deals: 2 }]); + }); + + it('the switch is presentation only: the dataset selection posted is the same with it on or off', async () => { + const off = makeSource({ deal_metrics: answer('count') }); + const { unmount } = render(); + await waitFor(() => expect(off.calls.length).toBeGreaterThan(0)); + unmount(); + const on = makeSource({ deal_metrics: answer('count') }); + render(); + await waitFor(() => expect(on.calls.length).toBe(off.calls.length)); + expect(on.calls).toEqual(off.calls); + }); +}); diff --git a/ui/packages/plugin-report/src/__tests__/emptyOptionGroups.test.ts b/ui/packages/plugin-report/src/__tests__/emptyOptionGroups.test.ts new file mode 100644 index 00000000000..f213abcd1e3 --- /dev/null +++ b/ui/packages/plugin-report/src/__tests__/emptyOptionGroups.test.ts @@ -0,0 +1,66 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36722 — `fillEmptyOptionGroups`, the rows `chart.showEmptyGroups` + * adds. The renderer-level cases live in `DatasetReportRenderer.test.tsx` + * (describe "chart.showEmptyGroups"); these pin the walk itself. + */ +import { describe, it, expect } from 'vitest'; +import { fillEmptyOptionGroups } from '../emptyOptionGroups'; + +const OPTIONS = [ + { value: 'open', label: 'Open' }, + { value: 'won', label: 'Won' }, + { value: 'lost', label: 'Lost' }, +]; + +describe('fillEmptyOptionGroups (objectstack#36722)', () => { + it('a row may carry the stored value, the authored label or the translated label: all three count as present', () => { + const rows = [{ s: 'open', n: 1 }, { s: 'Won', n: 2 }, { s: '输', n: 3 }]; + const localized = [ + { value: 'open', label: '进行中' }, + { value: 'won', label: '赢' }, + { value: 'lost', label: '输' }, + ]; + const out = fillEmptyOptionGroups(rows, { xAxis: 's', measures: ['n'], aggregate: 'count', options: OPTIONS, localizedOptions: localized }); + expect(out).toBe(rows); + }); + + it('appends after the answer, so every index below rows.length still addresses the answer', () => { + const rows = [{ s: 'Won', n: 2 }]; + const out = fillEmptyOptionGroups(rows, { xAxis: 's', measures: ['n'], aggregate: 'count_distinct', options: OPTIONS }); + expect(out[0]).toBe(rows[0]); + expect(out.slice(1)).toEqual([{ s: 'open', n: 0 }, { s: 'lost', n: 0 }]); + }); + + it('an aggregate the answer does not state gets no value (never a guessed 0)', () => { + const out = fillEmptyOptionGroups([{ s: 'Won', n: 2 }], { xAxis: 's', measures: ['n'], aggregate: undefined, options: OPTIONS }); + expect(out.slice(1)).toEqual([{ s: 'open' }, { s: 'lost' }]); + }); + + it('min and max are left empty, like avg', () => { + for (const aggregate of ['min', 'max', 'avg']) { + const out = fillEmptyOptionGroups([{ s: 'Won', n: 2 }], { xAxis: 's', measures: ['n'], aggregate, options: OPTIONS }); + expect(out.slice(1).every((r) => !('n' in r))).toBe(true); + } + }); + + it('with a split: one row per series value the answer holds, the null series included', () => { + const rows = [{ s: 'Won', o: 'amy', n: 1 }, { s: 'Won', o: null, n: 1 }]; + const out = fillEmptyOptionGroups(rows, { xAxis: 's', seriesBy: 'o', measures: ['n'], aggregate: 'sum', options: [OPTIONS[0], OPTIONS[1]] }); + expect(out.slice(2)).toEqual([{ s: 'open', o: 'amy', n: 0 }, { s: 'open', o: null, n: 0 }]); + }); + + it('a compared measure fills its __compare column with the same value', () => { + const out = fillEmptyOptionGroups([{ s: 'Won', n: 2, n__compare: 1 }], { xAxis: 's', measures: ['n', 'n__compare'], aggregate: 'count', options: [OPTIONS[0], OPTIONS[1]] }); + expect(out.slice(1)).toEqual([{ s: 'open', n: 0, n__compare: 0 }]); + }); + + it('bare-string options, a duplicate declaration, and no options at all', () => { + expect(fillEmptyOptionGroups([{ s: 'a' }], { xAxis: 's', measures: ['n'], aggregate: 'count', options: ['a', 'b', 'b'] }).slice(1)) + .toEqual([{ s: 'b', n: 0 }]); + const rows = [{ s: 'a' }]; + expect(fillEmptyOptionGroups(rows, { xAxis: 's', measures: ['n'], aggregate: 'count', options: undefined })).toBe(rows); + expect(fillEmptyOptionGroups(rows, { xAxis: 's', measures: ['n'], aggregate: 'count', options: [] })).toBe(rows); + }); +}); From 574fc6b7a01455f4a3320ebf2476f50c32048251 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:22:35 +0000 Subject: [PATCH 05/15] feat(plugin-report): report builder switch for showing groups with no records Claude-Session: https://claude.ai/code/session_01L9qibyFBwGSJLARjP5asi3 Co-Authored-By: Claude --- ui/packages/i18n/src/locales/ar.ts | 1 + ui/packages/i18n/src/locales/de.ts | 1 + ui/packages/i18n/src/locales/en.ts | 1 + ui/packages/i18n/src/locales/es.ts | 1 + ui/packages/i18n/src/locales/fr.ts | 1 + ui/packages/i18n/src/locales/ja.ts | 1 + ui/packages/i18n/src/locales/ko.ts | 1 + ui/packages/i18n/src/locales/pt-BR.ts | 1 + ui/packages/i18n/src/locales/ru.ts | 1 + ui/packages/i18n/src/locales/zh-Hans.ts | 1 + ui/packages/i18n/src/locales/zh-Hant.ts | 1 + .../__tests__/reportBuilder-36374.test.tsx | 85 +++++++++++++++++++ .../src/builder/ReportBuilder.tsx | 16 ++++ .../src/builder/reportBuilderModel.ts | 30 +++++++ 14 files changed, 142 insertions(+) diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 87d96a73ecc..b01755aedd5 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -4469,6 +4469,7 @@ const ar = { metric: "رقم", table: "جدول", showValues: "إظهار القيم", + showEmptyGroups: "إظهار المجموعات التي لا تحتوي على سجلات", targetLine: "خط الهدف", targetLabel: "الهدف", secondLayerTableOnly: "يرسم هذا المخطط التجميع الأول؛ أما الثاني ففي القيم المحسوبة.", diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index 206431f4c31..117a9b4ff5e 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -4119,6 +4119,7 @@ const de = { metric: "Zahl", table: "Tabelle", showValues: "Werte anzeigen", + showEmptyGroups: "Gruppen ohne Datensätze anzeigen", targetLine: "Ziellinie", targetLabel: "Ziel", secondLayerTableOnly: "Dieses Diagramm zeigt die erste Gruppierung; die zweite steht in den berechneten Werten.", diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index c74f15dd6ee..05d3bb620bc 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -2290,6 +2290,7 @@ const en = { metric: 'Number', table: 'Table', showValues: 'Show values', + showEmptyGroups: 'Show groups with no records', targetLine: 'Target line', targetLabel: 'Target', secondLayerTableOnly: 'This chart draws the first grouping; the second is in the computed values.', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index f0d03c893dd..c8f1e2a7746 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -4207,6 +4207,7 @@ const es = { metric: "Número", table: "Tabla", showValues: "Mostrar valores", + showEmptyGroups: "Mostrar grupos sin registros", targetLine: "Línea objetivo", targetLabel: "Objetivo", secondLayerTableOnly: "Este gráfico dibuja la primera agrupación; la segunda está en los valores calculados.", diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index f5a28722d08..423254cca15 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -4203,6 +4203,7 @@ const fr = { metric: "Nombre", table: "Tableau", showValues: "Afficher les valeurs", + showEmptyGroups: "Afficher les groupes sans enregistrements", targetLine: "Ligne d’objectif", targetLabel: "Objectif", secondLayerTableOnly: "Ce graphique trace le premier regroupement ; le second figure dans les valeurs calculées.", diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 52ccf63a4c3..7502236a8f1 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -4121,6 +4121,7 @@ const ja = { metric: "数値", table: "表", showValues: "値を表示", + showEmptyGroups: "レコードのないグループを表示", targetLine: "目標線", targetLabel: "目標", secondLayerTableOnly: "このグラフは最初のグループ化のみを描画します。2 つ目は計算値にあります。", diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index eb69abda7e1..ffc6e3734ed 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -4118,6 +4118,7 @@ const ko = { metric: "숫자", table: "표", showValues: "값 표시", + showEmptyGroups: "레코드가 없는 그룹 표시", targetLine: "목표선", targetLabel: "목표", secondLayerTableOnly: "이 차트는 첫 번째 그룹화만 그립니다. 두 번째는 계산 값에 있습니다.", diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 83346ee342f..0883b0312a2 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -4202,6 +4202,7 @@ const pt = { metric: "Número", table: "Tabela", showValues: "Mostrar valores", + showEmptyGroups: "Mostrar grupos sem registros", targetLine: "Linha de meta", targetLabel: "Meta", secondLayerTableOnly: "Este gráfico desenha o primeiro agrupamento; o segundo está nos valores calculados.", diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 2ff2cecf2d7..f7a47fd5d76 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -4304,6 +4304,7 @@ const ru = { metric: "Число", table: "Таблица", showValues: "Показывать значения", + showEmptyGroups: "Показывать группы без записей", targetLine: "Целевая линия", targetLabel: "Цель", secondLayerTableOnly: "Эта диаграмма показывает первую группировку; вторая — в вычисленных значениях.", diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index ac9f5e1d946..ef789c02c95 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -1924,6 +1924,7 @@ const zh = { metric: '数字', table: '表格', showValues: '显示数值', + showEmptyGroups: '显示数量为 0 的分组', targetLine: '目标线', targetLabel: '目标', secondLayerTableOnly: '这种图只画第一层分组,第二层在计算值里。', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index 7750c385c1f..abaa7ab0dd6 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -1924,6 +1924,7 @@ const zhHant = { metric: '數字', table: '表格', showValues: '顯示數值', + showEmptyGroups: '顯示數量為 0 的分組', targetLine: '目標線', targetLabel: '目標', secondLayerTableOnly: '這種圖只畫第一層分組,第二層在計算值裡。', diff --git a/ui/packages/plugin-report/src/__tests__/reportBuilder-36374.test.tsx b/ui/packages/plugin-report/src/__tests__/reportBuilder-36374.test.tsx index df2c4a10c5a..0bbc71eaf77 100644 --- a/ui/packages/plugin-report/src/__tests__/reportBuilder-36374.test.tsx +++ b/ui/packages/plugin-report/src/__tests__/reportBuilder-36374.test.tsx @@ -20,8 +20,10 @@ import { pickDataset, pickGrouping, pickMeasure, + setShowEmptyGroups, setShowValues, setTargetLine, + showsEmptyGroups, targetLine, type ReportBuilderMembers, type ReportDraft, @@ -400,3 +402,86 @@ describe('the report filter under the data source (objectstack#36645)', () => { expect(same.runtimeFilter).toEqual({ stage: { $eq: 'won' } }); }); }); + +/** + * objectstack#36722 — "Show groups with no records" (`chart.showEmptyGroups`): a switch + * in the chart settings, offered on the chart types that draw a category per + * group, written into the report the host saves and read back when it opens. + */ +describe('the show-groups-with-no-records switch (objectstack#36722)', () => { + beforeEach(() => { + ComponentRegistry.register('chart', () =>
); + }); + afterEach(() => { + cleanup(); + vi.restoreAllMocks(); + }); + + const box = (value = '') => ({ value, onChange: () => {} }); + const dataSource = { queryDataset: vi.fn(async () => ({ rows: [{ stage: 'Won', total_amount: 10 }], fields: [] })) }; + + /** The console host's shape: it saves the draft it holds when Save is pressed. */ + function SaveHarness({ initial, saved }: { initial: ReportDraft; saved: ReportDraft[] }) { + const [report, setReport] = React.useState(initial); + return ( + { saved.push(report); }} + onDiscard={() => setReport(initial)} + onClose={() => {}} + dirty={report !== initial} + dataSource={dataSource} + /> + ); + } + + it('turned on, it is in the report Save hands over; reopened, the switch reads on; off removes the key', () => { + const saved: ReportDraft[] = []; + const { unmount } = render(); + const toggle = screen.getByTestId('report-builder-show-empty-groups'); + expect(toggle).toHaveAttribute('aria-checked', 'false'); + fireEvent.click(toggle); + fireEvent.click(screen.getByTestId('report-builder-save')); + expect(saved).toHaveLength(1); + expect(saved[0].chart).toEqual({ ...(EXISTING.chart as object), showEmptyGroups: true }); + expectSpecValid(saved[0]); + unmount(); + + render(); + const reopened = screen.getByTestId('report-builder-show-empty-groups'); + expect(reopened).toHaveAttribute('aria-checked', 'true'); + fireEvent.click(reopened); + fireEvent.click(screen.getByTestId('report-builder-save')); + expect(saved[1].chart).toEqual(EXISTING.chart); + expect(saved[1].chart).not.toHaveProperty('showEmptyGroups'); + }); + + it('offered on bar, line and donut only; a number or a table drops the key', () => { + render(); + for (const type of ['line', 'donut', 'bar']) { + fireEvent.click(screen.getByTestId(`report-builder-chart-${type}`)); + expect(screen.getByTestId('report-builder-show-empty-groups')).toHaveAttribute('aria-checked', 'true'); + } + fireEvent.click(screen.getByTestId('report-builder-chart-metric')); + expect(screen.queryByTestId('report-builder-show-empty-groups')).toBeNull(); + }); + + it('the model: every chart edit keeps it where it draws, and drops it where it cannot', () => { + const on = setShowEmptyGroups(EXISTING, true); + expect(showsEmptyGroups(on)).toBe(true); + expect(showsEmptyGroups(pickGrouping(on, 'owner', '', MEMBERS))).toBe(true); + expect(showsEmptyGroups(pickMeasure(on, 'deal_count', MEMBERS))).toBe(true); + expect(showsEmptyGroups(pickChartType(on, 'line', MEMBERS))).toBe(true); + expect(pickChartType(on, 'metric', MEMBERS).chart).not.toHaveProperty('showEmptyGroups'); + expect(pickChartType(on, 'table', MEMBERS)).not.toHaveProperty('chart'); + expect(setShowEmptyGroups(on, false).chart).toEqual(EXISTING.chart); + // No chart to set it on: the report is returned as it is. + const noChart = { ...EXISTING, chart: undefined }; + expect(setShowEmptyGroups(noChart, true)).toBe(noChart); + }); +}); diff --git a/ui/packages/plugin-report/src/builder/ReportBuilder.tsx b/ui/packages/plugin-report/src/builder/ReportBuilder.tsx index a7ebdaaee46..b956e837bd6 100644 --- a/ui/packages/plugin-report/src/builder/ReportBuilder.tsx +++ b/ui/packages/plugin-report/src/builder/ReportBuilder.tsx @@ -46,6 +46,7 @@ import { REPORT_BUILDER_CHART_TYPES, boundDataset, chartSplits, + chartShowsEmptyGroups, chartTakesTargetLine, fillDefaults, missingPiece, @@ -57,7 +58,9 @@ import { selectedGrouping, selectedMeasure, setShowValues, + setShowEmptyGroups, setTargetLine, + showsEmptyGroups, targetLine, type ReportBuilderDataset, type ReportBuilderMembers, @@ -505,6 +508,19 @@ export function ReportBuilder({ />
) : null} + {chartShowsEmptyGroups(chartType) ? ( +
+ + onChange(setShowEmptyGroups(report, on))} + data-testid="report-builder-show-empty-groups" + /> +
+ ) : null} {chartTakesTargetLine(chartType) ? (
) : null} - {chartShowsEmptyGroups(chartType) ? ( + {offersShowEmptyGroups(report, members) ? (