@platforma-sdk/ui-vue 1.89.0 → 1.90.2
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 +7 -7
- package/.turbo/turbo-formatter$colon$check.log +1 -1
- package/.turbo/turbo-linter$colon$check.log +1 -1
- package/CHANGELOG.md +20 -0
- 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 +1 -1
- 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/package.json +6 -6
- package/src/components/PlAgDataTable/PlAgDataTableV2.vue +2 -1
- package/src/components/PlAgDataTable/__tests__/PlAgDataTableV2.gridApi.jsdomtest.ts +66 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -36,7 +36,7 @@ transforming...
|
|
|
36
36
|
rendering chunks...
|
|
37
37
|
[32m
|
|
38
38
|
[36m[unplugin:dts][32m Start generate declaration files...[39m
|
|
39
|
-
[32m[36m[unplugin:dts][32m Declaration files built in
|
|
39
|
+
[32m[36m[unplugin:dts][32m Declaration files built in 5099ms.
|
|
40
40
|
[39m
|
|
41
41
|
computing gzip size...
|
|
42
42
|
dist/components/PlAnnotations/components/PlAnnotations.vue_vue_type_style_index_0_lang.css 0.04 kB │ gzip: 0.06 kB
|
|
@@ -139,7 +139,7 @@ dist/components/PlAnnotations/components/PlAnnotations.js
|
|
|
139
139
|
dist/components/PlAnnotations/components/PlAnnotations.vue_vue_type_style_index_0_lang.module.js 0.34 kB │ gzip: 0.21 kB │ map: 3.26 kB
|
|
140
140
|
dist/components/PlAgDataTable/PlAgDataTableSheets.vue_vue_type_style_index_0_lang.module.js 0.34 kB │ gzip: 0.21 kB │ map: 2.42 kB
|
|
141
141
|
dist/components/PlAgDataTable/PlAgOverlayNoRows.js 0.34 kB │ gzip: 0.20 kB │ map: 1.48 kB
|
|
142
|
-
dist/components/PlAgDataTable/PlAgDataTableV2.js 0.34 kB │ gzip: 0.24 kB │ map: 24.
|
|
142
|
+
dist/components/PlAgDataTable/PlAgDataTableV2.js 0.34 kB │ gzip: 0.24 kB │ map: 24.25 kB
|
|
143
143
|
dist/plugins/Monetization/UserCabinetCard.js 0.34 kB │ gzip: 0.23 kB │ map: 3.23 kB
|
|
144
144
|
dist/components/PlAgCellStatusTag/PlAgCellStatusTag.js 0.34 kB │ gzip: 0.19 kB │ map: 0.90 kB
|
|
145
145
|
dist/components/PlAdvancedFilter/PlAdvancedFilter.js 0.34 kB │ gzip: 0.23 kB │ map: 14.28 kB
|
|
@@ -151,7 +151,7 @@ dist/components/PlAnnotations/components/PlAnnotationsModal.js
|
|
|
151
151
|
dist/components/PlBlockDependencies/PlBlockDependencies.js 0.35 kB │ gzip: 0.24 kB │ map: 4.33 kB
|
|
152
152
|
dist/components/PlAgGridColumnManager/PlAgGridColumnManager.js 0.36 kB │ gzip: 0.24 kB │ map: 5.71 kB
|
|
153
153
|
dist/components/PlAnnotations/components/FilterSidebar.vue_vue_type_style_index_0_lang.module.js 0.37 kB │ gzip: 0.24 kB │ map: 5.87 kB
|
|
154
|
-
dist/components/PlAgDataTable/PlAgDataTableV2.vue_vue_type_style_index_0_lang.module.js 0.37 kB │ gzip: 0.24 kB │ map:
|
|
154
|
+
dist/components/PlAgDataTable/PlAgDataTableV2.vue_vue_type_style_index_0_lang.module.js 0.37 kB │ gzip: 0.24 kB │ map: 24.15 kB
|
|
155
155
|
dist/lib/util/helpers/dist/strings.js 0.37 kB │ gzip: 0.26 kB │ map: 4.21 kB
|
|
156
156
|
dist/components/PlAgChartHistogramCell/PlAgChartHistogramCell.js 0.37 kB │ gzip: 0.20 kB │ map: 1.84 kB
|
|
157
157
|
dist/components/PlAgChartStackedBarCell/PlAgChartStackedBarCell.js 0.38 kB │ gzip: 0.20 kB │ map: 1.45 kB
|
|
@@ -265,12 +265,12 @@ dist/internal/createAppV3.js
|
|
|
265
265
|
dist/components/PlAgDataTable/sources/table-source-v2.js 7.76 kB │ gzip: 2.94 kB │ map: 30.69 kB
|
|
266
266
|
dist/components/PlAdvancedFilter/PlAdvancedFilter.vue_vue_type_script_setup_true_lang.js 9.05 kB │ gzip: 2.69 kB │ map: 21.15 kB
|
|
267
267
|
dist/components/PlAdvancedFilter/FilterEditor.vue_vue_type_script_setup_true_lang.js 11.71 kB │ gzip: 3.31 kB │ map: 28.56 kB
|
|
268
|
-
dist/components/PlAgDataTable/PlAgDataTableV2.vue_vue_type_script_setup_true_lang.js 12.
|
|
268
|
+
dist/components/PlAgDataTable/PlAgDataTableV2.vue_vue_type_script_setup_true_lang.js 12.72 kB │ gzip: 4.05 kB │ map: 34.95 kB
|
|
269
269
|
|
|
270
|
-
[32m✓ built in
|
|
271
|
-
[33m[33m[PLUGIN_TIMINGS] [0mJavaScript callbacks ran for
|
|
270
|
+
[32m✓ built in 5.98s[39m
|
|
271
|
+
[33m[33m[PLUGIN_TIMINGS] [0mJavaScript callbacks ran for 5.9s of this 6.0s build (99%).
|
|
272
272
|
The slowest callbacks, timed inside each callback (the wait before a callback starts is excluded, the time it awaits is included):
|
|
273
|
-
- plugin unplugin-dts buildStart (
|
|
273
|
+
- plugin unplugin-dts buildStart (81%, 4.8s, 1 call)
|
|
274
274
|
Additional callback time came from the callbacks below and from callbacks under 1s.
|
|
275
275
|
2 callbacks are listed without a time. Their calls overlapped, so the time inside one call includes work from other calls. To find their cost, profile the build with `node --cpu-prof`:
|
|
276
276
|
- plugin sourcemaps load (144 calls)
|
|
@@ -4,5 +4,5 @@ $ ts-builder linter --check
|
|
|
4
4
|
Linting project...
|
|
5
5
|
↳ oxlint --config /home/runner/_work/platforma/platforma/sdk/ui-vue/.oxlintrc.json --deny-warnings
|
|
6
6
|
Found 0 warnings and 0 errors.
|
|
7
|
-
Finished in
|
|
7
|
+
Finished in 29ms on 143 files with 108 rules using 16 threads.
|
|
8
8
|
Linting completed successfully
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @platforma-sdk/ui-vue
|
|
2
2
|
|
|
3
|
+
## 1.90.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [fd21724]
|
|
8
|
+
- @platforma-sdk/model@1.90.2
|
|
9
|
+
- @milaboratories/uikit@2.17.10
|
|
10
|
+
|
|
11
|
+
## 1.90.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 7959b69: PlAgDataTableV2: a destroyed grid clears the table's grid api only when it is the grid on screen, so the column manager and export buttons stay after the inner grid is replaced.
|
|
16
|
+
- Updated dependencies [92cf16f]
|
|
17
|
+
- @milaboratories/pl-model-common@1.56.0
|
|
18
|
+
- @milaboratories/pf-spec-driver@1.6.0
|
|
19
|
+
- @milaboratories/columns-collection-driver@0.3.0
|
|
20
|
+
- @platforma-sdk/model@1.90.0
|
|
21
|
+
- @milaboratories/uikit@2.17.9
|
|
22
|
+
|
|
3
23
|
## 1.89.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlAgDataTableV2.js","names":["style0","_sfc_main","_plugin_vue_export_helper_default","PlAgDataTableV2_vue_vue_type_script_setup_true_lang_default","PlAgDataTableV2_vue_vue_type_style_index_0_lang_module_default","PlAgDataTableV2_default","\"$style\""],"sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { promiseTimeout, isJsonEqual } from \"@milaboratories/helpers\";\nimport type {\n AxisId,\n PlDataTableColumnsMeta,\n PlDataTableGridStateCore,\n PlDataTableStateV2,\n PlSelectionModel,\n PlTableColumnIdJson,\n PTableColumnId,\n PTableColumnSpec,\n PTableKey,\n} from \"@platforma-sdk/model\";\nimport {\n getRawPlatformaInstance,\n createPlSelectionModel,\n matchAxisId,\n getAxisId,\n canonicalizeJson,\n isAbortError,\n} from \"@platforma-sdk/model\";\nimport type { CellRendererSelectorFunc, GridApi, GridState } from \"ag-grid-enterprise\";\nimport { AgGridVue } from \"ag-grid-vue3\";\nimport { computed, effectScope, nextTick, ref, shallowRef, toRefs, watch, watchEffect } from \"vue\";\nimport PlAgCsvExporter from \"../PlAgCsvExporter/PlAgCsvExporter.vue\";\nimport { PlAgGridColumnManager } from \"../PlAgGridColumnManager\";\nimport PlTableFiltersV2 from \"../PlTableFilters/PlTableFiltersV2.vue\";\nimport { PlTableFastSearch } from \"../PlTableFastSearch\";\nimport PlAgDataTableSheets from \"./PlAgDataTableSheets.vue\";\nimport PlAgRowCount from \"./PlAgRowCount.vue\";\nimport { DeferredCircular, ensureNodeVisible } from \"./sources/focus-row\";\nimport { PlAgDataTableRowNumberColId } from \"./sources/row-number\";\nimport type { PlAgCellButtonAxisParams } from \"./sources/table-source-v2\";\nimport { calculateGridOptions, effectiveVisibility } from \"./sources/table-source-v2\";\nimport { createGridRestoreState, isStoredStateApplied, readGridReport } from \"./sources/grid-state\";\nimport { useTableState } from \"./sources/table-state-v2\";\nimport type {\n PlAgDataTableV2Controller,\n PlAgDataTableV2Row,\n PlAgOverlayLoadingParams,\n PlAgOverlayNoRowsParams,\n PlDataTableSettingsV2,\n PlTableRowId,\n} from \"./types\";\nimport { useFilterableColumns } from \"./compositions/useFilterableColumns\";\nimport { useGrid } from \"./compositions/useGrid\";\nimport { AgGridTheme } from \"../../AgGridVue/AgGridTheme\";\n\nconst tableState = defineModel<PlDataTableStateV2>({\n required: true,\n});\n/** Warning: selection model value updates are ignored, use updateSelection instead */\nconst selection = defineModel<PlSelectionModel>(\"selection\");\nconst props = defineProps<{\n /** Required component settings */\n settings: Readonly<PlDataTableSettingsV2>;\n\n /**\n * The disableColumnsPanel prop controls the display of a button that activates\n * the columns management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableColumnsPanel?: boolean;\n\n /**\n * The disableFiltersPanel prop controls the display of a button that activates\n * the filters management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableFiltersPanel?: boolean;\n\n /**\n * The showExportButton prop controls the display of a button that allows\n * to export table data in CSV format. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n showExportButton?: boolean;\n\n /**\n * The AxisId property is used to configure and display the PlAgTextAndButtonCell component\n */\n showCellButtonForAxisId?: AxisId;\n\n /**\n * If cellButtonInvokeRowsOnDoubleClick = true, clicking a button inside the row\n * triggers the doubleClick event for the entire row.\n *\n * If cellButtonInvokeRowsOnDoubleClick = false, the doubleClick event for the row\n * is not triggered, but will triggered cellButtonClicked event with (key: PTableRowKey) argument.\n */\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n\n /** @see {@link PlAgOverlayLoadingParams.loadingText} */\n loadingText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.runningText} */\n runningText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.notReadyText} */\n notReadyText?: string;\n\n /** @see {@link PlAgOverlayNoRowsParams.text} */\n noRowsText?: string;\n\n /**\n * Callback to override the default renderer for a given cell.\n * @see https://www.ag-grid.com/vue-data-grid/component-cell-renderer/#dynamic-component-selection\n */\n cellRendererSelector?: CellRendererSelectorFunc<PlAgDataTableV2Row>;\n}>();\nconst { settings } = toRefs(props);\nconst emit = defineEmits<{\n rowDoubleClicked: [key?: PTableKey];\n cellButtonClicked: [key?: PTableKey];\n newDataRendered: [];\n}>();\n\nconst dataRenderedTracker = new DeferredCircular<GridApi<PlAgDataTableV2Row>>();\nconst { gridApi, gridOptions } = useGrid({\n selection,\n noRowsText: props.noRowsText,\n runningText: props.runningText,\n loadingText: props.loadingText,\n notReadyText: props.notReadyText,\n cellRendererSelector: props.cellRendererSelector,\n});\nlet isReloading = false;\n/** Source the grid's columns were built for; `null` while the grid has none. */\nconst boundSourceId = shallowRef<null | string>(null);\ngridOptions.value.onGridPreDestroyed = (event) => {\n if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));\n gridOptions.value.initialState = restoreState.value;\n gridApi.value = null;\n};\ngridOptions.value.onRowDoubleClicked = (event) => {\n if (event.data && event.data.axesKey) emit(\"rowDoubleClicked\", event.data.axesKey);\n};\ngridOptions.value.onStateUpdated = (event) => {\n saveGridState(event.api, makePartialState(event.state));\n // Keep initialState in step with the stored grid state, so the grid recreated\n // by the reload watch below comes back with it.\n gridOptions.value.initialState = restoreState.value;\n\n if (!isJsonEqual(event.sources, [\"columnSizing\"])) {\n event.api.autoSizeColumns(\n event.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n }\n};\n\nconst [filterableColumns] = useFilterableColumns(\n () => settings.value.sourceId,\n () => gridOptions.value.columnDefs ?? null,\n);\nconst defaultFilters = computed(() =>\n settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,\n);\nconst {\n sourceId: shownSourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry,\n updateGrid,\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n} = useTableState(tableState, settings, defaultFilters);\nconst sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));\nconst restoreState = computed(() =>\n createGridRestoreState({\n gridState: gridState.value,\n sorting: sorting.value,\n hiddenColIds: hiddenColIds.value,\n }),\n);\ngridOptions.value.initialState = restoreState.value;\n\n/**\n * Store what the grid reports under the source its columns belong to: while\n * the table switches sources the grid still holds the previous source's\n * columns, and their state must not land on the new source.\n */\nfunction saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {\n const sourceId = boundSourceId.value;\n // AG Grid reports an entirely empty state until its columns have been taken\n // into its own state. Such a report says nothing about the user's choices, and\n // reading defaults from the live columns at that point would invent some.\n // Wait for the grid to say something about itself; it always does once its\n // columns are in.\n if (sourceId === null || isJsonEqual(reported, {})) return;\n updateGrid(\n sourceId,\n readGridReport(reported, getEntry(sourceId), () =>\n getDefaultHiddenColIds(api, getColumnsMeta()),\n ),\n );\n}\n\n// Restore proper types erased by AgGrid\nfunction makePartialState(state: GridState): PlDataTableGridStateCore {\n return {\n columnOrder: state.columnOrder as\n | {\n orderedColIds: PlTableColumnIdJson[];\n }\n | undefined,\n sort: state.sort as\n | {\n sortModel: {\n colId: PlTableColumnIdJson;\n sort: \"asc\" | \"desc\";\n }[];\n }\n | undefined,\n columnVisibility: state.columnVisibility as\n | {\n hiddenColIds: PlTableColumnIdJson[];\n }\n | undefined,\n };\n}\n\n/** Sidecar display meta is only on the `model` branch of the settings union. */\nfunction getColumnsMeta(): PlDataTableColumnsMeta | undefined {\n return \"model\" in props.settings ? props.settings.model?.columnsMeta : undefined;\n}\n\nfunction getDefaultHiddenColIds(\n api: GridApi<PlAgDataTableV2Row>,\n columnsMeta: PlDataTableColumnsMeta | undefined,\n): PlTableColumnIdJson[] {\n const cols = api.getAllGridColumns();\n if (!cols) return [];\n\n return cols\n .filter((col) => {\n const spec = col.getColDef().context as PTableColumnSpec | undefined;\n return (\n spec !== undefined &&\n spec.type === \"column\" &&\n effectiveVisibility(spec, columnsMeta) === \"optional\"\n );\n })\n .map((col) => col.getColId() as PlTableColumnIdJson);\n}\n\n// Reload AgGrid when new state arrives from server, or when the grid takes the\n// columns of a source whose stored state it does not show yet\nconst reloadKey = ref(0);\nwatch(\n () => [gridApi.value, restoreState.value, boundSourceId.value] as const,\n ([gridApi, restoreState, boundSourceId]) => {\n if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;\n const selfState = makePartialState(gridApi.getState());\n const gridColIds = new Set(\n (gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),\n );\n if (\n !isJsonEqual(restoreState, {}) &&\n !isStoredStateApplied(restoreState, selfState, gridColIds)\n ) {\n isReloading = true;\n gridOptions.value.initialState = restoreState;\n ++reloadKey.value;\n nextTick(() => {\n isReloading = false;\n });\n }\n },\n);\n\n// Make cellRendererSelector reactive\nconst cellRendererSelector = computed(() => props.cellRendererSelector ?? null);\nwatch(\n () => [gridApi.value, cellRendererSelector.value] as const,\n ([gridApi, cellRendererSelector]) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.setGridOption(\"defaultColDef\", {\n ...gridOptions.value.defaultColDef,\n cellRendererSelector: cellRendererSelector ?? undefined,\n });\n },\n);\n\ndefineExpose<PlAgDataTableV2Controller>({\n focusRow: async (rowKey) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n return ensureNodeVisible(gridApi, (row) => isJsonEqual(row.data?.axesKey, rowKey));\n },\n updateSelection: async ({ axesSpec, selectedKeys }) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n const axes = selection.value?.axesSpec;\n if (!axes || axes.length !== axesSpec.length) return false;\n\n const mapping = axesSpec.map((spec) => {\n const id = getAxisId(spec);\n return axes.findIndex((axis) => matchAxisId(axis, id));\n });\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) return false;\n\n const selectedNodes = selectedKeys.map((key) =>\n canonicalizeJson<PlTableRowId>(mapping.map((index) => key[index])),\n );\n const oldSelectedKeys = gridApi.getServerSideSelectionState()?.toggledNodes ?? [];\n if (!isJsonEqual(oldSelectedKeys, selectedNodes)) {\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes,\n });\n\n // wait for `onSelectionChanged` to update `selection` model\n const scope = effectScope();\n const { resolve, promise } = Promise.withResolvers();\n scope.run(() => watch(selection, resolve, { once: true }));\n try {\n await promiseTimeout(promise, 500);\n } catch {\n return false;\n } finally {\n scope.stop();\n }\n }\n return true;\n },\n});\n\n// Update AgGrid when settings change\nconst defaultSelection = createPlSelectionModel();\nlet oldSettings: PlDataTableSettingsV2 | null = null;\nconst generation = ref(0);\nwatch(\n () => [gridApi.value, settings.value] as const,\n ([gridApi, settings]) => {\n // Wait for AgGrid reinitialization, gridApi will eventually become initialized\n if (!gridApi || gridApi.isDestroyed()) return;\n // Verify that this is not a false watch trigger\n if (isJsonEqual(settings, oldSettings)) return;\n try {\n // Hide no rows overlay if it is shown, or else loading overlay will not be shown\n gridApi.hideOverlay();\n dataRenderedTracker.reset();\n\n // No data source selected -> reset state to default\n if (settings.sourceId === null) {\n ++generation.value;\n boundSourceId.value = null;\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: settings.pending ? \"running\" : \"not-ready\",\n } satisfies PlAgOverlayLoadingParams,\n columnDefs: undefined,\n serverSideDatasource: undefined,\n });\n if (selection.value) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n return;\n }\n\n // The model is between handles — it is recomputing. Nothing is started here,\n // so moving the generation would only cancel the calculation in flight and\n // leave whatever it was going to do (not least taking the loading overlay\n // down) undone — which is how the table came to sit on \"Loading data…\"\n // forever. The exception is a change of source: then the calculation in\n // flight belongs to the old one and must not be allowed to land under the\n // new settings.\n if (\n settings.model?.fullTableHandle === undefined ||\n settings.model?.visibleTableHandle === undefined\n ) {\n if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;\n // A grid that already shows a table keeps showing it; one that is still\n // waiting says why.\n if (gridApi.getGridOption(\"loading\") === true) {\n setLoadingVariant(gridApi, settings.pending ? \"running\" : \"not-ready\");\n }\n return;\n }\n\n ++generation.value;\n\n // Data source changed -> show full page loader, clear selection\n if (settings.sourceId !== oldSettings?.sourceId) {\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: \"loading\",\n } satisfies PlAgOverlayLoadingParams,\n });\n if (selection.value && oldSettings?.sourceId) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n }\n\n // Model built for another source -> show skeletons until it catches up.\n // A model that reports no source was built from a state that names none,\n // or does not take the state at all, and is shown as it is.\n const sourceChanged =\n settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;\n if (sourceChanged) {\n if (gridApi.getGridOption(\"loading\") === true) setLoadingVariant(gridApi, \"loading\");\n return gridApi.updateGridOptions({\n serverSideDatasource: {\n getRows: (params) => {\n params.success({ rowData: [], rowCount: 1 });\n },\n },\n });\n }\n\n // Model ready -> calculate new state\n const stateGeneration = generation.value;\n const stateSourceId = settings.sourceId;\n calculateGridOptions({\n generation,\n pfDriver: getRawPlatformaInstance().pFrameDriver,\n fullTableHandle: settings.model?.fullTableHandle,\n visibleTableHandle: settings.model?.visibleTableHandle,\n columnsMeta: settings.model?.columnsMeta,\n sheets: settings.sheets ?? [],\n dataRenderedTracker,\n hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),\n cellButtonAxisParams: {\n showCellButtonForAxisId: props.showCellButtonForAxisId,\n cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,\n trigger: (key?: PTableKey) => emit(\"cellButtonClicked\", key),\n } satisfies PlAgCellButtonAxisParams,\n })\n .then((result) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n const { axesSpec, ...options } = result;\n gridApi.updateGridOptions({\n ...options,\n });\n boundSourceId.value = stateSourceId;\n if (selection.value) {\n // Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys\n const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;\n if (!isJsonEqual(oldAxesSpec, axesSpec)) {\n if (!oldAxesSpec || axesSpec.length !== oldAxesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const mapping = oldAxesSpec\n .map(getAxisId)\n .map((id) => axesSpec.findIndex((axis) => matchAxisId(axis, id)));\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const selectedNodes = oldSelectedKeys.map((key) =>\n mapping.map((index) => key[index]),\n );\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: selectedNodes };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes.map((key) => canonicalizeJson<PlTableRowId>(key)),\n });\n }\n }\n })\n .catch((error: unknown) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n if (isAbortError(error)) return;\n console.trace(error);\n })\n .finally(() => {\n // Only the current calculation may take the overlay down: a superseded\n // one would hide the overlay the newer settings just put up.\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n gridApi.updateGridOptions({\n loading: false,\n });\n });\n dataRenderedTracker.promise.then(() => emit(\"newDataRendered\"));\n } catch (error: unknown) {\n console.trace(error);\n } finally {\n oldSettings = settings;\n }\n },\n);\n\nfunction setLoadingVariant(\n api: GridApi<PlAgDataTableV2Row>,\n variant: PlAgOverlayLoadingParams[\"variant\"],\n): void {\n api.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant,\n } satisfies PlAgOverlayLoadingParams,\n });\n}\n\nwatch(\n () => ({\n gridApi: gridApi.value,\n loadingText: props.loadingText,\n runningText: props.runningText,\n notReadyText: props.notReadyText,\n noRowsText: props.noRowsText,\n }),\n ({ gridApi, loadingText, runningText, notReadyText, noRowsText }) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n loadingText,\n runningText,\n notReadyText,\n },\n noRowsOverlayComponentParams: {\n ...gridOptions.value.noRowsOverlayComponentParams,\n text: noRowsText,\n },\n });\n },\n);\n\nwatchEffect(() => {\n if (!gridApi.value || gridApi.value?.isDestroyed()) return;\n gridApi.value.updateGridOptions({\n statusBar: gridOptions.value.loading\n ? undefined\n : {\n statusPanels: [{ statusPanel: PlAgRowCount, align: \"left\" }],\n },\n });\n});\n</script>\n\n<template>\n <div data-testid=\"pl-ag-data-table\" :class=\"$style.container\">\n <PlAgGridColumnManager v-if=\"gridApi && !disableColumnsPanel\" :api=\"gridApi\" />\n <PlTableFiltersV2\n v-if=\"!disableFiltersPanel\"\n :filters=\"filtersState\"\n :default-filters=\"defaultFiltersState\"\n :pframe-handle=\"'model' in settings ? settings?.model?.fullPframeHandle : undefined\"\n :columns=\"filterableColumns\"\n :columns-meta=\"getColumnsMeta()\"\n @updateFilters=\"(v) => (filtersState = v)\"\n @resetDefaultFilters=\"resetDefaultFilters\"\n @updateDefaultFilters=\"(v) => (defaultFiltersState = v)\"\n v-model=\"filtersState\"\n />\n <PlAgCsvExporter\n v-if=\"gridApi && showExportButton\"\n :api=\"gridApi\"\n :table-handle=\"'model' in settings ? settings?.model?.visibleTableHandle : undefined\"\n :columns-meta=\"getColumnsMeta()\"\n />\n <PlAgDataTableSheets\n :sheets=\"sheets\"\n :state=\"sheetsState\"\n :on-change=\"(state) => (sheetsState = state)\"\n >\n <template v-if=\"$slots['before-sheets']\" #before>\n <slot name=\"before-sheets\" />\n </template>\n <template v-if=\"$slots['after-sheets']\" #after>\n <slot name=\"after-sheets\" />\n </template>\n </PlAgDataTableSheets>\n <PlTableFastSearch v-model=\"searchString\" />\n <AgGridVue\n :key=\"reloadKey\"\n data-testid=\"pl-ag-data-table-grid\"\n :theme=\"AgGridTheme\"\n :class=\"$style.grid\"\n :grid-options=\"gridOptions\"\n />\n </div>\n</template>\n\n<style lang=\"css\" module>\n.container {\n display: flex;\n flex-direction: column;\n height: 100%;\n gap: 12px;\n}\n\n.grid {\n flex: 1;\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"PlAgDataTableV2.js","names":["style0","_sfc_main","_plugin_vue_export_helper_default","PlAgDataTableV2_vue_vue_type_script_setup_true_lang_default","PlAgDataTableV2_vue_vue_type_style_index_0_lang_module_default","PlAgDataTableV2_default","\"$style\""],"sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { promiseTimeout, isJsonEqual } from \"@milaboratories/helpers\";\nimport type {\n AxisId,\n PlDataTableColumnsMeta,\n PlDataTableGridStateCore,\n PlDataTableStateV2,\n PlSelectionModel,\n PlTableColumnIdJson,\n PTableColumnId,\n PTableColumnSpec,\n PTableKey,\n} from \"@platforma-sdk/model\";\nimport {\n getRawPlatformaInstance,\n createPlSelectionModel,\n matchAxisId,\n getAxisId,\n canonicalizeJson,\n isAbortError,\n} from \"@platforma-sdk/model\";\nimport type { CellRendererSelectorFunc, GridApi, GridState } from \"ag-grid-enterprise\";\nimport { AgGridVue } from \"ag-grid-vue3\";\nimport { computed, effectScope, nextTick, ref, shallowRef, toRefs, watch, watchEffect } from \"vue\";\nimport PlAgCsvExporter from \"../PlAgCsvExporter/PlAgCsvExporter.vue\";\nimport { PlAgGridColumnManager } from \"../PlAgGridColumnManager\";\nimport PlTableFiltersV2 from \"../PlTableFilters/PlTableFiltersV2.vue\";\nimport { PlTableFastSearch } from \"../PlTableFastSearch\";\nimport PlAgDataTableSheets from \"./PlAgDataTableSheets.vue\";\nimport PlAgRowCount from \"./PlAgRowCount.vue\";\nimport { DeferredCircular, ensureNodeVisible } from \"./sources/focus-row\";\nimport { PlAgDataTableRowNumberColId } from \"./sources/row-number\";\nimport type { PlAgCellButtonAxisParams } from \"./sources/table-source-v2\";\nimport { calculateGridOptions, effectiveVisibility } from \"./sources/table-source-v2\";\nimport { createGridRestoreState, isStoredStateApplied, readGridReport } from \"./sources/grid-state\";\nimport { useTableState } from \"./sources/table-state-v2\";\nimport type {\n PlAgDataTableV2Controller,\n PlAgDataTableV2Row,\n PlAgOverlayLoadingParams,\n PlAgOverlayNoRowsParams,\n PlDataTableSettingsV2,\n PlTableRowId,\n} from \"./types\";\nimport { useFilterableColumns } from \"./compositions/useFilterableColumns\";\nimport { useGrid } from \"./compositions/useGrid\";\nimport { AgGridTheme } from \"../../AgGridVue/AgGridTheme\";\n\nconst tableState = defineModel<PlDataTableStateV2>({\n required: true,\n});\n/** Warning: selection model value updates are ignored, use updateSelection instead */\nconst selection = defineModel<PlSelectionModel>(\"selection\");\nconst props = defineProps<{\n /** Required component settings */\n settings: Readonly<PlDataTableSettingsV2>;\n\n /**\n * The disableColumnsPanel prop controls the display of a button that activates\n * the columns management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableColumnsPanel?: boolean;\n\n /**\n * The disableFiltersPanel prop controls the display of a button that activates\n * the filters management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableFiltersPanel?: boolean;\n\n /**\n * The showExportButton prop controls the display of a button that allows\n * to export table data in CSV format. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n showExportButton?: boolean;\n\n /**\n * The AxisId property is used to configure and display the PlAgTextAndButtonCell component\n */\n showCellButtonForAxisId?: AxisId;\n\n /**\n * If cellButtonInvokeRowsOnDoubleClick = true, clicking a button inside the row\n * triggers the doubleClick event for the entire row.\n *\n * If cellButtonInvokeRowsOnDoubleClick = false, the doubleClick event for the row\n * is not triggered, but will triggered cellButtonClicked event with (key: PTableRowKey) argument.\n */\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n\n /** @see {@link PlAgOverlayLoadingParams.loadingText} */\n loadingText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.runningText} */\n runningText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.notReadyText} */\n notReadyText?: string;\n\n /** @see {@link PlAgOverlayNoRowsParams.text} */\n noRowsText?: string;\n\n /**\n * Callback to override the default renderer for a given cell.\n * @see https://www.ag-grid.com/vue-data-grid/component-cell-renderer/#dynamic-component-selection\n */\n cellRendererSelector?: CellRendererSelectorFunc<PlAgDataTableV2Row>;\n}>();\nconst { settings } = toRefs(props);\nconst emit = defineEmits<{\n rowDoubleClicked: [key?: PTableKey];\n cellButtonClicked: [key?: PTableKey];\n newDataRendered: [];\n}>();\n\nconst dataRenderedTracker = new DeferredCircular<GridApi<PlAgDataTableV2Row>>();\nconst { gridApi, gridOptions } = useGrid({\n selection,\n noRowsText: props.noRowsText,\n runningText: props.runningText,\n loadingText: props.loadingText,\n notReadyText: props.notReadyText,\n cellRendererSelector: props.cellRendererSelector,\n});\nlet isReloading = false;\n/** Source the grid's columns were built for; `null` while the grid has none. */\nconst boundSourceId = shallowRef<null | string>(null);\ngridOptions.value.onGridPreDestroyed = (event) => {\n if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));\n gridOptions.value.initialState = restoreState.value;\n // A replaced grid destroyed after its successor is ready must leave the successor's api in place\n if (gridApi.value?.getGridId() === event.api.getGridId()) gridApi.value = null;\n};\ngridOptions.value.onRowDoubleClicked = (event) => {\n if (event.data && event.data.axesKey) emit(\"rowDoubleClicked\", event.data.axesKey);\n};\ngridOptions.value.onStateUpdated = (event) => {\n saveGridState(event.api, makePartialState(event.state));\n // Keep initialState in step with the stored grid state, so the grid recreated\n // by the reload watch below comes back with it.\n gridOptions.value.initialState = restoreState.value;\n\n if (!isJsonEqual(event.sources, [\"columnSizing\"])) {\n event.api.autoSizeColumns(\n event.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n }\n};\n\nconst [filterableColumns] = useFilterableColumns(\n () => settings.value.sourceId,\n () => gridOptions.value.columnDefs ?? null,\n);\nconst defaultFilters = computed(() =>\n settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,\n);\nconst {\n sourceId: shownSourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry,\n updateGrid,\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n} = useTableState(tableState, settings, defaultFilters);\nconst sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));\nconst restoreState = computed(() =>\n createGridRestoreState({\n gridState: gridState.value,\n sorting: sorting.value,\n hiddenColIds: hiddenColIds.value,\n }),\n);\ngridOptions.value.initialState = restoreState.value;\n\n/**\n * Store what the grid reports under the source its columns belong to: while\n * the table switches sources the grid still holds the previous source's\n * columns, and their state must not land on the new source.\n */\nfunction saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {\n const sourceId = boundSourceId.value;\n // AG Grid reports an entirely empty state until its columns have been taken\n // into its own state. Such a report says nothing about the user's choices, and\n // reading defaults from the live columns at that point would invent some.\n // Wait for the grid to say something about itself; it always does once its\n // columns are in.\n if (sourceId === null || isJsonEqual(reported, {})) return;\n updateGrid(\n sourceId,\n readGridReport(reported, getEntry(sourceId), () =>\n getDefaultHiddenColIds(api, getColumnsMeta()),\n ),\n );\n}\n\n// Restore proper types erased by AgGrid\nfunction makePartialState(state: GridState): PlDataTableGridStateCore {\n return {\n columnOrder: state.columnOrder as\n | {\n orderedColIds: PlTableColumnIdJson[];\n }\n | undefined,\n sort: state.sort as\n | {\n sortModel: {\n colId: PlTableColumnIdJson;\n sort: \"asc\" | \"desc\";\n }[];\n }\n | undefined,\n columnVisibility: state.columnVisibility as\n | {\n hiddenColIds: PlTableColumnIdJson[];\n }\n | undefined,\n };\n}\n\n/** Sidecar display meta is only on the `model` branch of the settings union. */\nfunction getColumnsMeta(): PlDataTableColumnsMeta | undefined {\n return \"model\" in props.settings ? props.settings.model?.columnsMeta : undefined;\n}\n\nfunction getDefaultHiddenColIds(\n api: GridApi<PlAgDataTableV2Row>,\n columnsMeta: PlDataTableColumnsMeta | undefined,\n): PlTableColumnIdJson[] {\n const cols = api.getAllGridColumns();\n if (!cols) return [];\n\n return cols\n .filter((col) => {\n const spec = col.getColDef().context as PTableColumnSpec | undefined;\n return (\n spec !== undefined &&\n spec.type === \"column\" &&\n effectiveVisibility(spec, columnsMeta) === \"optional\"\n );\n })\n .map((col) => col.getColId() as PlTableColumnIdJson);\n}\n\n// Reload AgGrid when new state arrives from server, or when the grid takes the\n// columns of a source whose stored state it does not show yet\nconst reloadKey = ref(0);\nwatch(\n () => [gridApi.value, restoreState.value, boundSourceId.value] as const,\n ([gridApi, restoreState, boundSourceId]) => {\n if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;\n const selfState = makePartialState(gridApi.getState());\n const gridColIds = new Set(\n (gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),\n );\n if (\n !isJsonEqual(restoreState, {}) &&\n !isStoredStateApplied(restoreState, selfState, gridColIds)\n ) {\n isReloading = true;\n gridOptions.value.initialState = restoreState;\n ++reloadKey.value;\n nextTick(() => {\n isReloading = false;\n });\n }\n },\n);\n\n// Make cellRendererSelector reactive\nconst cellRendererSelector = computed(() => props.cellRendererSelector ?? null);\nwatch(\n () => [gridApi.value, cellRendererSelector.value] as const,\n ([gridApi, cellRendererSelector]) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.setGridOption(\"defaultColDef\", {\n ...gridOptions.value.defaultColDef,\n cellRendererSelector: cellRendererSelector ?? undefined,\n });\n },\n);\n\ndefineExpose<PlAgDataTableV2Controller>({\n focusRow: async (rowKey) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n return ensureNodeVisible(gridApi, (row) => isJsonEqual(row.data?.axesKey, rowKey));\n },\n updateSelection: async ({ axesSpec, selectedKeys }) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n const axes = selection.value?.axesSpec;\n if (!axes || axes.length !== axesSpec.length) return false;\n\n const mapping = axesSpec.map((spec) => {\n const id = getAxisId(spec);\n return axes.findIndex((axis) => matchAxisId(axis, id));\n });\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) return false;\n\n const selectedNodes = selectedKeys.map((key) =>\n canonicalizeJson<PlTableRowId>(mapping.map((index) => key[index])),\n );\n const oldSelectedKeys = gridApi.getServerSideSelectionState()?.toggledNodes ?? [];\n if (!isJsonEqual(oldSelectedKeys, selectedNodes)) {\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes,\n });\n\n // wait for `onSelectionChanged` to update `selection` model\n const scope = effectScope();\n const { resolve, promise } = Promise.withResolvers();\n scope.run(() => watch(selection, resolve, { once: true }));\n try {\n await promiseTimeout(promise, 500);\n } catch {\n return false;\n } finally {\n scope.stop();\n }\n }\n return true;\n },\n});\n\n// Update AgGrid when settings change\nconst defaultSelection = createPlSelectionModel();\nlet oldSettings: PlDataTableSettingsV2 | null = null;\nconst generation = ref(0);\nwatch(\n () => [gridApi.value, settings.value] as const,\n ([gridApi, settings]) => {\n // Wait for AgGrid reinitialization, gridApi will eventually become initialized\n if (!gridApi || gridApi.isDestroyed()) return;\n // Verify that this is not a false watch trigger\n if (isJsonEqual(settings, oldSettings)) return;\n try {\n // Hide no rows overlay if it is shown, or else loading overlay will not be shown\n gridApi.hideOverlay();\n dataRenderedTracker.reset();\n\n // No data source selected -> reset state to default\n if (settings.sourceId === null) {\n ++generation.value;\n boundSourceId.value = null;\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: settings.pending ? \"running\" : \"not-ready\",\n } satisfies PlAgOverlayLoadingParams,\n columnDefs: undefined,\n serverSideDatasource: undefined,\n });\n if (selection.value) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n return;\n }\n\n // The model is between handles — it is recomputing. Nothing is started here,\n // so moving the generation would only cancel the calculation in flight and\n // leave whatever it was going to do (not least taking the loading overlay\n // down) undone — which is how the table came to sit on \"Loading data…\"\n // forever. The exception is a change of source: then the calculation in\n // flight belongs to the old one and must not be allowed to land under the\n // new settings.\n if (\n settings.model?.fullTableHandle === undefined ||\n settings.model?.visibleTableHandle === undefined\n ) {\n if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;\n // A grid that already shows a table keeps showing it; one that is still\n // waiting says why.\n if (gridApi.getGridOption(\"loading\") === true) {\n setLoadingVariant(gridApi, settings.pending ? \"running\" : \"not-ready\");\n }\n return;\n }\n\n ++generation.value;\n\n // Data source changed -> show full page loader, clear selection\n if (settings.sourceId !== oldSettings?.sourceId) {\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: \"loading\",\n } satisfies PlAgOverlayLoadingParams,\n });\n if (selection.value && oldSettings?.sourceId) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n }\n\n // Model built for another source -> show skeletons until it catches up.\n // A model that reports no source was built from a state that names none,\n // or does not take the state at all, and is shown as it is.\n const sourceChanged =\n settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;\n if (sourceChanged) {\n if (gridApi.getGridOption(\"loading\") === true) setLoadingVariant(gridApi, \"loading\");\n return gridApi.updateGridOptions({\n serverSideDatasource: {\n getRows: (params) => {\n params.success({ rowData: [], rowCount: 1 });\n },\n },\n });\n }\n\n // Model ready -> calculate new state\n const stateGeneration = generation.value;\n const stateSourceId = settings.sourceId;\n calculateGridOptions({\n generation,\n pfDriver: getRawPlatformaInstance().pFrameDriver,\n fullTableHandle: settings.model?.fullTableHandle,\n visibleTableHandle: settings.model?.visibleTableHandle,\n columnsMeta: settings.model?.columnsMeta,\n sheets: settings.sheets ?? [],\n dataRenderedTracker,\n hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),\n cellButtonAxisParams: {\n showCellButtonForAxisId: props.showCellButtonForAxisId,\n cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,\n trigger: (key?: PTableKey) => emit(\"cellButtonClicked\", key),\n } satisfies PlAgCellButtonAxisParams,\n })\n .then((result) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n const { axesSpec, ...options } = result;\n gridApi.updateGridOptions({\n ...options,\n });\n boundSourceId.value = stateSourceId;\n if (selection.value) {\n // Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys\n const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;\n if (!isJsonEqual(oldAxesSpec, axesSpec)) {\n if (!oldAxesSpec || axesSpec.length !== oldAxesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const mapping = oldAxesSpec\n .map(getAxisId)\n .map((id) => axesSpec.findIndex((axis) => matchAxisId(axis, id)));\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const selectedNodes = oldSelectedKeys.map((key) =>\n mapping.map((index) => key[index]),\n );\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: selectedNodes };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes.map((key) => canonicalizeJson<PlTableRowId>(key)),\n });\n }\n }\n })\n .catch((error: unknown) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n if (isAbortError(error)) return;\n console.trace(error);\n })\n .finally(() => {\n // Only the current calculation may take the overlay down: a superseded\n // one would hide the overlay the newer settings just put up.\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n gridApi.updateGridOptions({\n loading: false,\n });\n });\n dataRenderedTracker.promise.then(() => emit(\"newDataRendered\"));\n } catch (error: unknown) {\n console.trace(error);\n } finally {\n oldSettings = settings;\n }\n },\n);\n\nfunction setLoadingVariant(\n api: GridApi<PlAgDataTableV2Row>,\n variant: PlAgOverlayLoadingParams[\"variant\"],\n): void {\n api.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant,\n } satisfies PlAgOverlayLoadingParams,\n });\n}\n\nwatch(\n () => ({\n gridApi: gridApi.value,\n loadingText: props.loadingText,\n runningText: props.runningText,\n notReadyText: props.notReadyText,\n noRowsText: props.noRowsText,\n }),\n ({ gridApi, loadingText, runningText, notReadyText, noRowsText }) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n loadingText,\n runningText,\n notReadyText,\n },\n noRowsOverlayComponentParams: {\n ...gridOptions.value.noRowsOverlayComponentParams,\n text: noRowsText,\n },\n });\n },\n);\n\nwatchEffect(() => {\n if (!gridApi.value || gridApi.value?.isDestroyed()) return;\n gridApi.value.updateGridOptions({\n statusBar: gridOptions.value.loading\n ? undefined\n : {\n statusPanels: [{ statusPanel: PlAgRowCount, align: \"left\" }],\n },\n });\n});\n</script>\n\n<template>\n <div data-testid=\"pl-ag-data-table\" :class=\"$style.container\">\n <PlAgGridColumnManager v-if=\"gridApi && !disableColumnsPanel\" :api=\"gridApi\" />\n <PlTableFiltersV2\n v-if=\"!disableFiltersPanel\"\n :filters=\"filtersState\"\n :default-filters=\"defaultFiltersState\"\n :pframe-handle=\"'model' in settings ? settings?.model?.fullPframeHandle : undefined\"\n :columns=\"filterableColumns\"\n :columns-meta=\"getColumnsMeta()\"\n @updateFilters=\"(v) => (filtersState = v)\"\n @resetDefaultFilters=\"resetDefaultFilters\"\n @updateDefaultFilters=\"(v) => (defaultFiltersState = v)\"\n v-model=\"filtersState\"\n />\n <PlAgCsvExporter\n v-if=\"gridApi && showExportButton\"\n :api=\"gridApi\"\n :table-handle=\"'model' in settings ? settings?.model?.visibleTableHandle : undefined\"\n :columns-meta=\"getColumnsMeta()\"\n />\n <PlAgDataTableSheets\n :sheets=\"sheets\"\n :state=\"sheetsState\"\n :on-change=\"(state) => (sheetsState = state)\"\n >\n <template v-if=\"$slots['before-sheets']\" #before>\n <slot name=\"before-sheets\" />\n </template>\n <template v-if=\"$slots['after-sheets']\" #after>\n <slot name=\"after-sheets\" />\n </template>\n </PlAgDataTableSheets>\n <PlTableFastSearch v-model=\"searchString\" />\n <AgGridVue\n :key=\"reloadKey\"\n data-testid=\"pl-ag-data-table-grid\"\n :theme=\"AgGridTheme\"\n :class=\"$style.grid\"\n :grid-options=\"gridOptions\"\n />\n </div>\n</template>\n\n<style lang=\"css\" module>\n.container {\n display: flex;\n flex-direction: column;\n height: 100%;\n gap: 12px;\n}\n\n.grid {\n flex: 1;\n}\n</style>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlAgDataTableV2.vue_vue_type_style_index_0_lang.module.js","names":["container","grid","PlAgDataTableV2_vue_vue_type_style_index_0_lang_module_default"],"sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { promiseTimeout, isJsonEqual } from \"@milaboratories/helpers\";\nimport type {\n AxisId,\n PlDataTableColumnsMeta,\n PlDataTableGridStateCore,\n PlDataTableStateV2,\n PlSelectionModel,\n PlTableColumnIdJson,\n PTableColumnId,\n PTableColumnSpec,\n PTableKey,\n} from \"@platforma-sdk/model\";\nimport {\n getRawPlatformaInstance,\n createPlSelectionModel,\n matchAxisId,\n getAxisId,\n canonicalizeJson,\n isAbortError,\n} from \"@platforma-sdk/model\";\nimport type { CellRendererSelectorFunc, GridApi, GridState } from \"ag-grid-enterprise\";\nimport { AgGridVue } from \"ag-grid-vue3\";\nimport { computed, effectScope, nextTick, ref, shallowRef, toRefs, watch, watchEffect } from \"vue\";\nimport PlAgCsvExporter from \"../PlAgCsvExporter/PlAgCsvExporter.vue\";\nimport { PlAgGridColumnManager } from \"../PlAgGridColumnManager\";\nimport PlTableFiltersV2 from \"../PlTableFilters/PlTableFiltersV2.vue\";\nimport { PlTableFastSearch } from \"../PlTableFastSearch\";\nimport PlAgDataTableSheets from \"./PlAgDataTableSheets.vue\";\nimport PlAgRowCount from \"./PlAgRowCount.vue\";\nimport { DeferredCircular, ensureNodeVisible } from \"./sources/focus-row\";\nimport { PlAgDataTableRowNumberColId } from \"./sources/row-number\";\nimport type { PlAgCellButtonAxisParams } from \"./sources/table-source-v2\";\nimport { calculateGridOptions, effectiveVisibility } from \"./sources/table-source-v2\";\nimport { createGridRestoreState, isStoredStateApplied, readGridReport } from \"./sources/grid-state\";\nimport { useTableState } from \"./sources/table-state-v2\";\nimport type {\n PlAgDataTableV2Controller,\n PlAgDataTableV2Row,\n PlAgOverlayLoadingParams,\n PlAgOverlayNoRowsParams,\n PlDataTableSettingsV2,\n PlTableRowId,\n} from \"./types\";\nimport { useFilterableColumns } from \"./compositions/useFilterableColumns\";\nimport { useGrid } from \"./compositions/useGrid\";\nimport { AgGridTheme } from \"../../AgGridVue/AgGridTheme\";\n\nconst tableState = defineModel<PlDataTableStateV2>({\n required: true,\n});\n/** Warning: selection model value updates are ignored, use updateSelection instead */\nconst selection = defineModel<PlSelectionModel>(\"selection\");\nconst props = defineProps<{\n /** Required component settings */\n settings: Readonly<PlDataTableSettingsV2>;\n\n /**\n * The disableColumnsPanel prop controls the display of a button that activates\n * the columns management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableColumnsPanel?: boolean;\n\n /**\n * The disableFiltersPanel prop controls the display of a button that activates\n * the filters management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableFiltersPanel?: boolean;\n\n /**\n * The showExportButton prop controls the display of a button that allows\n * to export table data in CSV format. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n showExportButton?: boolean;\n\n /**\n * The AxisId property is used to configure and display the PlAgTextAndButtonCell component\n */\n showCellButtonForAxisId?: AxisId;\n\n /**\n * If cellButtonInvokeRowsOnDoubleClick = true, clicking a button inside the row\n * triggers the doubleClick event for the entire row.\n *\n * If cellButtonInvokeRowsOnDoubleClick = false, the doubleClick event for the row\n * is not triggered, but will triggered cellButtonClicked event with (key: PTableRowKey) argument.\n */\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n\n /** @see {@link PlAgOverlayLoadingParams.loadingText} */\n loadingText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.runningText} */\n runningText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.notReadyText} */\n notReadyText?: string;\n\n /** @see {@link PlAgOverlayNoRowsParams.text} */\n noRowsText?: string;\n\n /**\n * Callback to override the default renderer for a given cell.\n * @see https://www.ag-grid.com/vue-data-grid/component-cell-renderer/#dynamic-component-selection\n */\n cellRendererSelector?: CellRendererSelectorFunc<PlAgDataTableV2Row>;\n}>();\nconst { settings } = toRefs(props);\nconst emit = defineEmits<{\n rowDoubleClicked: [key?: PTableKey];\n cellButtonClicked: [key?: PTableKey];\n newDataRendered: [];\n}>();\n\nconst dataRenderedTracker = new DeferredCircular<GridApi<PlAgDataTableV2Row>>();\nconst { gridApi, gridOptions } = useGrid({\n selection,\n noRowsText: props.noRowsText,\n runningText: props.runningText,\n loadingText: props.loadingText,\n notReadyText: props.notReadyText,\n cellRendererSelector: props.cellRendererSelector,\n});\nlet isReloading = false;\n/** Source the grid's columns were built for; `null` while the grid has none. */\nconst boundSourceId = shallowRef<null | string>(null);\ngridOptions.value.onGridPreDestroyed = (event) => {\n if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));\n gridOptions.value.initialState = restoreState.value;\n gridApi.value = null;\n};\ngridOptions.value.onRowDoubleClicked = (event) => {\n if (event.data && event.data.axesKey) emit(\"rowDoubleClicked\", event.data.axesKey);\n};\ngridOptions.value.onStateUpdated = (event) => {\n saveGridState(event.api, makePartialState(event.state));\n // Keep initialState in step with the stored grid state, so the grid recreated\n // by the reload watch below comes back with it.\n gridOptions.value.initialState = restoreState.value;\n\n if (!isJsonEqual(event.sources, [\"columnSizing\"])) {\n event.api.autoSizeColumns(\n event.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n }\n};\n\nconst [filterableColumns] = useFilterableColumns(\n () => settings.value.sourceId,\n () => gridOptions.value.columnDefs ?? null,\n);\nconst defaultFilters = computed(() =>\n settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,\n);\nconst {\n sourceId: shownSourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry,\n updateGrid,\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n} = useTableState(tableState, settings, defaultFilters);\nconst sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));\nconst restoreState = computed(() =>\n createGridRestoreState({\n gridState: gridState.value,\n sorting: sorting.value,\n hiddenColIds: hiddenColIds.value,\n }),\n);\ngridOptions.value.initialState = restoreState.value;\n\n/**\n * Store what the grid reports under the source its columns belong to: while\n * the table switches sources the grid still holds the previous source's\n * columns, and their state must not land on the new source.\n */\nfunction saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {\n const sourceId = boundSourceId.value;\n // AG Grid reports an entirely empty state until its columns have been taken\n // into its own state. Such a report says nothing about the user's choices, and\n // reading defaults from the live columns at that point would invent some.\n // Wait for the grid to say something about itself; it always does once its\n // columns are in.\n if (sourceId === null || isJsonEqual(reported, {})) return;\n updateGrid(\n sourceId,\n readGridReport(reported, getEntry(sourceId), () =>\n getDefaultHiddenColIds(api, getColumnsMeta()),\n ),\n );\n}\n\n// Restore proper types erased by AgGrid\nfunction makePartialState(state: GridState): PlDataTableGridStateCore {\n return {\n columnOrder: state.columnOrder as\n | {\n orderedColIds: PlTableColumnIdJson[];\n }\n | undefined,\n sort: state.sort as\n | {\n sortModel: {\n colId: PlTableColumnIdJson;\n sort: \"asc\" | \"desc\";\n }[];\n }\n | undefined,\n columnVisibility: state.columnVisibility as\n | {\n hiddenColIds: PlTableColumnIdJson[];\n }\n | undefined,\n };\n}\n\n/** Sidecar display meta is only on the `model` branch of the settings union. */\nfunction getColumnsMeta(): PlDataTableColumnsMeta | undefined {\n return \"model\" in props.settings ? props.settings.model?.columnsMeta : undefined;\n}\n\nfunction getDefaultHiddenColIds(\n api: GridApi<PlAgDataTableV2Row>,\n columnsMeta: PlDataTableColumnsMeta | undefined,\n): PlTableColumnIdJson[] {\n const cols = api.getAllGridColumns();\n if (!cols) return [];\n\n return cols\n .filter((col) => {\n const spec = col.getColDef().context as PTableColumnSpec | undefined;\n return (\n spec !== undefined &&\n spec.type === \"column\" &&\n effectiveVisibility(spec, columnsMeta) === \"optional\"\n );\n })\n .map((col) => col.getColId() as PlTableColumnIdJson);\n}\n\n// Reload AgGrid when new state arrives from server, or when the grid takes the\n// columns of a source whose stored state it does not show yet\nconst reloadKey = ref(0);\nwatch(\n () => [gridApi.value, restoreState.value, boundSourceId.value] as const,\n ([gridApi, restoreState, boundSourceId]) => {\n if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;\n const selfState = makePartialState(gridApi.getState());\n const gridColIds = new Set(\n (gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),\n );\n if (\n !isJsonEqual(restoreState, {}) &&\n !isStoredStateApplied(restoreState, selfState, gridColIds)\n ) {\n isReloading = true;\n gridOptions.value.initialState = restoreState;\n ++reloadKey.value;\n nextTick(() => {\n isReloading = false;\n });\n }\n },\n);\n\n// Make cellRendererSelector reactive\nconst cellRendererSelector = computed(() => props.cellRendererSelector ?? null);\nwatch(\n () => [gridApi.value, cellRendererSelector.value] as const,\n ([gridApi, cellRendererSelector]) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.setGridOption(\"defaultColDef\", {\n ...gridOptions.value.defaultColDef,\n cellRendererSelector: cellRendererSelector ?? undefined,\n });\n },\n);\n\ndefineExpose<PlAgDataTableV2Controller>({\n focusRow: async (rowKey) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n return ensureNodeVisible(gridApi, (row) => isJsonEqual(row.data?.axesKey, rowKey));\n },\n updateSelection: async ({ axesSpec, selectedKeys }) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n const axes = selection.value?.axesSpec;\n if (!axes || axes.length !== axesSpec.length) return false;\n\n const mapping = axesSpec.map((spec) => {\n const id = getAxisId(spec);\n return axes.findIndex((axis) => matchAxisId(axis, id));\n });\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) return false;\n\n const selectedNodes = selectedKeys.map((key) =>\n canonicalizeJson<PlTableRowId>(mapping.map((index) => key[index])),\n );\n const oldSelectedKeys = gridApi.getServerSideSelectionState()?.toggledNodes ?? [];\n if (!isJsonEqual(oldSelectedKeys, selectedNodes)) {\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes,\n });\n\n // wait for `onSelectionChanged` to update `selection` model\n const scope = effectScope();\n const { resolve, promise } = Promise.withResolvers();\n scope.run(() => watch(selection, resolve, { once: true }));\n try {\n await promiseTimeout(promise, 500);\n } catch {\n return false;\n } finally {\n scope.stop();\n }\n }\n return true;\n },\n});\n\n// Update AgGrid when settings change\nconst defaultSelection = createPlSelectionModel();\nlet oldSettings: PlDataTableSettingsV2 | null = null;\nconst generation = ref(0);\nwatch(\n () => [gridApi.value, settings.value] as const,\n ([gridApi, settings]) => {\n // Wait for AgGrid reinitialization, gridApi will eventually become initialized\n if (!gridApi || gridApi.isDestroyed()) return;\n // Verify that this is not a false watch trigger\n if (isJsonEqual(settings, oldSettings)) return;\n try {\n // Hide no rows overlay if it is shown, or else loading overlay will not be shown\n gridApi.hideOverlay();\n dataRenderedTracker.reset();\n\n // No data source selected -> reset state to default\n if (settings.sourceId === null) {\n ++generation.value;\n boundSourceId.value = null;\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: settings.pending ? \"running\" : \"not-ready\",\n } satisfies PlAgOverlayLoadingParams,\n columnDefs: undefined,\n serverSideDatasource: undefined,\n });\n if (selection.value) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n return;\n }\n\n // The model is between handles — it is recomputing. Nothing is started here,\n // so moving the generation would only cancel the calculation in flight and\n // leave whatever it was going to do (not least taking the loading overlay\n // down) undone — which is how the table came to sit on \"Loading data…\"\n // forever. The exception is a change of source: then the calculation in\n // flight belongs to the old one and must not be allowed to land under the\n // new settings.\n if (\n settings.model?.fullTableHandle === undefined ||\n settings.model?.visibleTableHandle === undefined\n ) {\n if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;\n // A grid that already shows a table keeps showing it; one that is still\n // waiting says why.\n if (gridApi.getGridOption(\"loading\") === true) {\n setLoadingVariant(gridApi, settings.pending ? \"running\" : \"not-ready\");\n }\n return;\n }\n\n ++generation.value;\n\n // Data source changed -> show full page loader, clear selection\n if (settings.sourceId !== oldSettings?.sourceId) {\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: \"loading\",\n } satisfies PlAgOverlayLoadingParams,\n });\n if (selection.value && oldSettings?.sourceId) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n }\n\n // Model built for another source -> show skeletons until it catches up.\n // A model that reports no source was built from a state that names none,\n // or does not take the state at all, and is shown as it is.\n const sourceChanged =\n settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;\n if (sourceChanged) {\n if (gridApi.getGridOption(\"loading\") === true) setLoadingVariant(gridApi, \"loading\");\n return gridApi.updateGridOptions({\n serverSideDatasource: {\n getRows: (params) => {\n params.success({ rowData: [], rowCount: 1 });\n },\n },\n });\n }\n\n // Model ready -> calculate new state\n const stateGeneration = generation.value;\n const stateSourceId = settings.sourceId;\n calculateGridOptions({\n generation,\n pfDriver: getRawPlatformaInstance().pFrameDriver,\n fullTableHandle: settings.model?.fullTableHandle,\n visibleTableHandle: settings.model?.visibleTableHandle,\n columnsMeta: settings.model?.columnsMeta,\n sheets: settings.sheets ?? [],\n dataRenderedTracker,\n hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),\n cellButtonAxisParams: {\n showCellButtonForAxisId: props.showCellButtonForAxisId,\n cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,\n trigger: (key?: PTableKey) => emit(\"cellButtonClicked\", key),\n } satisfies PlAgCellButtonAxisParams,\n })\n .then((result) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n const { axesSpec, ...options } = result;\n gridApi.updateGridOptions({\n ...options,\n });\n boundSourceId.value = stateSourceId;\n if (selection.value) {\n // Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys\n const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;\n if (!isJsonEqual(oldAxesSpec, axesSpec)) {\n if (!oldAxesSpec || axesSpec.length !== oldAxesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const mapping = oldAxesSpec\n .map(getAxisId)\n .map((id) => axesSpec.findIndex((axis) => matchAxisId(axis, id)));\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const selectedNodes = oldSelectedKeys.map((key) =>\n mapping.map((index) => key[index]),\n );\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: selectedNodes };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes.map((key) => canonicalizeJson<PlTableRowId>(key)),\n });\n }\n }\n })\n .catch((error: unknown) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n if (isAbortError(error)) return;\n console.trace(error);\n })\n .finally(() => {\n // Only the current calculation may take the overlay down: a superseded\n // one would hide the overlay the newer settings just put up.\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n gridApi.updateGridOptions({\n loading: false,\n });\n });\n dataRenderedTracker.promise.then(() => emit(\"newDataRendered\"));\n } catch (error: unknown) {\n console.trace(error);\n } finally {\n oldSettings = settings;\n }\n },\n);\n\nfunction setLoadingVariant(\n api: GridApi<PlAgDataTableV2Row>,\n variant: PlAgOverlayLoadingParams[\"variant\"],\n): void {\n api.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant,\n } satisfies PlAgOverlayLoadingParams,\n });\n}\n\nwatch(\n () => ({\n gridApi: gridApi.value,\n loadingText: props.loadingText,\n runningText: props.runningText,\n notReadyText: props.notReadyText,\n noRowsText: props.noRowsText,\n }),\n ({ gridApi, loadingText, runningText, notReadyText, noRowsText }) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n loadingText,\n runningText,\n notReadyText,\n },\n noRowsOverlayComponentParams: {\n ...gridOptions.value.noRowsOverlayComponentParams,\n text: noRowsText,\n },\n });\n },\n);\n\nwatchEffect(() => {\n if (!gridApi.value || gridApi.value?.isDestroyed()) return;\n gridApi.value.updateGridOptions({\n statusBar: gridOptions.value.loading\n ? undefined\n : {\n statusPanels: [{ statusPanel: PlAgRowCount, align: \"left\" }],\n },\n });\n});\n</script>\n\n<template>\n <div data-testid=\"pl-ag-data-table\" :class=\"$style.container\">\n <PlAgGridColumnManager v-if=\"gridApi && !disableColumnsPanel\" :api=\"gridApi\" />\n <PlTableFiltersV2\n v-if=\"!disableFiltersPanel\"\n :filters=\"filtersState\"\n :default-filters=\"defaultFiltersState\"\n :pframe-handle=\"'model' in settings ? settings?.model?.fullPframeHandle : undefined\"\n :columns=\"filterableColumns\"\n :columns-meta=\"getColumnsMeta()\"\n @updateFilters=\"(v) => (filtersState = v)\"\n @resetDefaultFilters=\"resetDefaultFilters\"\n @updateDefaultFilters=\"(v) => (defaultFiltersState = v)\"\n v-model=\"filtersState\"\n />\n <PlAgCsvExporter\n v-if=\"gridApi && showExportButton\"\n :api=\"gridApi\"\n :table-handle=\"'model' in settings ? settings?.model?.visibleTableHandle : undefined\"\n :columns-meta=\"getColumnsMeta()\"\n />\n <PlAgDataTableSheets\n :sheets=\"sheets\"\n :state=\"sheetsState\"\n :on-change=\"(state) => (sheetsState = state)\"\n >\n <template v-if=\"$slots['before-sheets']\" #before>\n <slot name=\"before-sheets\" />\n </template>\n <template v-if=\"$slots['after-sheets']\" #after>\n <slot name=\"after-sheets\" />\n </template>\n </PlAgDataTableSheets>\n <PlTableFastSearch v-model=\"searchString\" />\n <AgGridVue\n :key=\"reloadKey\"\n data-testid=\"pl-ag-data-table-grid\"\n :theme=\"AgGridTheme\"\n :class=\"$style.grid\"\n :grid-options=\"gridOptions\"\n />\n </div>\n</template>\n\n<style lang=\"css\" module>\n.container {\n display: flex;\n flex-direction: column;\n height: 100%;\n gap: 12px;\n}\n\n.grid {\n flex: 1;\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"PlAgDataTableV2.vue_vue_type_style_index_0_lang.module.js","names":["container","grid","PlAgDataTableV2_vue_vue_type_style_index_0_lang_module_default"],"sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { promiseTimeout, isJsonEqual } from \"@milaboratories/helpers\";\nimport type {\n AxisId,\n PlDataTableColumnsMeta,\n PlDataTableGridStateCore,\n PlDataTableStateV2,\n PlSelectionModel,\n PlTableColumnIdJson,\n PTableColumnId,\n PTableColumnSpec,\n PTableKey,\n} from \"@platforma-sdk/model\";\nimport {\n getRawPlatformaInstance,\n createPlSelectionModel,\n matchAxisId,\n getAxisId,\n canonicalizeJson,\n isAbortError,\n} from \"@platforma-sdk/model\";\nimport type { CellRendererSelectorFunc, GridApi, GridState } from \"ag-grid-enterprise\";\nimport { AgGridVue } from \"ag-grid-vue3\";\nimport { computed, effectScope, nextTick, ref, shallowRef, toRefs, watch, watchEffect } from \"vue\";\nimport PlAgCsvExporter from \"../PlAgCsvExporter/PlAgCsvExporter.vue\";\nimport { PlAgGridColumnManager } from \"../PlAgGridColumnManager\";\nimport PlTableFiltersV2 from \"../PlTableFilters/PlTableFiltersV2.vue\";\nimport { PlTableFastSearch } from \"../PlTableFastSearch\";\nimport PlAgDataTableSheets from \"./PlAgDataTableSheets.vue\";\nimport PlAgRowCount from \"./PlAgRowCount.vue\";\nimport { DeferredCircular, ensureNodeVisible } from \"./sources/focus-row\";\nimport { PlAgDataTableRowNumberColId } from \"./sources/row-number\";\nimport type { PlAgCellButtonAxisParams } from \"./sources/table-source-v2\";\nimport { calculateGridOptions, effectiveVisibility } from \"./sources/table-source-v2\";\nimport { createGridRestoreState, isStoredStateApplied, readGridReport } from \"./sources/grid-state\";\nimport { useTableState } from \"./sources/table-state-v2\";\nimport type {\n PlAgDataTableV2Controller,\n PlAgDataTableV2Row,\n PlAgOverlayLoadingParams,\n PlAgOverlayNoRowsParams,\n PlDataTableSettingsV2,\n PlTableRowId,\n} from \"./types\";\nimport { useFilterableColumns } from \"./compositions/useFilterableColumns\";\nimport { useGrid } from \"./compositions/useGrid\";\nimport { AgGridTheme } from \"../../AgGridVue/AgGridTheme\";\n\nconst tableState = defineModel<PlDataTableStateV2>({\n required: true,\n});\n/** Warning: selection model value updates are ignored, use updateSelection instead */\nconst selection = defineModel<PlSelectionModel>(\"selection\");\nconst props = defineProps<{\n /** Required component settings */\n settings: Readonly<PlDataTableSettingsV2>;\n\n /**\n * The disableColumnsPanel prop controls the display of a button that activates\n * the columns management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableColumnsPanel?: boolean;\n\n /**\n * The disableFiltersPanel prop controls the display of a button that activates\n * the filters management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableFiltersPanel?: boolean;\n\n /**\n * The showExportButton prop controls the display of a button that allows\n * to export table data in CSV format. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n showExportButton?: boolean;\n\n /**\n * The AxisId property is used to configure and display the PlAgTextAndButtonCell component\n */\n showCellButtonForAxisId?: AxisId;\n\n /**\n * If cellButtonInvokeRowsOnDoubleClick = true, clicking a button inside the row\n * triggers the doubleClick event for the entire row.\n *\n * If cellButtonInvokeRowsOnDoubleClick = false, the doubleClick event for the row\n * is not triggered, but will triggered cellButtonClicked event with (key: PTableRowKey) argument.\n */\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n\n /** @see {@link PlAgOverlayLoadingParams.loadingText} */\n loadingText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.runningText} */\n runningText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.notReadyText} */\n notReadyText?: string;\n\n /** @see {@link PlAgOverlayNoRowsParams.text} */\n noRowsText?: string;\n\n /**\n * Callback to override the default renderer for a given cell.\n * @see https://www.ag-grid.com/vue-data-grid/component-cell-renderer/#dynamic-component-selection\n */\n cellRendererSelector?: CellRendererSelectorFunc<PlAgDataTableV2Row>;\n}>();\nconst { settings } = toRefs(props);\nconst emit = defineEmits<{\n rowDoubleClicked: [key?: PTableKey];\n cellButtonClicked: [key?: PTableKey];\n newDataRendered: [];\n}>();\n\nconst dataRenderedTracker = new DeferredCircular<GridApi<PlAgDataTableV2Row>>();\nconst { gridApi, gridOptions } = useGrid({\n selection,\n noRowsText: props.noRowsText,\n runningText: props.runningText,\n loadingText: props.loadingText,\n notReadyText: props.notReadyText,\n cellRendererSelector: props.cellRendererSelector,\n});\nlet isReloading = false;\n/** Source the grid's columns were built for; `null` while the grid has none. */\nconst boundSourceId = shallowRef<null | string>(null);\ngridOptions.value.onGridPreDestroyed = (event) => {\n if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));\n gridOptions.value.initialState = restoreState.value;\n // A replaced grid destroyed after its successor is ready must leave the successor's api in place\n if (gridApi.value?.getGridId() === event.api.getGridId()) gridApi.value = null;\n};\ngridOptions.value.onRowDoubleClicked = (event) => {\n if (event.data && event.data.axesKey) emit(\"rowDoubleClicked\", event.data.axesKey);\n};\ngridOptions.value.onStateUpdated = (event) => {\n saveGridState(event.api, makePartialState(event.state));\n // Keep initialState in step with the stored grid state, so the grid recreated\n // by the reload watch below comes back with it.\n gridOptions.value.initialState = restoreState.value;\n\n if (!isJsonEqual(event.sources, [\"columnSizing\"])) {\n event.api.autoSizeColumns(\n event.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n }\n};\n\nconst [filterableColumns] = useFilterableColumns(\n () => settings.value.sourceId,\n () => gridOptions.value.columnDefs ?? null,\n);\nconst defaultFilters = computed(() =>\n settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,\n);\nconst {\n sourceId: shownSourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry,\n updateGrid,\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n} = useTableState(tableState, settings, defaultFilters);\nconst sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));\nconst restoreState = computed(() =>\n createGridRestoreState({\n gridState: gridState.value,\n sorting: sorting.value,\n hiddenColIds: hiddenColIds.value,\n }),\n);\ngridOptions.value.initialState = restoreState.value;\n\n/**\n * Store what the grid reports under the source its columns belong to: while\n * the table switches sources the grid still holds the previous source's\n * columns, and their state must not land on the new source.\n */\nfunction saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {\n const sourceId = boundSourceId.value;\n // AG Grid reports an entirely empty state until its columns have been taken\n // into its own state. Such a report says nothing about the user's choices, and\n // reading defaults from the live columns at that point would invent some.\n // Wait for the grid to say something about itself; it always does once its\n // columns are in.\n if (sourceId === null || isJsonEqual(reported, {})) return;\n updateGrid(\n sourceId,\n readGridReport(reported, getEntry(sourceId), () =>\n getDefaultHiddenColIds(api, getColumnsMeta()),\n ),\n );\n}\n\n// Restore proper types erased by AgGrid\nfunction makePartialState(state: GridState): PlDataTableGridStateCore {\n return {\n columnOrder: state.columnOrder as\n | {\n orderedColIds: PlTableColumnIdJson[];\n }\n | undefined,\n sort: state.sort as\n | {\n sortModel: {\n colId: PlTableColumnIdJson;\n sort: \"asc\" | \"desc\";\n }[];\n }\n | undefined,\n columnVisibility: state.columnVisibility as\n | {\n hiddenColIds: PlTableColumnIdJson[];\n }\n | undefined,\n };\n}\n\n/** Sidecar display meta is only on the `model` branch of the settings union. */\nfunction getColumnsMeta(): PlDataTableColumnsMeta | undefined {\n return \"model\" in props.settings ? props.settings.model?.columnsMeta : undefined;\n}\n\nfunction getDefaultHiddenColIds(\n api: GridApi<PlAgDataTableV2Row>,\n columnsMeta: PlDataTableColumnsMeta | undefined,\n): PlTableColumnIdJson[] {\n const cols = api.getAllGridColumns();\n if (!cols) return [];\n\n return cols\n .filter((col) => {\n const spec = col.getColDef().context as PTableColumnSpec | undefined;\n return (\n spec !== undefined &&\n spec.type === \"column\" &&\n effectiveVisibility(spec, columnsMeta) === \"optional\"\n );\n })\n .map((col) => col.getColId() as PlTableColumnIdJson);\n}\n\n// Reload AgGrid when new state arrives from server, or when the grid takes the\n// columns of a source whose stored state it does not show yet\nconst reloadKey = ref(0);\nwatch(\n () => [gridApi.value, restoreState.value, boundSourceId.value] as const,\n ([gridApi, restoreState, boundSourceId]) => {\n if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;\n const selfState = makePartialState(gridApi.getState());\n const gridColIds = new Set(\n (gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),\n );\n if (\n !isJsonEqual(restoreState, {}) &&\n !isStoredStateApplied(restoreState, selfState, gridColIds)\n ) {\n isReloading = true;\n gridOptions.value.initialState = restoreState;\n ++reloadKey.value;\n nextTick(() => {\n isReloading = false;\n });\n }\n },\n);\n\n// Make cellRendererSelector reactive\nconst cellRendererSelector = computed(() => props.cellRendererSelector ?? null);\nwatch(\n () => [gridApi.value, cellRendererSelector.value] as const,\n ([gridApi, cellRendererSelector]) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.setGridOption(\"defaultColDef\", {\n ...gridOptions.value.defaultColDef,\n cellRendererSelector: cellRendererSelector ?? undefined,\n });\n },\n);\n\ndefineExpose<PlAgDataTableV2Controller>({\n focusRow: async (rowKey) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n return ensureNodeVisible(gridApi, (row) => isJsonEqual(row.data?.axesKey, rowKey));\n },\n updateSelection: async ({ axesSpec, selectedKeys }) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n const axes = selection.value?.axesSpec;\n if (!axes || axes.length !== axesSpec.length) return false;\n\n const mapping = axesSpec.map((spec) => {\n const id = getAxisId(spec);\n return axes.findIndex((axis) => matchAxisId(axis, id));\n });\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) return false;\n\n const selectedNodes = selectedKeys.map((key) =>\n canonicalizeJson<PlTableRowId>(mapping.map((index) => key[index])),\n );\n const oldSelectedKeys = gridApi.getServerSideSelectionState()?.toggledNodes ?? [];\n if (!isJsonEqual(oldSelectedKeys, selectedNodes)) {\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes,\n });\n\n // wait for `onSelectionChanged` to update `selection` model\n const scope = effectScope();\n const { resolve, promise } = Promise.withResolvers();\n scope.run(() => watch(selection, resolve, { once: true }));\n try {\n await promiseTimeout(promise, 500);\n } catch {\n return false;\n } finally {\n scope.stop();\n }\n }\n return true;\n },\n});\n\n// Update AgGrid when settings change\nconst defaultSelection = createPlSelectionModel();\nlet oldSettings: PlDataTableSettingsV2 | null = null;\nconst generation = ref(0);\nwatch(\n () => [gridApi.value, settings.value] as const,\n ([gridApi, settings]) => {\n // Wait for AgGrid reinitialization, gridApi will eventually become initialized\n if (!gridApi || gridApi.isDestroyed()) return;\n // Verify that this is not a false watch trigger\n if (isJsonEqual(settings, oldSettings)) return;\n try {\n // Hide no rows overlay if it is shown, or else loading overlay will not be shown\n gridApi.hideOverlay();\n dataRenderedTracker.reset();\n\n // No data source selected -> reset state to default\n if (settings.sourceId === null) {\n ++generation.value;\n boundSourceId.value = null;\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: settings.pending ? \"running\" : \"not-ready\",\n } satisfies PlAgOverlayLoadingParams,\n columnDefs: undefined,\n serverSideDatasource: undefined,\n });\n if (selection.value) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n return;\n }\n\n // The model is between handles — it is recomputing. Nothing is started here,\n // so moving the generation would only cancel the calculation in flight and\n // leave whatever it was going to do (not least taking the loading overlay\n // down) undone — which is how the table came to sit on \"Loading data…\"\n // forever. The exception is a change of source: then the calculation in\n // flight belongs to the old one and must not be allowed to land under the\n // new settings.\n if (\n settings.model?.fullTableHandle === undefined ||\n settings.model?.visibleTableHandle === undefined\n ) {\n if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;\n // A grid that already shows a table keeps showing it; one that is still\n // waiting says why.\n if (gridApi.getGridOption(\"loading\") === true) {\n setLoadingVariant(gridApi, settings.pending ? \"running\" : \"not-ready\");\n }\n return;\n }\n\n ++generation.value;\n\n // Data source changed -> show full page loader, clear selection\n if (settings.sourceId !== oldSettings?.sourceId) {\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: \"loading\",\n } satisfies PlAgOverlayLoadingParams,\n });\n if (selection.value && oldSettings?.sourceId) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n }\n\n // Model built for another source -> show skeletons until it catches up.\n // A model that reports no source was built from a state that names none,\n // or does not take the state at all, and is shown as it is.\n const sourceChanged =\n settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;\n if (sourceChanged) {\n if (gridApi.getGridOption(\"loading\") === true) setLoadingVariant(gridApi, \"loading\");\n return gridApi.updateGridOptions({\n serverSideDatasource: {\n getRows: (params) => {\n params.success({ rowData: [], rowCount: 1 });\n },\n },\n });\n }\n\n // Model ready -> calculate new state\n const stateGeneration = generation.value;\n const stateSourceId = settings.sourceId;\n calculateGridOptions({\n generation,\n pfDriver: getRawPlatformaInstance().pFrameDriver,\n fullTableHandle: settings.model?.fullTableHandle,\n visibleTableHandle: settings.model?.visibleTableHandle,\n columnsMeta: settings.model?.columnsMeta,\n sheets: settings.sheets ?? [],\n dataRenderedTracker,\n hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),\n cellButtonAxisParams: {\n showCellButtonForAxisId: props.showCellButtonForAxisId,\n cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,\n trigger: (key?: PTableKey) => emit(\"cellButtonClicked\", key),\n } satisfies PlAgCellButtonAxisParams,\n })\n .then((result) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n const { axesSpec, ...options } = result;\n gridApi.updateGridOptions({\n ...options,\n });\n boundSourceId.value = stateSourceId;\n if (selection.value) {\n // Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys\n const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;\n if (!isJsonEqual(oldAxesSpec, axesSpec)) {\n if (!oldAxesSpec || axesSpec.length !== oldAxesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const mapping = oldAxesSpec\n .map(getAxisId)\n .map((id) => axesSpec.findIndex((axis) => matchAxisId(axis, id)));\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const selectedNodes = oldSelectedKeys.map((key) =>\n mapping.map((index) => key[index]),\n );\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: selectedNodes };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes.map((key) => canonicalizeJson<PlTableRowId>(key)),\n });\n }\n }\n })\n .catch((error: unknown) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n if (isAbortError(error)) return;\n console.trace(error);\n })\n .finally(() => {\n // Only the current calculation may take the overlay down: a superseded\n // one would hide the overlay the newer settings just put up.\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n gridApi.updateGridOptions({\n loading: false,\n });\n });\n dataRenderedTracker.promise.then(() => emit(\"newDataRendered\"));\n } catch (error: unknown) {\n console.trace(error);\n } finally {\n oldSettings = settings;\n }\n },\n);\n\nfunction setLoadingVariant(\n api: GridApi<PlAgDataTableV2Row>,\n variant: PlAgOverlayLoadingParams[\"variant\"],\n): void {\n api.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant,\n } satisfies PlAgOverlayLoadingParams,\n });\n}\n\nwatch(\n () => ({\n gridApi: gridApi.value,\n loadingText: props.loadingText,\n runningText: props.runningText,\n notReadyText: props.notReadyText,\n noRowsText: props.noRowsText,\n }),\n ({ gridApi, loadingText, runningText, notReadyText, noRowsText }) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n loadingText,\n runningText,\n notReadyText,\n },\n noRowsOverlayComponentParams: {\n ...gridOptions.value.noRowsOverlayComponentParams,\n text: noRowsText,\n },\n });\n },\n);\n\nwatchEffect(() => {\n if (!gridApi.value || gridApi.value?.isDestroyed()) return;\n gridApi.value.updateGridOptions({\n statusBar: gridOptions.value.loading\n ? undefined\n : {\n statusPanels: [{ statusPanel: PlAgRowCount, align: \"left\" }],\n },\n });\n});\n</script>\n\n<template>\n <div data-testid=\"pl-ag-data-table\" :class=\"$style.container\">\n <PlAgGridColumnManager v-if=\"gridApi && !disableColumnsPanel\" :api=\"gridApi\" />\n <PlTableFiltersV2\n v-if=\"!disableFiltersPanel\"\n :filters=\"filtersState\"\n :default-filters=\"defaultFiltersState\"\n :pframe-handle=\"'model' in settings ? settings?.model?.fullPframeHandle : undefined\"\n :columns=\"filterableColumns\"\n :columns-meta=\"getColumnsMeta()\"\n @updateFilters=\"(v) => (filtersState = v)\"\n @resetDefaultFilters=\"resetDefaultFilters\"\n @updateDefaultFilters=\"(v) => (defaultFiltersState = v)\"\n v-model=\"filtersState\"\n />\n <PlAgCsvExporter\n v-if=\"gridApi && showExportButton\"\n :api=\"gridApi\"\n :table-handle=\"'model' in settings ? settings?.model?.visibleTableHandle : undefined\"\n :columns-meta=\"getColumnsMeta()\"\n />\n <PlAgDataTableSheets\n :sheets=\"sheets\"\n :state=\"sheetsState\"\n :on-change=\"(state) => (sheetsState = state)\"\n >\n <template v-if=\"$slots['before-sheets']\" #before>\n <slot name=\"before-sheets\" />\n </template>\n <template v-if=\"$slots['after-sheets']\" #after>\n <slot name=\"after-sheets\" />\n </template>\n </PlAgDataTableSheets>\n <PlTableFastSearch v-model=\"searchString\" />\n <AgGridVue\n :key=\"reloadKey\"\n data-testid=\"pl-ag-data-table-grid\"\n :theme=\"AgGridTheme\"\n :class=\"$style.grid\"\n :grid-options=\"gridOptions\"\n />\n </div>\n</template>\n\n<style lang=\"css\" module>\n.container {\n display: flex;\n flex-direction: column;\n height: 100%;\n gap: 12px;\n}\n\n.grid {\n flex: 1;\n}\n</style>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlAgDataTableV2.vue.d.ts","sourceRoot":"","sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlAgDataTableV2.vue.d.ts","sourceRoot":"","sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"names":[],"mappings":"AA+nBA,OAAO,KAAK,EACV,MAAM,EAGN,kBAAkB,EAClB,gBAAgB,EAIhB,SAAS,EACV,MAAM,sBAAsB,CAAC;AAS9B,OAAO,KAAK,EAAE,wBAAwB,EAAsB,MAAM,oBAAoB,CAAC;AAevF,OAAO,KAAK,EACV,yBAAyB,EACzB,kBAAkB,EAGlB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAUjB,KAAK,WAAW,GAAG;IACjB,kCAAkC;IAClC,QAAQ,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAE1C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC;;;;;;OAMG;IACH,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAE5C,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;CACrE,CAAC;AAsdF,KAAK,gBAAgB,GAAG;IACxB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,sFAAsF;IACtF,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAC9B,CAAC;AAMF,KAAK,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;AA6KxD,QAAA,IAAI,QAAQ,IAAW,EAAE,QAAQ,IAAY,CAAE;AAC/C,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,GACrD;IAAE,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAKvD,QAAA,MAAM,UAAU;;;;;;;;;;;;kFAId,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -56,7 +56,7 @@ var A = /*@__PURE__*/ h({
|
|
|
56
56
|
cellRendererSelector: M.cellRendererSelector
|
|
57
57
|
}), R = !1, z = pe(null);
|
|
58
58
|
L.value.onGridPreDestroyed = (e) => {
|
|
59
|
-
R || K(e.api, q(e.api.getState())), L.value.initialState = G.value, I.value = null;
|
|
59
|
+
R || K(e.api, q(e.api.getState())), L.value.initialState = G.value, I.value?.getGridId() === e.api.getGridId() && (I.value = null);
|
|
60
60
|
}, L.value.onRowDoubleClicked = (e) => {
|
|
61
61
|
e.data && e.data.axesKey && P("rowDoubleClicked", e.data.axesKey);
|
|
62
62
|
}, L.value.onStateUpdated = (t) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlAgDataTableV2.vue_vue_type_script_setup_true_lang.js","names":["$style","$slots","_useModel","PlAgRowCount","_openBlock","_createElementBlock","_normalizeClass","_unref","_createBlock","PlAgGridColumnManager","_createCommentVNode","PlTableFiltersV2","_isRef","PlAgCsvExporter","_createVNode","PlAgDataTableSheets","_createSlots","_withCtx","_renderSlot","PlTableFastSearch","PlAgCsvExporter_default","PlAgGridColumnManager_default","PlTableFiltersV2_default","PlTableFastSearch_default","PlAgDataTableSheets_default","PlAgRowCount_default","PlAgDataTableV2_vue_vue_type_script_setup_true_lang_default","\"modelValue\"","\"modelModifiers\"","\"selection\"","\"selectionModifiers\"","__expose","__emit","tableState","useModel","__props","selection","props","toRefs","emit","dataRenderedTracker","DeferredCircular","useGrid","isReloading","boundSourceId","shallowRef","saveGridState","event","makePartialState","restoreState","isJsonEqual","column","PlAgDataTableRowNumberColId","filterableColumns","useFilterableColumns","settings","gridOptions","defaultFilters","computed","shownSourceId","useTableState","sheets","createGridRestoreState","gridState","sorting","hiddenColIds","sourceId","reported","updateGrid","readGridReport","getEntry","getDefaultHiddenColIds","api","getColumnsMeta","state","cols","spec","col","effectiveVisibility","columnsMeta","reloadKey","ref","gridApi","selfState","gridColIds","isStoredStateApplied","nextTick","cellRendererSelector","watch","ensureNodeVisible","row","rowKey","axes","axesSpec","mapping","id","getAxisId","matchAxisId","axis","mappingSet","selectedNodes","selectedKeys","canonicalizeJson","key","index","oldSelectedKeys","scope","effectScope","resolve","promiseTimeout","promise","defaultSelection","createPlSelectionModel","oldSettings","generation","setLoadingVariant","stateGeneration","stateSourceId","calculateGridOptions","getRawPlatformaInstance","options","result","oldAxesSpec","newSelection","isAbortError","error","noRowsText","watchEffect","openBlock","createElementBlock","normalizeClass","_ctx","unref","createBlock","createCommentVNode","filtersState","defaultFiltersState","_cache","v","resetDefaultFilters","isRef","$event","createVNode","sheetsState","createSlots","withCtx","renderSlot","searchString","AgGridVue","AgGridTheme"],"sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { promiseTimeout, isJsonEqual } from \"@milaboratories/helpers\";\nimport type {\n AxisId,\n PlDataTableColumnsMeta,\n PlDataTableGridStateCore,\n PlDataTableStateV2,\n PlSelectionModel,\n PlTableColumnIdJson,\n PTableColumnId,\n PTableColumnSpec,\n PTableKey,\n} from \"@platforma-sdk/model\";\nimport {\n getRawPlatformaInstance,\n createPlSelectionModel,\n matchAxisId,\n getAxisId,\n canonicalizeJson,\n isAbortError,\n} from \"@platforma-sdk/model\";\nimport type { CellRendererSelectorFunc, GridApi, GridState } from \"ag-grid-enterprise\";\nimport { AgGridVue } from \"ag-grid-vue3\";\nimport { computed, effectScope, nextTick, ref, shallowRef, toRefs, watch, watchEffect } from \"vue\";\nimport PlAgCsvExporter from \"../PlAgCsvExporter/PlAgCsvExporter.vue\";\nimport { PlAgGridColumnManager } from \"../PlAgGridColumnManager\";\nimport PlTableFiltersV2 from \"../PlTableFilters/PlTableFiltersV2.vue\";\nimport { PlTableFastSearch } from \"../PlTableFastSearch\";\nimport PlAgDataTableSheets from \"./PlAgDataTableSheets.vue\";\nimport PlAgRowCount from \"./PlAgRowCount.vue\";\nimport { DeferredCircular, ensureNodeVisible } from \"./sources/focus-row\";\nimport { PlAgDataTableRowNumberColId } from \"./sources/row-number\";\nimport type { PlAgCellButtonAxisParams } from \"./sources/table-source-v2\";\nimport { calculateGridOptions, effectiveVisibility } from \"./sources/table-source-v2\";\nimport { createGridRestoreState, isStoredStateApplied, readGridReport } from \"./sources/grid-state\";\nimport { useTableState } from \"./sources/table-state-v2\";\nimport type {\n PlAgDataTableV2Controller,\n PlAgDataTableV2Row,\n PlAgOverlayLoadingParams,\n PlAgOverlayNoRowsParams,\n PlDataTableSettingsV2,\n PlTableRowId,\n} from \"./types\";\nimport { useFilterableColumns } from \"./compositions/useFilterableColumns\";\nimport { useGrid } from \"./compositions/useGrid\";\nimport { AgGridTheme } from \"../../AgGridVue/AgGridTheme\";\n\nconst tableState = defineModel<PlDataTableStateV2>({\n required: true,\n});\n/** Warning: selection model value updates are ignored, use updateSelection instead */\nconst selection = defineModel<PlSelectionModel>(\"selection\");\nconst props = defineProps<{\n /** Required component settings */\n settings: Readonly<PlDataTableSettingsV2>;\n\n /**\n * The disableColumnsPanel prop controls the display of a button that activates\n * the columns management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableColumnsPanel?: boolean;\n\n /**\n * The disableFiltersPanel prop controls the display of a button that activates\n * the filters management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableFiltersPanel?: boolean;\n\n /**\n * The showExportButton prop controls the display of a button that allows\n * to export table data in CSV format. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n showExportButton?: boolean;\n\n /**\n * The AxisId property is used to configure and display the PlAgTextAndButtonCell component\n */\n showCellButtonForAxisId?: AxisId;\n\n /**\n * If cellButtonInvokeRowsOnDoubleClick = true, clicking a button inside the row\n * triggers the doubleClick event for the entire row.\n *\n * If cellButtonInvokeRowsOnDoubleClick = false, the doubleClick event for the row\n * is not triggered, but will triggered cellButtonClicked event with (key: PTableRowKey) argument.\n */\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n\n /** @see {@link PlAgOverlayLoadingParams.loadingText} */\n loadingText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.runningText} */\n runningText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.notReadyText} */\n notReadyText?: string;\n\n /** @see {@link PlAgOverlayNoRowsParams.text} */\n noRowsText?: string;\n\n /**\n * Callback to override the default renderer for a given cell.\n * @see https://www.ag-grid.com/vue-data-grid/component-cell-renderer/#dynamic-component-selection\n */\n cellRendererSelector?: CellRendererSelectorFunc<PlAgDataTableV2Row>;\n}>();\nconst { settings } = toRefs(props);\nconst emit = defineEmits<{\n rowDoubleClicked: [key?: PTableKey];\n cellButtonClicked: [key?: PTableKey];\n newDataRendered: [];\n}>();\n\nconst dataRenderedTracker = new DeferredCircular<GridApi<PlAgDataTableV2Row>>();\nconst { gridApi, gridOptions } = useGrid({\n selection,\n noRowsText: props.noRowsText,\n runningText: props.runningText,\n loadingText: props.loadingText,\n notReadyText: props.notReadyText,\n cellRendererSelector: props.cellRendererSelector,\n});\nlet isReloading = false;\n/** Source the grid's columns were built for; `null` while the grid has none. */\nconst boundSourceId = shallowRef<null | string>(null);\ngridOptions.value.onGridPreDestroyed = (event) => {\n if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));\n gridOptions.value.initialState = restoreState.value;\n gridApi.value = null;\n};\ngridOptions.value.onRowDoubleClicked = (event) => {\n if (event.data && event.data.axesKey) emit(\"rowDoubleClicked\", event.data.axesKey);\n};\ngridOptions.value.onStateUpdated = (event) => {\n saveGridState(event.api, makePartialState(event.state));\n // Keep initialState in step with the stored grid state, so the grid recreated\n // by the reload watch below comes back with it.\n gridOptions.value.initialState = restoreState.value;\n\n if (!isJsonEqual(event.sources, [\"columnSizing\"])) {\n event.api.autoSizeColumns(\n event.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n }\n};\n\nconst [filterableColumns] = useFilterableColumns(\n () => settings.value.sourceId,\n () => gridOptions.value.columnDefs ?? null,\n);\nconst defaultFilters = computed(() =>\n settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,\n);\nconst {\n sourceId: shownSourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry,\n updateGrid,\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n} = useTableState(tableState, settings, defaultFilters);\nconst sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));\nconst restoreState = computed(() =>\n createGridRestoreState({\n gridState: gridState.value,\n sorting: sorting.value,\n hiddenColIds: hiddenColIds.value,\n }),\n);\ngridOptions.value.initialState = restoreState.value;\n\n/**\n * Store what the grid reports under the source its columns belong to: while\n * the table switches sources the grid still holds the previous source's\n * columns, and their state must not land on the new source.\n */\nfunction saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {\n const sourceId = boundSourceId.value;\n // AG Grid reports an entirely empty state until its columns have been taken\n // into its own state. Such a report says nothing about the user's choices, and\n // reading defaults from the live columns at that point would invent some.\n // Wait for the grid to say something about itself; it always does once its\n // columns are in.\n if (sourceId === null || isJsonEqual(reported, {})) return;\n updateGrid(\n sourceId,\n readGridReport(reported, getEntry(sourceId), () =>\n getDefaultHiddenColIds(api, getColumnsMeta()),\n ),\n );\n}\n\n// Restore proper types erased by AgGrid\nfunction makePartialState(state: GridState): PlDataTableGridStateCore {\n return {\n columnOrder: state.columnOrder as\n | {\n orderedColIds: PlTableColumnIdJson[];\n }\n | undefined,\n sort: state.sort as\n | {\n sortModel: {\n colId: PlTableColumnIdJson;\n sort: \"asc\" | \"desc\";\n }[];\n }\n | undefined,\n columnVisibility: state.columnVisibility as\n | {\n hiddenColIds: PlTableColumnIdJson[];\n }\n | undefined,\n };\n}\n\n/** Sidecar display meta is only on the `model` branch of the settings union. */\nfunction getColumnsMeta(): PlDataTableColumnsMeta | undefined {\n return \"model\" in props.settings ? props.settings.model?.columnsMeta : undefined;\n}\n\nfunction getDefaultHiddenColIds(\n api: GridApi<PlAgDataTableV2Row>,\n columnsMeta: PlDataTableColumnsMeta | undefined,\n): PlTableColumnIdJson[] {\n const cols = api.getAllGridColumns();\n if (!cols) return [];\n\n return cols\n .filter((col) => {\n const spec = col.getColDef().context as PTableColumnSpec | undefined;\n return (\n spec !== undefined &&\n spec.type === \"column\" &&\n effectiveVisibility(spec, columnsMeta) === \"optional\"\n );\n })\n .map((col) => col.getColId() as PlTableColumnIdJson);\n}\n\n// Reload AgGrid when new state arrives from server, or when the grid takes the\n// columns of a source whose stored state it does not show yet\nconst reloadKey = ref(0);\nwatch(\n () => [gridApi.value, restoreState.value, boundSourceId.value] as const,\n ([gridApi, restoreState, boundSourceId]) => {\n if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;\n const selfState = makePartialState(gridApi.getState());\n const gridColIds = new Set(\n (gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),\n );\n if (\n !isJsonEqual(restoreState, {}) &&\n !isStoredStateApplied(restoreState, selfState, gridColIds)\n ) {\n isReloading = true;\n gridOptions.value.initialState = restoreState;\n ++reloadKey.value;\n nextTick(() => {\n isReloading = false;\n });\n }\n },\n);\n\n// Make cellRendererSelector reactive\nconst cellRendererSelector = computed(() => props.cellRendererSelector ?? null);\nwatch(\n () => [gridApi.value, cellRendererSelector.value] as const,\n ([gridApi, cellRendererSelector]) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.setGridOption(\"defaultColDef\", {\n ...gridOptions.value.defaultColDef,\n cellRendererSelector: cellRendererSelector ?? undefined,\n });\n },\n);\n\ndefineExpose<PlAgDataTableV2Controller>({\n focusRow: async (rowKey) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n return ensureNodeVisible(gridApi, (row) => isJsonEqual(row.data?.axesKey, rowKey));\n },\n updateSelection: async ({ axesSpec, selectedKeys }) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n const axes = selection.value?.axesSpec;\n if (!axes || axes.length !== axesSpec.length) return false;\n\n const mapping = axesSpec.map((spec) => {\n const id = getAxisId(spec);\n return axes.findIndex((axis) => matchAxisId(axis, id));\n });\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) return false;\n\n const selectedNodes = selectedKeys.map((key) =>\n canonicalizeJson<PlTableRowId>(mapping.map((index) => key[index])),\n );\n const oldSelectedKeys = gridApi.getServerSideSelectionState()?.toggledNodes ?? [];\n if (!isJsonEqual(oldSelectedKeys, selectedNodes)) {\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes,\n });\n\n // wait for `onSelectionChanged` to update `selection` model\n const scope = effectScope();\n const { resolve, promise } = Promise.withResolvers();\n scope.run(() => watch(selection, resolve, { once: true }));\n try {\n await promiseTimeout(promise, 500);\n } catch {\n return false;\n } finally {\n scope.stop();\n }\n }\n return true;\n },\n});\n\n// Update AgGrid when settings change\nconst defaultSelection = createPlSelectionModel();\nlet oldSettings: PlDataTableSettingsV2 | null = null;\nconst generation = ref(0);\nwatch(\n () => [gridApi.value, settings.value] as const,\n ([gridApi, settings]) => {\n // Wait for AgGrid reinitialization, gridApi will eventually become initialized\n if (!gridApi || gridApi.isDestroyed()) return;\n // Verify that this is not a false watch trigger\n if (isJsonEqual(settings, oldSettings)) return;\n try {\n // Hide no rows overlay if it is shown, or else loading overlay will not be shown\n gridApi.hideOverlay();\n dataRenderedTracker.reset();\n\n // No data source selected -> reset state to default\n if (settings.sourceId === null) {\n ++generation.value;\n boundSourceId.value = null;\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: settings.pending ? \"running\" : \"not-ready\",\n } satisfies PlAgOverlayLoadingParams,\n columnDefs: undefined,\n serverSideDatasource: undefined,\n });\n if (selection.value) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n return;\n }\n\n // The model is between handles — it is recomputing. Nothing is started here,\n // so moving the generation would only cancel the calculation in flight and\n // leave whatever it was going to do (not least taking the loading overlay\n // down) undone — which is how the table came to sit on \"Loading data…\"\n // forever. The exception is a change of source: then the calculation in\n // flight belongs to the old one and must not be allowed to land under the\n // new settings.\n if (\n settings.model?.fullTableHandle === undefined ||\n settings.model?.visibleTableHandle === undefined\n ) {\n if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;\n // A grid that already shows a table keeps showing it; one that is still\n // waiting says why.\n if (gridApi.getGridOption(\"loading\") === true) {\n setLoadingVariant(gridApi, settings.pending ? \"running\" : \"not-ready\");\n }\n return;\n }\n\n ++generation.value;\n\n // Data source changed -> show full page loader, clear selection\n if (settings.sourceId !== oldSettings?.sourceId) {\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: \"loading\",\n } satisfies PlAgOverlayLoadingParams,\n });\n if (selection.value && oldSettings?.sourceId) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n }\n\n // Model built for another source -> show skeletons until it catches up.\n // A model that reports no source was built from a state that names none,\n // or does not take the state at all, and is shown as it is.\n const sourceChanged =\n settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;\n if (sourceChanged) {\n if (gridApi.getGridOption(\"loading\") === true) setLoadingVariant(gridApi, \"loading\");\n return gridApi.updateGridOptions({\n serverSideDatasource: {\n getRows: (params) => {\n params.success({ rowData: [], rowCount: 1 });\n },\n },\n });\n }\n\n // Model ready -> calculate new state\n const stateGeneration = generation.value;\n const stateSourceId = settings.sourceId;\n calculateGridOptions({\n generation,\n pfDriver: getRawPlatformaInstance().pFrameDriver,\n fullTableHandle: settings.model?.fullTableHandle,\n visibleTableHandle: settings.model?.visibleTableHandle,\n columnsMeta: settings.model?.columnsMeta,\n sheets: settings.sheets ?? [],\n dataRenderedTracker,\n hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),\n cellButtonAxisParams: {\n showCellButtonForAxisId: props.showCellButtonForAxisId,\n cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,\n trigger: (key?: PTableKey) => emit(\"cellButtonClicked\", key),\n } satisfies PlAgCellButtonAxisParams,\n })\n .then((result) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n const { axesSpec, ...options } = result;\n gridApi.updateGridOptions({\n ...options,\n });\n boundSourceId.value = stateSourceId;\n if (selection.value) {\n // Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys\n const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;\n if (!isJsonEqual(oldAxesSpec, axesSpec)) {\n if (!oldAxesSpec || axesSpec.length !== oldAxesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const mapping = oldAxesSpec\n .map(getAxisId)\n .map((id) => axesSpec.findIndex((axis) => matchAxisId(axis, id)));\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const selectedNodes = oldSelectedKeys.map((key) =>\n mapping.map((index) => key[index]),\n );\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: selectedNodes };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes.map((key) => canonicalizeJson<PlTableRowId>(key)),\n });\n }\n }\n })\n .catch((error: unknown) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n if (isAbortError(error)) return;\n console.trace(error);\n })\n .finally(() => {\n // Only the current calculation may take the overlay down: a superseded\n // one would hide the overlay the newer settings just put up.\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n gridApi.updateGridOptions({\n loading: false,\n });\n });\n dataRenderedTracker.promise.then(() => emit(\"newDataRendered\"));\n } catch (error: unknown) {\n console.trace(error);\n } finally {\n oldSettings = settings;\n }\n },\n);\n\nfunction setLoadingVariant(\n api: GridApi<PlAgDataTableV2Row>,\n variant: PlAgOverlayLoadingParams[\"variant\"],\n): void {\n api.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant,\n } satisfies PlAgOverlayLoadingParams,\n });\n}\n\nwatch(\n () => ({\n gridApi: gridApi.value,\n loadingText: props.loadingText,\n runningText: props.runningText,\n notReadyText: props.notReadyText,\n noRowsText: props.noRowsText,\n }),\n ({ gridApi, loadingText, runningText, notReadyText, noRowsText }) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n loadingText,\n runningText,\n notReadyText,\n },\n noRowsOverlayComponentParams: {\n ...gridOptions.value.noRowsOverlayComponentParams,\n text: noRowsText,\n },\n });\n },\n);\n\nwatchEffect(() => {\n if (!gridApi.value || gridApi.value?.isDestroyed()) return;\n gridApi.value.updateGridOptions({\n statusBar: gridOptions.value.loading\n ? undefined\n : {\n statusPanels: [{ statusPanel: PlAgRowCount, align: \"left\" }],\n },\n });\n});\n</script>\n\n<template>\n <div data-testid=\"pl-ag-data-table\" :class=\"$style.container\">\n <PlAgGridColumnManager v-if=\"gridApi && !disableColumnsPanel\" :api=\"gridApi\" />\n <PlTableFiltersV2\n v-if=\"!disableFiltersPanel\"\n :filters=\"filtersState\"\n :default-filters=\"defaultFiltersState\"\n :pframe-handle=\"'model' in settings ? settings?.model?.fullPframeHandle : undefined\"\n :columns=\"filterableColumns\"\n :columns-meta=\"getColumnsMeta()\"\n @updateFilters=\"(v) => (filtersState = v)\"\n @resetDefaultFilters=\"resetDefaultFilters\"\n @updateDefaultFilters=\"(v) => (defaultFiltersState = v)\"\n v-model=\"filtersState\"\n />\n <PlAgCsvExporter\n v-if=\"gridApi && showExportButton\"\n :api=\"gridApi\"\n :table-handle=\"'model' in settings ? settings?.model?.visibleTableHandle : undefined\"\n :columns-meta=\"getColumnsMeta()\"\n />\n <PlAgDataTableSheets\n :sheets=\"sheets\"\n :state=\"sheetsState\"\n :on-change=\"(state) => (sheetsState = state)\"\n >\n <template v-if=\"$slots['before-sheets']\" #before>\n <slot name=\"before-sheets\" />\n </template>\n <template v-if=\"$slots['after-sheets']\" #after>\n <slot name=\"after-sheets\" />\n </template>\n </PlAgDataTableSheets>\n <PlTableFastSearch v-model=\"searchString\" />\n <AgGridVue\n :key=\"reloadKey\"\n data-testid=\"pl-ag-data-table-grid\"\n :theme=\"AgGridTheme\"\n :class=\"$style.grid\"\n :grid-options=\"gridOptions\"\n />\n </div>\n</template>\n\n<style lang=\"css\" module>\n.container {\n display: flex;\n flex-direction: column;\n height: 100%;\n gap: 12px;\n}\n\n.grid {\n flex: 1;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgDA,IAAMiC,KAAa/B,EAA+BiC,GAAA,YAEjD,GAEKC,IAAYlC,EAA6BiC,GAAC,WAAW,GACrDE,IAAQF,GA4DR,EAAE,gBAAaG,GAAOD,CAAK,GAC3BE,IAAOP,GAMPQ,IAAsB,IAAIC,EAA8C,GACxE,EAAE,YAAS,mBAAgBC,GAAQ;GACvC;GACA,YAAYL,EAAM;GAClB,aAAaA,EAAM;GACnB,aAAaA,EAAM;GACnB,cAAcA,EAAM;GACpB,sBAAsBA,EAAM;EAC9B,CAAC,GACGM,IAAc,IAEZC,IAAgBC,GAA0B,IAAI;EASpD,AARA,EAAY,MAAM,sBAAsB,MAAU;GAGhD,AAFKF,KAAaG,EAAcC,EAAM,KAAKC,EAAiBD,EAAM,IAAI,SAAS,CAAC,CAAC,GACjF,EAAY,MAAM,eAAeE,EAAa,OAC9C,EAAQ,QAAQ;EAClB,GACA,EAAY,MAAM,sBAAsB,MAAU;GAChD,AAAIF,EAAM,QAAQA,EAAM,KAAK,WAASR,E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IAHC,KAAKN,EAAA2E,CAAA;IACL,gBAAY,WAAa3E,EAAAgD,CAAA,IAAWhD,EAAAgD,CAAA,CAAQ,EAAE,OAAO,qBAAqB,KAAA;IAC1E,gBAAckB,EAAc;;;;;;GAE/B3D,EAWsBC,IAAA;IAVnB,QAAQ8C,GAAA;IACR,OAAOtD,EAAAwI,CAAA;IACP,cAAY,MAAW,EAAA,QAAcrE;G,iBAEtBzE,EAAAA,OAAM,mB;IAAoB,MAAA;IACxC,IAAAgB,QAA6B,CAA7BC,EAA6BiH,EAAA,QAAA,eAAA,C;;G,YAEflI,EAAAA,OAAM,kB;IAAmB,MAAA;IACvC,IAAAgB,QAA4B,CAA5BC,EAA4BiH,EAAA,QAAA,cAAA,C;;;;;;;GAGhCrH,EAA4CP,EAAAY,EAAA,GAAA;IAAhB,YAAAZ,EAAA4I,CAAA;IAAA,uBAAA,AAAAV,EAAA,QAAA,MAAA7H,EAAAuI,CAAA,IAAA,EAAY,QAAAN,IAAA;;IACxCzI,EAAA,GAAAI,EAMED,EAAA6I,EAAA,GAAA;IALC,KAAKpE,EAAA;IACN,eAAY;IACX,OAAOzE,EAAA8I,EAAA;IACP,OAAK/I,EAAEN,EAAAA,OAAO,IAAI;IAClB,gBAAcO,EAAAiD,CAAA"}
|
|
1
|
+
{"version":3,"file":"PlAgDataTableV2.vue_vue_type_script_setup_true_lang.js","names":["$style","$slots","_useModel","PlAgRowCount","_openBlock","_createElementBlock","_normalizeClass","_unref","_createBlock","PlAgGridColumnManager","_createCommentVNode","PlTableFiltersV2","_isRef","PlAgCsvExporter","_createVNode","PlAgDataTableSheets","_createSlots","_withCtx","_renderSlot","PlTableFastSearch","PlAgCsvExporter_default","PlAgGridColumnManager_default","PlTableFiltersV2_default","PlTableFastSearch_default","PlAgDataTableSheets_default","PlAgRowCount_default","PlAgDataTableV2_vue_vue_type_script_setup_true_lang_default","\"modelValue\"","\"modelModifiers\"","\"selection\"","\"selectionModifiers\"","__expose","__emit","tableState","useModel","__props","selection","props","toRefs","emit","dataRenderedTracker","DeferredCircular","useGrid","isReloading","boundSourceId","shallowRef","saveGridState","event","makePartialState","restoreState","gridApi","isJsonEqual","column","PlAgDataTableRowNumberColId","filterableColumns","useFilterableColumns","settings","gridOptions","defaultFilters","computed","shownSourceId","useTableState","sheets","createGridRestoreState","gridState","sorting","hiddenColIds","sourceId","reported","updateGrid","readGridReport","getEntry","getDefaultHiddenColIds","api","getColumnsMeta","state","cols","spec","col","effectiveVisibility","columnsMeta","reloadKey","ref","selfState","gridColIds","isStoredStateApplied","nextTick","cellRendererSelector","watch","ensureNodeVisible","row","rowKey","axes","axesSpec","mapping","id","getAxisId","matchAxisId","axis","mappingSet","selectedNodes","selectedKeys","canonicalizeJson","key","index","oldSelectedKeys","scope","effectScope","resolve","promiseTimeout","promise","defaultSelection","createPlSelectionModel","oldSettings","generation","setLoadingVariant","stateGeneration","stateSourceId","calculateGridOptions","getRawPlatformaInstance","options","result","oldAxesSpec","newSelection","isAbortError","error","noRowsText","watchEffect","openBlock","createElementBlock","normalizeClass","_ctx","unref","createBlock","createCommentVNode","filtersState","defaultFiltersState","_cache","v","resetDefaultFilters","isRef","$event","createVNode","sheetsState","createSlots","withCtx","renderSlot","searchString","AgGridVue","AgGridTheme"],"sources":["../../../src/components/PlAgDataTable/PlAgDataTableV2.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { promiseTimeout, isJsonEqual } from \"@milaboratories/helpers\";\nimport type {\n AxisId,\n PlDataTableColumnsMeta,\n PlDataTableGridStateCore,\n PlDataTableStateV2,\n PlSelectionModel,\n PlTableColumnIdJson,\n PTableColumnId,\n PTableColumnSpec,\n PTableKey,\n} from \"@platforma-sdk/model\";\nimport {\n getRawPlatformaInstance,\n createPlSelectionModel,\n matchAxisId,\n getAxisId,\n canonicalizeJson,\n isAbortError,\n} from \"@platforma-sdk/model\";\nimport type { CellRendererSelectorFunc, GridApi, GridState } from \"ag-grid-enterprise\";\nimport { AgGridVue } from \"ag-grid-vue3\";\nimport { computed, effectScope, nextTick, ref, shallowRef, toRefs, watch, watchEffect } from \"vue\";\nimport PlAgCsvExporter from \"../PlAgCsvExporter/PlAgCsvExporter.vue\";\nimport { PlAgGridColumnManager } from \"../PlAgGridColumnManager\";\nimport PlTableFiltersV2 from \"../PlTableFilters/PlTableFiltersV2.vue\";\nimport { PlTableFastSearch } from \"../PlTableFastSearch\";\nimport PlAgDataTableSheets from \"./PlAgDataTableSheets.vue\";\nimport PlAgRowCount from \"./PlAgRowCount.vue\";\nimport { DeferredCircular, ensureNodeVisible } from \"./sources/focus-row\";\nimport { PlAgDataTableRowNumberColId } from \"./sources/row-number\";\nimport type { PlAgCellButtonAxisParams } from \"./sources/table-source-v2\";\nimport { calculateGridOptions, effectiveVisibility } from \"./sources/table-source-v2\";\nimport { createGridRestoreState, isStoredStateApplied, readGridReport } from \"./sources/grid-state\";\nimport { useTableState } from \"./sources/table-state-v2\";\nimport type {\n PlAgDataTableV2Controller,\n PlAgDataTableV2Row,\n PlAgOverlayLoadingParams,\n PlAgOverlayNoRowsParams,\n PlDataTableSettingsV2,\n PlTableRowId,\n} from \"./types\";\nimport { useFilterableColumns } from \"./compositions/useFilterableColumns\";\nimport { useGrid } from \"./compositions/useGrid\";\nimport { AgGridTheme } from \"../../AgGridVue/AgGridTheme\";\n\nconst tableState = defineModel<PlDataTableStateV2>({\n required: true,\n});\n/** Warning: selection model value updates are ignored, use updateSelection instead */\nconst selection = defineModel<PlSelectionModel>(\"selection\");\nconst props = defineProps<{\n /** Required component settings */\n settings: Readonly<PlDataTableSettingsV2>;\n\n /**\n * The disableColumnsPanel prop controls the display of a button that activates\n * the columns management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableColumnsPanel?: boolean;\n\n /**\n * The disableFiltersPanel prop controls the display of a button that activates\n * the filters management panel in the table. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n disableFiltersPanel?: boolean;\n\n /**\n * The showExportButton prop controls the display of a button that allows\n * to export table data in CSV format. To make the button functional\n * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.\n * This component serves as the target for teleporting the button.\n */\n showExportButton?: boolean;\n\n /**\n * The AxisId property is used to configure and display the PlAgTextAndButtonCell component\n */\n showCellButtonForAxisId?: AxisId;\n\n /**\n * If cellButtonInvokeRowsOnDoubleClick = true, clicking a button inside the row\n * triggers the doubleClick event for the entire row.\n *\n * If cellButtonInvokeRowsOnDoubleClick = false, the doubleClick event for the row\n * is not triggered, but will triggered cellButtonClicked event with (key: PTableRowKey) argument.\n */\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n\n /** @see {@link PlAgOverlayLoadingParams.loadingText} */\n loadingText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.runningText} */\n runningText?: string;\n\n /** @see {@link PlAgOverlayLoadingParams.notReadyText} */\n notReadyText?: string;\n\n /** @see {@link PlAgOverlayNoRowsParams.text} */\n noRowsText?: string;\n\n /**\n * Callback to override the default renderer for a given cell.\n * @see https://www.ag-grid.com/vue-data-grid/component-cell-renderer/#dynamic-component-selection\n */\n cellRendererSelector?: CellRendererSelectorFunc<PlAgDataTableV2Row>;\n}>();\nconst { settings } = toRefs(props);\nconst emit = defineEmits<{\n rowDoubleClicked: [key?: PTableKey];\n cellButtonClicked: [key?: PTableKey];\n newDataRendered: [];\n}>();\n\nconst dataRenderedTracker = new DeferredCircular<GridApi<PlAgDataTableV2Row>>();\nconst { gridApi, gridOptions } = useGrid({\n selection,\n noRowsText: props.noRowsText,\n runningText: props.runningText,\n loadingText: props.loadingText,\n notReadyText: props.notReadyText,\n cellRendererSelector: props.cellRendererSelector,\n});\nlet isReloading = false;\n/** Source the grid's columns were built for; `null` while the grid has none. */\nconst boundSourceId = shallowRef<null | string>(null);\ngridOptions.value.onGridPreDestroyed = (event) => {\n if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));\n gridOptions.value.initialState = restoreState.value;\n // A replaced grid destroyed after its successor is ready must leave the successor's api in place\n if (gridApi.value?.getGridId() === event.api.getGridId()) gridApi.value = null;\n};\ngridOptions.value.onRowDoubleClicked = (event) => {\n if (event.data && event.data.axesKey) emit(\"rowDoubleClicked\", event.data.axesKey);\n};\ngridOptions.value.onStateUpdated = (event) => {\n saveGridState(event.api, makePartialState(event.state));\n // Keep initialState in step with the stored grid state, so the grid recreated\n // by the reload watch below comes back with it.\n gridOptions.value.initialState = restoreState.value;\n\n if (!isJsonEqual(event.sources, [\"columnSizing\"])) {\n event.api.autoSizeColumns(\n event.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n }\n};\n\nconst [filterableColumns] = useFilterableColumns(\n () => settings.value.sourceId,\n () => gridOptions.value.columnDefs ?? null,\n);\nconst defaultFilters = computed(() =>\n settings.value.sourceId !== null ? settings.value.model?.defaultFilters : undefined,\n);\nconst {\n sourceId: shownSourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry,\n updateGrid,\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n} = useTableState(tableState, settings, defaultFilters);\nconst sheets = computed(() => (settings.value.sourceId !== null ? settings.value.sheets : []));\nconst restoreState = computed(() =>\n createGridRestoreState({\n gridState: gridState.value,\n sorting: sorting.value,\n hiddenColIds: hiddenColIds.value,\n }),\n);\ngridOptions.value.initialState = restoreState.value;\n\n/**\n * Store what the grid reports under the source its columns belong to: while\n * the table switches sources the grid still holds the previous source's\n * columns, and their state must not land on the new source.\n */\nfunction saveGridState(api: GridApi<PlAgDataTableV2Row>, reported: PlDataTableGridStateCore) {\n const sourceId = boundSourceId.value;\n // AG Grid reports an entirely empty state until its columns have been taken\n // into its own state. Such a report says nothing about the user's choices, and\n // reading defaults from the live columns at that point would invent some.\n // Wait for the grid to say something about itself; it always does once its\n // columns are in.\n if (sourceId === null || isJsonEqual(reported, {})) return;\n updateGrid(\n sourceId,\n readGridReport(reported, getEntry(sourceId), () =>\n getDefaultHiddenColIds(api, getColumnsMeta()),\n ),\n );\n}\n\n// Restore proper types erased by AgGrid\nfunction makePartialState(state: GridState): PlDataTableGridStateCore {\n return {\n columnOrder: state.columnOrder as\n | {\n orderedColIds: PlTableColumnIdJson[];\n }\n | undefined,\n sort: state.sort as\n | {\n sortModel: {\n colId: PlTableColumnIdJson;\n sort: \"asc\" | \"desc\";\n }[];\n }\n | undefined,\n columnVisibility: state.columnVisibility as\n | {\n hiddenColIds: PlTableColumnIdJson[];\n }\n | undefined,\n };\n}\n\n/** Sidecar display meta is only on the `model` branch of the settings union. */\nfunction getColumnsMeta(): PlDataTableColumnsMeta | undefined {\n return \"model\" in props.settings ? props.settings.model?.columnsMeta : undefined;\n}\n\nfunction getDefaultHiddenColIds(\n api: GridApi<PlAgDataTableV2Row>,\n columnsMeta: PlDataTableColumnsMeta | undefined,\n): PlTableColumnIdJson[] {\n const cols = api.getAllGridColumns();\n if (!cols) return [];\n\n return cols\n .filter((col) => {\n const spec = col.getColDef().context as PTableColumnSpec | undefined;\n return (\n spec !== undefined &&\n spec.type === \"column\" &&\n effectiveVisibility(spec, columnsMeta) === \"optional\"\n );\n })\n .map((col) => col.getColId() as PlTableColumnIdJson);\n}\n\n// Reload AgGrid when new state arrives from server, or when the grid takes the\n// columns of a source whose stored state it does not show yet\nconst reloadKey = ref(0);\nwatch(\n () => [gridApi.value, restoreState.value, boundSourceId.value] as const,\n ([gridApi, restoreState, boundSourceId]) => {\n if (!gridApi || gridApi.isDestroyed() || boundSourceId !== shownSourceId.value) return;\n const selfState = makePartialState(gridApi.getState());\n const gridColIds = new Set(\n (gridApi.getAllGridColumns() ?? []).map((column) => column.getColId() as PlTableColumnIdJson),\n );\n if (\n !isJsonEqual(restoreState, {}) &&\n !isStoredStateApplied(restoreState, selfState, gridColIds)\n ) {\n isReloading = true;\n gridOptions.value.initialState = restoreState;\n ++reloadKey.value;\n nextTick(() => {\n isReloading = false;\n });\n }\n },\n);\n\n// Make cellRendererSelector reactive\nconst cellRendererSelector = computed(() => props.cellRendererSelector ?? null);\nwatch(\n () => [gridApi.value, cellRendererSelector.value] as const,\n ([gridApi, cellRendererSelector]) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.setGridOption(\"defaultColDef\", {\n ...gridOptions.value.defaultColDef,\n cellRendererSelector: cellRendererSelector ?? undefined,\n });\n },\n);\n\ndefineExpose<PlAgDataTableV2Controller>({\n focusRow: async (rowKey) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n return ensureNodeVisible(gridApi, (row) => isJsonEqual(row.data?.axesKey, rowKey));\n },\n updateSelection: async ({ axesSpec, selectedKeys }) => {\n const gridApi = await dataRenderedTracker.promise;\n if (gridApi.isDestroyed()) return false;\n\n const axes = selection.value?.axesSpec;\n if (!axes || axes.length !== axesSpec.length) return false;\n\n const mapping = axesSpec.map((spec) => {\n const id = getAxisId(spec);\n return axes.findIndex((axis) => matchAxisId(axis, id));\n });\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) return false;\n\n const selectedNodes = selectedKeys.map((key) =>\n canonicalizeJson<PlTableRowId>(mapping.map((index) => key[index])),\n );\n const oldSelectedKeys = gridApi.getServerSideSelectionState()?.toggledNodes ?? [];\n if (!isJsonEqual(oldSelectedKeys, selectedNodes)) {\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes,\n });\n\n // wait for `onSelectionChanged` to update `selection` model\n const scope = effectScope();\n const { resolve, promise } = Promise.withResolvers();\n scope.run(() => watch(selection, resolve, { once: true }));\n try {\n await promiseTimeout(promise, 500);\n } catch {\n return false;\n } finally {\n scope.stop();\n }\n }\n return true;\n },\n});\n\n// Update AgGrid when settings change\nconst defaultSelection = createPlSelectionModel();\nlet oldSettings: PlDataTableSettingsV2 | null = null;\nconst generation = ref(0);\nwatch(\n () => [gridApi.value, settings.value] as const,\n ([gridApi, settings]) => {\n // Wait for AgGrid reinitialization, gridApi will eventually become initialized\n if (!gridApi || gridApi.isDestroyed()) return;\n // Verify that this is not a false watch trigger\n if (isJsonEqual(settings, oldSettings)) return;\n try {\n // Hide no rows overlay if it is shown, or else loading overlay will not be shown\n gridApi.hideOverlay();\n dataRenderedTracker.reset();\n\n // No data source selected -> reset state to default\n if (settings.sourceId === null) {\n ++generation.value;\n boundSourceId.value = null;\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: settings.pending ? \"running\" : \"not-ready\",\n } satisfies PlAgOverlayLoadingParams,\n columnDefs: undefined,\n serverSideDatasource: undefined,\n });\n if (selection.value) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n return;\n }\n\n // The model is between handles — it is recomputing. Nothing is started here,\n // so moving the generation would only cancel the calculation in flight and\n // leave whatever it was going to do (not least taking the loading overlay\n // down) undone — which is how the table came to sit on \"Loading data…\"\n // forever. The exception is a change of source: then the calculation in\n // flight belongs to the old one and must not be allowed to land under the\n // new settings.\n if (\n settings.model?.fullTableHandle === undefined ||\n settings.model?.visibleTableHandle === undefined\n ) {\n if (settings.sourceId !== oldSettings?.sourceId) ++generation.value;\n // A grid that already shows a table keeps showing it; one that is still\n // waiting says why.\n if (gridApi.getGridOption(\"loading\") === true) {\n setLoadingVariant(gridApi, settings.pending ? \"running\" : \"not-ready\");\n }\n return;\n }\n\n ++generation.value;\n\n // Data source changed -> show full page loader, clear selection\n if (settings.sourceId !== oldSettings?.sourceId) {\n gridApi.updateGridOptions({\n loading: true,\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant: \"loading\",\n } satisfies PlAgOverlayLoadingParams,\n });\n if (selection.value && oldSettings?.sourceId) {\n if (selection.value && !isJsonEqual(selection.value, defaultSelection)) {\n selection.value = createPlSelectionModel();\n }\n gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n }\n\n // Model built for another source -> show skeletons until it catches up.\n // A model that reports no source was built from a state that names none,\n // or does not take the state at all, and is shown as it is.\n const sourceChanged =\n settings.model.sourceId !== null && settings.model.sourceId !== settings.sourceId;\n if (sourceChanged) {\n if (gridApi.getGridOption(\"loading\") === true) setLoadingVariant(gridApi, \"loading\");\n return gridApi.updateGridOptions({\n serverSideDatasource: {\n getRows: (params) => {\n params.success({ rowData: [], rowCount: 1 });\n },\n },\n });\n }\n\n // Model ready -> calculate new state\n const stateGeneration = generation.value;\n const stateSourceId = settings.sourceId;\n calculateGridOptions({\n generation,\n pfDriver: getRawPlatformaInstance().pFrameDriver,\n fullTableHandle: settings.model?.fullTableHandle,\n visibleTableHandle: settings.model?.visibleTableHandle,\n columnsMeta: settings.model?.columnsMeta,\n sheets: settings.sheets ?? [],\n dataRenderedTracker,\n hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),\n cellButtonAxisParams: {\n showCellButtonForAxisId: props.showCellButtonForAxisId,\n cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,\n trigger: (key?: PTableKey) => emit(\"cellButtonClicked\", key),\n } satisfies PlAgCellButtonAxisParams,\n })\n .then((result) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n const { axesSpec, ...options } = result;\n gridApi.updateGridOptions({\n ...options,\n });\n boundSourceId.value = stateSourceId;\n if (selection.value) {\n // Update selection if axesSpec changed, as order of axes may have changed and so we need to remap selected keys\n const { axesSpec: oldAxesSpec, selectedKeys: oldSelectedKeys } = selection.value;\n if (!isJsonEqual(oldAxesSpec, axesSpec)) {\n if (!oldAxesSpec || axesSpec.length !== oldAxesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const mapping = oldAxesSpec\n .map(getAxisId)\n .map((id) => axesSpec.findIndex((axis) => matchAxisId(axis, id)));\n const mappingSet = new Set(mapping);\n if (mappingSet.has(-1) || mappingSet.size !== axesSpec.length) {\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: [] };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: [],\n });\n }\n\n const selectedNodes = oldSelectedKeys.map((key) =>\n mapping.map((index) => key[index]),\n );\n const newSelection: PlSelectionModel = { axesSpec, selectedKeys: selectedNodes };\n if (!isJsonEqual(selection.value, newSelection)) {\n selection.value = newSelection;\n }\n return gridApi.setServerSideSelectionState({\n selectAll: false,\n toggledNodes: selectedNodes.map((key) => canonicalizeJson<PlTableRowId>(key)),\n });\n }\n }\n })\n .catch((error: unknown) => {\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n if (isAbortError(error)) return;\n console.trace(error);\n })\n .finally(() => {\n // Only the current calculation may take the overlay down: a superseded\n // one would hide the overlay the newer settings just put up.\n if (gridApi.isDestroyed() || stateGeneration !== generation.value) return;\n gridApi.updateGridOptions({\n loading: false,\n });\n });\n dataRenderedTracker.promise.then(() => emit(\"newDataRendered\"));\n } catch (error: unknown) {\n console.trace(error);\n } finally {\n oldSettings = settings;\n }\n },\n);\n\nfunction setLoadingVariant(\n api: GridApi<PlAgDataTableV2Row>,\n variant: PlAgOverlayLoadingParams[\"variant\"],\n): void {\n api.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n variant,\n } satisfies PlAgOverlayLoadingParams,\n });\n}\n\nwatch(\n () => ({\n gridApi: gridApi.value,\n loadingText: props.loadingText,\n runningText: props.runningText,\n notReadyText: props.notReadyText,\n noRowsText: props.noRowsText,\n }),\n ({ gridApi, loadingText, runningText, notReadyText, noRowsText }) => {\n if (!gridApi || gridApi.isDestroyed()) return;\n gridApi.updateGridOptions({\n loadingOverlayComponentParams: {\n ...gridOptions.value.loadingOverlayComponentParams,\n loadingText,\n runningText,\n notReadyText,\n },\n noRowsOverlayComponentParams: {\n ...gridOptions.value.noRowsOverlayComponentParams,\n text: noRowsText,\n },\n });\n },\n);\n\nwatchEffect(() => {\n if (!gridApi.value || gridApi.value?.isDestroyed()) return;\n gridApi.value.updateGridOptions({\n statusBar: gridOptions.value.loading\n ? undefined\n : {\n statusPanels: [{ statusPanel: PlAgRowCount, align: \"left\" }],\n },\n });\n});\n</script>\n\n<template>\n <div data-testid=\"pl-ag-data-table\" :class=\"$style.container\">\n <PlAgGridColumnManager v-if=\"gridApi && !disableColumnsPanel\" :api=\"gridApi\" />\n <PlTableFiltersV2\n v-if=\"!disableFiltersPanel\"\n :filters=\"filtersState\"\n :default-filters=\"defaultFiltersState\"\n :pframe-handle=\"'model' in settings ? settings?.model?.fullPframeHandle : undefined\"\n :columns=\"filterableColumns\"\n :columns-meta=\"getColumnsMeta()\"\n @updateFilters=\"(v) => (filtersState = v)\"\n @resetDefaultFilters=\"resetDefaultFilters\"\n @updateDefaultFilters=\"(v) => (defaultFiltersState = v)\"\n v-model=\"filtersState\"\n />\n <PlAgCsvExporter\n v-if=\"gridApi && showExportButton\"\n :api=\"gridApi\"\n :table-handle=\"'model' in settings ? settings?.model?.visibleTableHandle : undefined\"\n :columns-meta=\"getColumnsMeta()\"\n />\n <PlAgDataTableSheets\n :sheets=\"sheets\"\n :state=\"sheetsState\"\n :on-change=\"(state) => (sheetsState = state)\"\n >\n <template v-if=\"$slots['before-sheets']\" #before>\n <slot name=\"before-sheets\" />\n </template>\n <template v-if=\"$slots['after-sheets']\" #after>\n <slot name=\"after-sheets\" />\n </template>\n </PlAgDataTableSheets>\n <PlTableFastSearch v-model=\"searchString\" />\n <AgGridVue\n :key=\"reloadKey\"\n data-testid=\"pl-ag-data-table-grid\"\n :theme=\"AgGridTheme\"\n :class=\"$style.grid\"\n :grid-options=\"gridOptions\"\n />\n </div>\n</template>\n\n<style lang=\"css\" module>\n.container {\n display: flex;\n flex-direction: column;\n height: 100%;\n gap: 12px;\n}\n\n.grid {\n flex: 1;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgDA,IAAMiC,KAAa/B,EAA+BiC,GAAA,YAEjD,GAEKC,IAAYlC,EAA6BiC,GAAC,WAAW,GACrDE,IAAQF,GA4DR,EAAE,gBAAaG,GAAOD,CAAK,GAC3BE,IAAOP,GAMPQ,IAAsB,IAAIC,EAA8C,GACxE,EAAE,YAAS,mBAAgBC,GAAQ;GACvC;GACA,YAAYL,EAAM;GAClB,aAAaA,EAAM;GACnB,aAAaA,EAAM;GACnB,cAAcA,EAAM;GACpB,sBAAsBA,EAAM;EAC9B,CAAC,GACGM,IAAc,IAEZC,IAAgBC,GAA0B,IAAI;EAUpD,AATA,EAAY,MAAM,sBAAsB,MAAU;GAIhD,AAHKF,KAAaG,EAAcC,EAAM,KAAKC,EAAiBD,EAAM,IAAI,SAAS,CAAC,CAAC,GACjF,EAAY,MAAM,eAAeE,EAAa,OAE1CC,EAAQ,OAAO,UAAU,MAAMH,EAAM,IAAI,UAAU,MAAG,EAAQ,QAAQ;EAC5E,GACA,EAAY,MAAM,sBAAsB,MAAU;GAChD,AAAIA,EAAM,QAAQA,EAAM,KAAK,WAASR,EAAK,oBAAoBQ,EAAM,KAAK,OAAO;EACnF,GACA,EAAY,MAAM,kBAAkB,MAAU;GAM5C,AALAD,EAAcC,EAAM,KAAKC,EAAiBD,EAAM,KAAK,CAAC,GAGtD,EAAY,MAAM,eAAeE,EAAa,OAEzCE,EAAYJ,EAAM,SAAS,CAAC,cAAc,CAAC,KAC9CA,EAAM,IAAI,gBACRA,EAAM,IACH,uBAAuB,CAAA,CACvB,QAAQ,MAAWK,EAAO,SAAS,MAAMC,CAA2B,CACzE;EAEJ;EAEA,IAA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G,YAEflI,EAAAA,OAAM,kB;IAAmB,MAAA;IACvC,IAAAgB,QAA4B,CAA5BC,EAA4BiH,EAAA,QAAA,cAAA,C;;;;;;;GAGhCrH,EAA4CP,EAAAY,EAAA,GAAA;IAAhB,YAAAZ,EAAA4I,CAAA;IAAA,uBAAA,AAAAV,EAAA,QAAA,MAAA7H,EAAAuI,CAAA,IAAA,EAAY,QAAAN,IAAA;;IACxCzI,EAAA,GAAAI,EAMED,EAAA6I,EAAA,GAAA;IALC,KAAKnE,EAAA;IACN,eAAY;IACX,OAAO1E,EAAA8I,EAAA;IACP,OAAK/I,EAAEN,EAAAA,OAAO,IAAI;IAClB,gBAAcO,EAAAkD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlAgDataTableV2.gridApi.jsdomtest.d.ts","sourceRoot":"","sources":["../../../../src/components/PlAgDataTable/__tests__/PlAgDataTableV2.gridApi.jsdomtest.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/ui-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.90.2",
|
|
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.10",
|
|
18
|
+
"@platforma-sdk/model": "1.90.2",
|
|
19
19
|
"@types/d3-format": "^3.0.4",
|
|
20
20
|
"@types/node": "~24.19.2",
|
|
21
21
|
"@types/semver": "^7.7.0",
|
|
@@ -133,7 +133,8 @@ const boundSourceId = shallowRef<null | string>(null);
|
|
|
133
133
|
gridOptions.value.onGridPreDestroyed = (event) => {
|
|
134
134
|
if (!isReloading) saveGridState(event.api, makePartialState(event.api.getState()));
|
|
135
135
|
gridOptions.value.initialState = restoreState.value;
|
|
136
|
-
|
|
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;
|
|
137
138
|
};
|
|
138
139
|
gridOptions.value.onRowDoubleClicked = (event) => {
|
|
139
140
|
if (event.data && event.data.axesKey) emit("rowDoubleClicked", event.data.axesKey);
|
|
@@ -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
|
+
}
|