@xh/hoist 90.0.0 → 90.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +136 -54
- package/admin/columns/Tracking.ts +9 -3
- package/admin/tabs/activity/tracking/ActivityTrackingModel.ts +155 -47
- package/admin/tabs/activity/tracking/ActivityTrackingPanel.ts +25 -4
- package/admin/tabs/activity/tracking/chart/AggChartModel.ts +2 -3
- package/appcontainer/ImpersonationBarModel.ts +8 -5
- package/build/types/admin/tabs/activity/tracking/ActivityTrackingModel.d.ts +25 -5
- package/build/types/cmp/cubegrid/CubeGrid.d.ts +26 -0
- package/build/types/cmp/cubegrid/CubeGridModel.d.ts +103 -0
- package/build/types/cmp/cubegrid/CubeGridPivotModel.d.ts +181 -0
- package/build/types/cmp/cubegrid/Types.d.ts +85 -0
- package/build/types/cmp/cubegrid/index.d.ts +4 -0
- package/build/types/cmp/dataview/DataViewModel.d.ts +6 -10
- package/build/types/cmp/grid/GridModel.d.ts +8 -33
- package/build/types/cmp/grid/Types.d.ts +51 -1
- package/build/types/cmp/grid/columns/Column.d.ts +2 -1
- package/build/types/cmp/grid/columns/ColumnGroup.d.ts +6 -0
- package/build/types/cmp/grid/helpers/GridCountLabel.d.ts +6 -3
- package/build/types/cmp/grid/impl/ColumnWidthCalculator.d.ts +6 -0
- package/build/types/cmp/grid/impl/GridLikeModel.d.ts +3 -0
- package/build/types/cmp/grid/impl/MenuSupport.d.ts +13 -0
- package/build/types/cmp/pdfviewer/PdfViewer.d.ts +14 -0
- package/build/types/cmp/pdfviewer/PdfViewerModel.d.ts +150 -0
- package/build/types/cmp/pdfviewer/Types.d.ts +55 -0
- package/build/types/cmp/pdfviewer/impl/PdfFindInputModel.d.ts +14 -0
- package/build/types/cmp/pdfviewer/impl/PdfViewerToolbarModel.d.ts +34 -0
- package/build/types/cmp/pdfviewer/impl/ZoomOptions.d.ts +10 -0
- package/build/types/cmp/pdfviewer/index.d.ts +3 -0
- package/build/types/cmp/statcard/StatCard.d.ts +90 -0
- package/build/types/cmp/statcard/index.d.ts +1 -0
- package/build/types/cmp/store/StoreFilterField.d.ts +8 -9
- package/build/types/cmp/store/impl/StoreFilterFieldImplModel.d.ts +4 -4
- package/build/types/cmp/zoneGrid/ZoneGridModel.d.ts +6 -10
- package/build/types/core/types/Types.d.ts +6 -0
- package/build/types/data/Field.d.ts +8 -1
- package/build/types/data/Store.d.ts +12 -0
- package/build/types/data/cube/Cube.d.ts +2 -0
- package/build/types/data/cube/CubeField.d.ts +3 -2
- package/build/types/data/cube/Query.d.ts +66 -4
- package/build/types/data/cube/View.d.ts +82 -4
- package/build/types/data/cube/ViewRowData.d.ts +13 -0
- package/build/types/data/cube/aggregate/MedianAggregator.d.ts +19 -0
- package/build/types/data/cube/aggregate/SumIfSameAggregator.d.ts +30 -0
- package/build/types/data/cube/impl/RowCache.d.ts +5 -0
- package/build/types/data/cube/impl/RowDataGenerator.d.ts +26 -0
- package/build/types/data/cube/impl/ViewDiagnostics.d.ts +27 -0
- package/build/types/data/cube/pivot/PivotCellRow.d.ts +27 -0
- package/build/types/data/cube/pivot/PivotPath.d.ts +45 -0
- package/build/types/data/cube/pivot/impl/PivotCells.d.ts +111 -0
- package/build/types/data/cube/pivot/impl/PivotReference.d.ts +39 -0
- package/build/types/data/cube/pivot/impl/PivotStructure.d.ts +105 -0
- package/build/types/data/cube/row/BaseRow.d.ts +12 -0
- package/build/types/data/cube/row/LeafRow.d.ts +4 -4
- package/build/types/data/cube/row/ParentRow.d.ts +20 -4
- package/build/types/data/cube/row/RowUpdate.d.ts +2 -0
- package/build/types/data/index.d.ts +3 -0
- package/build/types/desktop/cmp/button/grid/ColAutosizeButton.d.ts +6 -3
- package/build/types/desktop/cmp/button/grid/ColChooserButton.d.ts +7 -3
- package/build/types/desktop/cmp/button/grid/ExpandToLevelButton.d.ts +6 -3
- package/build/types/desktop/cmp/button/grid/ExportButton.d.ts +6 -3
- package/build/types/desktop/cmp/grid/find/GridFindField.d.ts +8 -9
- package/build/types/desktop/cmp/grid/find/impl/GridFindFieldImplModel.d.ts +3 -4
- package/build/types/desktop/cmp/pdfviewer/impl/PdfViewerToolbar.d.ts +12 -0
- package/build/types/desktop/cmp/statcard/impl/StatCardInfoImpl.d.ts +12 -0
- package/build/types/dynamics/desktop.d.ts +2 -0
- package/build/types/dynamics/mobile.d.ts +1 -0
- package/build/types/icon/Icon.d.ts +12 -0
- package/build/types/kit/pdfjs/index.d.ts +23 -0
- package/build/types/kit/pdfjs/styles.d.ts +2 -0
- package/build/types/kit/swiper/index.d.ts +7 -7
- package/build/types/mobile/cmp/button/grid/ColAutosizeButton.d.ts +6 -3
- package/build/types/mobile/cmp/button/grid/ColChooserButton.d.ts +6 -3
- package/build/types/mobile/cmp/button/grid/ExpandCollapseButton.d.ts +4 -4
- package/build/types/mobile/cmp/button/grid/ExpandToLevelButton.d.ts +4 -4
- package/build/types/mobile/cmp/pdfviewer/impl/PdfViewerToolbar.d.ts +12 -0
- package/cmp/README.md +3 -0
- package/cmp/ag-grid/AgGrid.ts +25 -3
- package/cmp/cubegrid/CubeGrid.ts +60 -0
- package/cmp/cubegrid/CubeGridModel.ts +365 -0
- package/cmp/cubegrid/CubeGridPivotModel.ts +943 -0
- package/cmp/cubegrid/README.md +343 -0
- package/cmp/cubegrid/Types.ts +105 -0
- package/cmp/cubegrid/index.ts +10 -0
- package/cmp/dataview/DataViewModel.ts +13 -8
- package/cmp/grid/Grid.scss +21 -5
- package/cmp/grid/GridModel.ts +41 -47
- package/cmp/grid/Types.ts +58 -1
- package/cmp/grid/columns/Column.ts +3 -1
- package/cmp/grid/columns/ColumnGroup.ts +10 -0
- package/cmp/grid/helpers/GridCountLabel.ts +12 -5
- package/cmp/grid/impl/ColumnGroupHeader.ts +18 -4
- package/cmp/grid/impl/ColumnWidthCalculator.ts +24 -0
- package/cmp/grid/impl/GridLikeModel.ts +17 -0
- package/cmp/grid/impl/MenuSupport.ts +36 -20
- package/cmp/pdfviewer/PdfViewer.scss +48 -0
- package/cmp/pdfviewer/PdfViewer.ts +102 -0
- package/cmp/pdfviewer/PdfViewerModel.ts +641 -0
- package/cmp/pdfviewer/README.md +224 -0
- package/cmp/pdfviewer/Types.ts +72 -0
- package/cmp/pdfviewer/impl/PdfFindInputModel.ts +44 -0
- package/cmp/pdfviewer/impl/PdfViewerToolbarModel.ts +45 -0
- package/cmp/pdfviewer/impl/ZoomOptions.ts +36 -0
- package/cmp/pdfviewer/index.ts +9 -0
- package/cmp/statcard/StatCard.scss +181 -0
- package/cmp/statcard/StatCard.ts +320 -0
- package/cmp/statcard/index.ts +1 -0
- package/cmp/store/StoreFilterField.ts +8 -9
- package/cmp/store/impl/StoreFilterFieldImplModel.ts +14 -14
- package/cmp/zoneGrid/ZoneGridModel.ts +13 -8
- package/core/types/Types.ts +7 -0
- package/data/Field.ts +10 -0
- package/data/Store.ts +25 -2
- package/data/cube/Cube.ts +5 -0
- package/data/cube/CubeField.ts +5 -0
- package/data/cube/Query.ts +170 -17
- package/data/cube/README.md +77 -2
- package/data/cube/View.ts +211 -32
- package/data/cube/ViewRowData.ts +22 -0
- package/data/cube/aggregate/MedianAggregator.ts +88 -0
- package/data/cube/aggregate/SumIfSameAggregator.ts +128 -0
- package/data/cube/impl/RowCache.ts +32 -11
- package/data/cube/impl/RowDataGenerator.ts +96 -4
- package/data/cube/impl/ViewDiagnostics.ts +47 -0
- package/data/cube/pivot/PivotCellRow.ts +73 -0
- package/data/cube/pivot/PivotPath.ts +67 -0
- package/data/cube/pivot/impl/PivotCells.ts +538 -0
- package/data/cube/pivot/impl/PivotReference.ts +125 -0
- package/data/cube/pivot/impl/PivotStructure.ts +500 -0
- package/data/cube/row/BaseRow.ts +26 -0
- package/data/cube/row/LeafRow.ts +9 -8
- package/data/cube/row/ParentRow.ts +58 -25
- package/data/cube/row/RowUpdate.ts +8 -0
- package/data/index.ts +3 -0
- package/desktop/appcontainer/AppContainer.ts +5 -1
- package/desktop/cmp/button/grid/ColAutosizeButton.ts +21 -5
- package/desktop/cmp/button/grid/ColChooserButton.ts +11 -5
- package/desktop/cmp/button/grid/ExpandToLevelButton.ts +20 -5
- package/desktop/cmp/button/grid/ExportButton.ts +19 -7
- package/desktop/cmp/dash/canvas/DashCanvas.ts +26 -2
- package/desktop/cmp/grid/find/GridFindField.ts +8 -9
- package/desktop/cmp/grid/find/impl/GridFindFieldImplModel.ts +15 -16
- package/desktop/cmp/grid/impl/colchooser/ColChooserBucketModel.ts +1 -1
- package/desktop/cmp/pdfviewer/impl/PdfViewerToolbar.ts +190 -0
- package/desktop/cmp/statcard/impl/StatCardInfoImpl.ts +27 -0
- package/docs/README.md +6 -2
- package/docs/doc-registry.json +21 -5
- package/docs/upgrade-notes/v90-upgrade-notes.md +130 -0
- package/docs/version-compatibility.md +2 -1
- package/dynamics/desktop.ts +4 -0
- package/dynamics/mobile.ts +2 -0
- package/format/FormatNumber.ts +6 -2
- package/icon/Icon.ts +18 -0
- package/icon/index.ts +32 -0
- package/kit/README.md +2 -0
- package/kit/pdfjs/PdfJs.scss +25 -0
- package/kit/pdfjs/index.ts +103 -0
- package/kit/pdfjs/pdf_viewer.css +6481 -0
- package/kit/pdfjs/styles.ts +12 -0
- package/mcp/README.md +13 -0
- package/mcp/data/import-paths.ts +4 -8
- package/mcp/data/index-cache.ts +2 -1
- package/mcp/data/ts-registry.ts +8 -29
- package/mcp/util/paths.ts +26 -0
- package/mobile/appcontainer/AppContainer.ts +3 -1
- package/mobile/cmp/button/grid/ColAutosizeButton.ts +20 -5
- package/mobile/cmp/button/grid/ColChooserButton.ts +12 -5
- package/mobile/cmp/button/grid/ExpandCollapseButton.ts +10 -6
- package/mobile/cmp/button/grid/ExpandToLevelButton.ts +10 -6
- package/mobile/cmp/pdfviewer/impl/PdfViewerToolbar.ts +137 -0
- package/package.json +14 -8
- package/public/msal-redirect-bridge.min.js +1 -1
- package/styles/vars.scss +59 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
import type {
|
|
8
|
+
ColumnGroupSpec,
|
|
9
|
+
ColumnSpec,
|
|
10
|
+
GridConfig,
|
|
11
|
+
GridEnsureVisibleOptions,
|
|
12
|
+
GridFilterBindTarget,
|
|
13
|
+
GridFilterModelConfig,
|
|
14
|
+
GridLikeModel,
|
|
15
|
+
GridModelPersistOptions,
|
|
16
|
+
GridSelectFirstOptions,
|
|
17
|
+
GridSelectOptions
|
|
18
|
+
} from '@xh/hoist/cmp/grid';
|
|
19
|
+
import {GridModel} from '@xh/hoist/cmp/grid';
|
|
20
|
+
import {initPersist} from '@xh/hoist/cmp/grid/impl/InitPersist';
|
|
21
|
+
import {createExpandCollapseItem} from '@xh/hoist/cmp/grid/impl/MenuSupport';
|
|
22
|
+
import type {Awaitable, ReactionSpec, Some, VSide} from '@xh/hoist/core';
|
|
23
|
+
import {HoistModel, managed} from '@xh/hoist/core';
|
|
24
|
+
import type {Cube, QueryConfig, Store, StoreRecordOrId, View} from '@xh/hoist/data';
|
|
25
|
+
import {action, bindableRef} from '@xh/hoist/mobx';
|
|
26
|
+
import {throwIf} from '@xh/hoist/utils/js';
|
|
27
|
+
import {isEmpty, isEqual, isFunction, keyBy, pick} from 'lodash';
|
|
28
|
+
import type {CubeGridPivotConfig} from './CubeGridPivotModel';
|
|
29
|
+
import {CubeGridPivotModel} from './CubeGridPivotModel';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for a {@link CubeGridModel}.
|
|
33
|
+
*
|
|
34
|
+
* Supply the data as either an existing `view` or a `cube` with a `query`. Query configuration -
|
|
35
|
+
* `dimensions`, `pivot`, `includeRoot` and the rest - lives on the {@link Query}, and apps
|
|
36
|
+
* reconfigure by calling `view.updateQuery()`. Everything else here is presentational.
|
|
37
|
+
*
|
|
38
|
+
* @see CubeGridModel
|
|
39
|
+
*/
|
|
40
|
+
export interface CubeGridConfig {
|
|
41
|
+
/**
|
|
42
|
+
* View supplying this grid's data. Owned by the *application* - this model neither manages nor
|
|
43
|
+
* destroys it, and cannot swap it after construction. Two CubeGridModels may bind to one view;
|
|
44
|
+
* each mints its own Store. Omit to create a view from `cube` and `query` instead.
|
|
45
|
+
*/
|
|
46
|
+
view?: View;
|
|
47
|
+
|
|
48
|
+
/** Cube to query, when no `view` is supplied. The model creates and owns a connected View. */
|
|
49
|
+
cube?: Cube;
|
|
50
|
+
|
|
51
|
+
/** Query for the view this model creates from `cube`. Ignored when `view` is supplied. */
|
|
52
|
+
query?: QueryConfig;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Columns for the fixed region, as on {@link GridConfig.columns}. Bind them to the view's
|
|
56
|
+
* fields - a measure's bare name is its row summary, whether or not the query pivots. When
|
|
57
|
+
* none is a tree column, a label column for the row dimensions is placed first. Pivot columns,
|
|
58
|
+
* if any, follow this region.
|
|
59
|
+
*/
|
|
60
|
+
columns?: Array<ColumnSpec | ColumnGroupSpec>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Config for the underlying GridModel. `store`, `treeMode` and `columns` are managed by this
|
|
64
|
+
* model and cannot be set here; everything else is a default this config overrides. A
|
|
65
|
+
* `showSummary` row needs `includeRoot` on the query, which is what produces it. `persistWith`
|
|
66
|
+
* attaches once the pivot columns exist, so saved state can name them.
|
|
67
|
+
*
|
|
68
|
+
* A `filterModel` binds to `'view'` by default, filtering the source records and
|
|
69
|
+
* re-aggregating. Bind it to `'store'` to filter the group rows by their aggregates instead.
|
|
70
|
+
*/
|
|
71
|
+
gridConfig?: Omit<GridConfig, 'store' | 'treeMode' | 'columns' | 'filterModel'> & {
|
|
72
|
+
filterModel?:
|
|
73
|
+
| boolean
|
|
74
|
+
| (Omit<GridFilterModelConfig, 'bind'> & {
|
|
75
|
+
bind?: GridFilterBindTarget | 'view' | 'store';
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Config for the pivot region, held by {@link CubeGridModel.pivotModel}. */
|
|
80
|
+
pivotConfig?: CubeGridPivotConfig;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Grid presentation of a Cube {@link View} - a tree grid of group rows with the app's own columns,
|
|
85
|
+
* and when the query sets {@link QueryConfig.pivot}, a column group per pivot path appended to
|
|
86
|
+
* their right, with optional docked summaries.
|
|
87
|
+
*
|
|
88
|
+
* Owns everything downstream of the view: the Store, the {@link GridModel} and the column
|
|
89
|
+
* hierarchy, rebuilt when `result.paths` changes identity. Owns the view too when created from
|
|
90
|
+
* `cube` and `query`.
|
|
91
|
+
*
|
|
92
|
+
* @see CubeGridConfig
|
|
93
|
+
* @mcpHint tree grid on a Cube view - app columns, plus pivot paths as column groups when pivoted
|
|
94
|
+
*/
|
|
95
|
+
export class CubeGridModel extends HoistModel implements GridLikeModel {
|
|
96
|
+
/** View supplying this grid's data. Not swappable. */
|
|
97
|
+
readonly view: View;
|
|
98
|
+
|
|
99
|
+
@bindableRef accessor columns: Array<ColumnSpec | ColumnGroupSpec>;
|
|
100
|
+
|
|
101
|
+
//------------------------
|
|
102
|
+
// Child Models
|
|
103
|
+
//------------------------
|
|
104
|
+
|
|
105
|
+
/** Store projecting the view's rows. Owned here - GridModel never manages a store instance. */
|
|
106
|
+
@managed readonly store: Store;
|
|
107
|
+
@managed readonly gridModel: GridModel;
|
|
108
|
+
@managed readonly pivotModel: CubeGridPivotModel;
|
|
109
|
+
|
|
110
|
+
constructor({view, cube, query, columns = [], gridConfig, pivotConfig}: CubeGridConfig) {
|
|
111
|
+
super();
|
|
112
|
+
|
|
113
|
+
throwIf(
|
|
114
|
+
!view && !cube,
|
|
115
|
+
'CubeGridModel requires either a `view` or a `cube` with a `query`.'
|
|
116
|
+
);
|
|
117
|
+
throwIf(view && cube, 'Specify either `view` or `cube` for a CubeGridModel, not both.');
|
|
118
|
+
this.view = view ?? this.markManaged(cube.createView({query, connect: true}));
|
|
119
|
+
|
|
120
|
+
this.columns = columns;
|
|
121
|
+
this.pivotModel = new CubeGridPivotModel(pivotConfig ?? {}, this);
|
|
122
|
+
|
|
123
|
+
this.store = this.view.createStore({connect: true});
|
|
124
|
+
const {persistWith, ...restGridConfig} = gridConfig ?? {};
|
|
125
|
+
this.gridModel = this.createGridModel(restGridConfig);
|
|
126
|
+
|
|
127
|
+
this._pendingPersistWith = persistWith;
|
|
128
|
+
this.initPersistWhenReady();
|
|
129
|
+
|
|
130
|
+
// Rebuilds react first, so a pivot option change re-autosizes the rebuilt columns.
|
|
131
|
+
this.addReaction(this.columnsReaction(), this.regionsReaction());
|
|
132
|
+
this.pivotModel.initWidths();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//------------------------
|
|
136
|
+
// Selection and state - delegated to the GridModel, as in ZoneGridModel
|
|
137
|
+
//------------------------
|
|
138
|
+
|
|
139
|
+
get innerGridModel(): GridModel {
|
|
140
|
+
return this.gridModel;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get empty() {
|
|
144
|
+
return this.gridModel.empty;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The grid's summary row, as {@link GridModel.showSummary}. Needs `includeRoot` on the query. */
|
|
148
|
+
get showSummary(): boolean | VSide {
|
|
149
|
+
return this.gridModel.showSummary;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setShowSummary(v: boolean | VSide) {
|
|
153
|
+
this.gridModel.showSummary = v;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
get selModel() {
|
|
157
|
+
return this.gridModel.selModel;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
get hasSelection() {
|
|
161
|
+
return this.gridModel.hasSelection;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
get selectedRecords() {
|
|
165
|
+
return this.gridModel.selectedRecords;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
get selectedRecord() {
|
|
169
|
+
return this.gridModel.selectedRecord;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get selectedId() {
|
|
173
|
+
return this.gridModel.selectedId;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
selectAsync(records: Some<StoreRecordOrId>, opts?: GridSelectOptions) {
|
|
177
|
+
return this.gridModel.selectAsync(records, opts);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
preSelectFirstAsync() {
|
|
181
|
+
return this.gridModel.preSelectFirstAsync();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
selectFirstAsync(opts?: GridSelectFirstOptions) {
|
|
185
|
+
return this.gridModel.selectFirstAsync(opts);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
ensureSelectionVisibleAsync(opts?: GridEnsureVisibleOptions) {
|
|
189
|
+
return this.gridModel.ensureSelectionVisibleAsync(opts);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//------------------------
|
|
193
|
+
// Implementation
|
|
194
|
+
//------------------------
|
|
195
|
+
|
|
196
|
+
private get query() {
|
|
197
|
+
return this.view.query;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// `equals: 'shallow'` - the track fn allocates a fresh array per run.
|
|
201
|
+
private columnsReaction(): ReactionSpec {
|
|
202
|
+
return {
|
|
203
|
+
equals: 'shallow',
|
|
204
|
+
track: () => [this.view.result.paths, this.columns, ...this.pivotModel.regionDeps],
|
|
205
|
+
run: () => this.rebuildColumns()
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private createGridModel(config: CubeGridConfig['gridConfig']): GridModel {
|
|
210
|
+
return new GridModel({
|
|
211
|
+
emptyText: 'No data',
|
|
212
|
+
colChooserModel: true,
|
|
213
|
+
stripeRows: true,
|
|
214
|
+
rowBorders: true,
|
|
215
|
+
levelLabels: () => this.rowLevelLabels,
|
|
216
|
+
...config,
|
|
217
|
+
filterModel: this.parseFilterModel(config.filterModel),
|
|
218
|
+
headerContextMenu: this.parseHeaderContextMenu(config),
|
|
219
|
+
store: this.store,
|
|
220
|
+
treeMode: true,
|
|
221
|
+
columns: this.buildColumns(),
|
|
222
|
+
restoreDefaultsFn: () => this.restoreDefaultsAsync(config.restoreDefaultsFn)
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Each row dimension. The root, if any, loads as the summary record, not a tree level. Read on
|
|
227
|
+
// use, so it follows the query.
|
|
228
|
+
private get rowLevelLabels(): string[] {
|
|
229
|
+
return this.query.dimensions.map(it => it.displayName);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// In a header menu, `expandCollapse` expands the pivot columns, and shows only over them. It
|
|
233
|
+
// leads the default menu. A grid with no context menu gets no default header menu.
|
|
234
|
+
private parseHeaderContextMenu({
|
|
235
|
+
headerContextMenu: spec,
|
|
236
|
+
contextMenu
|
|
237
|
+
}: CubeGridConfig['gridConfig']): GridConfig['headerContextMenu'] {
|
|
238
|
+
if (spec === false) return false;
|
|
239
|
+
if (spec == null && (contextMenu === false || contextMenu === null)) return undefined;
|
|
240
|
+
const {pivotModel} = this,
|
|
241
|
+
items = spec ?? ['expandCollapse', '-', ...GridModel.defaults.headerContextMenu];
|
|
242
|
+
return (agParams, gridModel) =>
|
|
243
|
+
(isFunction(items) ? items(agParams, gridModel) : items).flatMap(it =>
|
|
244
|
+
it === 'expandCollapse'
|
|
245
|
+
? pivotModel.isInRegion(agParams)
|
|
246
|
+
? createExpandCollapseItem(pivotModel)
|
|
247
|
+
: []
|
|
248
|
+
: it
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Column filters bind to the view, so they filter the source records and re-aggregate. The
|
|
253
|
+
// view and store are this model's own, so their names stand for them. Specs default to the
|
|
254
|
+
// query's fields either way, as the store's include a field per cell.
|
|
255
|
+
private parseFilterModel(
|
|
256
|
+
filterModel: CubeGridConfig['gridConfig']['filterModel']
|
|
257
|
+
): GridConfig['filterModel'] {
|
|
258
|
+
if (!filterModel) return null;
|
|
259
|
+
const {bind = 'view', ...rest} = filterModel === true ? {} : filterModel;
|
|
260
|
+
return {
|
|
261
|
+
fieldSpecs: this.view.fieldNames,
|
|
262
|
+
...rest,
|
|
263
|
+
bind: bind === 'view' ? this.view : bind === 'store' ? this.store : bind
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// The GridModel's defaults hold the columns it was built with, before the view had paths or
|
|
268
|
+
// at paths since gone. A restore rebuilds the pivot region at the current paths, state and
|
|
269
|
+
// all, then sizes it as the GridModel sized its own defaults.
|
|
270
|
+
private async restoreDefaultsAsync(appFn: () => Awaitable<void>) {
|
|
271
|
+
const {gridModel} = this;
|
|
272
|
+
gridModel.setColumns(this.buildColumns());
|
|
273
|
+
if (gridModel.autosizeOptions.mode === 'managed') await gridModel.autosizeAsync();
|
|
274
|
+
await appFn?.();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// `setColumns` resets column and group state. Cell field names and path keys are stable ids,
|
|
278
|
+
// so prior state carries over: fixed columns keep their order, and pivot columns keep their
|
|
279
|
+
// width but take the order of the build, since that order is the view's, not the user's. Any
|
|
280
|
+
// fixed column dragged into the pivot region returns to its own.
|
|
281
|
+
@action
|
|
282
|
+
private rebuildColumns() {
|
|
283
|
+
const {gridModel, pivotModel} = this,
|
|
284
|
+
{columnState: prior, columnGroupState} = gridModel,
|
|
285
|
+
priorById = keyBy(prior, 'colId');
|
|
286
|
+
|
|
287
|
+
gridModel.setColumns(this.buildColumns());
|
|
288
|
+
|
|
289
|
+
const {colIds} = pivotModel,
|
|
290
|
+
fixed = prior.filter(it => !colIds.has(it.colId)),
|
|
291
|
+
pivot = gridModel.columnState
|
|
292
|
+
.filter(it => colIds.has(it.colId))
|
|
293
|
+
.map(it => ({
|
|
294
|
+
...it,
|
|
295
|
+
width: pivotModel.widthFor(it.colId) ?? it.width,
|
|
296
|
+
...pick(priorById[it.colId], 'width', 'manuallySized')
|
|
297
|
+
}));
|
|
298
|
+
|
|
299
|
+
gridModel.setColumnState([...fixed, ...pivot]);
|
|
300
|
+
gridModel.setColumnGroupState(columnGroupState);
|
|
301
|
+
this.initPersistWhenReady();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// The column chooser's own drag knows nothing of ag-Grid's position lock, so a fixed column
|
|
305
|
+
// dropped among the pivot columns there is put back as soon as the state lands.
|
|
306
|
+
private regionsReaction(): ReactionSpec {
|
|
307
|
+
return {
|
|
308
|
+
track: () => this.gridModel.columnState,
|
|
309
|
+
run: () => this.enforceRegions()
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
@action
|
|
314
|
+
private enforceRegions() {
|
|
315
|
+
const {gridModel} = this,
|
|
316
|
+
{colIds} = this.pivotModel,
|
|
317
|
+
{columnState} = gridModel,
|
|
318
|
+
ordered = [
|
|
319
|
+
...columnState.filter(it => !colIds.has(it.colId)),
|
|
320
|
+
...columnState.filter(it => colIds.has(it.colId))
|
|
321
|
+
];
|
|
322
|
+
if (!isEqual(ordered, columnState)) gridModel.setColumnState(ordered);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Persisted state names pivot columns, which exist only once a pivoted view has paths.
|
|
326
|
+
// Attaching earlier would restore and rewrite that state without them.
|
|
327
|
+
private initPersistWhenReady() {
|
|
328
|
+
const persistWith = this._pendingPersistWith;
|
|
329
|
+
if (!persistWith || (this.query.isPivoted && isEmpty(this.view.result.paths))) return;
|
|
330
|
+
initPersist(this.gridModel, persistWith);
|
|
331
|
+
this._pendingPersistWith = null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private buildColumns(): Array<ColumnSpec | ColumnGroupSpec> {
|
|
335
|
+
return [...this.buildFixedColumns(), ...this.pivotModel.buildRegion()];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// The app's columns, with a default label column first unless the app supplied a tree column.
|
|
339
|
+
private buildFixedColumns(): Array<ColumnSpec | ColumnGroupSpec> {
|
|
340
|
+
const {columns} = this,
|
|
341
|
+
hasTreeCol = columns.some(it => 'isTreeColumn' in it && it.isTreeColumn);
|
|
342
|
+
return hasTreeCol ? columns : [this.buildLabelColumn(), ...columns];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private buildLabelColumn(): ColumnSpec {
|
|
346
|
+
return {
|
|
347
|
+
field: 'cubeLabel',
|
|
348
|
+
isTreeColumn: true,
|
|
349
|
+
pinned: 'left',
|
|
350
|
+
headerName: () => this.query.dimensions.map(it => it.displayName).join(' › '),
|
|
351
|
+
// Sort on the raw value behind the stringified label. A field, not a function, so
|
|
352
|
+
// `GridTransactionManager` can prove a tick leaves row order alone.
|
|
353
|
+
sortValue: 'cubeLabelValue',
|
|
354
|
+
renderer: v => (isEmpty(v) || v === 'null' ? '(empty)' : v)
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private _pendingPersistWith: GridModelPersistOptions = null;
|
|
359
|
+
|
|
360
|
+
override destroy() {
|
|
361
|
+
// The view registered this store rather than owning it, and outlives any grid bound to it.
|
|
362
|
+
this.view?.disconnectStore(this.store);
|
|
363
|
+
super.destroy();
|
|
364
|
+
}
|
|
365
|
+
}
|