@xh/hoist 71.0.0-SNAPSHOT.1736188078116 → 71.0.0-SNAPSHOT.1736191971390

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.
@@ -15,7 +15,7 @@ export declare class DataAccess<T> {
15
15
  state: ViewUserState;
16
16
  }>;
17
17
  /** Fetch the latest version of a view. */
18
- fetchViewAsync(info: ViewInfo): Promise<View<T>>;
18
+ fetchViewAsync(token: String): Promise<View<T>>;
19
19
  /** Create a new view, owned by the current user.*/
20
20
  createViewAsync(spec: ViewCreateSpec): Promise<View<T>>;
21
21
  /** Update all aspects of a view's metadata.*/
@@ -183,9 +183,7 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
183
183
  */
184
184
  private constructor();
185
185
  doLoadAsync(loadSpec: LoadSpec): Promise<void>;
186
- selectViewAsync(info: ViewInfo, opts?: {
187
- alertUnsavedChanges: boolean;
188
- }): Promise<void>;
186
+ selectViewAsync(token: string): Promise<void>;
189
187
  saveAsAsync(spec: ViewCreateSpec): Promise<void>;
190
188
  saveAsync(): Promise<void>;
191
189
  resetAsync(): Promise<void>;
@@ -48,14 +48,14 @@ export class DataAccess<T> {
48
48
  }
49
49
 
50
50
  /** Fetch the latest version of a view. */
51
- async fetchViewAsync(info: ViewInfo): Promise<View<T>> {
51
+ async fetchViewAsync(token: String): Promise<View<T>> {
52
52
  const {model} = this;
53
- if (!info) return View.createDefault(model);
53
+ if (!token) return View.createDefault(model);
54
54
  try {
55
- const raw = await XH.fetchJson({url: 'xhView/get', params: {token: info.token}});
55
+ const raw = await XH.fetchJson({url: 'xhView/get', params: {token}});
56
56
  return View.fromBlob(raw, model);
57
57
  } catch (e) {
58
- throw XH.exception({message: `Unable to fetch ${info.typedName}`, cause: e});
58
+ throw XH.exception({message: `Unable to fetch view with token ${token}`, cause: e});
59
59
  }
60
60
  }
61
61
 
@@ -21,7 +21,7 @@ import {fmtDateTime} from '@xh/hoist/format';
21
21
  import {action, bindable, makeObservable, observable, comparer, runInAction} from '@xh/hoist/mobx';
22
22
  import {olderThan, SECONDS} from '@xh/hoist/utils/datetime';
23
23
  import {executeIfFunction, pluralize, throwIf} from '@xh/hoist/utils/js';
24
- import {find, isEqual, isNil, isNull, isUndefined, lowerCase, uniqBy} from 'lodash';
24
+ import {find, isEqual, isNil, isNull, isUndefined, lowerCase} from 'lodash';
25
25
  import {ReactNode} from 'react';
26
26
  import {ViewInfo} from './ViewInfo';
27
27
  import {View} from './View';
@@ -337,7 +337,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
337
337
  if (!view.isDefault) {
338
338
  const latestInfo = find(views, {token: view.token});
339
339
  if (latestInfo && latestInfo.lastUpdated > view.lastUpdated) {
340
- this.loadViewAsync(latestInfo, this.pendingValue);
340
+ this.loadViewAsync(view.token, this.pendingValue);
341
341
  }
342
342
  }
343
343
  } catch (e) {
@@ -346,23 +346,18 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
346
346
  }
347
347
  }
348
348
 
349
- async selectViewAsync(info: ViewInfo, opts = {alertUnsavedChanges: true}): Promise<void> {
349
+ async selectViewAsync(token: string): Promise<void> {
350
350
  // ensure any pending auto-save gets completed
351
351
  if (this.isValueDirty && this.isViewAutoSavable) {
352
352
  await this.maybeAutoSaveAsync();
353
353
  }
354
354
 
355
355
  // if still dirty, require confirm
356
- if (
357
- opts.alertUnsavedChanges &&
358
- this.isValueDirty &&
359
- this.view.isOwned &&
360
- !(await this.confirmDiscardChangesAsync())
361
- ) {
356
+ if (this.isValueDirty && this.view.isOwned && !(await this.confirmDiscardChangesAsync())) {
362
357
  return;
363
358
  }
364
359
 
365
- await this.loadViewAsync(info).catch(e => this.handleException(e));
360
+ return this.loadViewAsync(token);
366
361
  }
367
362
 
368
363
  async saveAsAsync(spec: ViewCreateSpec): Promise<void> {
@@ -399,7 +394,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
399
394
  }
400
395
 
401
396
  async resetAsync(): Promise<void> {
402
- await this.loadViewAsync(this.view.info).catch(e => this.handleException(e));
397
+ await this.loadViewAsync(this.view.info.token).catch(e => this.handleException(e));
403
398
  }
404
399
 
405
400
  //--------------------------------
@@ -483,7 +478,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
483
478
  const {views} = this;
484
479
 
485
480
  if (toDelete.some(view => view.isCurrentView) && !views.some(view => view.isCurrentView)) {
486
- await this.loadViewAsync(this.initialViewSpec?.(views));
481
+ await this.loadViewAsync(this.initialViewSpec?.(views)?.token);
487
482
  }
488
483
 
489
484
  if (exception) throw exception;
@@ -569,13 +564,13 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
569
564
  }
570
565
 
571
566
  private async loadViewAsync(
572
- info: ViewInfo,
567
+ token: String,
573
568
  pendingValue: PendingValue<T> = null
574
569
  ): Promise<void> {
575
570
  return this.dataAccess
576
- .fetchViewAsync(info)
571
+ .fetchViewAsync(token)
577
572
  .thenAction(latest => {
578
- this.setAsView(latest, pendingValue?.token == info?.token ? pendingValue : null);
573
+ this.setAsView(latest, pendingValue?.token == token ? pendingValue : null);
579
574
  this.providers.forEach(it => it.pushStateToTarget());
580
575
  this.lastPushed = Date.now();
581
576
  })
@@ -609,7 +604,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
609
604
  this.pendingValue = pendingValue;
610
605
  // Ensure we update meta-data as well.
611
606
  if (!view.isDefault) {
612
- this.views = uniqBy([view.info, ...this.views], 'token');
607
+ this.views = this.views.map(v => (v.token === view.token ? view.info : v));
613
608
  }
614
609
  }
615
610
 
@@ -649,7 +644,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
649
644
 
650
645
  private async maybeConfirmSaveAsync(view: View, pendingValue: PendingValue<T>) {
651
646
  // Get latest from server for reference
652
- const latest = await this.dataAccess.fetchViewAsync(view.info),
647
+ const latest = await this.dataAccess.fetchViewAsync(view.info.token),
653
648
  isGlobal = latest.isGlobal,
654
649
  isStale = latest.lastUpdated > pendingValue.baseUpdated;
655
650
  if (!isStale && !isGlobal) return true;
@@ -63,7 +63,7 @@ function getNavMenuItems(model: ViewManagerModel): ReactNode[] {
63
63
  className: 'xh-view-manager__menu-item',
64
64
  icon: view.isDefault ? Icon.check() : Icon.placeholder(),
65
65
  text: `Default ${startCase(typeDisplayName)}`,
66
- onClick: () => model.selectViewAsync(null)
66
+ onClick: () => model.selectViewAsync(null).catchDefault()
67
67
  })
68
68
  );
69
69
  }
@@ -168,6 +168,6 @@ function viewMenuItem(view: ViewInfo, model: ViewManagerModel): ReactNode {
168
168
  text: view.name,
169
169
  title: title.join(' | '),
170
170
  icon,
171
- onClick: () => model.selectViewAsync(view)
171
+ onClick: () => model.selectViewAsync(view.token).catchDefault()
172
172
  });
173
173
  }
@@ -86,7 +86,7 @@ export class ManageDialogModel extends HoistModel {
86
86
  }
87
87
 
88
88
  activateSelectedViewAndClose() {
89
- this.viewManagerModel.selectViewAsync(this.selectedView);
89
+ this.viewManagerModel.selectViewAsync(this.selectedView.token).catchDefault();
90
90
  this.close();
91
91
  }
92
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "71.0.0-SNAPSHOT.1736188078116",
3
+ "version": "71.0.0-SNAPSHOT.1736191971390",
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",