|
1 | | -import { ITableWidgetColumnGroups, ITableWidgetConditionalStyles, ITableWidgetConfiguration, IWidgetCrossNavigation, ITableWidgetHeaders, IWidgetInteractions, IWidgetSelection, ITableWidgetSettings, ITableWidgetVisualization, IWidget, IWidgetColumn, ITableWidgetTooltipStyle, ITableWidgetColumnStyles } from '../../../../Dashboard' |
2 | | - |
3 | | -const columnIdNameMap = {} |
| 1 | +import { ITableWidgetColumnGroups, ITableWidgetConditionalStyles, ITableWidgetConfiguration, IWidgetCrossNavigation, ITableWidgetHeaders, IWidgetInteractions, IWidgetSelection, ITableWidgetSettings, ITableWidgetVisualization, IWidget, ITableWidgetTooltipStyle, ITableWidgetColumnStyles } from '../../../../Dashboard' |
4 | 2 |
|
5 | 3 | export function formatTableWidgetForSave(widget: IWidget) { |
6 | 4 | if (!widget) return |
7 | 5 |
|
8 | | - loadColumnIdNameMap(widget) |
9 | | - formatTableSelectedColumns(widget.columns) |
| 6 | + // Per-column settings (styles, precision, alignment, visualization types, tooltips, |
| 7 | + // column groups, header rules, sorting, selection, cross navigation) are persisted |
| 8 | + // using the column's stable `id`, NOT its physical field name (`columnName`). |
| 9 | + // |
| 10 | + // The id is what keeps two columns built from the SAME field distinct — e.g. the same |
| 11 | + // UNIT_SALES field used as two measures with different aggregations/aliases. Collapsing |
| 12 | + // targets to columnName merged those columns together on reload, so styles were shared |
| 13 | + // and one alias overwrote the other. We therefore keep `column.id` on the saved model |
| 14 | + // (see addColumnIdsToWidgetColumns / formatDashboardTableWidgetAfterLoading on load). |
10 | 15 | formatTableSettings(widget.settings) |
11 | 16 | } |
12 | 17 |
|
13 | | -function formatTableSelectedColumns(columns: IWidgetColumn[]) { |
14 | | - if (!columns) return |
15 | | - columns.forEach((column: IWidgetColumn) => { |
16 | | - delete column.id |
17 | | - }) |
18 | | -} |
19 | | - |
20 | | -const loadColumnIdNameMap = (widget: IWidget) => { |
21 | | - widget.columns?.forEach((column: IWidgetColumn) => { |
22 | | - if (column.id) columnIdNameMap[column.id] = column.columnName |
23 | | - }) |
24 | | -} |
25 | | - |
| 18 | +// Targets already reference the column `id` in the in-memory model, so persistence is an |
| 19 | +// identity mapping. Kept as a single indirection point so the save/load token format stays |
| 20 | +// symmetric with getColumnId() in TableWidgetFunctions.ts. |
26 | 21 | const getColumnName = (columnId: string) => { |
27 | | - return columnId ? columnIdNameMap[columnId] : '' |
| 22 | + return columnId || '' |
28 | 23 | } |
29 | 24 |
|
30 | 25 | const formatTableSettings = (widgetSettings: ITableWidgetSettings) => { |
|
0 commit comments