@platforma-sdk/ui-vue 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/.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 +30 -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/__tests__/PlAgDataTableV2.gridApi.jsdomtest.d.ts +2 -0
- package/dist/components/PlAgDataTable/__tests__/PlAgDataTableV2.gridApi.jsdomtest.d.ts.map +1 -0
- 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 +6 -6
- package/src/components/PlAgDataTable/PlAgDataTableSheets.vue +23 -67
- package/src/components/PlAgDataTable/PlAgDataTableV2.vue +93 -121
- package/src/components/PlAgDataTable/__tests__/PlAgDataTableV2.gridApi.jsdomtest.ts +66 -0
- 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.90.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@milaboratories/columns-collection-driver": "0.
|
|
15
|
-
"@milaboratories/pf-spec-driver": "1.
|
|
16
|
-
"@milaboratories/pl-model-common": "1.
|
|
17
|
-
"@milaboratories/uikit": "2.17.
|
|
18
|
-
"@platforma-sdk/model": "1.
|
|
14
|
+
"@milaboratories/columns-collection-driver": "0.3.0",
|
|
15
|
+
"@milaboratories/pf-spec-driver": "1.6.0",
|
|
16
|
+
"@milaboratories/pl-model-common": "1.56.0",
|
|
17
|
+
"@milaboratories/uikit": "2.17.9",
|
|
18
|
+
"@platforma-sdk/model": "1.90.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,22 @@ 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
|
-
|
|
135
|
-
|
|
136
|
-
event.api,
|
|
137
|
-
getColumnsMeta(),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
gridApi.value = null;
|
|
134
|
+
if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));
|
|
135
|
+
gridOptions.value.initialState = restoreState.value;
|
|
136
|
+
// A replaced grid destroyed after its successor is ready must leave the successor's api in place
|
|
137
|
+
if (gridApi.value?.getGridId() === event.api.getGridId()) gridApi.value = null;
|
|
141
138
|
};
|
|
142
139
|
gridOptions.value.onRowDoubleClicked = (event) => {
|
|
143
140
|
if (event.data && event.data.axesKey) emit("rowDoubleClicked", event.data.axesKey);
|
|
144
141
|
};
|
|
145
142
|
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;
|
|
143
|
+
saveGridState(event.api, makePartialState(event.state));
|
|
144
|
+
// Keep initialState in step with the stored grid state, so the grid recreated
|
|
145
|
+
// by the reload watch below comes back with it.
|
|
146
|
+
gridOptions.value.initialState = restoreState.value;
|
|
163
147
|
|
|
164
148
|
if (!isJsonEqual(event.sources, ["columnSizing"])) {
|
|
165
149
|
event.api.autoSizeColumns(
|
|
@@ -170,7 +154,7 @@ gridOptions.value.onStateUpdated = (event) => {
|
|
|
170
154
|
}
|
|
171
155
|
};
|
|
172
156
|
|
|
173
|
-
const [filterableColumns
|
|
157
|
+
const [filterableColumns] = useFilterableColumns(
|
|
174
158
|
() => settings.value.sourceId,
|
|
175
159
|
() => gridOptions.value.columnDefs ?? null,
|
|
176
160
|
);
|
|
@@ -178,26 +162,48 @@ const defaultFilters = computed(() =>
|
|
|
178
162
|
settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,
|
|
179
163
|
);
|
|
180
164
|
const {
|
|
165
|
+
sourceId: shownSourceId,
|
|
181
166
|
gridState,
|
|
167
|
+
sorting,
|
|
168
|
+
hiddenColIds,
|
|
169
|
+
getEntry,
|
|
170
|
+
updateGrid,
|
|
182
171
|
sheetsState,
|
|
183
172
|
searchString,
|
|
184
173
|
filtersState,
|
|
185
174
|
defaultFiltersState,
|
|
186
175
|
resetDefaultFilters,
|
|
187
|
-
} = useTableState(tableState, settings,
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
176
|
+
} = useTableState(tableState, settings, defaultFilters);
|
|
177
|
+
const sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));
|
|
178
|
+
const restoreState = computed(() =>
|
|
179
|
+
createGridRestoreState({
|
|
180
|
+
gridState: gridState.value,
|
|
181
|
+
sorting: sorting.value,
|
|
182
|
+
hiddenColIds: hiddenColIds.value,
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
gridOptions.value.initialState = restoreState.value;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Store what the grid reports under the source its columns belong to: while
|
|
189
|
+
* the table switches sources the grid still holds the previous source's
|
|
190
|
+
* columns, and their state must not land on the new source.
|
|
191
|
+
*/
|
|
192
|
+
function saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {
|
|
193
|
+
const sourceId = boundSourceId.value;
|
|
194
|
+
// AG Grid reports an entirely empty state until its columns have been taken
|
|
195
|
+
// into its own state. Such a report says nothing about the user's choices, and
|
|
196
|
+
// reading defaults from the live columns at that point would invent some.
|
|
197
|
+
// Wait for the grid to say something about itself; it always does once its
|
|
198
|
+
// columns are in.
|
|
199
|
+
if (sourceId === null || isJsonEqual(reported, {})) return;
|
|
200
|
+
updateGrid(
|
|
201
|
+
sourceId,
|
|
202
|
+
readGridReport(reported, getEntry(sourceId), () =>
|
|
203
|
+
getDefaultHiddenColIds(api, getColumnsMeta()),
|
|
204
|
+
),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
201
207
|
|
|
202
208
|
// Restore proper types erased by AgGrid
|
|
203
209
|
function makePartialState(state: GridState): PlDataTableGridStateCore {
|
|
@@ -223,69 +229,6 @@ function makePartialState(state: GridState): PlDataTableGridStateCore {
|
|
|
223
229
|
};
|
|
224
230
|
}
|
|
225
231
|
|
|
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
232
|
/** Sidecar display meta is only on the `model` branch of the settings union. */
|
|
290
233
|
function getColumnsMeta(): PlDataTableColumnsMeta | undefined {
|
|
291
234
|
return "model" in props.settings ? props.settings.model?.columnsMeta : undefined;
|
|
@@ -310,19 +253,23 @@ function getDefaultHiddenColIds(
|
|
|
310
253
|
.map((col) => col.getColId() as PlTableColumnIdJson);
|
|
311
254
|
}
|
|
312
255
|
|
|
313
|
-
// Reload AgGrid when new state arrives from server
|
|
256
|
+
// Reload AgGrid when new state arrives from server, or when the grid takes the
|
|
257
|
+
// columns of a source whose stored state it does not show yet
|
|
314
258
|
const reloadKey = ref(0);
|
|
315
259
|
watch(
|
|
316
|
-
() => [gridApi.value,
|
|
317
|
-
([gridApi,
|
|
318
|
-
if (!gridApi || gridApi.isDestroyed()) return;
|
|
260
|
+
() => [gridApi.value, restoreState.value, boundSourceId.value] as const,
|
|
261
|
+
([gridApi, restoreState, boundSourceId]) => {
|
|
262
|
+
if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;
|
|
319
263
|
const selfState = makePartialState(gridApi.getState());
|
|
320
264
|
const gridColIds = new Set(
|
|
321
265
|
(gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),
|
|
322
266
|
);
|
|
323
|
-
if (
|
|
267
|
+
if (
|
|
268
|
+
!isJsonEqual(restoreState, {}) &&
|
|
269
|
+
!isStoredStateApplied(restoreState, selfState, gridColIds)
|
|
270
|
+
) {
|
|
324
271
|
isReloading = true;
|
|
325
|
-
gridOptions.value.initialState =
|
|
272
|
+
gridOptions.value.initialState = restoreState;
|
|
326
273
|
++reloadKey.value;
|
|
327
274
|
nextTick(() => {
|
|
328
275
|
isReloading = false;
|
|
@@ -410,6 +357,7 @@ watch(
|
|
|
410
357
|
// No data source selected -> reset state to default
|
|
411
358
|
if (settings.sourceId === null) {
|
|
412
359
|
++generation.value;
|
|
360
|
+
boundSourceId.value = null;
|
|
413
361
|
gridApi.updateGridOptions({
|
|
414
362
|
loading: true,
|
|
415
363
|
loadingOverlayComponentParams: {
|
|
@@ -443,6 +391,11 @@ watch(
|
|
|
443
391
|
settings.model?.visibleTableHandle === undefined
|
|
444
392
|
) {
|
|
445
393
|
if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;
|
|
394
|
+
// A grid that already shows a table keeps showing it; one that is still
|
|
395
|
+
// waiting says why.
|
|
396
|
+
if (gridApi.getGridOption("loading") === true) {
|
|
397
|
+
setLoadingVariant(gridApi, settings.pending ? "running" : "not-ready");
|
|
398
|
+
}
|
|
446
399
|
return;
|
|
447
400
|
}
|
|
448
401
|
|
|
@@ -468,16 +421,17 @@ watch(
|
|
|
468
421
|
}
|
|
469
422
|
}
|
|
470
423
|
|
|
471
|
-
// Model
|
|
424
|
+
// Model built for another source -> show skeletons until it catches up.
|
|
425
|
+
// A model that reports no source was built from a state that names none,
|
|
426
|
+
// or does not take the state at all, and is shown as it is.
|
|
472
427
|
const sourceChanged =
|
|
473
|
-
settings.model
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
const rowCount = !sourceChanged && state.length > 0 ? state[0].rowCount : 1;
|
|
428
|
+
settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;
|
|
429
|
+
if (sourceChanged) {
|
|
430
|
+
if (gridApi.getGridOption("loading") === true) setLoadingVariant(gridApi, "loading");
|
|
477
431
|
return gridApi.updateGridOptions({
|
|
478
432
|
serverSideDatasource: {
|
|
479
433
|
getRows: (params) => {
|
|
480
|
-
params.success({ rowData: [], rowCount });
|
|
434
|
+
params.success({ rowData: [], rowCount: 1 });
|
|
481
435
|
},
|
|
482
436
|
},
|
|
483
437
|
});
|
|
@@ -485,6 +439,7 @@ watch(
|
|
|
485
439
|
|
|
486
440
|
// Model ready -> calculate new state
|
|
487
441
|
const stateGeneration = generation.value;
|
|
442
|
+
const stateSourceId = settings.sourceId;
|
|
488
443
|
calculateGridOptions({
|
|
489
444
|
generation,
|
|
490
445
|
pfDriver: getRawPlatformaInstance().pFrameDriver,
|
|
@@ -493,7 +448,7 @@ watch(
|
|
|
493
448
|
columnsMeta: settings.model?.columnsMeta,
|
|
494
449
|
sheets: settings.sheets ?? [],
|
|
495
450
|
dataRenderedTracker,
|
|
496
|
-
hiddenColIds:
|
|
451
|
+
hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),
|
|
497
452
|
cellButtonAxisParams: {
|
|
498
453
|
showCellButtonForAxisId: props.showCellButtonForAxisId,
|
|
499
454
|
cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,
|
|
@@ -506,6 +461,7 @@ watch(
|
|
|
506
461
|
gridApi.updateGridOptions({
|
|
507
462
|
...options,
|
|
508
463
|
});
|
|
464
|
+
boundSourceId.value = stateSourceId;
|
|
509
465
|
if (selection.value) {
|
|
510
466
|
// Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys
|
|
511
467
|
const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;
|
|
@@ -572,6 +528,18 @@ watch(
|
|
|
572
528
|
},
|
|
573
529
|
);
|
|
574
530
|
|
|
531
|
+
function setLoadingVariant(
|
|
532
|
+
api: GridApi<PlAgDataTableV2Row>,
|
|
533
|
+
variant: PlAgOverlayLoadingParams["variant"],
|
|
534
|
+
): void {
|
|
535
|
+
api.updateGridOptions({
|
|
536
|
+
loadingOverlayComponentParams: {
|
|
537
|
+
...gridOptions.value.loadingOverlayComponentParams,
|
|
538
|
+
variant,
|
|
539
|
+
} satisfies PlAgOverlayLoadingParams,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
575
543
|
watch(
|
|
576
544
|
() => ({
|
|
577
545
|
gridApi: gridApi.value,
|
|
@@ -630,7 +598,11 @@ watchEffect(() => {
|
|
|
630
598
|
:table-handle="'model' in settings ? settings?.model?.visibleTableHandle : undefined"
|
|
631
599
|
:columns-meta="getColumnsMeta()"
|
|
632
600
|
/>
|
|
633
|
-
<PlAgDataTableSheets
|
|
601
|
+
<PlAgDataTableSheets
|
|
602
|
+
:sheets="sheets"
|
|
603
|
+
:state="sheetsState"
|
|
604
|
+
:on-change="(state) => (sheetsState = state)"
|
|
605
|
+
>
|
|
634
606
|
<template v-if="$slots['before-sheets']" #before>
|
|
635
607
|
<slot name="before-sheets" />
|
|
636
608
|
</template>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The column manager and the export button are shown only while the table holds
|
|
3
|
+
* the api of the grid on screen. A replaced grid can be destroyed after its
|
|
4
|
+
* successor is ready, and that late destroy must leave the successor's api in place.
|
|
5
|
+
*/
|
|
6
|
+
import { mount } from "@vue/test-utils";
|
|
7
|
+
import type { GridApi, GridPreDestroyedEvent } from "ag-grid-enterprise";
|
|
8
|
+
import { createGrid } from "ag-grid-enterprise";
|
|
9
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
10
|
+
import { nextTick } from "vue";
|
|
11
|
+
import type { PlAgDataTableV2Row } from "../types";
|
|
12
|
+
|
|
13
|
+
// The CSV exporter reaches the pf-spec WASM module, which cannot initialise
|
|
14
|
+
// under jsdom; nothing here exercises export.
|
|
15
|
+
vi.mock("@milaboratories/pf-spec-driver", () => ({ SpecDriver: class {} }));
|
|
16
|
+
vi.mock("@milaboratories/columns-collection-driver", () => ({
|
|
17
|
+
ColumnsCollectionDriverImpl: class {},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const { activateAgGrid } = await import("../../../composition/AgGrid");
|
|
21
|
+
const { createPlDataTableStateV2 } = await import("@platforma-sdk/model");
|
|
22
|
+
const PlAgDataTableV2 = (await import("../PlAgDataTableV2.vue")).default;
|
|
23
|
+
const { PlAgGridColumnManager } = await import("../../PlAgGridColumnManager");
|
|
24
|
+
|
|
25
|
+
beforeAll(() => activateAgGrid());
|
|
26
|
+
|
|
27
|
+
describe("PlAgDataTableV2 grid api", () => {
|
|
28
|
+
it("keeps the api of the grid on screen when a replaced grid is destroyed", async () => {
|
|
29
|
+
const wrapper = mount(PlAgDataTableV2, {
|
|
30
|
+
attachTo: document.body,
|
|
31
|
+
props: {
|
|
32
|
+
modelValue: createPlDataTableStateV2(),
|
|
33
|
+
"onUpdate:modelValue": () => {},
|
|
34
|
+
settings: { sourceId: null, pending: false, error: null },
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
await vi.waitFor(() =>
|
|
38
|
+
expect(wrapper.findComponent(PlAgGridColumnManager).exists()).toBe(true),
|
|
39
|
+
);
|
|
40
|
+
const shown: GridApi<PlAgDataTableV2Row> = wrapper
|
|
41
|
+
.findComponent(PlAgGridColumnManager)
|
|
42
|
+
.props("api");
|
|
43
|
+
const onGridPreDestroyed = shown.getGridOption("onGridPreDestroyed");
|
|
44
|
+
const replaced = createGrid<PlAgDataTableV2Row>(document.createElement("div"), {});
|
|
45
|
+
|
|
46
|
+
onGridPreDestroyed?.(preDestroyed(replaced));
|
|
47
|
+
await nextTick();
|
|
48
|
+
const kept = wrapper.findComponent(PlAgGridColumnManager);
|
|
49
|
+
expect(kept.exists()).toBe(true);
|
|
50
|
+
expect(kept.props("api").getGridId()).toBe(shown.getGridId());
|
|
51
|
+
|
|
52
|
+
onGridPreDestroyed?.(preDestroyed(shown));
|
|
53
|
+
await nextTick();
|
|
54
|
+
expect(wrapper.findComponent(PlAgGridColumnManager).exists()).toBe(false);
|
|
55
|
+
|
|
56
|
+
replaced.destroy();
|
|
57
|
+
wrapper.unmount();
|
|
58
|
+
document.body.innerHTML = "";
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Internals
|
|
63
|
+
|
|
64
|
+
function preDestroyed(api: GridApi<PlAgDataTableV2Row>): GridPreDestroyedEvent<PlAgDataTableV2Row> {
|
|
65
|
+
return { type: "gridPreDestroyed", api, context: undefined, state: api.getState() };
|
|
66
|
+
}
|
|
@@ -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);
|