@xh/hoist 89.1.0 → 89.3.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/build/types/cmp/grid/GridModel.d.ts +6 -0
  3. package/build/types/cmp/viewmanager/ViewManagerModel.d.ts +4 -2
  4. package/build/types/core/XH.d.ts +2 -1
  5. package/build/types/core/persist/PersistenceProvider.d.ts +3 -0
  6. package/build/types/desktop/cmp/dash/DashViewSpec.d.ts +2 -1
  7. package/build/types/desktop/cmp/dash/canvas/impl/DashCanvasContextMenu.d.ts +1 -1
  8. package/build/types/desktop/cmp/dash/canvas/widgetchooser/DashCanvasWidgetChooser.d.ts +3 -2
  9. package/build/types/desktop/cmp/dash/container/impl/DashContainerContextMenu.d.ts +1 -1
  10. package/build/types/desktop/cmp/dash/impl/DashUtils.d.ts +35 -0
  11. package/build/types/desktop/cmp/tab/dynamic/DynamicTabSwitcherModel.d.ts +1 -2
  12. package/build/types/svc/FetchService.d.ts +24 -2
  13. package/cmp/grid/Grid.ts +2 -2
  14. package/cmp/grid/GridModel.ts +14 -1
  15. package/cmp/grid/columns/Column.ts +2 -1
  16. package/cmp/viewmanager/ViewManagerModel.ts +25 -7
  17. package/core/XH.ts +8 -3
  18. package/core/persist/PersistenceProvider.ts +15 -1
  19. package/desktop/cmp/dash/DashViewSpec.ts +2 -1
  20. package/desktop/cmp/dash/README.md +6 -5
  21. package/desktop/cmp/dash/canvas/impl/DashCanvasContextMenu.ts +1 -1
  22. package/desktop/cmp/dash/canvas/impl/utils.ts +16 -51
  23. package/desktop/cmp/dash/canvas/widgetchooser/DashCanvasWidgetChooser.ts +37 -54
  24. package/desktop/cmp/dash/container/impl/DashContainerContextMenu.ts +8 -39
  25. package/desktop/cmp/dash/impl/DashUtils.ts +90 -0
  26. package/desktop/cmp/grid/impl/colchooser/ColChooser.scss +3 -6
  27. package/desktop/cmp/tab/TabSwitcher.ts +4 -6
  28. package/desktop/cmp/tab/dynamic/DynamicTabSwitcher.ts +4 -5
  29. package/desktop/cmp/tab/dynamic/DynamicTabSwitcherModel.ts +2 -7
  30. package/docs/build-and-publish.md +21 -11
  31. package/docs/doc-registry.json +1 -1
  32. package/docs/lifecycle-models-and-services.md +2 -1
  33. package/docs/persistence.md +2 -0
  34. package/docs/telemetry.md +29 -0
  35. package/package.json +1 -1
  36. package/svc/FetchService.ts +87 -32
  37. package/svc/README.md +9 -4
  38. package/svc/impl/NdjsonResultImpl.ts +17 -12
  39. package/build/types/desktop/cmp/tab/impl/TabContextMenuItems.d.ts +0 -4
  40. package/desktop/cmp/tab/impl/TabContextMenuItems.ts +0 -23
package/CHANGELOG.md CHANGED
@@ -11,6 +11,55 @@
11
11
  codebase, or with the symbol itself (`Foo.bar` now ...) when a living API changed behavior.
12
12
  3. Plain ASCII punctuation only. Use " - " for in-sentence breaks, never an em dash.
13
13
  -->
14
+ ## 89.3.0 - 2026-10-21
15
+
16
+ ### 🎁 New Features
17
+ * `fetchNdjson` streams are now aborted cleanly and fully via the `autoAbortKey` or if the reading
18
+ consumer closes the connection early.
19
+
20
+ ### 🐞 Bug Fixes
21
+ * Fixed a `FetchOptions.fetchOpts.signal` replacing `FetchService`'s own, which left `timeout` and
22
+ `autoAbortKey` unable to abort the request. The two signals are now joined, and an abort with a
23
+ custom reason reports as "Fetch Aborted".
24
+ * Fixed oversized pinned column zones in the desktop column chooser. They now fit their columns.
25
+
26
+
27
+ ## 89.2.0 - 2026-10-20
28
+
29
+ ### 🎁 New Features
30
+
31
+ * Added `FetchOptions.propagateTrace` and `FetchService.defaults.propagateTrace` to choose which
32
+ requests carry a `traceparent` header, with `FetchService.isHoistServerUrl()` as the default.
33
+ * `DashViewSpec.groupName` now nests groups when it separates names with `/`, as in `Charts/Line`.
34
+ The add view menus of `DashContainer` and `DashCanvas` show each level as a submenu, and
35
+ `DashCanvasWidgetChooser` shows each as a card. Existing group names that contain `/` now nest.
36
+ * `DashCanvas` add view menus and `DashCanvasWidgetChooser` now list each group where its first
37
+ view spec appears, as `DashContainer` does, not ahead of all ungrouped specs. To keep groups at
38
+ the top, define grouped specs first.
39
+
40
+ ### 🐞 Bug Fixes
41
+
42
+ * Fixed `ViewManagerModel` reinstalling the prior view when a save of it finished after the user
43
+ selected another view. Auto-save could then write the new view's state into the prior view.
44
+ * Fixed `ViewManagerModel` installing an earlier selected view when it finished loading after a
45
+ later one. A refresh also reloaded the prior view over a newer selection.
46
+ * Fixed `ViewManagerModel` dashboards picking up a change made in the prior view just before a
47
+ switch, which marked the new view dirty. A destroyed `PersistenceProvider` now writes any pending
48
+ change at once.
49
+ * Fixed desktop tab switcher context menus throwing for an `extraMenuItems` entry with a static
50
+ `items` submenu. Items a `prepareFn` adds now also receive the tab in their `actionFn`.
51
+ * Fixed `XH.safeDestroy()` stopping at the first `destroy()` that threw, which left the remaining
52
+ objects - and the rest of a model's managed children - undestroyed. It now logs the error.
53
+
54
+ ### ⚙️ Technical
55
+
56
+ * Added protected `PersistenceProvider.cancelPendingWrite()`. `pushStateToTarget()` now drops any
57
+ pending write. A custom provider that overrides it without calling `super` should call this
58
+ method.
59
+ * `FetchService` now sends the `traceparent` header only to the app's own server, so cross-origin
60
+ requests cannot fail a CORS preflight on it. Set `propagateTrace` to send it elsewhere.
61
+
62
+
14
63
  ## 89.1.0 - 2026-10-19
15
64
 
16
65
  ### 🎁 New Features
@@ -33,6 +82,9 @@
33
82
  * Fixed desktop `NumberInput` with `min` or `max` rendering blank on mount when its formatted value
34
83
  was not a plain number, as with `displayWithCommas` and a value of 1,000 or more, or a
35
84
  `valueLabel`. Changing `min` or `max` on such an input could also set its value to 0.
85
+ * Fixed a grouped `Grid` showing its grouped column again on any column state change, such as a
86
+ resize, an autosize or a view restore. A header drag while grouped also saved the column as
87
+ hidden, so it stayed hidden after ungrouping.
36
88
  * Fixed `onShowLazy` tabs and other managed refresh contexts replaying a missed auto-refresh as a
37
89
  manual refresh when shown. The replay now stays an auto-refresh unless a missed refresh was manual.
38
90
  * Fixed a model created with `creates()` re-running `onLinked()` on every render when its component
@@ -673,6 +673,12 @@ export declare class GridModel extends HoistModel {
673
673
  * property is not updated with state changes.
674
674
  */
675
675
  isColumnVisible(colId: string): boolean;
676
+ /**
677
+ * True if ag-Grid is hiding this column because the grid is grouped by it. Hoist leaves the
678
+ * visibility of such a column to ag-Grid, keeping its own `hidden` state for after ungrouping.
679
+ * @internal
680
+ */
681
+ isColumnHiddenByGrouping(colId: string): boolean;
676
682
  setColumnVisible(colId: string, visible: boolean): void;
677
683
  showColumn(colId: string): void;
678
684
  hideColumn(colId: string): void;
@@ -187,6 +187,8 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
187
187
  * state to the target components when the model's selected `value` changes.
188
188
  */
189
189
  private providers;
190
+ /** Count of calls to {@link loadViewAsync}, used to identify the latest. */
191
+ private viewLoadCount;
190
192
  /** Data access for persisting views. */
191
193
  private dataAccess;
192
194
  get isValueDirty(): boolean;
@@ -254,8 +256,8 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
254
256
  private stateReactions;
255
257
  private loadViewAsync;
256
258
  private maybeAutoSaveAsync;
257
- /** Install a saved view, keeping as pending any value set while the save was in flight. */
258
- private setAsSavedView;
259
+ /** Apply a completed save, installing the saved view only if it is still current. */
260
+ private applySavedView;
259
261
  private setAsView;
260
262
  private handleException;
261
263
  private noteSuccess;
@@ -466,7 +466,8 @@ export declare class XHApi {
466
466
  restoreDefaultsAsync(): Promise<void>;
467
467
  /**
468
468
  * Helper method to destroy resources safely (e.g. child HoistModels). Will quietly skip args
469
- * that are null / undefined or that do not implement destroy().
469
+ * that are null / undefined or that do not implement destroy(). Logs, rather than throws, an
470
+ * error from any destroy(), so the remaining args are still destroyed.
470
471
  *
471
472
  * @param args - objects to be destroyed. If any argument is an array, each top-level element
472
473
  * in the array will be destroyed. (Note this is *not* done recursively.)
@@ -81,6 +81,8 @@ export declare abstract class PersistenceProvider<S = any> {
81
81
  protected writeInternal(data: S): void;
82
82
  protected writeRaw(obj: Record<typeof this.path, S>): void;
83
83
  protected readRaw(): Record<typeof this.path, S>;
84
+ /** Drop any debounced write still pending. */
85
+ protected cancelPendingWrite(): void;
84
86
  /**
85
87
  * Resolve the PersistenceProvider class that the given options would produce, applying the
86
88
  * same precedence used by {@link create}. Throws if the options do not resolve to a known
@@ -93,6 +95,7 @@ export declare abstract class PersistenceProvider<S = any> {
93
95
  * @internal - not intended for application use.
94
96
  */
95
97
  static parseProviderClass<S>(opts: PersistOptions): Class<PersistenceProvider<S>, [PersistenceProviderConfig<S>]>;
98
+ private get debouncedWrite();
96
99
  private ensureValid;
97
100
  }
98
101
  export {};
@@ -17,7 +17,8 @@ export interface DashViewSpec {
17
17
  icon?: ReactElement;
18
18
  /**
19
19
  * Group name to display within the add view component. The default context menu will
20
- * automatically group its available views if provided.
20
+ * automatically group its available views if provided. Separate names with '/' to nest
21
+ * groups - e.g. `Charts/Line`.
21
22
  */
22
23
  groupName?: string;
23
24
  /**
@@ -2,7 +2,7 @@
2
2
  * Context menu to add items to a DashCanvas
3
3
  *
4
4
  * Available view specs are listed in their defined order, optionally
5
- * grouped by their 'groupName' property
5
+ * grouped by their `groupName` property into (nested) submenus.
6
6
  * @internal
7
7
  */
8
8
  export declare const dashCanvasContextMenu: import("@xh/hoist/core").ElementFactory<import("@xh/hoist/core").DefaultHoistProps<import("@xh/hoist/core").HoistModel>>;
@@ -7,7 +7,8 @@ export interface DashCanvasWidgetChooserProps extends HoistProps, TestSupportPro
7
7
  }
8
8
  /**
9
9
  * Displays available {@link DashCanvasViewSpec}s as draggable items that can be dropped onto a
10
- * {@link DashCanvas} to add new views. View specs are listed in their defined order, grouped by
11
- * their `groupName` property if present. Place inside a collapsible panel alongside a DashCanvas.
10
+ * {@link DashCanvas} to add new views. View specs are listed in their defined order, grouped into
11
+ * (nested) cards by their `groupName` property if present. Place inside a collapsible panel
12
+ * alongside a DashCanvas.
12
13
  */
13
14
  export declare const DashCanvasWidgetChooser: import("react").FC<DashCanvasWidgetChooserProps>, dashCanvasWidgetChooser: import("@xh/hoist/core").ElementFactory<DashCanvasWidgetChooserProps>;
@@ -3,7 +3,7 @@ import { DashContainerModel } from '../DashContainerModel';
3
3
  * Context menu for title bar/tabs of a stack in a DashContainer.
4
4
  *
5
5
  * Available view specs are listed in their defined order, optionally
6
- * grouped by their `groupName` property
6
+ * grouped by their `groupName` property into (nested) submenus.
7
7
  *
8
8
  * @internal
9
9
  */
@@ -0,0 +1,35 @@
1
+ import type { MenuItem, MenuItemLike } from '@xh/hoist/core';
2
+ import type { DashViewSpec } from '../DashViewSpec';
3
+ /**
4
+ * A group of view specs, built from their `groupName`. A slash-delimited name nests groups - e.g.
5
+ * a spec with `groupName: 'Charts/Line'` sits in group 'Line', within group 'Charts'.
6
+ * @internal
7
+ */
8
+ export declare class ViewSpecGroup<T extends DashViewSpec = DashViewSpec> {
9
+ /** One segment of a `groupName` - the name shown for this group. */
10
+ readonly name: string;
11
+ /** Nested groups and view specs, in the order each first appears in the source specs. */
12
+ readonly children: ViewSpecNode<T>[];
13
+ constructor(name: string);
14
+ /** All view specs within this group, including those within its nested groups. */
15
+ get allViewSpecs(): T[];
16
+ }
17
+ /** @internal */
18
+ export type ViewSpecNode<T extends DashViewSpec = DashViewSpec> = ViewSpecGroup<T> | T;
19
+ /**
20
+ * Arrange view specs into groups by their `groupName`, split on '/' into nested groups. Blank
21
+ * segments are ignored and surrounding spaces trimmed, so `Charts / Line` matches `Charts/Line`.
22
+ *
23
+ * @returns top-level groups and ungrouped specs, in the order each first appears.
24
+ * @internal
25
+ */
26
+ export declare function groupViewSpecs<T extends DashViewSpec>(viewSpecs: T[]): ViewSpecNode<T>[];
27
+ /**
28
+ * Create menu items for adding views, nesting specs into submenus by their `groupName`. Groups
29
+ * and specs are listed in the order each first appears.
30
+ *
31
+ * @param viewSpecs - specs to list, in their defined order.
32
+ * @param createItem - creates the menu item for a single spec.
33
+ * @internal
34
+ */
35
+ export declare function createViewSpecMenuItems<T extends DashViewSpec>(viewSpecs: T[], createItem: (viewSpec: T) => MenuItem): MenuItemLike[];
@@ -1,7 +1,6 @@
1
1
  import { TabContainerModel, TabModel } from '@xh/hoist/cmp/tab';
2
2
  import { IDynamicTabSwitcherModel, TabSwitcherConfig, TabSwitcherMenuContext } from '@xh/hoist/cmp/tab/Types';
3
3
  import { HoistModel, MenuItemLike, MenuToken } from '@xh/hoist/core';
4
- import React from 'react';
5
4
  /**
6
5
  * State management for the DynamicTabSwitcher component.
7
6
  * @internal
@@ -20,7 +19,7 @@ export declare class DynamicTabSwitcherModel extends HoistModel implements IDyna
20
19
  toggleTabFavorite(tabId: string): void;
21
20
  activate(tabId: string): void;
22
21
  hide(tabId: string): void;
23
- getContextMenuItems(e: React.MouseEvent<HTMLDivElement, MouseEvent>, tab: TabModel): Array<MenuItemLike<MenuToken, TabSwitcherMenuContext>>;
22
+ getContextMenuItems(tab: TabModel): Array<MenuItemLike<MenuToken, TabSwitcherMenuContext>>;
24
23
  setFavoriteTabIds(tabIds: string[]): void;
25
24
  onDragEnd(result: any): void;
26
25
  private activeTabReaction;
@@ -7,6 +7,7 @@ export interface FetchServiceDefaults {
7
7
  autoGenCorrelationIds?: boolean | ((opts: FetchOptions) => boolean);
8
8
  correlationIdHeaderKey?: string;
9
9
  genCorrelationId?: () => string;
10
+ propagateTrace?: boolean | ((opts: FetchOptions) => boolean);
10
11
  }
11
12
  /**
12
13
  * Service for making managed HTTP requests, both to the app's own Hoist server and to remote APIs.
@@ -23,6 +24,8 @@ export interface FetchServiceDefaults {
23
24
  * - Configurable timeouts (default 30s) via {@link FetchOptions.timeout}
24
25
  * - Auto-abort of duplicate in-flight requests via {@link FetchOptions.autoAbortKey}
25
26
  * - Optional correlation IDs for request tracking (see `defaults.autoGenCorrelationIds`)
27
+ * - W3C `traceparent` headers when tracing is enabled, sent by default only to the app's own
28
+ * server (see `defaults.propagateTrace` and {@link FetchOptions.propagateTrace})
26
29
  * - Request/response interceptors via {@link addInterceptor}
27
30
  * - Default headers for all requests via {@link addDefaultHeaders}
28
31
  * - Rich exception handling with HTTP status, server messages, and trace IDs
@@ -35,6 +38,11 @@ export declare class FetchService extends HoistService {
35
38
  static instance: FetchService;
36
39
  /** App-level defaults for FetchService. Instance options take precedence. */
37
40
  static defaults: FetchServiceDefaults;
41
+ /**
42
+ * Does a request url target the app's own server? True for relative and root-relative urls,
43
+ * and for absolute urls on the origin of the page or of {@link XH.baseUrl}.
44
+ */
45
+ static isHoistServerUrl(url: string): boolean;
38
46
  NO_JSON_RESPONSES: StatusCodes[];
39
47
  /**
40
48
  * Regex applied during failed response handling to determine if contentType indicates JSON.
@@ -169,15 +177,19 @@ export declare class FetchService extends HoistService {
169
177
  getInternStats(): PlainObject[];
170
178
  private static readonly defaultIdGenerator;
171
179
  /**
172
- * @param forStreaming - true when called by fetchNdjson, which applies its own span and
173
- * track across the full stream lifetime - suppresses both here.
180
+ * @param streamAborter - aborter for a stream, set by fetchNdjson. It applies its own span and
181
+ * track across the full stream lifetime - suppresses both here - and releases any
182
+ * autoAbortKey once the stream completes.
174
183
  */
175
184
  private fetchInternalAsync;
176
185
  private sendJsonInternalAsync;
177
186
  private withCorrelationId;
178
187
  private withTraceId;
179
188
  private withResolvedHeadersAsync;
189
+ private shouldPropagateTrace;
180
190
  private managedFetchAsync;
191
+ private isAborted;
192
+ private releaseAutoAbortKey;
181
193
  private abortableFetchAsync;
182
194
  private parseJsonAsync;
183
195
  private safeResponseTextAsync;
@@ -263,6 +275,16 @@ export interface FetchOptions {
263
275
  * `correlationId` will be set. If `true`, one will be auto-generated.
264
276
  */
265
277
  correlationId?: string | boolean;
278
+ /**
279
+ * True to send a W3C `traceparent` header with this request, false to omit it. Applies only
280
+ * when tracing is enabled. The request still records a client span either way, but only a
281
+ * server that receives the header can join the trace. Defaults to
282
+ * `FetchService.defaults.propagateTrace`, which sends the header only to the app's own server.
283
+ *
284
+ * Note `traceparent` is not a CORS-safelisted header. A cross-origin server must list it in
285
+ * `Access-Control-Allow-Headers`, or the browser blocks the request.
286
+ */
287
+ propagateTrace?: boolean;
266
288
  /**
267
289
  * Parameters to encode and append as a query string, or send with the request body
268
290
  * (for POSTs/PUTs sending form-url-encoded).
package/cmp/grid/Grid.ts CHANGED
@@ -442,7 +442,7 @@ export class GridLocalModel extends HoistModel {
442
442
 
443
443
  // Re-assert configured visibility - AG Grid re-shows a column when ungrouped (#4473).
444
444
  const state = model.columnState
445
- .filter(({colId}) => !groupBy.includes(colId))
445
+ .filter(({colId}) => !model.isColumnHiddenByGrouping(colId))
446
446
  .map(({colId, hidden}) => ({colId, hide: hidden}));
447
447
  agApi.applyColumnState({state});
448
448
  }
@@ -523,7 +523,7 @@ export class GridLocalModel extends HoistModel {
523
523
  hasChanges = true;
524
524
  }
525
525
 
526
- if (agCol.hide !== hidden) {
526
+ if (agCol.hide !== hidden && !model.isColumnHiddenByGrouping(colId)) {
527
527
  ret.hide = hidden;
528
528
  hasChanges = true;
529
529
  }
@@ -1439,7 +1439,7 @@ export class GridModel extends HoistModel {
1439
1439
  return {
1440
1440
  colId,
1441
1441
  pinned: isBoolean(pinned) ? (pinned ? 'left' : null) : pinned,
1442
- hidden: !!hide,
1442
+ hidden: this.isColumnHiddenByGrouping(colId) ? null : !!hide,
1443
1443
  width: col.flex ? undefined : width
1444
1444
  };
1445
1445
  }
@@ -1590,6 +1590,19 @@ export class GridModel extends HoistModel {
1590
1590
  return state ? !state.hidden : false;
1591
1591
  }
1592
1592
 
1593
+ /**
1594
+ * True if ag-Grid is hiding this column because the grid is grouped by it. Hoist leaves the
1595
+ * visibility of such a column to ag-Grid, keeping its own `hidden` state for after ungrouping.
1596
+ * @internal
1597
+ */
1598
+ isColumnHiddenByGrouping(colId: string): boolean {
1599
+ const {agApi} = this;
1600
+ if (!agApi || !this.groupBy.includes(colId)) return false;
1601
+
1602
+ const suppress = agApi.getGridOption('suppressGroupChangesColumnVisibility');
1603
+ return suppress !== true && suppress !== 'suppressHideOnGroup';
1604
+ }
1605
+
1593
1606
  setColumnVisible(colId: string, visible: boolean) {
1594
1607
  this.updateColumnState([{colId, hidden: !visible}]);
1595
1608
  }
@@ -807,7 +807,8 @@ export class Column {
807
807
  },
808
808
  headerClass: getAgHeaderClassFn(this),
809
809
  headerTooltip: this.headerTooltip,
810
- hide: this.hidden,
810
+ // Undefined keeps ag-Grid's current visibility on update.
811
+ hide: gridModel.isColumnHiddenByGrouping(this.colId) ? undefined : this.hidden,
811
812
  columnGroupShow: toAgColumnGroupShow(this.groupShowMode),
812
813
  minWidth: this.minWidth,
813
814
  maxWidth: this.maxWidth,
@@ -268,6 +268,9 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
268
268
  */
269
269
  private providers: ViewManagerProvider<any>[] = [];
270
270
 
271
+ /** Count of calls to {@link loadViewAsync}, used to identify the latest. */
272
+ private viewLoadCount = 0;
273
+
271
274
  /** Data access for persisting views. */
272
275
  private dataAccess: DataAccess<T>;
273
276
 
@@ -386,7 +389,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
386
389
  }
387
390
 
388
391
  override async doLoadAsync(loadSpec: LoadSpec) {
389
- const {dataAccess, view} = this;
392
+ const {dataAccess} = this;
390
393
  await this.runner({loadSpec})
391
394
  .span('refresh')
392
395
  .run(async ctx => {
@@ -400,8 +403,10 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
400
403
  this.serverManageGlobal = manageGlobal ?? null;
401
404
  });
402
405
 
403
- // potentially fast-forward current view.
404
- if (!view.isDefault) {
406
+ // Fast-forward the current view if it was updated elsewhere.
407
+ // Skip while an explicit view load is pending - this is subordinate background work
408
+ const {view} = this;
409
+ if (!view.isDefault && !this.selectTask.isPending) {
405
410
  const latestInfo = find(views, {token: view.token});
406
411
  if (latestInfo && latestInfo.lastUpdated > view.lastUpdated) {
407
412
  this.loadViewAsync(view.token, this.pendingValue, ctx);
@@ -470,7 +475,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
470
475
  .updateViewValueAsync(view, pendingValue.value, ctx)
471
476
  .linkTo(this.saveTask);
472
477
 
473
- this.setAsSavedView(updated, pendingValue);
478
+ this.applySavedView(updated, pendingValue);
474
479
  this.noteSuccess(`Saved ${view.typedName}`);
475
480
 
476
481
  this.refreshAsync();
@@ -719,12 +724,19 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
719
724
  pendingValue: PendingValue<T> = null,
720
725
  ctx: CallContext
721
726
  ): Promise<void> {
727
+ const loadNum = ++this.viewLoadCount,
728
+ isStale = () => loadNum !== this.viewLoadCount;
729
+
722
730
  return this.dataAccess
723
731
  .fetchViewAsync(token, ctx)
724
732
  .thenAction(latest => {
733
+ if (isStale()) return;
725
734
  this.setAsView(latest, pendingValue?.token == token ? pendingValue : null);
726
735
  this.providers.forEach(it => it.pushStateToTarget());
727
736
  })
737
+ .catch(e => {
738
+ if (!isStale()) throw e;
739
+ })
728
740
  .linkTo(this.selectTask);
729
741
  }
730
742
 
@@ -740,7 +752,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
740
752
  .updateViewValueAsync(view, pendingValue.value, ctx)
741
753
  .linkTo(this.saveTask);
742
754
 
743
- this.setAsSavedView(updated, pendingValue);
755
+ this.applySavedView(updated, pendingValue);
744
756
  } catch (e) {
745
757
  // TODO: How to alert but avoid for flaky or spam when user editing a deleted view
746
758
  // Keep count and alert server and user once at count n?
@@ -753,9 +765,15 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
753
765
  });
754
766
  }
755
767
 
756
- /** Install a saved view, keeping as pending any value set while the save was in flight. */
768
+ /** Apply a completed save, installing the saved view only if it is still current. */
757
769
  @action
758
- private setAsSavedView(saved: View<T>, sent: PendingValue<T>) {
770
+ private applySavedView(saved: View<T>, sent: PendingValue<T>) {
771
+ // User has moved on - just update the list entry (map, so a deleted view stays out).
772
+ if (saved.token !== this.view.token) {
773
+ this.views = this.views.map(it => (it.token === saved.token ? saved.info : it));
774
+ return;
775
+ }
776
+
759
777
  const value = this.getValue(),
760
778
  pendingValue = isEqual(value, sent.value)
761
779
  ? null
package/core/XH.ts CHANGED
@@ -35,7 +35,7 @@ import {
35
35
  TraceService,
36
36
  WebSocketService
37
37
  } from '@xh/hoist/svc';
38
- import {getLogLevel, LogLevel, setLogLevel} from '@xh/hoist/utils/js';
38
+ import {getLogLevel, logError, LogLevel, setLogLevel} from '@xh/hoist/utils/js';
39
39
  import {camelCase, flatten, isString, uniqueId} from 'lodash';
40
40
  import {Router, State} from 'router5';
41
41
  import {CancelFn} from 'router5/types/types/base';
@@ -915,7 +915,8 @@ export class XHApi {
915
915
 
916
916
  /**
917
917
  * Helper method to destroy resources safely (e.g. child HoistModels). Will quietly skip args
918
- * that are null / undefined or that do not implement destroy().
918
+ * that are null / undefined or that do not implement destroy(). Logs, rather than throws, an
919
+ * error from any destroy(), so the remaining args are still destroyed.
919
920
  *
920
921
  * @param args - objects to be destroyed. If any argument is an array, each top-level element
921
922
  * in the array will be destroyed. (Note this is *not* done recursively.)
@@ -924,7 +925,11 @@ export class XHApi {
924
925
  if (args) {
925
926
  args = flatten(args);
926
927
  args.forEach(it => {
927
- it?.destroy?.();
928
+ try {
929
+ it?.destroy?.();
930
+ } catch (e) {
931
+ logError(['Error destroying object', e], it);
932
+ }
928
933
  });
929
934
  }
930
935
  }
@@ -14,6 +14,7 @@ import {
14
14
  get,
15
15
  isArray,
16
16
  isEmpty,
17
+ isFunction,
17
18
  isNumber,
18
19
  isObject,
19
20
  isString,
@@ -138,7 +139,7 @@ export abstract class PersistenceProvider<S = any> {
138
139
 
139
140
  // Drop any debounced write still pending - it holds pre-clear state and would otherwise
140
141
  // land after this call and resurrect it.
141
- (this.writeInternal as DebouncedFunc<(data: S) => void>).cancel?.();
142
+ this.cancelPendingWrite();
142
143
 
143
144
  const obj = cloneDeep(this.readRaw()),
144
145
  path = toPath(this.path);
@@ -153,10 +154,12 @@ export abstract class PersistenceProvider<S = any> {
153
154
 
154
155
  destroy() {
155
156
  this.disposer?.();
157
+ this.debouncedWrite?.flush(); // write any pending change now
156
158
  }
157
159
 
158
160
  /** Push the current state of this provider to its target. */
159
161
  pushStateToTarget() {
162
+ this.cancelPendingWrite(); // stale - would overwrite pushed state
160
163
  const state = this.read();
161
164
  this.target.setPersistableState(state ? state : this.defaultState);
162
165
  }
@@ -223,6 +226,11 @@ export abstract class PersistenceProvider<S = any> {
223
226
  return null;
224
227
  }
225
228
 
229
+ /** Drop any debounced write still pending. */
230
+ protected cancelPendingWrite() {
231
+ this.debouncedWrite?.cancel();
232
+ }
233
+
226
234
  /**
227
235
  * Resolve the PersistenceProvider class that the given options would produce, applying the
228
236
  * same precedence used by {@link create}. Throws if the options do not resolve to a known
@@ -254,6 +262,12 @@ export abstract class PersistenceProvider<S = any> {
254
262
  return ret;
255
263
  }
256
264
 
265
+ // The debounced write function, or null if writes are not debounced - see constructor.
266
+ private get debouncedWrite(): DebouncedFunc<(data: S) => void> {
267
+ const ret = this.writeInternal as DebouncedFunc<(data: S) => void>;
268
+ return isFunction(ret.cancel) ? ret : null;
269
+ }
270
+
257
271
  private ensureValid() {
258
272
  const data = this.readRaw();
259
273
  throwIf(
@@ -28,7 +28,8 @@ export interface DashViewSpec {
28
28
 
29
29
  /**
30
30
  * Group name to display within the add view component. The default context menu will
31
- * automatically group its available views if provided.
31
+ * automatically group its available views if provided. Separate names with '/' to nest
32
+ * groups - e.g. `Charts/Line`.
32
33
  */
33
34
  groupName?: string;
34
35
 
@@ -78,7 +78,7 @@ DashViewSpec (base interface)
78
78
  ├── content: Content # Rendered content
79
79
  ├── title: string # Default title (defaults to startCase(id))
80
80
  ├── icon: ReactElement # Default icon
81
- ├── groupName: string # Menu grouping
81
+ ├── groupName: string # Menu grouping, '/' to nest
82
82
  ├── unique: boolean # Allow multiple instances?
83
83
  ├── allowAdd/Remove/Rename # Permission flags
84
84
  └── omit: Thunkable<boolean> # Exclude from dashboard
@@ -367,9 +367,10 @@ canvasModel.isEmpty; // No widgets?
367
367
  view specs for a `DashCanvas`. Users can drag widgets from the chooser and drop them onto the
368
368
  canvas. It is typically placed inside a collapsible panel alongside the canvas.
369
369
 
370
- Available view specs are listed in their defined order, grouped by their `groupName` property
371
- if present. Specs with `unique: true` that already have an instance on the canvas are
372
- automatically hidden from the chooser.
370
+ Available view specs are listed in their defined order, grouped into collapsible cards by their
371
+ `groupName` property if present - a slash-delimited name nests cards within cards. Specs with
372
+ `unique: true` that already have an instance on the canvas are automatically hidden from the
373
+ chooser.
373
374
 
374
375
  ### Requirements
375
376
 
@@ -413,7 +414,7 @@ Both dash types share these base properties on their ViewSpecs:
413
414
  | `content` | `Content` | View content to render. Required. |
414
415
  | `title` | `string` | Default display title. Defaults to `startCase(id)`. |
415
416
  | `icon` | `ReactElement` | Display icon. |
416
- | `groupName` | `string` | Group name for the "Add" menu — specs with the same group are nested into a submenu. |
417
+ | `groupName` | `string` | Group name for the "Add" menu - specs with the same group are nested into a submenu. Separate names with `/` to nest groups, e.g. `Charts/Line`. Each group is listed where its first spec appears. |
417
418
  | `omit` | `Thunkable<boolean>` | Skip this spec entirely. References in state are quietly dropped. Useful for role-based exclusion. Default `false`. |
418
419
  | `unique` | `boolean` | Only one instance allowed at a time. Default `false`. |
419
420
  | `allowAdd` | `boolean` | Can add new instances via the menu. Existing instances in state are still loaded. Default `true`. |
@@ -15,7 +15,7 @@ import {isEmpty} from 'lodash';
15
15
  * Context menu to add items to a DashCanvas
16
16
  *
17
17
  * Available view specs are listed in their defined order, optionally
18
- * grouped by their 'groupName' property
18
+ * grouped by their `groupName` property into (nested) submenus.
19
19
  * @internal
20
20
  */
21
21
  export const dashCanvasContextMenu = hoistCmp.factory({