@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/ui-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"@milaboratories/columns-collection-driver": "0.2.15",
|
|
15
15
|
"@milaboratories/pf-spec-driver": "1.5.17",
|
|
16
16
|
"@milaboratories/pl-model-common": "1.55.2",
|
|
17
|
-
"@milaboratories/uikit": "2.17.
|
|
18
|
-
"@platforma-sdk/model": "1.
|
|
17
|
+
"@milaboratories/uikit": "2.17.8",
|
|
18
|
+
"@platforma-sdk/model": "1.89.0",
|
|
19
19
|
"@types/d3-format": "^3.0.4",
|
|
20
20
|
"@types/node": "~24.19.2",
|
|
21
21
|
"@types/semver": "^7.7.0",
|
|
@@ -2,79 +2,36 @@
|
|
|
2
2
|
import { PlDropdownLine } from "@milaboratories/uikit";
|
|
3
3
|
import type { PlDataTableSheet, PlDataTableSheetState } from "@platforma-sdk/model";
|
|
4
4
|
import { getAxisId } from "@platforma-sdk/model";
|
|
5
|
-
import { computed
|
|
6
|
-
import type { PlDataTableSheetsSettings, PlDataTableSheetNormalized } from "./types";
|
|
5
|
+
import { computed } from "vue";
|
|
7
6
|
import { isJsonEqual } from "@milaboratories/helpers";
|
|
7
|
+
import type { PlDataTableSheetNormalized } from "./types";
|
|
8
8
|
|
|
9
|
-
const state = defineModel<PlDataTableSheetState[]>({
|
|
10
|
-
default: () => [],
|
|
11
|
-
});
|
|
12
9
|
const props = defineProps<{
|
|
13
|
-
|
|
10
|
+
/** Sheets of the source on screen */
|
|
11
|
+
sheets: PlDataTableSheet[];
|
|
12
|
+
/** Value picked on each sheet that has options, in the same order */
|
|
13
|
+
state: PlDataTableSheetState[];
|
|
14
|
+
onChange: (state: PlDataTableSheetState[]) => void;
|
|
14
15
|
}>();
|
|
15
16
|
|
|
16
|
-
//
|
|
17
|
-
const sheets = computed<PlDataTableSheetNormalized[]>(() =>
|
|
18
|
-
|
|
17
|
+
// Sheets without options are not shown
|
|
18
|
+
const sheets = computed<PlDataTableSheetNormalized[]>(() =>
|
|
19
|
+
props.sheets
|
|
19
20
|
.filter((sheet) => sheet.options.length > 0)
|
|
20
|
-
.map((sheet, i) => {
|
|
21
|
-
|
|
21
|
+
.map((sheet, i) => ({
|
|
22
|
+
axisId: getAxisId(sheet.axis),
|
|
23
|
+
prefix: (sheet.axis.annotations?.["pl7.app/label"]?.trim() ?? `Unlabeled axis ${i}`) + ":",
|
|
24
|
+
options: sheet.options,
|
|
25
|
+
})),
|
|
26
|
+
);
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return isJsonEqual(s.axisId, axisId);
|
|
26
|
-
});
|
|
27
|
-
if (cachedState && isValidOption(sheet, cachedState.value)) {
|
|
28
|
-
return cachedState.value;
|
|
29
|
-
}
|
|
30
|
-
if (sheet.defaultValue && isValidOption(sheet, sheet.defaultValue)) {
|
|
31
|
-
return sheet.defaultValue;
|
|
32
|
-
}
|
|
33
|
-
return sheet.options[0].value;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const makePrefix = (): string => {
|
|
37
|
-
return (sheet.axis.annotations?.["pl7.app/label"]?.trim() ?? `Unlabeled axis ${i}`) + ":";
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
axisId,
|
|
42
|
-
prefix: makePrefix(),
|
|
43
|
-
options: sheet.options,
|
|
44
|
-
defaultValue: getDefaultValue(),
|
|
45
|
-
} satisfies PlDataTableSheetNormalized;
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
function isValidOption(sheet: PlDataTableSheet, value: string | number): boolean {
|
|
50
|
-
return sheet.options.some((option) => option.value === value);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Restore state from settings
|
|
54
|
-
watchEffect(() => {
|
|
55
|
-
const oldState = [...state.value];
|
|
56
|
-
const newState = sheets.value.map((sheet, i) => makeStateEntry(i, sheet.defaultValue));
|
|
57
|
-
if (!isJsonEqual(oldState, newState)) {
|
|
58
|
-
state.value = newState;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
function makeStateEntry(i: number, value: string | number): PlDataTableSheetState {
|
|
28
|
+
function onSheetChanged(i: number, value: string | number): void {
|
|
29
|
+
if (props.state[i]?.value === value) return;
|
|
63
30
|
const axisId = sheets.value[i].axisId;
|
|
64
|
-
|
|
65
|
-
axisId,
|
|
66
|
-
value,
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function onSheetChanged(i: number, newValue: string | number): void {
|
|
71
|
-
const oldState = [...state.value];
|
|
72
|
-
const stateEntry = makeStateEntry(i, newValue);
|
|
73
|
-
if (!isJsonEqual(oldState[i], stateEntry)) {
|
|
74
|
-
const newState = [...oldState];
|
|
75
|
-
newState[i] = stateEntry;
|
|
76
|
-
state.value = newState;
|
|
77
|
-
}
|
|
31
|
+
props.onChange([
|
|
32
|
+
...props.state.filter((sheet) => !isJsonEqual(sheet.axisId, axisId)),
|
|
33
|
+
{ axisId, value },
|
|
34
|
+
]);
|
|
78
35
|
}
|
|
79
36
|
</script>
|
|
80
37
|
|
|
@@ -86,14 +43,13 @@ function onSheetChanged(i: number, newValue: string | number): void {
|
|
|
86
43
|
>
|
|
87
44
|
<slot name="before" />
|
|
88
45
|
<template v-for="(sheet, i) in sheets" :key="i">
|
|
89
|
-
<!-- For some reason state[i] is undefined when the sheet initially loads, so v-if to suppress the error -->
|
|
90
46
|
<PlDropdownLine
|
|
91
47
|
v-if="state[i]"
|
|
92
48
|
data-testid="pl-ag-data-table-sheets-dropdown"
|
|
93
49
|
:model-value="state[i].value"
|
|
94
50
|
:options="sheet.options"
|
|
95
51
|
:prefix="sheet.prefix"
|
|
96
|
-
@update:model-value="(
|
|
52
|
+
@update:model-value="(value: string | number) => onSheetChanged(i, value)"
|
|
97
53
|
/>
|
|
98
54
|
</template>
|
|
99
55
|
<slot name="after" />
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
PlDataTableStateV2,
|
|
8
8
|
PlSelectionModel,
|
|
9
9
|
PlTableColumnIdJson,
|
|
10
|
+
PTableColumnId,
|
|
10
11
|
PTableColumnSpec,
|
|
11
12
|
PTableKey,
|
|
12
13
|
} from "@platforma-sdk/model";
|
|
@@ -20,7 +21,7 @@ import {
|
|
|
20
21
|
} from "@platforma-sdk/model";
|
|
21
22
|
import type { CellRendererSelectorFunc, GridApi, GridState } from "ag-grid-enterprise";
|
|
22
23
|
import { AgGridVue } from "ag-grid-vue3";
|
|
23
|
-
import { computed, effectScope, nextTick, ref, toRefs, watch, watchEffect } from "vue";
|
|
24
|
+
import { computed, effectScope, nextTick, ref, shallowRef, toRefs, watch, watchEffect } from "vue";
|
|
24
25
|
import PlAgCsvExporter from "../PlAgCsvExporter/PlAgCsvExporter.vue";
|
|
25
26
|
import { PlAgGridColumnManager } from "../PlAgGridColumnManager";
|
|
26
27
|
import PlTableFiltersV2 from "../PlTableFilters/PlTableFiltersV2.vue";
|
|
@@ -31,7 +32,7 @@ import { DeferredCircular, ensureNodeVisible } from "./sources/focus-row";
|
|
|
31
32
|
import { PlAgDataTableRowNumberColId } from "./sources/row-number";
|
|
32
33
|
import type { PlAgCellButtonAxisParams } from "./sources/table-source-v2";
|
|
33
34
|
import { calculateGridOptions, effectiveVisibility } from "./sources/table-source-v2";
|
|
34
|
-
import { isStoredStateApplied } from "./sources/grid-state";
|
|
35
|
+
import { createGridRestoreState, isStoredStateApplied, readGridReport } from "./sources/grid-state";
|
|
35
36
|
import { useTableState } from "./sources/table-state-v2";
|
|
36
37
|
import type {
|
|
37
38
|
PlAgDataTableV2Controller,
|
|
@@ -39,7 +40,6 @@ import type {
|
|
|
39
40
|
PlAgOverlayLoadingParams,
|
|
40
41
|
PlAgOverlayNoRowsParams,
|
|
41
42
|
PlDataTableSettingsV2,
|
|
42
|
-
PlDataTableSheetsSettings,
|
|
43
43
|
PlTableRowId,
|
|
44
44
|
} from "./types";
|
|
45
45
|
import { useFilterableColumns } from "./compositions/useFilterableColumns";
|
|
@@ -128,38 +128,21 @@ const { gridApi, gridOptions } = useGrid({
|
|
|
128
128
|
cellRendererSelector: props.cellRendererSelector,
|
|
129
129
|
});
|
|
130
130
|
let isReloading = false;
|
|
131
|
+
/** Source the grid's columns were built for; `null` while the grid has none. */
|
|
132
|
+
const boundSourceId = shallowRef<null | string>(null);
|
|
131
133
|
gridOptions.value.onGridPreDestroyed = (event) => {
|
|
132
|
-
if (!isReloading)
|
|
133
|
-
|
|
134
|
-
makePartialState(event.api.getState()),
|
|
135
|
-
gridState.value,
|
|
136
|
-
event.api,
|
|
137
|
-
getColumnsMeta(),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
134
|
+
if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));
|
|
135
|
+
gridOptions.value.initialState = restoreState.value;
|
|
140
136
|
gridApi.value = null;
|
|
141
137
|
};
|
|
142
138
|
gridOptions.value.onRowDoubleClicked = (event) => {
|
|
143
139
|
if (event.data && event.data.axesKey) emit("rowDoubleClicked", event.data.axesKey);
|
|
144
140
|
};
|
|
145
141
|
gridOptions.value.onStateUpdated = (event) => {
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
// order) that the grid will never report back, and the reload watch below
|
|
151
|
-
// would then try to apply it on every remount, forever. Wait for the grid to
|
|
152
|
-
// say something about itself; it always does once its columns are in.
|
|
153
|
-
if (isJsonEqual(reportedState, {})) return;
|
|
154
|
-
|
|
155
|
-
const partialState = normalizeGridState(
|
|
156
|
-
reportedState,
|
|
157
|
-
gridState.value,
|
|
158
|
-
event.api,
|
|
159
|
-
getColumnsMeta(),
|
|
160
|
-
);
|
|
161
|
-
// We have to keep initialState synchronized with gridState for gridState recovery after key updating.
|
|
162
|
-
gridOptions.value.initialState = gridState.value = partialState;
|
|
142
|
+
saveGridState(event.api, makePartialState(event.state));
|
|
143
|
+
// Keep initialState in step with the stored grid state, so the grid recreated
|
|
144
|
+
// by the reload watch below comes back with it.
|
|
145
|
+
gridOptions.value.initialState = restoreState.value;
|
|
163
146
|
|
|
164
147
|
if (!isJsonEqual(event.sources, ["columnSizing"])) {
|
|
165
148
|
event.api.autoSizeColumns(
|
|
@@ -170,7 +153,7 @@ gridOptions.value.onStateUpdated = (event) => {
|
|
|
170
153
|
}
|
|
171
154
|
};
|
|
172
155
|
|
|
173
|
-
const [filterableColumns
|
|
156
|
+
const [filterableColumns] = useFilterableColumns(
|
|
174
157
|
() => settings.value.sourceId,
|
|
175
158
|
() => gridOptions.value.columnDefs ?? null,
|
|
176
159
|
);
|
|
@@ -178,26 +161,48 @@ const defaultFilters = computed(() =>
|
|
|
178
161
|
settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,
|
|
179
162
|
);
|
|
180
163
|
const {
|
|
164
|
+
sourceId: shownSourceId,
|
|
181
165
|
gridState,
|
|
166
|
+
sorting,
|
|
167
|
+
hiddenColIds,
|
|
168
|
+
getEntry,
|
|
169
|
+
updateGrid,
|
|
182
170
|
sheetsState,
|
|
183
171
|
searchString,
|
|
184
172
|
filtersState,
|
|
185
173
|
defaultFiltersState,
|
|
186
174
|
resetDefaultFilters,
|
|
187
|
-
} = useTableState(tableState, settings,
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
175
|
+
} = useTableState(tableState, settings, defaultFilters);
|
|
176
|
+
const sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));
|
|
177
|
+
const restoreState = computed(() =>
|
|
178
|
+
createGridRestoreState({
|
|
179
|
+
gridState: gridState.value,
|
|
180
|
+
sorting: sorting.value,
|
|
181
|
+
hiddenColIds: hiddenColIds.value,
|
|
182
|
+
}),
|
|
183
|
+
);
|
|
184
|
+
gridOptions.value.initialState = restoreState.value;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Store what the grid reports under the source its columns belong to: while
|
|
188
|
+
* the table switches sources the grid still holds the previous source's
|
|
189
|
+
* columns, and their state must not land on the new source.
|
|
190
|
+
*/
|
|
191
|
+
function saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {
|
|
192
|
+
const sourceId = boundSourceId.value;
|
|
193
|
+
// AG Grid reports an entirely empty state until its columns have been taken
|
|
194
|
+
// into its own state. Such a report says nothing about the user's choices, and
|
|
195
|
+
// reading defaults from the live columns at that point would invent some.
|
|
196
|
+
// Wait for the grid to say something about itself; it always does once its
|
|
197
|
+
// columns are in.
|
|
198
|
+
if (sourceId === null || isJsonEqual(reported, {})) return;
|
|
199
|
+
updateGrid(
|
|
200
|
+
sourceId,
|
|
201
|
+
readGridReport(reported, getEntry(sourceId), () =>
|
|
202
|
+
getDefaultHiddenColIds(api, getColumnsMeta()),
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
201
206
|
|
|
202
207
|
// Restore proper types erased by AgGrid
|
|
203
208
|
function makePartialState(state: GridState): PlDataTableGridStateCore {
|
|
@@ -223,69 +228,6 @@ function makePartialState(state: GridState): PlDataTableGridStateCore {
|
|
|
223
228
|
};
|
|
224
229
|
}
|
|
225
230
|
|
|
226
|
-
// AG Grid omits parts of its state that carry no information — columnVisibility
|
|
227
|
-
// when every column is visible, sort when nothing is sorted. The model needs
|
|
228
|
-
// "no state yet" (fall back to the block's defaults) to stay distinguishable
|
|
229
|
-
// from "user explicitly cleared it" (store []), so both are normalized against
|
|
230
|
-
// the previous state before the state is persisted.
|
|
231
|
-
function normalizeGridState(
|
|
232
|
-
partialState: PlDataTableGridStateCore,
|
|
233
|
-
prevState: PlDataTableGridStateCore,
|
|
234
|
-
api: GridApi<PlAgDataTableV2Row>,
|
|
235
|
-
columnsMeta: PlDataTableColumnsMeta | undefined,
|
|
236
|
-
): PlDataTableGridStateCore {
|
|
237
|
-
return normalizeSort(
|
|
238
|
-
normalizeColumnVisibility(partialState, prevState, api, columnsMeta),
|
|
239
|
-
prevState,
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// AG Grid returns sort: undefined when no column is sorted. Left as-is that
|
|
244
|
-
// erases the block's default sorting the moment any unrelated grid state is
|
|
245
|
-
// persisted, so the undefined is only turned into an explicit empty sort model
|
|
246
|
-
// once the user has actually sorted something before.
|
|
247
|
-
function normalizeSort(
|
|
248
|
-
partialState: PlDataTableGridStateCore,
|
|
249
|
-
prevState: PlDataTableGridStateCore,
|
|
250
|
-
): PlDataTableGridStateCore {
|
|
251
|
-
if (partialState.sort !== undefined) return partialState;
|
|
252
|
-
|
|
253
|
-
if (prevState.sort !== undefined) {
|
|
254
|
-
// Had an explicit sort model before → user cleared the sorting → store [].
|
|
255
|
-
return { ...partialState, sort: { sortModel: [] } };
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Never sorted → leave undefined so the model applies its default sorting.
|
|
259
|
-
return partialState;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// AG Grid returns columnVisibility: undefined when all columns are visible.
|
|
263
|
-
// We need to distinguish "no state yet" (use isColumnOptional defaults) from
|
|
264
|
-
// "user explicitly showed all columns" (store []). This function normalizes
|
|
265
|
-
// the undefined from AG Grid based on the previous state.
|
|
266
|
-
function normalizeColumnVisibility(
|
|
267
|
-
partialState: PlDataTableGridStateCore,
|
|
268
|
-
prevState: PlDataTableGridStateCore,
|
|
269
|
-
api: GridApi<PlAgDataTableV2Row>,
|
|
270
|
-
columnsMeta: PlDataTableColumnsMeta | undefined,
|
|
271
|
-
): PlDataTableGridStateCore {
|
|
272
|
-
if (partialState.columnVisibility !== undefined) return partialState;
|
|
273
|
-
|
|
274
|
-
if (prevState.columnVisibility !== undefined) {
|
|
275
|
-
// Had explicit visibility state before → user made all columns visible → store [].
|
|
276
|
-
return { ...partialState, columnVisibility: { hiddenColIds: [] } };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// No previous explicit state → compute defaults from current columns
|
|
280
|
-
// to replicate: hide: hiddenColIds?.includes(colId) ?? isColumnOptional(spec.spec)
|
|
281
|
-
const defaultHidden = getDefaultHiddenColIds(api, columnsMeta);
|
|
282
|
-
if (defaultHidden.length > 0) {
|
|
283
|
-
return { ...partialState, columnVisibility: { hiddenColIds: defaultHidden } };
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return partialState;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
231
|
/** Sidecar display meta is only on the `model` branch of the settings union. */
|
|
290
232
|
function getColumnsMeta(): PlDataTableColumnsMeta | undefined {
|
|
291
233
|
return "model" in props.settings ? props.settings.model?.columnsMeta : undefined;
|
|
@@ -310,19 +252,23 @@ function getDefaultHiddenColIds(
|
|
|
310
252
|
.map((col) => col.getColId() as PlTableColumnIdJson);
|
|
311
253
|
}
|
|
312
254
|
|
|
313
|
-
// Reload AgGrid when new state arrives from server
|
|
255
|
+
// Reload AgGrid when new state arrives from server, or when the grid takes the
|
|
256
|
+
// columns of a source whose stored state it does not show yet
|
|
314
257
|
const reloadKey = ref(0);
|
|
315
258
|
watch(
|
|
316
|
-
() => [gridApi.value,
|
|
317
|
-
([gridApi,
|
|
318
|
-
if (!gridApi || gridApi.isDestroyed()) return;
|
|
259
|
+
() => [gridApi.value, restoreState.value, boundSourceId.value] as const,
|
|
260
|
+
([gridApi, restoreState, boundSourceId]) => {
|
|
261
|
+
if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;
|
|
319
262
|
const selfState = makePartialState(gridApi.getState());
|
|
320
263
|
const gridColIds = new Set(
|
|
321
264
|
(gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),
|
|
322
265
|
);
|
|
323
|
-
if (
|
|
266
|
+
if (
|
|
267
|
+
!isJsonEqual(restoreState, {}) &&
|
|
268
|
+
!isStoredStateApplied(restoreState, selfState, gridColIds)
|
|
269
|
+
) {
|
|
324
270
|
isReloading = true;
|
|
325
|
-
gridOptions.value.initialState =
|
|
271
|
+
gridOptions.value.initialState = restoreState;
|
|
326
272
|
++reloadKey.value;
|
|
327
273
|
nextTick(() => {
|
|
328
274
|
isReloading = false;
|
|
@@ -410,6 +356,7 @@ watch(
|
|
|
410
356
|
// No data source selected -> reset state to default
|
|
411
357
|
if (settings.sourceId === null) {
|
|
412
358
|
++generation.value;
|
|
359
|
+
boundSourceId.value = null;
|
|
413
360
|
gridApi.updateGridOptions({
|
|
414
361
|
loading: true,
|
|
415
362
|
loadingOverlayComponentParams: {
|
|
@@ -443,6 +390,11 @@ watch(
|
|
|
443
390
|
settings.model?.visibleTableHandle === undefined
|
|
444
391
|
) {
|
|
445
392
|
if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;
|
|
393
|
+
// A grid that already shows a table keeps showing it; one that is still
|
|
394
|
+
// waiting says why.
|
|
395
|
+
if (gridApi.getGridOption("loading") === true) {
|
|
396
|
+
setLoadingVariant(gridApi, settings.pending ? "running" : "not-ready");
|
|
397
|
+
}
|
|
446
398
|
return;
|
|
447
399
|
}
|
|
448
400
|
|
|
@@ -468,16 +420,17 @@ watch(
|
|
|
468
420
|
}
|
|
469
421
|
}
|
|
470
422
|
|
|
471
|
-
// Model
|
|
423
|
+
// Model built for another source -> show skeletons until it catches up.
|
|
424
|
+
// A model that reports no source was built from a state that names none,
|
|
425
|
+
// or does not take the state at all, and is shown as it is.
|
|
472
426
|
const sourceChanged =
|
|
473
|
-
settings.model
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
const rowCount = !sourceChanged && state.length > 0 ? state[0].rowCount : 1;
|
|
427
|
+
settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;
|
|
428
|
+
if (sourceChanged) {
|
|
429
|
+
if (gridApi.getGridOption("loading") === true) setLoadingVariant(gridApi, "loading");
|
|
477
430
|
return gridApi.updateGridOptions({
|
|
478
431
|
serverSideDatasource: {
|
|
479
432
|
getRows: (params) => {
|
|
480
|
-
params.success({ rowData: [], rowCount });
|
|
433
|
+
params.success({ rowData: [], rowCount: 1 });
|
|
481
434
|
},
|
|
482
435
|
},
|
|
483
436
|
});
|
|
@@ -485,6 +438,7 @@ watch(
|
|
|
485
438
|
|
|
486
439
|
// Model ready -> calculate new state
|
|
487
440
|
const stateGeneration = generation.value;
|
|
441
|
+
const stateSourceId = settings.sourceId;
|
|
488
442
|
calculateGridOptions({
|
|
489
443
|
generation,
|
|
490
444
|
pfDriver: getRawPlatformaInstance().pFrameDriver,
|
|
@@ -493,7 +447,7 @@ watch(
|
|
|
493
447
|
columnsMeta: settings.model?.columnsMeta,
|
|
494
448
|
sheets: settings.sheets ?? [],
|
|
495
449
|
dataRenderedTracker,
|
|
496
|
-
hiddenColIds:
|
|
450
|
+
hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),
|
|
497
451
|
cellButtonAxisParams: {
|
|
498
452
|
showCellButtonForAxisId: props.showCellButtonForAxisId,
|
|
499
453
|
cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,
|
|
@@ -506,6 +460,7 @@ watch(
|
|
|
506
460
|
gridApi.updateGridOptions({
|
|
507
461
|
...options,
|
|
508
462
|
});
|
|
463
|
+
boundSourceId.value = stateSourceId;
|
|
509
464
|
if (selection.value) {
|
|
510
465
|
// Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys
|
|
511
466
|
const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;
|
|
@@ -572,6 +527,18 @@ watch(
|
|
|
572
527
|
},
|
|
573
528
|
);
|
|
574
529
|
|
|
530
|
+
function setLoadingVariant(
|
|
531
|
+
api: GridApi<PlAgDataTableV2Row>,
|
|
532
|
+
variant: PlAgOverlayLoadingParams["variant"],
|
|
533
|
+
): void {
|
|
534
|
+
api.updateGridOptions({
|
|
535
|
+
loadingOverlayComponentParams: {
|
|
536
|
+
...gridOptions.value.loadingOverlayComponentParams,
|
|
537
|
+
variant,
|
|
538
|
+
} satisfies PlAgOverlayLoadingParams,
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
|
|
575
542
|
watch(
|
|
576
543
|
() => ({
|
|
577
544
|
gridApi: gridApi.value,
|
|
@@ -630,7 +597,11 @@ watchEffect(() => {
|
|
|
630
597
|
:table-handle="'model' in settings ? settings?.model?.visibleTableHandle : undefined"
|
|
631
598
|
:columns-meta="getColumnsMeta()"
|
|
632
599
|
/>
|
|
633
|
-
<PlAgDataTableSheets
|
|
600
|
+
<PlAgDataTableSheets
|
|
601
|
+
:sheets="sheets"
|
|
602
|
+
:state="sheetsState"
|
|
603
|
+
:on-change="(state) => (sheetsState = state)"
|
|
604
|
+
>
|
|
634
605
|
<template v-if="$slots['before-sheets']" #before>
|
|
635
606
|
<slot name="before-sheets" />
|
|
636
607
|
</template>
|
|
@@ -98,6 +98,39 @@ const Host = defineComponent({
|
|
|
98
98
|
},
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Stands in for a block whose model builds the table from the stored state: the
|
|
103
|
+
* model reports the source the stored state points at, as a real one does.
|
|
104
|
+
*/
|
|
105
|
+
const ModelHost = defineComponent({
|
|
106
|
+
props: {
|
|
107
|
+
initial: { type: Object, required: true },
|
|
108
|
+
sourceId: { type: String, required: true },
|
|
109
|
+
},
|
|
110
|
+
setup(props) {
|
|
111
|
+
const stored = ref(JSON.parse(JSON.stringify(props.initial)) as Any);
|
|
112
|
+
return () =>
|
|
113
|
+
h(PlAgDataTableV2 as Any, {
|
|
114
|
+
modelValue: stored.value,
|
|
115
|
+
"onUpdate:modelValue": (state: Any) => {
|
|
116
|
+
const snapshot = JSON.parse(JSON.stringify(state)) as Any;
|
|
117
|
+
setTimeout(() => (stored.value = snapshot), 50);
|
|
118
|
+
},
|
|
119
|
+
settings: {
|
|
120
|
+
sourceId: props.sourceId,
|
|
121
|
+
sheets: [],
|
|
122
|
+
pending: false,
|
|
123
|
+
model: {
|
|
124
|
+
sourceId: stored.value.pTableParams.sourceId,
|
|
125
|
+
fullTableHandle: `full-${stored.value.pTableParams.sourceId}`,
|
|
126
|
+
visibleTableHandle: `visible-${stored.value.pTableParams.sourceId}`,
|
|
127
|
+
fullPframeHandle: `pf-${stored.value.pTableParams.sourceId}`,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
101
134
|
beforeAll(() => activateAgGrid());
|
|
102
135
|
|
|
103
136
|
describe("PlAgDataTableV2", () => {
|
|
@@ -156,6 +189,66 @@ describe("PlAgDataTableV2", () => {
|
|
|
156
189
|
expect(overlay).toBe(false);
|
|
157
190
|
});
|
|
158
191
|
|
|
192
|
+
it("loads when mounted on a source the stored state does not point at", async () => {
|
|
193
|
+
// A table inside a modal: the source changed while the modal was closed, so
|
|
194
|
+
// the stored state still names the previous one and the model built for it.
|
|
195
|
+
hoisted.driver.getSpec = async () => specs;
|
|
196
|
+
hoisted.driver.getShape = async () => ({ rows: 0, columns: specs.length });
|
|
197
|
+
hoisted.driver.getData = async () => [];
|
|
198
|
+
|
|
199
|
+
const wrapper = mount(ModelHost, {
|
|
200
|
+
attachTo: document.body,
|
|
201
|
+
props: {
|
|
202
|
+
sourceId: "src-B",
|
|
203
|
+
initial: {
|
|
204
|
+
version: 8,
|
|
205
|
+
stateCache: [
|
|
206
|
+
{
|
|
207
|
+
sourceId: "src-A",
|
|
208
|
+
gridState: {},
|
|
209
|
+
sheetsState: [],
|
|
210
|
+
filtersState: null,
|
|
211
|
+
defaultFiltersState: null,
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
pTableParams: {
|
|
215
|
+
sourceId: "src-A",
|
|
216
|
+
hiddenColIds: null,
|
|
217
|
+
sorting: null,
|
|
218
|
+
filters: null,
|
|
219
|
+
defaultFilters: null,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
await wait(600);
|
|
226
|
+
|
|
227
|
+
const text = document.body.textContent || "";
|
|
228
|
+
wrapper.unmount();
|
|
229
|
+
document.body.innerHTML = "";
|
|
230
|
+
expect(text).not.toContain("Data is not computed");
|
|
231
|
+
expect(text).not.toContain("Loading data...");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("says the table is computing, not that it is not computed, while the model computes it", async () => {
|
|
235
|
+
const wrapper = mount(Host, {
|
|
236
|
+
attachTo: document.body,
|
|
237
|
+
props: {
|
|
238
|
+
settings: { sourceId: "src-1", sheets: [], model: undefined, pending: true },
|
|
239
|
+
initial: { version: 8, stateCache: [], pTableParams: { sourceId: null } },
|
|
240
|
+
echoMs: 0,
|
|
241
|
+
pushEveryMs: 1000,
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
await wait(100);
|
|
245
|
+
|
|
246
|
+
const text = document.body.textContent || "";
|
|
247
|
+
wrapper.unmount();
|
|
248
|
+
document.body.innerHTML = "";
|
|
249
|
+
expect(text).not.toContain("Data is not computed");
|
|
250
|
+
});
|
|
251
|
+
|
|
159
252
|
it("stops recreating the grid once the stored state has been applied", async () => {
|
|
160
253
|
hoisted.driver.getSpec = async () => {
|
|
161
254
|
await wait(40);
|