Skip to content

Commit cfc5332

Browse files
committed
fix column config retention
1 parent db3ab50 commit cfc5332

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

x-pack/plugins/lens/public/datatable_visualization/visualization.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@ describe('Datatable Visualization', () => {
107107
expect(suggestions.length).toBeGreaterThan(0);
108108
});
109109

110+
it('should retain width and hidden config from existing state', () => {
111+
const suggestions = datatableVisualization.getSuggestions({
112+
state: {
113+
layerId: 'first',
114+
columns: [
115+
{ columnId: 'col1', width: 123 },
116+
{ columnId: 'col2', hidden: true },
117+
],
118+
},
119+
table: {
120+
isMultiRow: true,
121+
layerId: 'first',
122+
changeType: 'initial',
123+
columns: [numCol('col1'), strCol('col2'), strCol('col3')],
124+
},
125+
keptLayerIds: [],
126+
});
127+
128+
expect(suggestions.length).toBeGreaterThan(0);
129+
expect(suggestions[0].state.columns).toEqual([
130+
{ columnId: 'col1', width: 123 },
131+
{ columnId: 'col2', hidden: true },
132+
{ columnId: 'col3' },
133+
]);
134+
});
135+
110136
it('should not make suggestions when the table is unchanged', () => {
111137
const suggestions = datatableVisualization.getSuggestions({
112138
state: {

x-pack/plugins/lens/public/datatable_visualization/visualization.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export const datatableVisualization: Visualization<DatatableVisualizationState>
9797
) {
9898
return [];
9999
}
100+
const oldColumnSettings: Record<string, ColumnState> = {};
101+
if (state) {
102+
state.columns.forEach((column) => {
103+
oldColumnSettings[column.columnId] = column;
104+
});
105+
}
100106
const title =
101107
table.changeType === 'unchanged'
102108
? i18n.translate('xpack.lens.datatable.suggestionLabel', {
@@ -126,7 +132,10 @@ export const datatableVisualization: Visualization<DatatableVisualizationState>
126132
score: (Math.min(table.columns.length, 10) / 10) * 0.4,
127133
state: {
128134
layerId: table.layerId,
129-
columns: table.columns.map((col) => ({ columnId: col.columnId })),
135+
columns: table.columns.map((col) => ({
136+
...(oldColumnSettings[col.columnId] || {}),
137+
columnId: col.columnId,
138+
})),
130139
},
131140
previewIcon: LensIconChartDatatable,
132141
// tables are hidden from suggestion bar, but used for drag & drop and chart switching

0 commit comments

Comments
 (0)