@platforma-sdk/model 1.88.15 → 1.89.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/components/PlDataTable/columnResolver.cjs +11 -1
- package/dist/components/PlDataTable/columnResolver.cjs.map +1 -1
- package/dist/components/PlDataTable/columnResolver.js +11 -1
- package/dist/components/PlDataTable/columnResolver.js.map +1 -1
- 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 +172 -2
- package/dist/components/PlDataTable/state-migration.cjs.map +1 -1
- package/dist/components/PlDataTable/state-migration.d.ts +32 -3
- package/dist/components/PlDataTable/state-migration.d.ts.map +1 -1
- package/dist/components/PlDataTable/state-migration.js +173 -4
- 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 +14 -11
- package/dist/components/PlDataTable/typesV8.d.ts.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +2 -2
- package/src/components/PlDataTable/columnResolver.test.ts +10 -0
- package/src/components/PlDataTable/columnResolver.ts +12 -1
- 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 +210 -0
- package/src/components/PlDataTable/state-migration.ts +274 -5
- package/src/components/PlDataTable/tableParams.test.ts +291 -0
- package/src/components/PlDataTable/tableParams.ts +243 -0
- package/src/components/PlDataTable/typesV8.ts +20 -19
- package/src/components/PlDataTable/createPlDataTable/createPlDataTableV3.test.ts +0 -61
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
canonicalizeJson,
|
|
4
|
+
createGlobalPObjectId,
|
|
5
|
+
type ColumnUniversalId,
|
|
6
|
+
type PTableColumnId,
|
|
7
|
+
} from "@milaboratories/pl-model-common";
|
|
8
|
+
import {
|
|
9
|
+
type PlDataTableStateV2,
|
|
10
|
+
type PlDataTableStateV2V8,
|
|
11
|
+
upgradeLegacyColumnId,
|
|
12
|
+
upgradePlDataTableStateV2,
|
|
13
|
+
} from "./state-migration";
|
|
14
|
+
import type { PlDataTableFiltersWithMeta, PlTableColumnIdJson } from "./typesV8";
|
|
15
|
+
|
|
16
|
+
// Leaf ids as a result-pool export names them; the form did not change in the rework.
|
|
17
|
+
const property = createGlobalPObjectId(
|
|
18
|
+
"f9212394-932e-49ff-8366-017b840d47e9",
|
|
19
|
+
"pf.chain_0/property_16",
|
|
20
|
+
);
|
|
21
|
+
const clusterLabel = createGlobalPObjectId(
|
|
22
|
+
"d1efe0f6-9df0-43e4-8641-2777b88a5e7c",
|
|
23
|
+
"pf.clusterLabel6",
|
|
24
|
+
);
|
|
25
|
+
const linker = createGlobalPObjectId("d1efe0f6-9df0-43e4-8641-2777b88a5e7c", "pf.link3");
|
|
26
|
+
|
|
27
|
+
// Discovered ids as saved before the column-access rework: no `__isDiscovered` marker.
|
|
28
|
+
const legacyDirect = JSON.stringify({ column: property }) as ColumnUniversalId;
|
|
29
|
+
const legacyLinked = JSON.stringify({
|
|
30
|
+
column: clusterLabel,
|
|
31
|
+
path: [{ column: linker, type: "linker" }],
|
|
32
|
+
}) as ColumnUniversalId;
|
|
33
|
+
|
|
34
|
+
// The same columns as the current recipes name them: a hit reached with no linker by
|
|
35
|
+
// its own id, a linked one wrapped with its path.
|
|
36
|
+
const currentDirect = property;
|
|
37
|
+
const currentLinked =
|
|
38
|
+
`{"__isDiscovered":true,"column":${JSON.stringify(clusterLabel)},` +
|
|
39
|
+
`"path":[{"column":${JSON.stringify(linker)},"type":"linker"}]}`;
|
|
40
|
+
|
|
41
|
+
// Pre-rework anchored and filtered ids: relative to an anchor the state does not hold.
|
|
42
|
+
const legacyAnchored = JSON.stringify({ anchor: "main", name: "x" }) as ColumnUniversalId;
|
|
43
|
+
const legacyFiltered = JSON.stringify({
|
|
44
|
+
source: { anchor: "main", name: "x" },
|
|
45
|
+
axisFilters: [[0, "a"]],
|
|
46
|
+
}) as ColumnUniversalId;
|
|
47
|
+
|
|
48
|
+
const col = (id: ColumnUniversalId): PTableColumnId => ({ type: "column", id });
|
|
49
|
+
const colIdJson = (id: ColumnUniversalId): PlTableColumnIdJson => canonicalizeJson(col(id));
|
|
50
|
+
const ROW_NUMBER: PlTableColumnIdJson = canonicalizeJson(
|
|
51
|
+
"##RowNumberColumnId##",
|
|
52
|
+
) as PlTableColumnIdJson;
|
|
53
|
+
|
|
54
|
+
type StoredParams = PlDataTableStateV2V8["pTableParams"];
|
|
55
|
+
|
|
56
|
+
function params(over: Partial<Extract<StoredParams, { sourceId: string }>>): StoredParams {
|
|
57
|
+
return {
|
|
58
|
+
sourceId: '"static"',
|
|
59
|
+
hiddenColIds: null,
|
|
60
|
+
sorting: null,
|
|
61
|
+
filters: null,
|
|
62
|
+
defaultFilters: null,
|
|
63
|
+
...over,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function v8(
|
|
68
|
+
pTableParams: StoredParams,
|
|
69
|
+
gridColIds: PlTableColumnIdJson[] = [],
|
|
70
|
+
filtersState: null | PlDataTableFiltersWithMeta = null,
|
|
71
|
+
): PlDataTableStateV2V8 {
|
|
72
|
+
return {
|
|
73
|
+
version: 8,
|
|
74
|
+
stateCache: [
|
|
75
|
+
{
|
|
76
|
+
sourceId: '"static"',
|
|
77
|
+
gridState: {
|
|
78
|
+
columnOrder: { orderedColIds: gridColIds },
|
|
79
|
+
sort: { sortModel: gridColIds.slice(1, 2).map((colId) => ({ colId, sort: "desc" })) },
|
|
80
|
+
columnVisibility: { hiddenColIds: gridColIds.slice(1) },
|
|
81
|
+
},
|
|
82
|
+
sheetsState: [],
|
|
83
|
+
filtersState,
|
|
84
|
+
defaultFiltersState: null,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
pTableParams,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
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;
|
|
95
|
+
|
|
96
|
+
describe("upgradeLegacyColumnId", () => {
|
|
97
|
+
test("a pre-rework direct hit takes its own id", () => {
|
|
98
|
+
expect(upgradeLegacyColumnId(legacyDirect)).toBe(currentDirect);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("a pre-rework direct hit with qualifications stays wrapped", () => {
|
|
102
|
+
const columnQualifications = [
|
|
103
|
+
{ axis: { name: "pl7.app/sampleId" }, contextDomain: { a: "b" } },
|
|
104
|
+
];
|
|
105
|
+
const legacy = JSON.stringify({ column: property, columnQualifications });
|
|
106
|
+
expect(upgradeLegacyColumnId(legacy)).toBe(
|
|
107
|
+
`{"__isDiscovered":true,"column":${JSON.stringify(property)},` +
|
|
108
|
+
`"columnQualifications":${JSON.stringify(columnQualifications)}}`,
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("its linker path is carried over", () => {
|
|
113
|
+
expect(upgradeLegacyColumnId(legacyLinked)).toBe(currentLinked);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("a current id is left as it is", () => {
|
|
117
|
+
expect(upgradeLegacyColumnId(currentLinked)).toBe(currentLinked);
|
|
118
|
+
expect(upgradeLegacyColumnId(property)).toBe(property);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("ids relative to an unstored anchor cannot be carried over", () => {
|
|
122
|
+
expect(upgradeLegacyColumnId(legacyAnchored)).toBeUndefined();
|
|
123
|
+
expect(upgradeLegacyColumnId(legacyFiltered)).toBeUndefined();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("a string that is no id at all cannot be carried over", () => {
|
|
127
|
+
expect(upgradeLegacyColumnId("not json")).toBeUndefined();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("v8 -> v9", () => {
|
|
132
|
+
test("the user's sorting on a pre-rework id survives", () => {
|
|
133
|
+
// The state that broke the lead-selection table: sorting saved before the rework.
|
|
134
|
+
const state = v8(
|
|
135
|
+
params({
|
|
136
|
+
sorting: [
|
|
137
|
+
{ column: col(legacyDirect), ascending: false, naAndAbsentAreLeastValues: false },
|
|
138
|
+
],
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
141
|
+
const upgraded = upgradePlDataTableStateV2(state);
|
|
142
|
+
expect(upgraded.version).toBe(9);
|
|
143
|
+
expect(sortingOf(state)).toEqual([
|
|
144
|
+
{
|
|
145
|
+
column: col(currentDirect as ColumnUniversalId),
|
|
146
|
+
ascending: false,
|
|
147
|
+
naAndAbsentAreLeastValues: false,
|
|
148
|
+
},
|
|
149
|
+
]);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("a sorting left empty by dropped entries falls back to the default", () => {
|
|
153
|
+
const state = v8(
|
|
154
|
+
params({
|
|
155
|
+
sorting: [
|
|
156
|
+
{ column: col(legacyAnchored), ascending: true, naAndAbsentAreLeastValues: false },
|
|
157
|
+
],
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
expect(sortingOf(state)).toBeNull();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("a sorting the user cleared stays cleared", () => {
|
|
164
|
+
expect(sortingOf(v8(params({ sorting: [] })))).toEqual([]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("hidden columns are rewritten and unconvertible ones dropped", () => {
|
|
168
|
+
const state = v8(params({ hiddenColIds: [col(legacyLinked), col(legacyFiltered)] }));
|
|
169
|
+
expect(shownEntryOf(state).hiddenColIds).toEqual([col(currentLinked as ColumnUniversalId)]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("grid column ids are rewritten, the row-number column kept", () => {
|
|
173
|
+
const state = v8(params({}), [ROW_NUMBER, colIdJson(legacyDirect), colIdJson(legacyAnchored)]);
|
|
174
|
+
const grid = upgradePlDataTableStateV2(state).stateCache[0].gridState;
|
|
175
|
+
const expected = colIdJson(currentDirect as ColumnUniversalId);
|
|
176
|
+
expect(grid.columnOrder?.orderedColIds).toEqual([ROW_NUMBER, expected]);
|
|
177
|
+
expect(grid.sort?.sortModel).toEqual([{ colId: expected, sort: "desc" }]);
|
|
178
|
+
expect(grid.columnVisibility?.hiddenColIds).toEqual([expected]);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("filter leaves are rewritten; a group emptied by dropped leaves goes", () => {
|
|
182
|
+
const filtersState: PlDataTableFiltersWithMeta = {
|
|
183
|
+
id: 1,
|
|
184
|
+
type: "and",
|
|
185
|
+
filters: [
|
|
186
|
+
{ id: 2, type: "isNA", column: col(legacyDirect) },
|
|
187
|
+
{ id: 3, type: "or", filters: [{ id: 4, type: "isNotNA", column: col(legacyAnchored) }] },
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
expect(shownEntryOf(v8(params({}), [], filtersState)).filtersState).toEqual({
|
|
191
|
+
id: 1,
|
|
192
|
+
type: "and",
|
|
193
|
+
filters: [{ id: 2, type: "isNA", column: col(currentDirect as ColumnUniversalId) }],
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("a state with current ids comes through unchanged", () => {
|
|
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
|
+
});
|
|
206
|
+
|
|
207
|
+
test("a fresh state is already v9", () => {
|
|
208
|
+
expect(upgradePlDataTableStateV2(undefined).version).toBe(9);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AxisId,
|
|
3
|
+
AxisQualification,
|
|
3
4
|
CanonicalizedJson,
|
|
5
|
+
ColumnUniversalId,
|
|
4
6
|
PObjectId,
|
|
5
7
|
PTableColumnId,
|
|
6
8
|
PTableColumnSpec,
|
|
@@ -10,16 +12,20 @@ import type {
|
|
|
10
12
|
import {
|
|
11
13
|
canonicalizeJson,
|
|
12
14
|
getPTableColumnId,
|
|
15
|
+
isColumnUniversalKey,
|
|
13
16
|
parseJsonSafely,
|
|
17
|
+
stringifyColumnDiscoveredId,
|
|
14
18
|
} from "@milaboratories/pl-model-common";
|
|
15
19
|
import { distillFilterSpec } from "../../filters";
|
|
16
20
|
import type { PlDataTableFilterState, PlTableFilter } from "./typesV4";
|
|
17
21
|
import type {
|
|
18
22
|
PlDataTableFilters,
|
|
19
23
|
PlDataTableFiltersWithMeta,
|
|
24
|
+
PlDataTableGridStateCore,
|
|
20
25
|
PlDataTableSheetState,
|
|
21
26
|
PlDataTableStateV2CacheEntry,
|
|
22
27
|
PlDataTableStateV2Normalized,
|
|
28
|
+
PlTableColumnIdJson as PlTableColumnIdJsonV8,
|
|
23
29
|
PTableParamsV2,
|
|
24
30
|
} from "./typesV8";
|
|
25
31
|
import type {
|
|
@@ -155,9 +161,47 @@ export type PlDataTableStateV2 =
|
|
|
155
161
|
// v7 still had filter leaves serialised as `CanonicalizedJson<PTableColumnId>`
|
|
156
162
|
// strings and `sorting: []` for the "untouched" case.
|
|
157
163
|
| PlDataTableStateV2V7
|
|
164
|
+
// v8 may still hold column ids written before the column-access rework (see
|
|
165
|
+
// `upgradeLegacyColumnId`).
|
|
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
|
|
158
170
|
// Normalized state
|
|
159
171
|
| PlDataTableStateV2Normalized;
|
|
160
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;
|
|
187
|
+
};
|
|
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
|
+
|
|
161
205
|
/** Upgrade PlDataTableStateV2 to the latest version */
|
|
162
206
|
export function upgradePlDataTableStateV2(
|
|
163
207
|
state: PlDataTableStateV2 | undefined,
|
|
@@ -206,9 +250,47 @@ export function upgradePlDataTableStateV2(
|
|
|
206
250
|
if (state.version === 7) {
|
|
207
251
|
state = migrateV7toV8(state);
|
|
208
252
|
}
|
|
209
|
-
|
|
253
|
+
// v8 -> v9: rewrite column ids written before the column-access rework.
|
|
254
|
+
if (state.version === 8) {
|
|
255
|
+
state = migrateV8toV9(state);
|
|
256
|
+
}
|
|
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
|
+
};
|
|
210
288
|
}
|
|
211
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
|
+
|
|
212
294
|
/** Migrate v5 to v6: unwrap `{source, labeled}` colIds in gridState. */
|
|
213
295
|
function migrateV5toV6(state: Extract<PlDataTableStateV2, { version: 5 }>): PlDataTableStateV2V6 {
|
|
214
296
|
// pTableParams reset: v5 stored ColumnDiscoveredId-based hiddenColIds with
|
|
@@ -442,7 +524,7 @@ export function createDefaultPTableParams(): PTableParamsV2 {
|
|
|
442
524
|
|
|
443
525
|
export function createPlDataTableStateV2(): PlDataTableStateV2Normalized {
|
|
444
526
|
return {
|
|
445
|
-
version:
|
|
527
|
+
version: 9,
|
|
446
528
|
stateCache: [],
|
|
447
529
|
pTableParams: createDefaultPTableParams(),
|
|
448
530
|
};
|
|
@@ -454,8 +536,8 @@ export function createPlDataTableStateV2(): PlDataTableStateV2Normalized {
|
|
|
454
536
|
// are dropped; cache entries whose tree fully prunes get filtersState: null.
|
|
455
537
|
// Also translates `sorting: []` (legacy "untouched") into `sorting: null`.
|
|
456
538
|
|
|
457
|
-
function migrateV7toV8(state: PlDataTableStateV2V7):
|
|
458
|
-
const newCache:
|
|
539
|
+
function migrateV7toV8(state: PlDataTableStateV2V7): PlDataTableStateV2V8 {
|
|
540
|
+
const newCache: StoredCacheEntry[] = state.stateCache.map((entry) => ({
|
|
459
541
|
sourceId: entry.sourceId,
|
|
460
542
|
gridState: entry.gridState,
|
|
461
543
|
sheetsState: entry.sheetsState,
|
|
@@ -465,7 +547,7 @@ function migrateV7toV8(state: PlDataTableStateV2V7): PlDataTableStateV2Normalize
|
|
|
465
547
|
}));
|
|
466
548
|
|
|
467
549
|
const params = state.pTableParams;
|
|
468
|
-
let pTableParams:
|
|
550
|
+
let pTableParams: StoredPTableParams;
|
|
469
551
|
if (params.sourceId === null) {
|
|
470
552
|
pTableParams = createDefaultPTableParams();
|
|
471
553
|
} else {
|
|
@@ -548,3 +630,190 @@ function parseLegacyLeafColumn(s: unknown): PTableColumnId | undefined {
|
|
|
548
630
|
if (t !== "axis" && t !== "column") return undefined;
|
|
549
631
|
return parsed as PTableColumnId;
|
|
550
632
|
}
|
|
633
|
+
|
|
634
|
+
// --- v8 -> v9 migration ----------------------------------------------------
|
|
635
|
+
// The column-access rework (July 2026) marked discovered column ids with
|
|
636
|
+
// `__isDiscovered`. Ids saved before it — user sorting, hidden columns, column
|
|
637
|
+
// order, filter leaves — came through the v6 -> v8 steps unchanged, and the
|
|
638
|
+
// current id parser rejects them. Legacy discovered ids are rewritten to the
|
|
639
|
+
// current form, so the user's choices survive. Legacy anchored and filtered
|
|
640
|
+
// ids name a column relative to an anchor the state does not hold; entries
|
|
641
|
+
// using them are dropped.
|
|
642
|
+
|
|
643
|
+
function migrateV8toV9(state: PlDataTableStateV2V8): PlDataTableStateV2V9 {
|
|
644
|
+
return {
|
|
645
|
+
version: 9,
|
|
646
|
+
stateCache: state.stateCache.map((entry): StoredCacheEntry => ({
|
|
647
|
+
...entry,
|
|
648
|
+
gridState: upgradeGridStateColumnIds(entry.gridState),
|
|
649
|
+
filtersState: upgradeFilterColumnIds(entry.filtersState),
|
|
650
|
+
defaultFiltersState: upgradeFilterColumnIds(entry.defaultFiltersState),
|
|
651
|
+
})),
|
|
652
|
+
pTableParams: upgradeParamsColumnIds(state.pTableParams),
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** Keys a pre-rework discovered column id could carry; it had no marker. */
|
|
657
|
+
const LEGACY_DISCOVERED_KEYS = new Set([
|
|
658
|
+
"column",
|
|
659
|
+
"path",
|
|
660
|
+
"columnQualifications",
|
|
661
|
+
"queriesQualifications",
|
|
662
|
+
]);
|
|
663
|
+
|
|
664
|
+
type LegacyDiscoveredKey = {
|
|
665
|
+
column: string;
|
|
666
|
+
path?: { type: "linker"; column: string }[];
|
|
667
|
+
columnQualifications?: AxisQualification[];
|
|
668
|
+
queriesQualifications?: Record<PObjectId, AxisQualification[]>;
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
function isLegacyDiscoveredKey(value: unknown): value is LegacyDiscoveredKey {
|
|
672
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
673
|
+
if (!Object.keys(value).every((key) => LEGACY_DISCOVERED_KEYS.has(key))) return false;
|
|
674
|
+
const { column, path } = value as { column?: unknown; path?: unknown };
|
|
675
|
+
if (typeof column !== "string") return false;
|
|
676
|
+
if (path === undefined) return true;
|
|
677
|
+
return (
|
|
678
|
+
Array.isArray(path) &&
|
|
679
|
+
path.every(
|
|
680
|
+
(item: unknown) =>
|
|
681
|
+
typeof item === "object" &&
|
|
682
|
+
item !== null &&
|
|
683
|
+
(item as { type?: unknown }).type === "linker" &&
|
|
684
|
+
typeof (item as { column?: unknown }).column === "string",
|
|
685
|
+
)
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* A stored column id in its current form: unchanged when already current,
|
|
691
|
+
* rewritten when it is a pre-rework discovered id, `undefined` when it cannot be
|
|
692
|
+
* carried over (a pre-rework anchored or filtered id, or not an id at all).
|
|
693
|
+
*/
|
|
694
|
+
export function upgradeLegacyColumnId(id: string): ColumnUniversalId | undefined {
|
|
695
|
+
const key: unknown = parseJsonSafely(id);
|
|
696
|
+
if (isColumnUniversalKey(key)) return id as ColumnUniversalId;
|
|
697
|
+
if (!isLegacyDiscoveredKey(key)) return undefined;
|
|
698
|
+
|
|
699
|
+
const column = upgradeLegacyColumnId(key.column);
|
|
700
|
+
if (column === undefined) return undefined;
|
|
701
|
+
const path: { type: "linker"; column: ColumnUniversalId }[] = [];
|
|
702
|
+
for (const item of key.path ?? []) {
|
|
703
|
+
const linker = upgradeLegacyColumnId(item.column);
|
|
704
|
+
if (linker === undefined) return undefined;
|
|
705
|
+
path.push({ type: "linker", column: linker });
|
|
706
|
+
}
|
|
707
|
+
// Discovery names a hit reached with no linker and no qualifications by its own id
|
|
708
|
+
// and wraps only the rest; the pre-rework form wrapped every hit.
|
|
709
|
+
const hasQualifications =
|
|
710
|
+
(key.columnQualifications?.length ?? 0) > 0 ||
|
|
711
|
+
Object.keys(key.queriesQualifications ?? {}).length > 0;
|
|
712
|
+
if (path.length === 0 && !hasQualifications) return column;
|
|
713
|
+
return stringifyColumnDiscoveredId({
|
|
714
|
+
column,
|
|
715
|
+
path,
|
|
716
|
+
columnQualifications: key.columnQualifications,
|
|
717
|
+
queriesQualifications: key.queriesQualifications,
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function upgradeColumnRef(ref: PTableColumnId): PTableColumnId | undefined {
|
|
722
|
+
if (ref.type !== "column") return ref;
|
|
723
|
+
const id = upgradeLegacyColumnId(ref.id);
|
|
724
|
+
return id === undefined ? undefined : { type: "column", id };
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function upgradeParamsColumnIds(params: StoredPTableParams): StoredPTableParams {
|
|
728
|
+
if (params.sourceId === null) return params;
|
|
729
|
+
|
|
730
|
+
const hiddenColIds =
|
|
731
|
+
params.hiddenColIds === null
|
|
732
|
+
? null
|
|
733
|
+
: params.hiddenColIds.flatMap((ref) => upgradeColumnRef(ref) ?? []);
|
|
734
|
+
|
|
735
|
+
return {
|
|
736
|
+
...params,
|
|
737
|
+
hiddenColIds,
|
|
738
|
+
sorting: params.sorting === null ? null : upgradeSorting(params.sorting),
|
|
739
|
+
filters: upgradeFilterColumnIds(params.filters),
|
|
740
|
+
defaultFilters: upgradeFilterColumnIds(params.defaultFilters),
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/** `[]` is the user's cleared sorting and stays. A sorting emptied by dropped
|
|
745
|
+
* entries falls back to the default (`null`) instead of reading as cleared. */
|
|
746
|
+
function upgradeSorting(sorting: PTableSorting[]): null | PTableSorting[] {
|
|
747
|
+
if (sorting.length === 0) return sorting;
|
|
748
|
+
const kept = sorting.flatMap((entry): PTableSorting[] => {
|
|
749
|
+
const column = upgradeColumnRef(entry.column);
|
|
750
|
+
return column === undefined ? [] : [{ ...entry, column }];
|
|
751
|
+
});
|
|
752
|
+
return kept.length === 0 ? null : kept;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function upgradeGridColId(colId: PlTableColumnIdJsonV8): PlTableColumnIdJsonV8 | undefined {
|
|
756
|
+
const parsed: unknown = parseJsonSafely(colId);
|
|
757
|
+
// Not a column id: the row-number sentinel passes through unchanged.
|
|
758
|
+
if (typeof parsed !== "object" || parsed === null || !("type" in parsed) || !("id" in parsed)) {
|
|
759
|
+
return colId;
|
|
760
|
+
}
|
|
761
|
+
const ref = upgradeColumnRef(parsed as PTableColumnId);
|
|
762
|
+
if (ref === undefined) return undefined;
|
|
763
|
+
return ref === parsed ? colId : canonicalizeJson<PTableColumnId>(ref);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
function upgradeGridStateColumnIds(gridState: PlDataTableGridStateCore): PlDataTableGridStateCore {
|
|
767
|
+
const upgradeAll = (colIds: PlTableColumnIdJsonV8[]) =>
|
|
768
|
+
colIds.flatMap((colId) => upgradeGridColId(colId) ?? []);
|
|
769
|
+
return {
|
|
770
|
+
...gridState,
|
|
771
|
+
...(gridState.columnOrder && {
|
|
772
|
+
columnOrder: { orderedColIds: upgradeAll(gridState.columnOrder.orderedColIds) },
|
|
773
|
+
}),
|
|
774
|
+
...(gridState.sort && {
|
|
775
|
+
sort: {
|
|
776
|
+
sortModel: gridState.sort.sortModel.flatMap((s) => {
|
|
777
|
+
const colId = upgradeGridColId(s.colId);
|
|
778
|
+
return colId === undefined ? [] : [{ ...s, colId }];
|
|
779
|
+
}),
|
|
780
|
+
},
|
|
781
|
+
}),
|
|
782
|
+
...(gridState.columnVisibility && {
|
|
783
|
+
columnVisibility: { hiddenColIds: upgradeAll(gridState.columnVisibility.hiddenColIds) },
|
|
784
|
+
}),
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function upgradeFilterColumnIds<T extends PlDataTableFilters | PlDataTableFiltersWithMeta>(
|
|
789
|
+
node: null | T,
|
|
790
|
+
): null | T {
|
|
791
|
+
if (node === null) return null;
|
|
792
|
+
const result = upgradeFilterNode(node);
|
|
793
|
+
return result === undefined ? null : (result as T);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/** Rewrites the column ids in a filter tree. A leaf whose id cannot be carried
|
|
797
|
+
* over is dropped, and a group left empty with it. */
|
|
798
|
+
function upgradeFilterNode(node: unknown): unknown | undefined {
|
|
799
|
+
if (!node || typeof node !== "object") return undefined;
|
|
800
|
+
const n = node as { type?: unknown };
|
|
801
|
+
if (n.type === "and" || n.type === "or") {
|
|
802
|
+
const filters = (n as { filters?: unknown[] }).filters ?? [];
|
|
803
|
+
const kept = filters.map(upgradeFilterNode).filter((f): f is object => f !== undefined);
|
|
804
|
+
if (kept.length === 0) return undefined;
|
|
805
|
+
return { ...n, filters: kept };
|
|
806
|
+
}
|
|
807
|
+
if (n.type === "not") {
|
|
808
|
+
const inner = upgradeFilterNode((n as { filter?: unknown }).filter);
|
|
809
|
+
return inner === undefined ? undefined : { ...n, filter: inner };
|
|
810
|
+
}
|
|
811
|
+
const leaf: Record<string, unknown> = { ...n };
|
|
812
|
+
for (const field of ["column", "rhs"]) {
|
|
813
|
+
if (!(field in leaf)) continue;
|
|
814
|
+
const ref = upgradeColumnRef(leaf[field] as PTableColumnId);
|
|
815
|
+
if (ref === undefined) return undefined;
|
|
816
|
+
leaf[field] = ref;
|
|
817
|
+
}
|
|
818
|
+
return leaf;
|
|
819
|
+
}
|