@platforma-sdk/ui-vue 1.88.16 → 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/.turbo/turbo-build.log +14 -14
- package/.turbo/turbo-formatter$colon$check.log +1 -1
- package/.turbo/turbo-linter$colon$check.log +1 -1
- package/CHANGELOG.md +18 -0
- package/dist/components/PlAdvancedFilter/utils.js +5 -13
- package/dist/components/PlAdvancedFilter/utils.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.style.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue.d.ts +7 -12
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue.d.ts.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue2.js +28 -47
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue2.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableV2.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableV2.style.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableV2.vue.d.ts.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableV2.vue2.js +169 -184
- package/dist/components/PlAgDataTable/PlAgDataTableV2.vue2.js.map +1 -1
- package/dist/components/PlAgDataTable/sources/grid-state.d.ts +25 -1
- package/dist/components/PlAgDataTable/sources/grid-state.d.ts.map +1 -1
- package/dist/components/PlAgDataTable/sources/grid-state.js +55 -16
- package/dist/components/PlAgDataTable/sources/grid-state.js.map +1 -1
- package/dist/components/PlAgDataTable/sources/table-state-v2.d.ts +44 -15
- package/dist/components/PlAgDataTable/sources/table-state-v2.d.ts.map +1 -1
- package/dist/components/PlAgDataTable/sources/table-state-v2.js +130 -178
- package/dist/components/PlAgDataTable/sources/table-state-v2.js.map +1 -1
- package/dist/components/PlAgDataTable/types.d.ts +3 -9
- package/dist/components/PlAgDataTable/types.d.ts.map +1 -1
- package/dist/components/PlAgDataTable/types.js +8 -4
- package/dist/components/PlAgDataTable/types.js.map +1 -1
- package/dist/components/PlAnnotations/components/PlAnnotations.vue2.js.map +1 -1
- package/package.json +3 -3
- package/src/components/PlAgDataTable/PlAgDataTableSheets.vue +23 -67
- package/src/components/PlAgDataTable/PlAgDataTableV2.vue +91 -120
- package/src/components/PlAgDataTable/__tests__/PlAgDataTableV2.reload.jsdomtest.ts +93 -0
- package/src/components/PlAgDataTable/sources/grid-state.test.ts +97 -2
- package/src/components/PlAgDataTable/sources/grid-state.ts +95 -1
- package/src/components/PlAgDataTable/sources/table-state-v2.test.ts +192 -34
- package/src/components/PlAgDataTable/sources/table-state-v2.ts +197 -269
- package/src/components/PlAgDataTable/types.ts +6 -10
|
@@ -1,167 +1,191 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createDefaultPTableParams,
|
|
3
|
-
|
|
3
|
+
getAxisId,
|
|
4
4
|
upgradePlDataTableStateV2,
|
|
5
5
|
type FilterSpec,
|
|
6
|
-
type FilterSpecLeaf,
|
|
7
|
-
type PTableColumnId,
|
|
8
|
-
type PTableColumnSpec,
|
|
9
6
|
type PlDataTableGridStateCore,
|
|
7
|
+
type PlDataTableSheet,
|
|
10
8
|
type PlDataTableSheetState,
|
|
11
9
|
type PlDataTableStateV2,
|
|
12
10
|
type PlDataTableStateV2CacheEntry,
|
|
13
11
|
type PlDataTableStateV2Normalized,
|
|
14
|
-
type PTableParamsV2,
|
|
15
|
-
type PTableSorting,
|
|
16
12
|
type PlDataTableFilterSpecLeaf,
|
|
17
13
|
type PlDataTableFilterMeta,
|
|
18
14
|
type PlDataTableFilters,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
type PlDataTableFiltersWithMeta,
|
|
16
|
+
type PTableColumnId,
|
|
17
|
+
type PTableSorting,
|
|
22
18
|
} from "@platforma-sdk/model";
|
|
23
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
computed,
|
|
21
|
+
shallowRef,
|
|
22
|
+
watch,
|
|
23
|
+
type ComputedRef,
|
|
24
|
+
type Ref,
|
|
25
|
+
type WritableComputedRef,
|
|
26
|
+
} from "vue";
|
|
24
27
|
import type { PlDataTableSettingsV2 } from "../types";
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
|
|
28
|
+
import type { PlDataTableGridFields } from "./grid-state";
|
|
29
|
+
import { isJsonEqual, randomInt, getField, type Nil } from "@milaboratories/helpers";
|
|
30
|
+
import { isNil } from "es-toolkit";
|
|
31
|
+
|
|
32
|
+
/** The source the table shows, as the stored state has to describe it. */
|
|
33
|
+
export type PlDataTableTarget = {
|
|
34
|
+
sourceId: string;
|
|
35
|
+
sheets: PlDataTableSheet[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** A change the user made to the settings of one source. */
|
|
39
|
+
export type PlDataTableEdit = {
|
|
40
|
+
sourceId: string;
|
|
41
|
+
patch: Partial<Omit<PlDataTableStateV2CacheEntry, "sourceId">>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The stored state with the edits applied and, when a source is on screen,
|
|
46
|
+
* brought in line with it: the stored state points at that source, the source
|
|
47
|
+
* has an entry at the recent end of the cache, and its sheet selection names a
|
|
48
|
+
* value each sheet offers.
|
|
49
|
+
*
|
|
50
|
+
* Every write of the table state is this function's result, whether the user
|
|
51
|
+
* edited something or only the source on screen changed, so a table mounted
|
|
52
|
+
* on a source the stored state does not point at writes the same way a sort
|
|
53
|
+
* does.
|
|
54
|
+
*/
|
|
55
|
+
export function reduceTableState(
|
|
56
|
+
stored: PlDataTableStateV2Normalized,
|
|
57
|
+
target: null | PlDataTableTarget,
|
|
58
|
+
edits: PlDataTableEdit[],
|
|
59
|
+
): PlDataTableStateV2Normalized {
|
|
60
|
+
const edited = edits.reduce(applyEdit, stored);
|
|
61
|
+
const aligned = isNil(target) ? edited : alignWithTarget(edited, target);
|
|
62
|
+
return aligned.stateCache.length > CACHE_DEPTH
|
|
63
|
+
? { ...aligned, stateCache: aligned.stateCache.slice(-CACHE_DEPTH) }
|
|
64
|
+
: aligned;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The value shown on each sheet: the saved one while the sheet still offers it,
|
|
69
|
+
* otherwise the sheet's default, otherwise its first option. Sheets without
|
|
70
|
+
* options are not shown and get no entry.
|
|
71
|
+
*/
|
|
72
|
+
export function resolveSheetsState(
|
|
73
|
+
sheets: PlDataTableSheet[],
|
|
74
|
+
saved: PlDataTableSheetState[],
|
|
75
|
+
): PlDataTableSheetState[] {
|
|
76
|
+
return sheets
|
|
77
|
+
.filter((sheet) => sheet.options.length > 0)
|
|
78
|
+
.map((sheet) => {
|
|
79
|
+
const axisId = getAxisId(sheet.axis);
|
|
80
|
+
const savedValue = saved.find((s) => isJsonEqual(s.axisId, axisId))?.value;
|
|
81
|
+
const value =
|
|
82
|
+
!isNil(savedValue) && isSheetOption(sheet, savedValue)
|
|
83
|
+
? savedValue
|
|
84
|
+
: !isNil(sheet.defaultValue) && isSheetOption(sheet, sheet.defaultValue)
|
|
85
|
+
? sheet.defaultValue
|
|
86
|
+
: sheet.options[0].value;
|
|
87
|
+
return { axisId, value };
|
|
88
|
+
});
|
|
89
|
+
}
|
|
29
90
|
|
|
30
91
|
export function useTableState(
|
|
31
92
|
tableStateDenormalized: Ref<PlDataTableStateV2>,
|
|
32
93
|
settings: Ref<PlDataTableSettingsV2>,
|
|
33
|
-
columns: Ref<PTableColumnSpec[]>,
|
|
34
94
|
defaultFilters: Ref<Nil | PlDataTableFilters>,
|
|
35
95
|
): {
|
|
36
|
-
|
|
96
|
+
/** Source whose settings the controls show and edit; `null` while there is none. */
|
|
97
|
+
sourceId: ComputedRef<null | string>;
|
|
98
|
+
/** The grid's own state for the source on screen, to restore the grid from */
|
|
99
|
+
gridState: ComputedRef<PlDataTableGridStateCore>;
|
|
100
|
+
/** Sorting the user set on the source on screen; `null` while untouched */
|
|
101
|
+
sorting: ComputedRef<null | PTableSorting[]>;
|
|
102
|
+
/** Columns the user hid on the source on screen; `null` while untouched */
|
|
103
|
+
hiddenColIds: ComputedRef<null | PTableColumnId[]>;
|
|
104
|
+
getEntry: (sourceId: string) => undefined | PlDataTableStateV2CacheEntry;
|
|
105
|
+
updateGrid: (sourceId: string, grid: PlDataTableGridFields) => void;
|
|
37
106
|
sheetsState: WritableComputedRef<PlDataTableSheetState[]>;
|
|
38
|
-
|
|
39
107
|
searchString: WritableComputedRef<string>;
|
|
40
|
-
filtersState:
|
|
41
|
-
defaultFiltersState:
|
|
108
|
+
filtersState: WritableComputedRef<PlDataTableFiltersWithMeta>;
|
|
109
|
+
defaultFiltersState: WritableComputedRef<null | PlDataTableFiltersWithMeta>;
|
|
42
110
|
resetDefaultFilters: () => void;
|
|
43
111
|
} {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const tableState = computed<PlDataTableStateV2CacheEntryNullable>({
|
|
51
|
-
get: () => {
|
|
52
|
-
const defaultState = makeDefaultState();
|
|
53
|
-
|
|
54
|
-
const sourceId = settings.value.sourceId;
|
|
55
|
-
const undefinedSourceId = "error" in settings.value && settings.value.error == null;
|
|
56
|
-
if (!sourceId && undefinedSourceId) return defaultState;
|
|
57
|
-
|
|
58
|
-
const suitableSourceId = sourceId ?? tableStateNormalized.value.stateCache.at(-1)?.sourceId;
|
|
59
|
-
if (!suitableSourceId) return defaultState;
|
|
112
|
+
const stored = computed(() => upgradePlDataTableStateV2(tableStateDenormalized.value));
|
|
113
|
+
const target = computed<null | PlDataTableTarget>(() =>
|
|
114
|
+
settings.value.sourceId === null
|
|
115
|
+
? null
|
|
116
|
+
: { sourceId: settings.value.sourceId, sheets: settings.value.sheets },
|
|
117
|
+
);
|
|
60
118
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
119
|
+
// Edits are kept until the stored state reports them back. Until then the
|
|
120
|
+
// platform may hand back a state that predates them: a change by another
|
|
121
|
+
// author, such as a running block, replaces the whole block state with the
|
|
122
|
+
// project's copy, which lacks edits still waiting to be sent. Each such push
|
|
123
|
+
// would otherwise undo what the user just did.
|
|
124
|
+
const pendingEdits = shallowRef<PlDataTableEdit[]>([]);
|
|
125
|
+
const state = computed(() => reduceTableState(stored.value, target.value, pendingEdits.value));
|
|
126
|
+
|
|
127
|
+
function commit(): void {
|
|
128
|
+
const base = stored.value;
|
|
129
|
+
const unconfirmed = pendingEdits.value.filter(
|
|
130
|
+
(edit) =>
|
|
131
|
+
!isJsonEqual(
|
|
132
|
+
reduceTableState(base, target.value, [edit]),
|
|
133
|
+
reduceTableState(base, target.value, []),
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
if (unconfirmed.length !== pendingEdits.value.length) pendingEdits.value = unconfirmed;
|
|
65
137
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
...tableStateNormalized.value,
|
|
71
|
-
// Copy the cache before editing it below: spreading keeps the same array,
|
|
72
|
-
// and splicing it in place would edit the current state as well — the
|
|
73
|
-
// change check at the end would then compare the new state against
|
|
74
|
-
// itself, find them equal, and skip the assignment, so a change that
|
|
75
|
-
// leaves `pTableParams` untouched (reordering columns, say) would never
|
|
76
|
-
// be written back to the project.
|
|
77
|
-
stateCache: [...tableStateNormalized.value.stateCache],
|
|
78
|
-
pTableParams: createDefaultPTableParams(),
|
|
79
|
-
};
|
|
138
|
+
const next = reduceTableState(base, target.value, unconfirmed);
|
|
139
|
+
if (!isJsonEqual(next, base)) tableStateDenormalized.value = next;
|
|
140
|
+
}
|
|
141
|
+
watch([stored, target, pendingEdits], commit, { immediate: true });
|
|
80
142
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(entry) => entry.sourceId === state.sourceId,
|
|
86
|
-
);
|
|
87
|
-
if (stateIdx !== -1) {
|
|
88
|
-
newState.stateCache.splice(stateIdx, 1);
|
|
89
|
-
}
|
|
90
|
-
const CacheDepth = 5;
|
|
91
|
-
newState.stateCache.push(state);
|
|
92
|
-
newState.stateCache = newState.stateCache.slice(-CacheDepth);
|
|
93
|
-
}
|
|
143
|
+
function edit(change: PlDataTableEdit): void {
|
|
144
|
+
pendingEdits.value = [...pendingEdits.value, change];
|
|
145
|
+
commit();
|
|
146
|
+
}
|
|
94
147
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
148
|
+
// While the model reports an error there is no source on screen; the
|
|
149
|
+
// controls keep showing the last one, so a filter that caused the error can
|
|
150
|
+
// still be removed.
|
|
151
|
+
const sourceId = computed<null | string>(() => {
|
|
152
|
+
const current = settings.value;
|
|
153
|
+
if (current.sourceId !== null) return current.sourceId;
|
|
154
|
+
return current.error !== null ? stored.value.pTableParams.sourceId : null;
|
|
99
155
|
});
|
|
156
|
+
const entry = computed(() => findEntry(state.value, sourceId.value));
|
|
100
157
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
gridState,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
});
|
|
158
|
+
function editCurrent(patch: PlDataTableEdit["patch"]): void {
|
|
159
|
+
if (sourceId.value !== null) edit({ sourceId: sourceId.value, patch });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const gridState = computed<PlDataTableGridStateCore>(() => entry.value?.gridState ?? {});
|
|
163
|
+
const sorting = computed(() => entry.value?.sorting ?? null);
|
|
164
|
+
const hiddenColIds = computed(() => entry.value?.hiddenColIds ?? null);
|
|
113
165
|
|
|
114
166
|
const sheetsState = computed<PlDataTableSheetState[]>({
|
|
115
|
-
get: () =>
|
|
116
|
-
set: (sheetsState) => {
|
|
117
|
-
const oldState = tableState.value;
|
|
118
|
-
if (oldState.sourceId) {
|
|
119
|
-
tableState.value = {
|
|
120
|
-
...oldState,
|
|
121
|
-
sheetsState,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
},
|
|
167
|
+
get: () => entry.value?.sheetsState ?? [],
|
|
168
|
+
set: (sheetsState) => editCurrent({ sheetsState }),
|
|
125
169
|
});
|
|
126
170
|
|
|
127
|
-
// --- User filters (editable by user) ---
|
|
128
171
|
const filtersState = computed<PlDataTableFiltersWithMeta>({
|
|
129
172
|
get: () => {
|
|
130
|
-
const raw =
|
|
173
|
+
const raw = entry.value?.filtersState;
|
|
131
174
|
return isNil(raw) ? getEmptyGroupWithMeta() : normalizeFiltersState(raw);
|
|
132
175
|
},
|
|
133
|
-
set: (filtersState
|
|
134
|
-
const oldState = tableState.value;
|
|
135
|
-
if (oldState.sourceId) {
|
|
136
|
-
tableState.value = {
|
|
137
|
-
...oldState,
|
|
138
|
-
filtersState,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
},
|
|
176
|
+
set: (filtersState) => editCurrent({ filtersState }),
|
|
142
177
|
});
|
|
143
178
|
|
|
144
|
-
// --- Default filters (from model, separate list) ---
|
|
145
179
|
const defaultFiltersState = computed<null | PlDataTableFiltersWithMeta>({
|
|
146
180
|
get: () => {
|
|
147
|
-
const raw =
|
|
148
|
-
if (!isNil(raw))
|
|
149
|
-
return normalizeFiltersState(raw);
|
|
150
|
-
}
|
|
181
|
+
const raw = entry.value?.defaultFiltersState;
|
|
182
|
+
if (!isNil(raw)) return normalizeFiltersState(raw);
|
|
151
183
|
if (!isNil(defaultFilters.value)) {
|
|
152
184
|
return annotateFiltersWithIds(normalizeFiltersState(defaultFilters.value));
|
|
153
185
|
}
|
|
154
186
|
return null;
|
|
155
187
|
},
|
|
156
|
-
set: (defaultFiltersState
|
|
157
|
-
const oldState = tableState.value;
|
|
158
|
-
if (oldState.sourceId) {
|
|
159
|
-
tableState.value = {
|
|
160
|
-
...oldState,
|
|
161
|
-
defaultFiltersState,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
},
|
|
188
|
+
set: (defaultFiltersState) => editCurrent({ defaultFiltersState }),
|
|
165
189
|
});
|
|
166
190
|
|
|
167
191
|
function resetDefaultFilters(): void {
|
|
@@ -171,20 +195,17 @@ export function useTableState(
|
|
|
171
195
|
}
|
|
172
196
|
|
|
173
197
|
const searchString = computed<string>({
|
|
174
|
-
get: () =>
|
|
175
|
-
set: (searchString
|
|
176
|
-
const oldState = tableState.value;
|
|
177
|
-
if (oldState.sourceId) {
|
|
178
|
-
tableState.value = {
|
|
179
|
-
...oldState,
|
|
180
|
-
searchString,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
},
|
|
198
|
+
get: () => entry.value?.searchString ?? "",
|
|
199
|
+
set: (searchString) => editCurrent({ searchString }),
|
|
184
200
|
});
|
|
185
201
|
|
|
186
202
|
return {
|
|
203
|
+
sourceId,
|
|
187
204
|
gridState,
|
|
205
|
+
sorting,
|
|
206
|
+
hiddenColIds,
|
|
207
|
+
getEntry: (id) => findEntry(state.value, id),
|
|
208
|
+
updateGrid: (id, grid) => edit({ sourceId: id, patch: grid }),
|
|
188
209
|
sheetsState,
|
|
189
210
|
searchString,
|
|
190
211
|
filtersState,
|
|
@@ -193,62 +214,64 @@ export function useTableState(
|
|
|
193
214
|
};
|
|
194
215
|
}
|
|
195
216
|
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
| PlDataTableStateV2CacheEntry
|
|
200
|
-
| {
|
|
201
|
-
sourceId: null;
|
|
202
|
-
gridState: Record<string, never>;
|
|
203
|
-
sheetsState: [];
|
|
204
|
-
filtersState: null;
|
|
205
|
-
defaultFiltersState: null;
|
|
206
|
-
searchString?: string;
|
|
207
|
-
};
|
|
217
|
+
// Internals
|
|
218
|
+
|
|
219
|
+
const CACHE_DEPTH = 5;
|
|
208
220
|
|
|
209
221
|
type FilterNode = FilterSpec<PlDataTableFilterSpecLeaf>;
|
|
210
222
|
type AnnotatedFilterSpec = FilterSpec<PlDataTableFilterSpecLeaf, PlDataTableFilterMeta>;
|
|
211
223
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
...(isNil(unsuppressedUserFilters) ? [] : [unsuppressedUserFilters]),
|
|
226
|
-
...(isNil(searchNode) ? [] : [searchNode]),
|
|
227
|
-
];
|
|
228
|
-
const filters: null | PlDataTableFilters = distillFilterSpec(
|
|
229
|
-
userParts.length === 0
|
|
230
|
-
? null
|
|
231
|
-
: userParts.length === 1
|
|
232
|
-
? userParts[0]
|
|
233
|
-
: { type: "and", filters: userParts },
|
|
234
|
-
);
|
|
235
|
-
const unsuppressedDefaultFilters = isNil(state.defaultFiltersState)
|
|
236
|
-
? null
|
|
237
|
-
: stripSuppressedFilters(state.defaultFiltersState);
|
|
238
|
-
const defaultFilters: null | PlDataTableFilters = isNil(unsuppressedDefaultFilters)
|
|
239
|
-
? null
|
|
240
|
-
: // If all filters are suppressed, we should pass an empty filter group instead of null to prevent fallback to defaults in the model
|
|
241
|
-
(distillFilterSpec(unsuppressedDefaultFilters) ?? getEmptyGroup());
|
|
224
|
+
function applyEdit(
|
|
225
|
+
state: PlDataTableStateV2Normalized,
|
|
226
|
+
{ sourceId, patch }: PlDataTableEdit,
|
|
227
|
+
): PlDataTableStateV2Normalized {
|
|
228
|
+
const current = findEntry(state, sourceId);
|
|
229
|
+
const entry = { ...(current ?? createEntry(sourceId)), ...patch };
|
|
230
|
+
return {
|
|
231
|
+
...state,
|
|
232
|
+
stateCache: isNil(current)
|
|
233
|
+
? [...state.stateCache, entry]
|
|
234
|
+
: state.stateCache.map((e) => (e === current ? entry : e)),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
242
237
|
|
|
238
|
+
function alignWithTarget(
|
|
239
|
+
state: PlDataTableStateV2Normalized,
|
|
240
|
+
{ sourceId, sheets }: PlDataTableTarget,
|
|
241
|
+
): PlDataTableStateV2Normalized {
|
|
242
|
+
const current = findEntry(state, sourceId) ?? createEntry(sourceId);
|
|
243
|
+
const entry = { ...current, sheetsState: resolveSheetsState(sheets, current.sheetsState) };
|
|
243
244
|
return {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
filters,
|
|
248
|
-
defaultFilters,
|
|
245
|
+
...state,
|
|
246
|
+
stateCache: [...state.stateCache.filter((e) => e.sourceId !== sourceId), entry],
|
|
247
|
+
pTableParams: { ...createDefaultPTableParams(), sourceId },
|
|
249
248
|
};
|
|
250
249
|
}
|
|
251
250
|
|
|
251
|
+
function findEntry(
|
|
252
|
+
state: PlDataTableStateV2Normalized,
|
|
253
|
+
sourceId: null | string,
|
|
254
|
+
): undefined | PlDataTableStateV2CacheEntry {
|
|
255
|
+
if (isNil(sourceId)) return undefined;
|
|
256
|
+
return state.stateCache.find((e) => e.sourceId === sourceId);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function createEntry(sourceId: string): PlDataTableStateV2CacheEntry {
|
|
260
|
+
return {
|
|
261
|
+
sourceId,
|
|
262
|
+
gridState: {},
|
|
263
|
+
sorting: null,
|
|
264
|
+
hiddenColIds: null,
|
|
265
|
+
sheetsState: [],
|
|
266
|
+
filtersState: null,
|
|
267
|
+
defaultFiltersState: null,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isSheetOption(sheet: PlDataTableSheet, value: string | number): boolean {
|
|
272
|
+
return sheet.options.some((option) => option.value === value);
|
|
273
|
+
}
|
|
274
|
+
|
|
252
275
|
/**
|
|
253
276
|
* Normalizes raw filter state into a valid root filter structure.
|
|
254
277
|
* Valid structure is Root(Group, Group, ...) — double nesting required:
|
|
@@ -320,53 +343,6 @@ function getEmptyGroupWithMeta(): PlDataTableFiltersWithMeta {
|
|
|
320
343
|
} as PlDataTableFiltersWithMeta;
|
|
321
344
|
}
|
|
322
345
|
|
|
323
|
-
/**
|
|
324
|
-
* Recursively removes nodes where isSuppressed === true from a PlDataTableFiltersWithMeta tree.
|
|
325
|
-
*/
|
|
326
|
-
function stripSuppressedFilters(node: PlDataTableFiltersWithMeta): PlDataTableFiltersWithMeta {
|
|
327
|
-
return {
|
|
328
|
-
...node,
|
|
329
|
-
filters: node.filters
|
|
330
|
-
.filter((child) => !("isSuppressed" in child && child.isSuppressed === true))
|
|
331
|
-
.map((child) =>
|
|
332
|
-
"filters" in child && (child.type === "and" || child.type === "or")
|
|
333
|
-
? stripSuppressedFilters(child as PlDataTableFiltersWithMeta)
|
|
334
|
-
: child,
|
|
335
|
-
),
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function createSearchFilterNode(
|
|
340
|
-
columns: PTableColumnSpec[],
|
|
341
|
-
search: null | undefined | string,
|
|
342
|
-
): null | FilterSpec<FilterSpecLeaf<PTableColumnId>> {
|
|
343
|
-
const trimmed = search?.trim();
|
|
344
|
-
if (isNil(trimmed) || trimmed.length === 0) return null;
|
|
345
|
-
|
|
346
|
-
const parts: FilterSpec<FilterSpecLeaf<PTableColumnId>>[] = [];
|
|
347
|
-
const numericValue = Number(trimmed);
|
|
348
|
-
const isValidNumber = trimmed.length > 0 && !isNaN(numericValue) && isFinite(numericValue);
|
|
349
|
-
|
|
350
|
-
for (const col of columns) {
|
|
351
|
-
const column = getPTableColumnId(col);
|
|
352
|
-
const spec = col.spec;
|
|
353
|
-
|
|
354
|
-
if (isStringValueType(spec)) {
|
|
355
|
-
parts.push({ type: "patternEquals", column, value: trimmed });
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (isNumericValueType(spec) && isValidNumber) {
|
|
359
|
-
parts.push({ type: "equal", column, x: numericValue });
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (parts.length === 0) return null;
|
|
364
|
-
|
|
365
|
-
return { type: "or", filters: parts };
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// --- Helpers ---
|
|
369
|
-
|
|
370
346
|
/**
|
|
371
347
|
* Recursively ensures every node in a filter tree has an `id` field.
|
|
372
348
|
* Does not set `source` meta — defaults are now a separate list.
|
|
@@ -406,51 +382,3 @@ function annotateNodeWithIds(
|
|
|
406
382
|
return { ...node, id: getField(node, "id") ?? randomInt() } as AnnotatedFilterSpec;
|
|
407
383
|
}
|
|
408
384
|
}
|
|
409
|
-
|
|
410
|
-
// --- Utilities ---
|
|
411
|
-
|
|
412
|
-
function convertPartitionFiltersToFilterSpec(
|
|
413
|
-
sheetsState: PlDataTableSheetState[],
|
|
414
|
-
): FilterSpec<FilterSpecLeaf<PTableColumnId>>[] {
|
|
415
|
-
return sheetsState.map((s) => {
|
|
416
|
-
const column: PTableColumnId = { type: "axis", id: s.axisId };
|
|
417
|
-
return typeof s.value === "number"
|
|
418
|
-
? { type: "equal" as const, column, x: s.value }
|
|
419
|
-
: { type: "patternEquals" as const, column, value: s.value };
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* AG Grid omits `sort` from its state while nothing is sorted, so the absent
|
|
425
|
-
* state must stay distinguishable from an explicitly emptied sort model: the
|
|
426
|
-
* model falls back to the block's default sorting on `null` only, and treats
|
|
427
|
-
* `[]` as "user cleared the sorting" (see `resolveSorting` in
|
|
428
|
-
* `createPlDataTableV3`). `normalizeSort` in `PlAgDataTableV2.vue` turns the
|
|
429
|
-
* absent state into `{ sortModel: [] }` once an explicit one has been seen.
|
|
430
|
-
*/
|
|
431
|
-
export function convertAgSortingToPTableSorting(
|
|
432
|
-
state: PlDataTableGridStateCore["sort"],
|
|
433
|
-
): PTableSorting[] | null {
|
|
434
|
-
if (isNil(state)) return null;
|
|
435
|
-
return state.sortModel.map((item) => ({
|
|
436
|
-
column: parseJson<PTableColumnId>(item.colId),
|
|
437
|
-
ascending: item.sort === "asc",
|
|
438
|
-
naAndAbsentAreLeastValues: item.sort === "asc",
|
|
439
|
-
}));
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function getHiddenColIds(
|
|
443
|
-
state: PlDataTableGridStateCore["columnVisibility"],
|
|
444
|
-
): PTableColumnId[] | null {
|
|
445
|
-
return state?.hiddenColIds?.map((json) => parseJson<PTableColumnId>(json)) ?? null;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function makeDefaultState(): PlDataTableStateV2CacheEntryNullable {
|
|
449
|
-
return {
|
|
450
|
-
sourceId: null,
|
|
451
|
-
gridState: {},
|
|
452
|
-
sheetsState: [],
|
|
453
|
-
filtersState: null,
|
|
454
|
-
defaultFiltersState: null,
|
|
455
|
-
};
|
|
456
|
-
}
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
type ListOptionBase,
|
|
5
5
|
type PlDataTableModel,
|
|
6
6
|
type PlDataTableSheet,
|
|
7
|
-
type PlDataTableSheetState,
|
|
8
7
|
type PTableKey,
|
|
9
8
|
type PTableValue,
|
|
10
9
|
type OutputWithStatus,
|
|
@@ -25,6 +24,8 @@ export type PlDataTableSettingsV2Base =
|
|
|
25
24
|
sheets: PlDataTableSheet[];
|
|
26
25
|
/** Result of `createPlDataTableV2` */
|
|
27
26
|
model: PlDataTableModel | undefined;
|
|
27
|
+
/** The model is still computing its outputs */
|
|
28
|
+
pending: boolean;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
/** Data table V2 settings */
|
|
@@ -78,6 +79,7 @@ export function usePlDataTableSettingsV2<T>(
|
|
|
78
79
|
sourceId: canonicalize(sourceIdValue)!,
|
|
79
80
|
sheets: sheetsValue,
|
|
80
81
|
model: model.value,
|
|
82
|
+
pending: !model.stable,
|
|
81
83
|
}
|
|
82
84
|
: { sourceId: null, pending: !model.stable, error: null };
|
|
83
85
|
} else {
|
|
@@ -86,6 +88,7 @@ export function usePlDataTableSettingsV2<T>(
|
|
|
86
88
|
sourceId: canonicalize(sourceIdValue)!,
|
|
87
89
|
sheets: [],
|
|
88
90
|
model: model.value,
|
|
91
|
+
pending: !model.stable,
|
|
89
92
|
}
|
|
90
93
|
: { sourceId: null, pending: !model.stable, error: null };
|
|
91
94
|
}
|
|
@@ -97,6 +100,7 @@ export function usePlDataTableSettingsV2<T>(
|
|
|
97
100
|
sourceId: canonicalize("static")!,
|
|
98
101
|
sheets: sheetsValue,
|
|
99
102
|
model: model.value,
|
|
103
|
+
pending: !model.stable,
|
|
100
104
|
}
|
|
101
105
|
: { sourceId: null, pending: !model.stable, error: null };
|
|
102
106
|
} else {
|
|
@@ -105,6 +109,7 @@ export function usePlDataTableSettingsV2<T>(
|
|
|
105
109
|
sourceId: canonicalize("static")!,
|
|
106
110
|
sheets: [],
|
|
107
111
|
model: model.value,
|
|
112
|
+
pending: !model.stable,
|
|
108
113
|
}
|
|
109
114
|
: { sourceId: null, pending: !model.stable, error: null };
|
|
110
115
|
}
|
|
@@ -187,13 +192,6 @@ export type PlAgOverlayNoRowsParams = {
|
|
|
187
192
|
text?: string;
|
|
188
193
|
};
|
|
189
194
|
|
|
190
|
-
export type PlDataTableSheetsSettings = {
|
|
191
|
-
/** User-provided sheets for the sourceId */
|
|
192
|
-
sheets: PlDataTableSheet[];
|
|
193
|
-
/** Persisted selection for the sourceId */
|
|
194
|
-
cachedState: PlDataTableSheetState[];
|
|
195
|
-
};
|
|
196
|
-
|
|
197
195
|
export type PlDataTableSheetNormalized = {
|
|
198
196
|
/** id of the axis */
|
|
199
197
|
axisId: AxisId;
|
|
@@ -201,6 +199,4 @@ export type PlDataTableSheetNormalized = {
|
|
|
201
199
|
prefix: string;
|
|
202
200
|
/** options to show in the filter dropdown */
|
|
203
201
|
options: ListOptionBase<string | number>[];
|
|
204
|
-
/** default (selected) value */
|
|
205
|
-
defaultValue: string | number;
|
|
206
202
|
};
|