@xh/hoist 73.0.0-SNAPSHOT.1744147015222 → 73.0.0-SNAPSHOT.1744206740883

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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## v73.0.0-SNAPSHOT - unreleased
4
4
 
5
+ ### 🎁 New Features
6
+
7
+ `ViewManagerConfig` takes new optional key `viewMenuItemFn` to allow ViewManager implementations to customize
8
+ the menu items for views in the view manager menu.
9
+
5
10
  ### ⚙️ Technical
6
11
  * Added enhanced `ClientHealthService` for managing client health report.
7
12
 
@@ -1,5 +1,6 @@
1
1
  import { HoistModel, LoadSpec, PlainObject, TaskObserver, Thunkable } from '@xh/hoist/core';
2
2
  import type { ViewManagerProvider } from '@xh/hoist/core';
3
+ import { ReactNode } from 'react';
3
4
  import { ViewInfo } from './ViewInfo';
4
5
  import { View } from './View';
5
6
  export interface ViewCreateSpec {
@@ -85,6 +86,11 @@ export interface ViewManagerConfig {
85
86
  * Optional user-facing display name for describing global views. Defaults to 'global'
86
87
  */
87
88
  globalDisplayName?: string;
89
+ /**
90
+ * Optional key to pass a method that returns a customized BlueprintJS `menuItem` for listing
91
+ * views in the ViewManager menu.
92
+ */
93
+ viewMenuItemFn?: (view: ViewInfo, model: ViewManagerModel) => ReactNode;
88
94
  }
89
95
  /**
90
96
  * ViewManagerModel coordinates the loading, saving, and management of user-defined bundles of
@@ -121,6 +127,7 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
121
127
  readonly instance: string;
122
128
  readonly typeDisplayName: string;
123
129
  readonly globalDisplayName: string;
130
+ readonly viewMenuItemFn: (view: ViewInfo, model: ViewManagerModel) => ReactNode;
124
131
  readonly enableAutoSave: boolean;
125
132
  readonly enableDefault: boolean;
126
133
  readonly enableGlobal: boolean;
@@ -123,6 +123,12 @@ export interface ViewManagerConfig {
123
123
  * Optional user-facing display name for describing global views. Defaults to 'global'
124
124
  */
125
125
  globalDisplayName?: string;
126
+
127
+ /**
128
+ * Optional key to pass a method that returns a customized BlueprintJS `menuItem` for listing
129
+ * views in the ViewManager menu.
130
+ */
131
+ viewMenuItemFn?: (view: ViewInfo, model: ViewManagerModel) => ReactNode;
126
132
  }
127
133
 
128
134
  /**
@@ -165,6 +171,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
165
171
  readonly instance: string;
166
172
  readonly typeDisplayName: string;
167
173
  readonly globalDisplayName: string;
174
+ readonly viewMenuItemFn: (view: ViewInfo, model: ViewManagerModel) => ReactNode;
168
175
  readonly enableAutoSave: boolean;
169
176
  readonly enableDefault: boolean;
170
177
  readonly enableGlobal: boolean;
@@ -283,6 +290,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
283
290
  instance = 'default',
284
291
  typeDisplayName,
285
292
  globalDisplayName = 'global',
293
+ viewMenuItemFn,
286
294
  manageGlobal = false,
287
295
  enableAutoSave = true,
288
296
  enableDefault = true,
@@ -296,13 +304,14 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
296
304
 
297
305
  throwIf(
298
306
  !enableDefault && !initialViewSpec,
299
- "ViewManagerModel requires 'initialViewSpec' if `enableDefault` is false."
307
+ "ViewManagerModel requires 'initialViewSpec' if 'enableDefault' is false."
300
308
  );
301
309
 
302
310
  this.type = type;
303
311
  this.instance = instance;
304
312
  this.typeDisplayName = lowerCase(typeDisplayName ?? genDisplayName(type));
305
313
  this.globalDisplayName = globalDisplayName;
314
+ this.viewMenuItemFn = viewMenuItemFn;
306
315
  this.manageGlobal = executeIfFunction(manageGlobal) ?? false;
307
316
  this.enableDefault = enableDefault;
308
317
  this.enableGlobal = enableGlobal;
@@ -12,7 +12,7 @@ import {Icon} from '@xh/hoist/icon';
12
12
  import {menu, menuDivider, menuItem} from '@xh/hoist/kit/blueprint';
13
13
  import {pluralize} from '@xh/hoist/utils/js';
14
14
  import {Dictionary} from 'express-serve-static-core';
15
- import {each, filter, groupBy, isEmpty, orderBy, some, startCase} from 'lodash';
15
+ import {each, filter, groupBy, isEmpty, isFunction, orderBy, some, startCase} from 'lodash';
16
16
  import {ReactNode} from 'react';
17
17
  import {ViewManagerLocalModel} from './ViewManagerLocalModel';
18
18
 
@@ -162,12 +162,14 @@ function viewMenuItem(view: ViewInfo, model: ViewManagerModel): ReactNode {
162
162
  if (!view.isOwned && view.owner) title.push(view.owner);
163
163
  if (view.description) title.push(view.description);
164
164
 
165
- return menuItem({
166
- className: 'xh-view-manager__menu-item',
167
- key: view.token,
168
- text: view.name,
169
- title: title.join(' | '),
170
- icon,
171
- onClick: () => model.selectViewAsync(view).catchDefault()
172
- });
165
+ return isFunction(model.viewMenuItemFn)
166
+ ? model.viewMenuItemFn(view, model)
167
+ : menuItem({
168
+ className: 'xh-view-manager__menu-item',
169
+ key: view.token,
170
+ text: view.name,
171
+ title: title.join(' | '),
172
+ icon,
173
+ onClick: () => model.selectViewAsync(view).catchDefault()
174
+ });
173
175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "73.0.0-SNAPSHOT.1744147015222",
3
+ "version": "73.0.0-SNAPSHOT.1744206740883",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",