@platforma-sdk/model 1.88.16 → 1.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/columns/columns_collection.cjs +18 -0
- package/dist/columns/columns_collection.cjs.map +1 -1
- package/dist/columns/columns_collection.d.ts +21 -1
- package/dist/columns/columns_collection.d.ts.map +1 -1
- package/dist/columns/columns_collection.js +18 -0
- package/dist/columns/columns_collection.js.map +1 -1
- package/dist/columns/index.d.ts +2 -2
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.cjs +20 -5
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.js +21 -6
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs +28 -23
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js +29 -23
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js.map +1 -1
- package/dist/components/PlDataTable/state-migration.cjs +25 -1
- package/dist/components/PlDataTable/state-migration.cjs.map +1 -1
- package/dist/components/PlDataTable/state-migration.d.ts +31 -6
- package/dist/components/PlDataTable/state-migration.d.ts.map +1 -1
- package/dist/components/PlDataTable/state-migration.js +25 -1
- package/dist/components/PlDataTable/state-migration.js.map +1 -1
- package/dist/components/PlDataTable/tableParams.cjs +156 -0
- package/dist/components/PlDataTable/tableParams.cjs.map +1 -0
- package/dist/components/PlDataTable/tableParams.js +152 -0
- package/dist/components/PlDataTable/tableParams.js.map +1 -0
- package/dist/components/PlDataTable/typesV8.d.ts +12 -9
- package/dist/components/PlDataTable/typesV8.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +7 -7
- package/src/columns/__test_helpers__/collection_driver.ts +3 -0
- package/src/columns/columns_collection.test.ts +47 -0
- package/src/columns/columns_collection.ts +33 -0
- package/src/components/PlDataTable/createPlDataTable/createPlDataTableV2.ts +35 -6
- package/src/components/PlDataTable/createPlDataTable/createPlDataTableV3.ts +38 -23
- package/src/components/PlDataTable/state-migration.test.ts +26 -26
- package/src/components/PlDataTable/state-migration.ts +75 -11
- package/src/components/PlDataTable/tableParams.test.ts +291 -0
- package/src/components/PlDataTable/tableParams.ts +243 -0
- package/src/components/PlDataTable/typesV8.ts +18 -17
- package/src/components/PlDataTable/createPlDataTable/createPlDataTableV3.test.ts +0 -61
|
@@ -30,7 +30,14 @@ import type { PlDataTableStateV2 } from "../state-migration";
|
|
|
30
30
|
import { getMatchingLabelColumns } from "../labels";
|
|
31
31
|
import { collectFilterSpecColumns, traverseFilterSpec } from "../../../filters/traverse";
|
|
32
32
|
import { createPTableDefV2 } from "./createPTableDefV2";
|
|
33
|
-
import { isColumnOptional } from "./utils";
|
|
33
|
+
import { isColumnHidden, isColumnOptional } from "./utils";
|
|
34
|
+
import {
|
|
35
|
+
collectSearchColumns,
|
|
36
|
+
createSearchFilter,
|
|
37
|
+
createSheetFilters,
|
|
38
|
+
joinFilters,
|
|
39
|
+
readPlDataTableUserParams,
|
|
40
|
+
} from "../tableParams";
|
|
34
41
|
import { DataColumn } from "../../../columns";
|
|
35
42
|
import { createColumnResolver, type ColumnResolver } from "../columnResolver";
|
|
36
43
|
import { isNil, type Nil } from "@milaboratories/helpers";
|
|
@@ -61,7 +68,7 @@ export function createPlDataTableV2<A, U>(
|
|
|
61
68
|
): PlDataTableModel | undefined {
|
|
62
69
|
if (columns.length === 0) return undefined;
|
|
63
70
|
|
|
64
|
-
const
|
|
71
|
+
const params = readPlDataTableUserParams(upgradePlDataTableStateV2(tableState));
|
|
65
72
|
const allLabelColumns = getAllLabelColumns(ctx.resultPool) ?? [];
|
|
66
73
|
|
|
67
74
|
let fullLabelColumns = getMatchingLabelColumns(columns, allLabelColumns);
|
|
@@ -84,8 +91,30 @@ export function createPlDataTableV2<A, U>(
|
|
|
84
91
|
|
|
85
92
|
const resolver = createColumnResolver(fullColumns.map((c) => DataColumn.fromColumn(c)));
|
|
86
93
|
|
|
94
|
+
const searchFilter = createSearchFilter(
|
|
95
|
+
params.searchString,
|
|
96
|
+
collectSearchColumns({
|
|
97
|
+
columns: fullColumns.map((c) => ({
|
|
98
|
+
id: c.id,
|
|
99
|
+
spec: c.spec,
|
|
100
|
+
visibility: isColumnHidden(c.spec)
|
|
101
|
+
? "hidden"
|
|
102
|
+
: isColumnOptional(c.spec)
|
|
103
|
+
? "optional"
|
|
104
|
+
: "default",
|
|
105
|
+
})),
|
|
106
|
+
isAxisHidden: (axis) => isColumnHidden(axis),
|
|
107
|
+
sheetAxes: params.sheetsState.map((sheet) => sheet.axisId),
|
|
108
|
+
hiddenColIds: params.hiddenColIds,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
|
|
87
112
|
// -- Filtering: rewrite via resolver, throw if any reference is unresolved --
|
|
88
|
-
const rawFilters =
|
|
113
|
+
const rawFilters = joinFilters([
|
|
114
|
+
...createSheetFilters(params.sheetsState),
|
|
115
|
+
params.userFilters,
|
|
116
|
+
searchFilter,
|
|
117
|
+
]);
|
|
89
118
|
const rawDefaultFilters = options?.filters ?? undefined;
|
|
90
119
|
const filters = remapFiltersThrowing(rawFilters, resolver, "filter");
|
|
91
120
|
const defaultFilters = remapFiltersThrowing(
|
|
@@ -95,7 +124,7 @@ export function createPlDataTableV2<A, U>(
|
|
|
95
124
|
);
|
|
96
125
|
|
|
97
126
|
// -- Sorting: rewrite via resolver, throw if any reference is unresolved --
|
|
98
|
-
const userSorting =
|
|
127
|
+
const userSorting = params.sorting;
|
|
99
128
|
const rawSorting = (isNil(userSorting) ? options?.sorting : userSorting) ?? [];
|
|
100
129
|
const sorting = remapSortingThrowing(rawSorting, resolver);
|
|
101
130
|
|
|
@@ -118,7 +147,7 @@ export function createPlDataTableV2<A, U>(
|
|
|
118
147
|
// Inner join works as a filter - all columns must be present
|
|
119
148
|
if (coreJoinType === "inner") return [];
|
|
120
149
|
|
|
121
|
-
const hiddenColIds =
|
|
150
|
+
const hiddenColIds = params.hiddenColIds;
|
|
122
151
|
if (hiddenColIds !== null) {
|
|
123
152
|
return hiddenColIds
|
|
124
153
|
.filter((s): s is PTableColumnIdColumn => s.type === "column")
|
|
@@ -176,7 +205,7 @@ export function createPlDataTableV2<A, U>(
|
|
|
176
205
|
if (!visibleHandle) return undefined;
|
|
177
206
|
|
|
178
207
|
return {
|
|
179
|
-
sourceId:
|
|
208
|
+
sourceId: params.sourceId,
|
|
180
209
|
fullTableHandle: fullHandle,
|
|
181
210
|
fullPframeHandle: pframeHandle,
|
|
182
211
|
visibleTableHandle: visibleHandle,
|
|
@@ -25,6 +25,13 @@ import type {
|
|
|
25
25
|
} from "../typesV8";
|
|
26
26
|
import { upgradePlDataTableStateV2 } from "../state-migration";
|
|
27
27
|
import type { PlDataTableStateV2 } from "../state-migration";
|
|
28
|
+
import {
|
|
29
|
+
collectSearchColumns,
|
|
30
|
+
createSearchFilter,
|
|
31
|
+
createSheetFilters,
|
|
32
|
+
joinFilters,
|
|
33
|
+
readPlDataTableUserParams,
|
|
34
|
+
} from "../tableParams";
|
|
28
35
|
import type { MatchingMode } from "@milaboratories/pl-model-common";
|
|
29
36
|
import {
|
|
30
37
|
hasSingleDataColumn,
|
|
@@ -105,7 +112,7 @@ export function createPlDataTableV3<A, U>(
|
|
|
105
112
|
ctx: RenderCtxBase<A, U>,
|
|
106
113
|
options: createPlDataTableOptionsV3,
|
|
107
114
|
): PlDataTableModel | undefined {
|
|
108
|
-
const
|
|
115
|
+
const params = readPlDataTableUserParams(upgradePlDataTableStateV2(options.tableState));
|
|
109
116
|
const primaryJoinType = options.primaryJoinType ?? "full";
|
|
110
117
|
|
|
111
118
|
const resolved = resolveInputColumns(ctx, options);
|
|
@@ -148,17 +155,39 @@ export function createPlDataTableV3<A, U>(
|
|
|
148
155
|
...linked.flatMap((lc) => [...collectLinkerColumns(lc), lc]),
|
|
149
156
|
]);
|
|
150
157
|
|
|
158
|
+
const tableColumns = [...primary, ...direct, ...linked];
|
|
159
|
+
// The table shows only the axes of its primary columns.
|
|
160
|
+
const primaryAxisKeys = new Set(
|
|
161
|
+
primary.flatMap((c) => c.getSpec().axesSpec.map((a) => canonicalizeAxisId(a))),
|
|
162
|
+
);
|
|
163
|
+
const searchFilter = createSearchFilter(
|
|
164
|
+
params.searchString,
|
|
165
|
+
collectSearchColumns({
|
|
166
|
+
columns: tableColumns.map((c) => ({
|
|
167
|
+
id: c.id,
|
|
168
|
+
spec: c.getSpec(),
|
|
169
|
+
visibility: getEffectiveVisibility(toRuleColumn(c), visibilityByColId) ?? "default",
|
|
170
|
+
})),
|
|
171
|
+
isAxisHidden: (axis) =>
|
|
172
|
+
!primaryAxisKeys.has(canonicalizeAxisId(axis)) || isColumnHidden(axis),
|
|
173
|
+
sheetAxes: params.sheetsState.map((sheet) => sheet.axisId),
|
|
174
|
+
hiddenColIds: params.hiddenColIds,
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
|
|
151
178
|
const remapedDefaultFilters = remapFilterColumnIds(options.filters, resolver);
|
|
152
179
|
const filters = filterFilters(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
180
|
+
joinFilters([
|
|
181
|
+
...createSheetFilters(params.sheetsState),
|
|
182
|
+
params.userFilters,
|
|
183
|
+
searchFilter,
|
|
184
|
+
params.defaultFilters ?? remapedDefaultFilters,
|
|
185
|
+
]),
|
|
157
186
|
resolver,
|
|
158
187
|
);
|
|
159
188
|
|
|
160
189
|
const sorting = filterSorting(
|
|
161
|
-
resolveSorting(
|
|
190
|
+
resolveSorting(params.sorting, remapSortingColumnIds(options.sorting, resolver)),
|
|
162
191
|
resolver,
|
|
163
192
|
);
|
|
164
193
|
|
|
@@ -184,13 +213,12 @@ export function createPlDataTableV3<A, U>(
|
|
|
184
213
|
]),
|
|
185
214
|
);
|
|
186
215
|
|
|
187
|
-
const hiddenSpecs = state.pTableParams.hiddenColIds;
|
|
188
216
|
const hiddenColumnIds = computeHiddenColumns({
|
|
189
|
-
columns:
|
|
217
|
+
columns: tableColumns,
|
|
190
218
|
visibilityByColId,
|
|
191
219
|
sorting,
|
|
192
220
|
filters,
|
|
193
|
-
hiddenSpecs,
|
|
221
|
+
hiddenSpecs: params.hiddenColIds,
|
|
194
222
|
});
|
|
195
223
|
|
|
196
224
|
const visible = {
|
|
@@ -221,7 +249,7 @@ export function createPlDataTableV3<A, U>(
|
|
|
221
249
|
});
|
|
222
250
|
|
|
223
251
|
return {
|
|
224
|
-
sourceId:
|
|
252
|
+
sourceId: params.sourceId,
|
|
225
253
|
fullTableHandle: fullHandle,
|
|
226
254
|
fullPframeHandle: pframeHandle,
|
|
227
255
|
visibleTableHandle: visibleHandle,
|
|
@@ -412,19 +440,6 @@ function filterFilters(
|
|
|
412
440
|
return prune(filters) as Nil | PlDataTableFilters;
|
|
413
441
|
}
|
|
414
442
|
|
|
415
|
-
/** Merge two filter trees into one AND-combined tree. Returns the non-nil one if the other is nil.
|
|
416
|
-
* Exported for unit testing. */
|
|
417
|
-
export function concatFilters(
|
|
418
|
-
a: Nil | PlDataTableFilters,
|
|
419
|
-
b: Nil | PlDataTableFilters,
|
|
420
|
-
): Nil | PlDataTableFilters {
|
|
421
|
-
if (isNil(a)) return b;
|
|
422
|
-
if (isNil(b)) return a;
|
|
423
|
-
const operands = (f: PlDataTableFilters): PlDataTableFilterNode[] =>
|
|
424
|
-
f.type === "and" ? f.filters : [f as PlDataTableFilterNode];
|
|
425
|
-
return { type: "and", filters: [...operands(a), ...operands(b)] };
|
|
426
|
-
}
|
|
427
|
-
|
|
428
443
|
/** Pick user sorting from state if set, otherwise fall back to options default.
|
|
429
444
|
* null = user has not touched sorting → use default;
|
|
430
445
|
* [] = user has explicitly cleared sorting → no sorting (default ignored). */
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
upgradeLegacyColumnId,
|
|
12
12
|
upgradePlDataTableStateV2,
|
|
13
13
|
} from "./state-migration";
|
|
14
|
-
import type {
|
|
14
|
+
import type { PlDataTableFiltersWithMeta, PlTableColumnIdJson } from "./typesV8";
|
|
15
15
|
|
|
16
16
|
// Leaf ids as a result-pool export names them; the form did not change in the rework.
|
|
17
17
|
const property = createGlobalPObjectId(
|
|
@@ -51,7 +51,9 @@ const ROW_NUMBER: PlTableColumnIdJson = canonicalizeJson(
|
|
|
51
51
|
"##RowNumberColumnId##",
|
|
52
52
|
) as PlTableColumnIdJson;
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
type StoredParams = PlDataTableStateV2V8["pTableParams"];
|
|
55
|
+
|
|
56
|
+
function params(over: Partial<Extract<StoredParams, { sourceId: string }>>): StoredParams {
|
|
55
57
|
return {
|
|
56
58
|
sourceId: '"static"',
|
|
57
59
|
hiddenColIds: null,
|
|
@@ -63,8 +65,9 @@ function params(over: Partial<Extract<PTableParamsV2, { sourceId: string }>>): P
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
function v8(
|
|
66
|
-
pTableParams:
|
|
68
|
+
pTableParams: StoredParams,
|
|
67
69
|
gridColIds: PlTableColumnIdJson[] = [],
|
|
70
|
+
filtersState: null | PlDataTableFiltersWithMeta = null,
|
|
68
71
|
): PlDataTableStateV2V8 {
|
|
69
72
|
return {
|
|
70
73
|
version: 8,
|
|
@@ -77,7 +80,7 @@ function v8(
|
|
|
77
80
|
columnVisibility: { hiddenColIds: gridColIds.slice(1) },
|
|
78
81
|
},
|
|
79
82
|
sheetsState: [],
|
|
80
|
-
filtersState
|
|
83
|
+
filtersState,
|
|
81
84
|
defaultFiltersState: null,
|
|
82
85
|
},
|
|
83
86
|
],
|
|
@@ -85,10 +88,10 @@ function v8(
|
|
|
85
88
|
};
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
/** The upgraded settings of the source the state points at. */
|
|
92
|
+
const shownEntryOf = (state: PlDataTableStateV2) => upgradePlDataTableStateV2(state).stateCache[0];
|
|
93
|
+
|
|
94
|
+
const sortingOf = (state: PlDataTableStateV2) => shownEntryOf(state).sorting;
|
|
92
95
|
|
|
93
96
|
describe("upgradeLegacyColumnId", () => {
|
|
94
97
|
test("a pre-rework direct hit takes its own id", () => {
|
|
@@ -163,8 +166,7 @@ describe("v8 -> v9", () => {
|
|
|
163
166
|
|
|
164
167
|
test("hidden columns are rewritten and unconvertible ones dropped", () => {
|
|
165
168
|
const state = v8(params({ hiddenColIds: [col(legacyLinked), col(legacyFiltered)] }));
|
|
166
|
-
|
|
167
|
-
expect(p.hiddenColIds).toEqual([col(currentLinked as ColumnUniversalId)]);
|
|
169
|
+
expect(shownEntryOf(state).hiddenColIds).toEqual([col(currentLinked as ColumnUniversalId)]);
|
|
168
170
|
});
|
|
169
171
|
|
|
170
172
|
test("grid column ids are rewritten, the row-number column kept", () => {
|
|
@@ -177,31 +179,29 @@ describe("v8 -> v9", () => {
|
|
|
177
179
|
});
|
|
178
180
|
|
|
179
181
|
test("filter leaves are rewritten; a group emptied by dropped leaves goes", () => {
|
|
180
|
-
const
|
|
182
|
+
const filtersState: PlDataTableFiltersWithMeta = {
|
|
183
|
+
id: 1,
|
|
181
184
|
type: "and",
|
|
182
185
|
filters: [
|
|
183
|
-
{ type: "isNA", column: col(legacyDirect) },
|
|
184
|
-
{ type: "or", filters: [{ type: "isNotNA", column: col(legacyAnchored) }] },
|
|
186
|
+
{ id: 2, type: "isNA", column: col(legacyDirect) },
|
|
187
|
+
{ id: 3, type: "or", filters: [{ id: 4, type: "isNotNA", column: col(legacyAnchored) }] },
|
|
185
188
|
],
|
|
186
189
|
};
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
expect(shownEntryOf(v8(params({}), [], filtersState)).filtersState).toEqual({
|
|
191
|
+
id: 1,
|
|
189
192
|
type: "and",
|
|
190
|
-
filters: [{ type: "isNA", column: col(currentDirect as ColumnUniversalId) }],
|
|
193
|
+
filters: [{ id: 2, type: "isNA", column: col(currentDirect as ColumnUniversalId) }],
|
|
191
194
|
});
|
|
192
195
|
});
|
|
193
196
|
|
|
194
197
|
test("a state with current ids comes through unchanged", () => {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
);
|
|
202
|
-
const { version: _, ...rest } = upgradePlDataTableStateV2(state);
|
|
203
|
-
const { version: __, ...expected } = state;
|
|
204
|
-
expect(rest).toEqual(expected);
|
|
198
|
+
const hiddenColIds = [col(currentLinked as ColumnUniversalId)];
|
|
199
|
+
const sorting = [{ column: col(property), ascending: true, naAndAbsentAreLeastValues: false }];
|
|
200
|
+
const state = v8(params({ hiddenColIds, sorting }), [
|
|
201
|
+
ROW_NUMBER,
|
|
202
|
+
colIdJson(currentDirect as ColumnUniversalId),
|
|
203
|
+
]);
|
|
204
|
+
expect(shownEntryOf(state)).toEqual({ ...state.stateCache[0], sorting, hiddenColIds });
|
|
205
205
|
});
|
|
206
206
|
|
|
207
207
|
test("a fresh state is already v9", () => {
|
|
@@ -161,17 +161,47 @@ export type PlDataTableStateV2 =
|
|
|
161
161
|
// v7 still had filter leaves serialised as `CanonicalizedJson<PTableColumnId>`
|
|
162
162
|
// strings and `sorting: []` for the "untouched" case.
|
|
163
163
|
| PlDataTableStateV2V7
|
|
164
|
-
// v8
|
|
165
|
-
//
|
|
164
|
+
// v8 may still hold column ids written before the column-access rework (see
|
|
165
|
+
// `upgradeLegacyColumnId`).
|
|
166
166
|
| PlDataTableStateV2V8
|
|
167
|
+
// v9 as stored before the model read the source's entry itself, with that
|
|
168
|
+
// entry's settings also translated into pTableParams.
|
|
169
|
+
| PlDataTableStateV2V9
|
|
167
170
|
// Normalized state
|
|
168
171
|
| PlDataTableStateV2Normalized;
|
|
169
172
|
|
|
170
|
-
/** v8 state:
|
|
171
|
-
export type PlDataTableStateV2V8 =
|
|
172
|
-
|
|
173
|
+
/** v8 state: column ids not yet checked for the pre-rework form. */
|
|
174
|
+
export type PlDataTableStateV2V8 = StoredStateV8<8>;
|
|
175
|
+
|
|
176
|
+
/** v9 state as stored before the model read the source's entry itself. */
|
|
177
|
+
export type PlDataTableStateV2V9 = StoredStateV8<9>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The v8 shape as SDK versions before the model read the source's entry itself
|
|
181
|
+
* stored it: `pTableParams` also holds that entry's settings as table parameters.
|
|
182
|
+
*/
|
|
183
|
+
type StoredStateV8<V extends 8 | 9> = {
|
|
184
|
+
version: V;
|
|
185
|
+
stateCache: StoredCacheEntry[];
|
|
186
|
+
pTableParams: StoredPTableParams;
|
|
173
187
|
};
|
|
174
188
|
|
|
189
|
+
type StoredPTableParams =
|
|
190
|
+
| {
|
|
191
|
+
sourceId: null;
|
|
192
|
+
hiddenColIds: null;
|
|
193
|
+
sorting: null;
|
|
194
|
+
filters: null;
|
|
195
|
+
defaultFilters: null;
|
|
196
|
+
}
|
|
197
|
+
| {
|
|
198
|
+
sourceId: string;
|
|
199
|
+
hiddenColIds: null | PTableColumnId[];
|
|
200
|
+
sorting: null | PTableSorting[];
|
|
201
|
+
filters: null | PlDataTableFilters;
|
|
202
|
+
defaultFilters: null | PlDataTableFilters;
|
|
203
|
+
};
|
|
204
|
+
|
|
175
205
|
/** Upgrade PlDataTableStateV2 to the latest version */
|
|
176
206
|
export function upgradePlDataTableStateV2(
|
|
177
207
|
state: PlDataTableStateV2 | undefined,
|
|
@@ -224,9 +254,43 @@ export function upgradePlDataTableStateV2(
|
|
|
224
254
|
if (state.version === 8) {
|
|
225
255
|
state = migrateV8toV9(state);
|
|
226
256
|
}
|
|
227
|
-
return state;
|
|
257
|
+
return adoptLegacyTableParams(state);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Earlier SDK versions kept the sorting and hidden columns of the source on
|
|
262
|
+
* screen only in `pTableParams`, next to the pointer to that source. They move
|
|
263
|
+
* into that source's entry, other entries start untouched, and `pTableParams`
|
|
264
|
+
* keeps only the pointer.
|
|
265
|
+
*/
|
|
266
|
+
function adoptLegacyTableParams(
|
|
267
|
+
state: PlDataTableStateV2V9 | PlDataTableStateV2Normalized,
|
|
268
|
+
): PlDataTableStateV2Normalized {
|
|
269
|
+
const legacy: StoredPTableParams = state.pTableParams;
|
|
270
|
+
const stateCache: StoredCacheEntry[] = state.stateCache;
|
|
271
|
+
return {
|
|
272
|
+
version: 9,
|
|
273
|
+
stateCache: stateCache.map((entry) => {
|
|
274
|
+
const isShown = entry.sourceId === legacy.sourceId;
|
|
275
|
+
return {
|
|
276
|
+
...entry,
|
|
277
|
+
sorting: entry.sorting !== undefined ? entry.sorting : isShown ? legacy.sorting : null,
|
|
278
|
+
hiddenColIds:
|
|
279
|
+
entry.hiddenColIds !== undefined
|
|
280
|
+
? entry.hiddenColIds
|
|
281
|
+
: isShown
|
|
282
|
+
? legacy.hiddenColIds
|
|
283
|
+
: null,
|
|
284
|
+
};
|
|
285
|
+
}),
|
|
286
|
+
pTableParams: { ...createDefaultPTableParams(), sourceId: legacy.sourceId },
|
|
287
|
+
};
|
|
228
288
|
}
|
|
229
289
|
|
|
290
|
+
/** A cache entry as stored, possibly by an SDK version without the sorting fields. */
|
|
291
|
+
type StoredCacheEntry = Omit<PlDataTableStateV2CacheEntry, "sorting" | "hiddenColIds"> &
|
|
292
|
+
Partial<Pick<PlDataTableStateV2CacheEntry, "sorting" | "hiddenColIds">>;
|
|
293
|
+
|
|
230
294
|
/** Migrate v5 to v6: unwrap `{source, labeled}` colIds in gridState. */
|
|
231
295
|
function migrateV5toV6(state: Extract<PlDataTableStateV2, { version: 5 }>): PlDataTableStateV2V6 {
|
|
232
296
|
// pTableParams reset: v5 stored ColumnDiscoveredId-based hiddenColIds with
|
|
@@ -473,7 +537,7 @@ export function createPlDataTableStateV2(): PlDataTableStateV2Normalized {
|
|
|
473
537
|
// Also translates `sorting: []` (legacy "untouched") into `sorting: null`.
|
|
474
538
|
|
|
475
539
|
function migrateV7toV8(state: PlDataTableStateV2V7): PlDataTableStateV2V8 {
|
|
476
|
-
const newCache:
|
|
540
|
+
const newCache: StoredCacheEntry[] = state.stateCache.map((entry) => ({
|
|
477
541
|
sourceId: entry.sourceId,
|
|
478
542
|
gridState: entry.gridState,
|
|
479
543
|
sheetsState: entry.sheetsState,
|
|
@@ -483,7 +547,7 @@ function migrateV7toV8(state: PlDataTableStateV2V7): PlDataTableStateV2V8 {
|
|
|
483
547
|
}));
|
|
484
548
|
|
|
485
549
|
const params = state.pTableParams;
|
|
486
|
-
let pTableParams:
|
|
550
|
+
let pTableParams: StoredPTableParams;
|
|
487
551
|
if (params.sourceId === null) {
|
|
488
552
|
pTableParams = createDefaultPTableParams();
|
|
489
553
|
} else {
|
|
@@ -576,10 +640,10 @@ function parseLegacyLeafColumn(s: unknown): PTableColumnId | undefined {
|
|
|
576
640
|
// ids name a column relative to an anchor the state does not hold; entries
|
|
577
641
|
// using them are dropped.
|
|
578
642
|
|
|
579
|
-
function migrateV8toV9(state: PlDataTableStateV2V8):
|
|
643
|
+
function migrateV8toV9(state: PlDataTableStateV2V8): PlDataTableStateV2V9 {
|
|
580
644
|
return {
|
|
581
645
|
version: 9,
|
|
582
|
-
stateCache: state.stateCache.map((entry):
|
|
646
|
+
stateCache: state.stateCache.map((entry): StoredCacheEntry => ({
|
|
583
647
|
...entry,
|
|
584
648
|
gridState: upgradeGridStateColumnIds(entry.gridState),
|
|
585
649
|
filtersState: upgradeFilterColumnIds(entry.filtersState),
|
|
@@ -660,7 +724,7 @@ function upgradeColumnRef(ref: PTableColumnId): PTableColumnId | undefined {
|
|
|
660
724
|
return id === undefined ? undefined : { type: "column", id };
|
|
661
725
|
}
|
|
662
726
|
|
|
663
|
-
function upgradeParamsColumnIds(params:
|
|
727
|
+
function upgradeParamsColumnIds(params: StoredPTableParams): StoredPTableParams {
|
|
664
728
|
if (params.sourceId === null) return params;
|
|
665
729
|
|
|
666
730
|
const hiddenColIds =
|