@xh/hoist 71.0.0-SNAPSHOT.1731709792477 → 71.0.0-SNAPSHOT.1732369566945
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 +5 -0
- package/admin/tabs/cluster/ClusterTabModel.ts +35 -15
- package/build/types/admin/tabs/cluster/ClusterTabModel.d.ts +6 -4
- package/build/types/core/persist/viewmanager/Types.d.ts +3 -1
- package/build/types/core/persist/viewmanager/ViewManagerModel.d.ts +10 -19
- package/build/types/core/persist/viewmanager/impl/BuildViewTree.d.ts +8 -0
- package/build/types/desktop/cmp/dash/container/DashContainerModel.d.ts +1 -4
- package/build/types/desktop/cmp/viewmanager/ViewManager.d.ts +16 -2
- package/build/types/desktop/cmp/viewmanager/index.d.ts +0 -2
- package/build/types/svc/JsonBlobService.d.ts +2 -2
- package/core/persist/viewmanager/Types.ts +3 -1
- package/core/persist/viewmanager/ViewManagerModel.ts +110 -156
- package/core/persist/viewmanager/impl/BuildViewTree.ts +68 -0
- package/core/persist/viewmanager/impl/ManageDialogModel.ts +2 -0
- package/core/persist/viewmanager/impl/SaveDialogModel.ts +1 -1
- package/desktop/cmp/dash/container/DashContainerModel.ts +34 -32
- package/desktop/cmp/viewmanager/ViewManager.ts +97 -50
- package/desktop/cmp/viewmanager/{cmp → impl}/ManageDialog.ts +1 -1
- package/desktop/cmp/viewmanager/index.ts +0 -2
- package/package.json +1 -1
- package/svc/JsonBlobService.ts +3 -6
- package/tsconfig.tsbuildinfo +1 -1
- /package/build/types/desktop/cmp/viewmanager/{cmp → impl}/ManageDialog.d.ts +0 -0
- /package/build/types/desktop/cmp/viewmanager/{cmp → impl}/SaveDialog.d.ts +0 -0
- /package/desktop/cmp/viewmanager/{cmp → impl}/SaveDialog.ts +0 -0
|
@@ -14,11 +14,11 @@ import {
|
|
|
14
14
|
} from '@xh/hoist/core';
|
|
15
15
|
import {genDisplayName} from '@xh/hoist/data';
|
|
16
16
|
import {action, bindable, computed, makeObservable, observable} from '@xh/hoist/mobx';
|
|
17
|
-
import {wait} from '@xh/hoist/promise';
|
|
18
17
|
import {executeIfFunction, pluralize, throwIf} from '@xh/hoist/utils/js';
|
|
19
|
-
import {
|
|
18
|
+
import {isEqual, isNil, isUndefined, lowerCase, startCase} from 'lodash';
|
|
20
19
|
import {runInAction} from 'mobx';
|
|
21
20
|
import {SaveDialogModel} from './impl/SaveDialogModel';
|
|
21
|
+
import {buildViewTree} from './impl/BuildViewTree';
|
|
22
22
|
import {View, ViewTree} from './Types';
|
|
23
23
|
|
|
24
24
|
export interface ViewManagerConfig {
|
|
@@ -104,16 +104,19 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
104
104
|
/** Current state of the active view, can include not-yet-persisted changes. */
|
|
105
105
|
@observable.ref pendingValue: T = {} as T;
|
|
106
106
|
/** Loaded saved view definitions - both private and shared. */
|
|
107
|
-
@observable.ref views: View<T>[] =
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
@observable.ref views: View<T>[] = null;
|
|
108
|
+
|
|
109
|
+
/** Currently selected view, or null if in default mode. Token only will be set during pre-loading.*/
|
|
110
|
+
@observable selectedToken: string = null;
|
|
111
|
+
@observable.ref selectedView: View<T> = null;
|
|
112
|
+
|
|
110
113
|
/** List of tokens for the user's favorite views. */
|
|
111
114
|
@bindable favorites: string[] = [];
|
|
112
115
|
/**
|
|
113
116
|
* True if user has opted-in to automatically saving changes to personal views (if auto-save
|
|
114
117
|
* generally available as per `enableAutoSave`).
|
|
115
118
|
*/
|
|
116
|
-
@bindable
|
|
119
|
+
@bindable autoSave = false;
|
|
117
120
|
|
|
118
121
|
/**
|
|
119
122
|
* TaskObserver linked to {@link selectViewAsync}. If a change to the active view is likely to
|
|
@@ -137,51 +140,30 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
137
140
|
return executeIfFunction(this._enableSharing);
|
|
138
141
|
}
|
|
139
142
|
|
|
140
|
-
get selectedView(): View<T> {
|
|
141
|
-
return this.views.find(it => it.token === this.selectedToken);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@computed
|
|
145
|
-
get isSharedViewSelected(): boolean {
|
|
146
|
-
return !!this.selectedView?.isShared;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
143
|
@computed
|
|
150
144
|
get canSave(): boolean {
|
|
151
|
-
const {selectedView} = this;
|
|
152
|
-
return (
|
|
153
|
-
selectedView &&
|
|
154
|
-
this.isDirty &&
|
|
155
|
-
(this.enableSharing || !selectedView.isShared) &&
|
|
156
|
-
!this.loadModel.isPending
|
|
157
|
-
);
|
|
145
|
+
const {loadModel, selectedView, enableSharing} = this;
|
|
146
|
+
return !loadModel.isPending && selectedView && (enableSharing || !selectedView.isShared);
|
|
158
147
|
}
|
|
159
148
|
|
|
160
|
-
/**
|
|
161
|
-
* True if displaying the save button is appropriate from the model's point of view, even if
|
|
162
|
-
* that button might be disabled due to no changes having been made. Works in concert with the
|
|
163
|
-
* desktop ViewManager component's `showSaveButton` prop.
|
|
164
|
-
*/
|
|
165
149
|
@computed
|
|
166
|
-
get
|
|
167
|
-
const {selectedView} = this;
|
|
150
|
+
get canAutoSave(): boolean {
|
|
151
|
+
const {enableAutoSave, autoSave, loadModel, selectedView} = this;
|
|
168
152
|
return (
|
|
153
|
+
!loadModel.isPending &&
|
|
154
|
+
enableAutoSave &&
|
|
155
|
+
autoSave &&
|
|
169
156
|
selectedView &&
|
|
170
|
-
|
|
171
|
-
(this.enableSharing || !selectedView.isShared)
|
|
157
|
+
!selectedView.isShared
|
|
172
158
|
);
|
|
173
159
|
}
|
|
174
160
|
|
|
175
161
|
@computed
|
|
176
|
-
get
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
get disabledAutoSaveReason(): string {
|
|
182
|
-
const {displayName} = this;
|
|
183
|
-
if (!this.selectedView) return `Cannot auto-save default ${displayName}.`;
|
|
184
|
-
if (this.isSharedViewSelected) return `Cannot auto-save shared ${displayName}.`;
|
|
162
|
+
get autoSaveUnavailableReason(): string {
|
|
163
|
+
const {canAutoSave, selectedView, displayName} = this;
|
|
164
|
+
if (canAutoSave) return null;
|
|
165
|
+
if (!selectedView) return `Cannot auto-save default ${displayName}.`;
|
|
166
|
+
if (selectedView.isShared) return `Cannot auto-save shared ${displayName}.`;
|
|
185
167
|
return null;
|
|
186
168
|
}
|
|
187
169
|
|
|
@@ -207,11 +189,11 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
207
189
|
}
|
|
208
190
|
|
|
209
191
|
get sharedViewTree(): ViewTree[] {
|
|
210
|
-
return
|
|
192
|
+
return buildViewTree(this.sharedViews, this);
|
|
211
193
|
}
|
|
212
194
|
|
|
213
195
|
get privateViewTree(): ViewTree[] {
|
|
214
|
-
return
|
|
196
|
+
return buildViewTree(this.privateViews, this);
|
|
215
197
|
}
|
|
216
198
|
|
|
217
199
|
/**
|
|
@@ -257,12 +239,9 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
257
239
|
|
|
258
240
|
this.addReaction(
|
|
259
241
|
{
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
{
|
|
264
|
-
track: () => this.autoSaveActive,
|
|
265
|
-
run: () => this.maybeAutoSaveAsync({skipToast: false})
|
|
242
|
+
// Track pendingValue, so we retry on fail if view stays dirty -- could use backup timer
|
|
243
|
+
track: () => [this.pendingValue, this.autoSave],
|
|
244
|
+
run: () => this.maybeAutoSaveAsync()
|
|
266
245
|
},
|
|
267
246
|
{
|
|
268
247
|
track: () => this.favorites,
|
|
@@ -274,53 +253,51 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
274
253
|
override async doLoadAsync(loadSpec: LoadSpec) {
|
|
275
254
|
const rawViews = await XH.jsonBlobService.listAsync({
|
|
276
255
|
type: this.viewType,
|
|
277
|
-
includeValue:
|
|
256
|
+
includeValue: false,
|
|
278
257
|
loadSpec
|
|
279
258
|
});
|
|
280
259
|
if (loadSpec.isStale) return;
|
|
281
260
|
|
|
282
|
-
runInAction(() =>
|
|
261
|
+
runInAction(() => {
|
|
262
|
+
this.views = rawViews.map(it => this.processRaw(it));
|
|
263
|
+
});
|
|
283
264
|
|
|
284
265
|
const token =
|
|
285
266
|
loadSpec.meta.selectToken ??
|
|
286
|
-
this.
|
|
267
|
+
this.selectedToken ??
|
|
287
268
|
(this.enableDefault ? null : this.views[0]?.token);
|
|
288
269
|
await this.selectViewAsync(token);
|
|
289
270
|
}
|
|
290
271
|
|
|
291
272
|
async selectViewAsync(token: string) {
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// selected token before views have been loaded. Once views are loaded, this method will
|
|
299
|
-
// be called again with the desired token and will proceed to set the value.
|
|
300
|
-
if (isEmpty(this.views)) return;
|
|
301
|
-
|
|
302
|
-
this.setValue(this.selectedView?.value ?? ({} as T));
|
|
303
|
-
})
|
|
304
|
-
.linkTo(this.viewSelectionObserver);
|
|
273
|
+
// If views have not been loaded yet (e.g. constructing), nothing to be done but pre-set state
|
|
274
|
+
if (!this.views) {
|
|
275
|
+
this.selectedToken = token;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
await this.selectViewInternalAsync(token).linkTo(this.viewSelectionObserver);
|
|
305
279
|
}
|
|
306
280
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
281
|
+
//------------------------
|
|
282
|
+
// Saving/resetting
|
|
283
|
+
//------------------------
|
|
284
|
+
async saveAsync() {
|
|
285
|
+
const {canSave, selectedToken, pendingValue, selectedView, DisplayName} = this;
|
|
286
|
+
throwIf(!canSave, 'Unable to save view.');
|
|
310
287
|
|
|
311
|
-
if (
|
|
288
|
+
if (selectedView?.isShared) {
|
|
312
289
|
if (!(await this.confirmSaveForSharedViewAsync())) return;
|
|
313
290
|
}
|
|
314
291
|
|
|
315
292
|
try {
|
|
316
293
|
await XH.jsonBlobService.updateAsync(selectedToken, {value: pendingValue});
|
|
294
|
+
runInAction(() => {
|
|
295
|
+
this.value = this.pendingValue;
|
|
296
|
+
});
|
|
297
|
+
XH.successToast(`${DisplayName} successfully saved.`);
|
|
317
298
|
} catch (e) {
|
|
318
299
|
XH.handleException(e, {alertType: 'toast'});
|
|
319
|
-
skipToast = true; // don't show the success toast below, but still refresh.
|
|
320
300
|
}
|
|
321
|
-
|
|
322
|
-
await this.refreshAsync({selectToken: selectedToken});
|
|
323
|
-
if (!skipToast) XH.successToast(`${DisplayName} successfully saved.`);
|
|
324
301
|
}
|
|
325
302
|
|
|
326
303
|
async saveAsAsync() {
|
|
@@ -364,10 +341,6 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
364
341
|
this.manageDialogOpen = false;
|
|
365
342
|
}
|
|
366
343
|
|
|
367
|
-
getHierarchyDisplayName(name: string) {
|
|
368
|
-
return name?.substring(name.lastIndexOf('\\') + 1);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
344
|
//------------------
|
|
372
345
|
// Favorites
|
|
373
346
|
//------------------
|
|
@@ -391,38 +364,69 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
391
364
|
// Persistable
|
|
392
365
|
//------------------
|
|
393
366
|
getPersistableState(): PersistableState<ViewManagerModelPersistState> {
|
|
394
|
-
|
|
367
|
+
const state: ViewManagerModelPersistState = {
|
|
368
|
+
selectedToken: this.selectedToken,
|
|
369
|
+
favorites: this.favorites
|
|
370
|
+
};
|
|
371
|
+
if (this.enableAutoSave) {
|
|
372
|
+
state.autoSave = this.autoSave;
|
|
373
|
+
}
|
|
374
|
+
return new PersistableState(state);
|
|
395
375
|
}
|
|
396
376
|
|
|
397
377
|
setPersistableState(state: PersistableState<ViewManagerModelPersistState>) {
|
|
398
|
-
const {selectedToken, favorites} = state.value;
|
|
399
|
-
if (selectedToken)
|
|
400
|
-
|
|
378
|
+
const {selectedToken, favorites, autoSave} = state.value;
|
|
379
|
+
if (!isUndefined(selectedToken)) {
|
|
380
|
+
this.selectViewAsync(selectedToken);
|
|
381
|
+
}
|
|
382
|
+
if (!isUndefined(favorites)) {
|
|
383
|
+
this.favorites = favorites;
|
|
384
|
+
}
|
|
385
|
+
if (!isUndefined(autoSave) && this.enableAutoSave) {
|
|
386
|
+
this.autoSave = autoSave;
|
|
387
|
+
}
|
|
401
388
|
}
|
|
402
389
|
|
|
403
390
|
//------------------
|
|
404
391
|
// Implementation
|
|
405
392
|
//------------------
|
|
406
|
-
private
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
393
|
+
private async selectViewInternalAsync(token: string) {
|
|
394
|
+
let view: View<T> = null;
|
|
395
|
+
if (token != null) {
|
|
396
|
+
try {
|
|
397
|
+
const raw = await XH.jsonBlobService.getAsync(token);
|
|
398
|
+
view = this.processRaw(raw);
|
|
399
|
+
} catch (e) {
|
|
400
|
+
XH.handleException(e, {showAlert: false});
|
|
401
|
+
view = null;
|
|
402
|
+
token = null;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
runInAction(() => {
|
|
407
|
+
this.selectedToken = token;
|
|
408
|
+
this.selectedView = view;
|
|
409
|
+
this.setValue(this.selectedView?.value ?? ({} as T));
|
|
416
410
|
});
|
|
417
411
|
}
|
|
418
412
|
|
|
419
|
-
|
|
413
|
+
private processRaw(raw: PlainObject): View<T> {
|
|
414
|
+
const name = pluralize(this.DisplayName);
|
|
415
|
+
const isShared = raw.acl === '*';
|
|
416
|
+
return {
|
|
417
|
+
...raw,
|
|
418
|
+
shortName: raw.name?.substring(raw.name.lastIndexOf('\\') + 1),
|
|
419
|
+
isShared,
|
|
420
|
+
group: isShared ? `Shared ${name}` : `My ${name}`,
|
|
421
|
+
isFavorite: this.isFavorite(raw.token)
|
|
422
|
+
} as View<T>;
|
|
423
|
+
}
|
|
424
|
+
|
|
420
425
|
private setValue(value: T) {
|
|
421
426
|
value = this.cleanValue(value);
|
|
422
427
|
if (isEqual(value, this.value) && isEqual(value, this.pendingValue)) return;
|
|
423
428
|
|
|
424
|
-
this.value = value;
|
|
425
|
-
this.pendingValue = value;
|
|
429
|
+
this.value = this.pendingValue = value;
|
|
426
430
|
this.providers.forEach(it => it.pushStateToTarget());
|
|
427
431
|
}
|
|
428
432
|
|
|
@@ -447,69 +451,18 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
447
451
|
});
|
|
448
452
|
}
|
|
449
453
|
|
|
450
|
-
private async maybeAutoSaveAsync(
|
|
451
|
-
if (
|
|
452
|
-
this
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
private buildViewTree(views: View<T>[], depth: number = 0): ViewTree[] {
|
|
462
|
-
const groups = {},
|
|
463
|
-
unbalancedStableGroupsAndViews = [];
|
|
464
|
-
|
|
465
|
-
views.forEach(view => {
|
|
466
|
-
// Leaf Node
|
|
467
|
-
if (this.getNameHierarchySubstring(view.name, depth + 1) == null) {
|
|
468
|
-
unbalancedStableGroupsAndViews.push(view);
|
|
469
|
-
return;
|
|
454
|
+
private async maybeAutoSaveAsync() {
|
|
455
|
+
if (this.canAutoSave && this.isDirty) {
|
|
456
|
+
const {selectedToken, pendingValue} = this;
|
|
457
|
+
try {
|
|
458
|
+
await XH.jsonBlobService.updateAsync(selectedToken, {value: pendingValue});
|
|
459
|
+
runInAction(() => {
|
|
460
|
+
this.value = this.pendingValue;
|
|
461
|
+
});
|
|
462
|
+
} catch (e) {
|
|
463
|
+
XH.handleException(e, {showAlert: false});
|
|
470
464
|
}
|
|
471
|
-
// Belongs to an already defined group
|
|
472
|
-
const group = this.getNameHierarchySubstring(view.name, depth);
|
|
473
|
-
if (groups[group]) {
|
|
474
|
-
groups[group].children.push(view);
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
// Belongs to a not defined group, create it
|
|
478
|
-
groups[group] = {name: group, children: [view], isMenuFolder: true};
|
|
479
|
-
unbalancedStableGroupsAndViews.push(groups[group]);
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
return unbalancedStableGroupsAndViews.map(it => {
|
|
483
|
-
const {name, isMenuFolder, children, description, token} = it;
|
|
484
|
-
if (isMenuFolder) {
|
|
485
|
-
return {
|
|
486
|
-
type: 'folder',
|
|
487
|
-
text: name,
|
|
488
|
-
items: this.buildViewTree(children, depth + 1),
|
|
489
|
-
selected: this.isFolderForEntry(name, this.selectedView?.name, depth)
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
return {
|
|
493
|
-
type: 'view',
|
|
494
|
-
text: this.getHierarchyDisplayName(name),
|
|
495
|
-
selected: this.selectedToken === token,
|
|
496
|
-
token,
|
|
497
|
-
description
|
|
498
|
-
};
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
private getNameHierarchySubstring(name: string, depth: number) {
|
|
503
|
-
const arr = name?.split('\\') ?? [];
|
|
504
|
-
if (arr.length <= depth) {
|
|
505
|
-
return null;
|
|
506
465
|
}
|
|
507
|
-
return arr.slice(0, depth + 1).join('\\');
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
private isFolderForEntry(folderName: string, entryName: string, depth: number) {
|
|
511
|
-
const name = this.getNameHierarchySubstring(entryName, depth);
|
|
512
|
-
return name && name === folderName && folderName.length < entryName.length;
|
|
513
466
|
}
|
|
514
467
|
|
|
515
468
|
// Update flag on each view, replacing entire views collection for observability.
|
|
@@ -522,6 +475,7 @@ export class ViewManagerModel<T extends PlainObject = PlainObject>
|
|
|
522
475
|
}
|
|
523
476
|
|
|
524
477
|
interface ViewManagerModelPersistState {
|
|
525
|
-
selectedToken
|
|
526
|
-
favorites
|
|
478
|
+
selectedToken?: string;
|
|
479
|
+
favorites?: string[];
|
|
480
|
+
autoSave?: boolean;
|
|
527
481
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {View, ViewManagerModel, ViewTree} from '@xh/hoist/core/persist/viewmanager';
|
|
2
|
+
import {sortBy} from 'lodash';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a menu-friendly, tree representation of a set of views, using the `\`
|
|
6
|
+
* in view names to create folders.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function buildViewTree(views: View[], model: ViewManagerModel): ViewTree[] {
|
|
11
|
+
views = sortBy(views, 'name');
|
|
12
|
+
return buildTreeInternal(views, model.selectedView, 0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function buildTreeInternal(views: View[], selected: View, depth: number): ViewTree[] {
|
|
16
|
+
// 1) Get groups and leaves at this level.
|
|
17
|
+
const groups = {},
|
|
18
|
+
groupsAndLeaves = [];
|
|
19
|
+
views.forEach(view => {
|
|
20
|
+
// Leaf Node
|
|
21
|
+
if (getNameAtDepth(view.name, depth + 1) == null) {
|
|
22
|
+
groupsAndLeaves.push(view);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Belongs to an already defined group
|
|
26
|
+
const group = getNameAtDepth(view.name, depth);
|
|
27
|
+
if (groups[group]) {
|
|
28
|
+
groups[group].children.push(view);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Belongs to a not defined group, create it
|
|
32
|
+
groups[group] = {name: group, children: [view], isMenuFolder: true};
|
|
33
|
+
groupsAndLeaves.push(groups[group]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 2) Make ViewTree, recursing for groups
|
|
37
|
+
return groupsAndLeaves.map(it => {
|
|
38
|
+
const {name, isMenuFolder, children, description, token} = it;
|
|
39
|
+
return isMenuFolder
|
|
40
|
+
? {
|
|
41
|
+
type: 'folder',
|
|
42
|
+
text: getFolderDisplayName(name, depth),
|
|
43
|
+
items: buildTreeInternal(children, selected, depth + 1),
|
|
44
|
+
selected: isFolderForEntry(name, selected?.name, depth)
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
type: 'view',
|
|
48
|
+
text: it.shortName,
|
|
49
|
+
selected: selected?.token === token,
|
|
50
|
+
token,
|
|
51
|
+
description
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getNameAtDepth(name: string, depth: number) {
|
|
57
|
+
const arr = name?.split('\\') ?? [];
|
|
58
|
+
return arr.length <= depth ? null : arr.slice(0, depth + 1).join('\\');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isFolderForEntry(folderName: string, entryName: string, depth: number) {
|
|
62
|
+
const name = getNameAtDepth(entryName, depth);
|
|
63
|
+
return name && name === folderName && folderName.length < entryName.length;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getFolderDisplayName(name: string, depth: number) {
|
|
67
|
+
return name?.split('\\')[depth];
|
|
68
|
+
}
|
|
@@ -214,8 +214,12 @@ export class DashContainerModel
|
|
|
214
214
|
// Initialize GoldenLayout with initial state once ref is ready
|
|
215
215
|
this.addReaction(
|
|
216
216
|
{
|
|
217
|
-
track: () => [this.containerRef.current, this.layoutLocked],
|
|
218
|
-
run: () =>
|
|
217
|
+
track: () => [this.containerRef.current, this.layoutLocked] as const,
|
|
218
|
+
run: ([ref, locked]) => {
|
|
219
|
+
// This reaction is intended to run when ref becomes available.
|
|
220
|
+
// It's a no-op if ref *removed* due to component re-render.
|
|
221
|
+
if (ref) this.loadStateAsync(this.state);
|
|
222
|
+
}
|
|
219
223
|
},
|
|
220
224
|
{
|
|
221
225
|
track: () => this.viewState,
|
|
@@ -239,32 +243,36 @@ export class DashContainerModel
|
|
|
239
243
|
await this.loadStateAsync(restoreState.initialState);
|
|
240
244
|
}
|
|
241
245
|
|
|
242
|
-
/**
|
|
243
|
-
* Load state into the DashContainer, recreating its layout and contents
|
|
244
|
-
* @param state - State to load
|
|
245
|
-
*/
|
|
246
|
+
/** Load state into the DashContainer, recreating its layout and contents */
|
|
246
247
|
async loadStateAsync(state: DashViewState[]) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
'DashboardContainer not yet rendered - cannot update state - change will be discarded!'
|
|
251
|
-
);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
248
|
+
// Always save a reference to the state, even if the container is not yet rendered.
|
|
249
|
+
// Allows ref reaction on this class to loop back and apply it once GL is ready.
|
|
250
|
+
runInAction(() => (this.state = state));
|
|
254
251
|
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
252
|
+
// DOM required from this point on to recreate GL with new state.
|
|
253
|
+
const containerEl = this.containerRef.current;
|
|
254
|
+
if (!containerEl) return;
|
|
255
|
+
|
|
256
|
+
// Use of async below requires we check after each wait to ensure we haven't re-rendered
|
|
257
|
+
// again with a new ref. Bail out if so - ref reaction will re-enter and complete the job.
|
|
258
|
+
const refIsStale = () => this.containerRef.current !== containerEl;
|
|
259
|
+
|
|
260
|
+
return (
|
|
261
|
+
wait()
|
|
262
|
+
.thenAction(() => {
|
|
263
|
+
if (refIsStale()) return;
|
|
264
|
+
this.destroyGoldenLayout();
|
|
265
|
+
this.goldenLayout = this.createGoldenLayout(containerEl, state);
|
|
266
|
+
})
|
|
263
267
|
// Since React v18, it's necessary to wait a short while for ViewModels to be available.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
+
.wait(500)
|
|
269
|
+
.then(() => {
|
|
270
|
+
if (refIsStale()) return;
|
|
271
|
+
this.refreshActiveViews();
|
|
272
|
+
this.updateTabHeaders();
|
|
273
|
+
})
|
|
274
|
+
.linkTo(this.loadingStateTask)
|
|
275
|
+
);
|
|
268
276
|
}
|
|
269
277
|
|
|
270
278
|
/**
|
|
@@ -343,13 +351,7 @@ export class DashContainerModel
|
|
|
343
351
|
|
|
344
352
|
setPersistableState(persistableState: PersistableState<{state: DashViewState[]}>) {
|
|
345
353
|
const {state} = persistableState.value;
|
|
346
|
-
if (
|
|
347
|
-
if (this.containerRef.current) {
|
|
348
|
-
this.loadStateAsync(state);
|
|
349
|
-
} else {
|
|
350
|
-
// If the container is not yet rendered, store the state directly
|
|
351
|
-
this.state = state;
|
|
352
|
-
}
|
|
354
|
+
if (state) this.loadStateAsync(state);
|
|
353
355
|
}
|
|
354
356
|
|
|
355
357
|
//------------------------
|