From 0ee190e3dcb6e42c7d8a02a7450f0111244f448c Mon Sep 17 00:00:00 2001 From: Lee Wexler Date: Mon, 30 Dec 2024 14:32:14 -0500 Subject: [PATCH] Minor fixes to Views (#3879) * Checkpoint * Checkpoint --- cmp/viewmanager/DataAccess.ts | 32 +++---------------- cmp/viewmanager/ViewManagerModel.ts | 32 +++++++++++++++---- desktop/cmp/viewmanager/ViewMenu.ts | 2 -- .../viewmanager/dialog/SaveAsDialogModel.ts | 4 ++- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/cmp/viewmanager/DataAccess.ts b/cmp/viewmanager/DataAccess.ts index 1efc65062..a27276df6 100644 --- a/cmp/viewmanager/DataAccess.ts +++ b/cmp/viewmanager/DataAccess.ts @@ -5,34 +5,12 @@ * Copyright © 2025 Extremely Heavy Industries Inc. */ -import {PlainObject, XH} from '@xh/hoist/core'; +import {XH} from '@xh/hoist/core'; import {pluralize, throwIf} from '@xh/hoist/utils/js'; import {map} from 'lodash'; import {ViewInfo} from './ViewInfo'; import {View} from './View'; -import {ViewManagerModel} from './ViewManagerModel'; - -export interface ViewCreateSpec { - name: string; - group: string; - description: string; - isShared: boolean; - value?: PlainObject; -} - -export interface ViewUpdateSpec { - name: string; - group: string; - description: string; - isShared?: boolean; - isDefaultPinned?: boolean; -} - -export interface ViewUserState { - currentView?: string; - userPinned: Record; - autoSave: boolean; -} +import {ViewManagerModel, ViewUserState, ViewUpdateSpec, ViewCreateSpec} from './ViewManagerModel'; /** * Supporting class for accessing and updating ViewManager and View data. @@ -100,7 +78,7 @@ export class DataAccess { try { this.ensureEditable(view); const raw = await XH.postJson({ - url: 'xhView/updateViewInfo', + url: 'xhView/updateInfo', params: {token: view.token}, body: updates }); @@ -157,9 +135,9 @@ export class DataAccess { //-------------------------- // State related changes //-------------------------- - async updateStateAsync(update: Partial) { + async updateStateAsync(update: Partial): Promise { const {type, instance} = this.model; - await XH.postJson({ + return XH.postJson({ url: 'xhView/updateState', params: {type, viewInstance: instance}, body: update diff --git a/cmp/viewmanager/ViewManagerModel.ts b/cmp/viewmanager/ViewManagerModel.ts index 205af0e95..ef86b7939 100644 --- a/cmp/viewmanager/ViewManagerModel.ts +++ b/cmp/viewmanager/ViewManagerModel.ts @@ -25,7 +25,30 @@ import {find, isEqual, isNil, isNull, isUndefined, lowerCase} from 'lodash'; import {ReactNode} from 'react'; import {ViewInfo} from './ViewInfo'; import {View} from './View'; -import {DataAccess, ViewCreateSpec, ViewUpdateSpec, ViewUserState} from './DataAccess'; +import {DataAccess} from './DataAccess'; + +export interface ViewCreateSpec { + name: string; + group: string; + description: string; + isShared: boolean; + isPinned: boolean; + value: PlainObject; +} + +export interface ViewUpdateSpec { + name: string; + group: string; + description: string; + isShared?: boolean; + isDefaultPinned?: boolean; +} + +export interface ViewUserState { + currentView?: string; + userPinned: Record; + autoSave: boolean; +} export interface ViewManagerConfig { /** @@ -338,9 +361,8 @@ export class ViewManagerModel extends HoistModel { } async saveAsAsync(spec: ViewCreateSpec): Promise { - const view = await this.dataAccess.createViewAsync({...spec, value: this.getValue()}); + const view = await this.dataAccess.createViewAsync(spec); this.noteSuccess(`Created ${view.typedName}`); - this.userPin(view.info); this.setAsView(view); } @@ -404,10 +426,6 @@ export class ViewManagerModel extends HoistModel { //------------------ // Pinning //------------------ - togglePinned(view: ViewInfo) { - view.isPinned ? this.userUnpin(view) : this.userPin(view); - } - @action userPin(view: ViewInfo) { this.userPinned = {...this.userPinned, [view.token]: true}; diff --git a/desktop/cmp/viewmanager/ViewMenu.ts b/desktop/cmp/viewmanager/ViewMenu.ts index 7dd1bde11..3156c2962 100644 --- a/desktop/cmp/viewmanager/ViewMenu.ts +++ b/desktop/cmp/viewmanager/ViewMenu.ts @@ -78,7 +78,6 @@ function getOtherMenuItems(model: ViewManagerLocalModel): ReactNode[] { autoSaveUnavailableReason, autoSave, isViewSavable, - views, isValueDirty, typeDisplayName } = parent; @@ -119,7 +118,6 @@ function getOtherMenuItems(model: ViewManagerLocalModel): ReactNode[] { menuDivider(), menuItem({ icon: Icon.gear(), - disabled: isEmpty(views), text: `Manage ${pluralName}...`, onClick: () => model.manageDialogModel.open() }) diff --git a/desktop/cmp/viewmanager/dialog/SaveAsDialogModel.ts b/desktop/cmp/viewmanager/dialog/SaveAsDialogModel.ts index 3d348223a..43f6b57f3 100644 --- a/desktop/cmp/viewmanager/dialog/SaveAsDialogModel.ts +++ b/desktop/cmp/viewmanager/dialog/SaveAsDialogModel.ts @@ -86,7 +86,9 @@ export class SaveAsDialogModel extends HoistModel { name: name.trim(), group: group?.trim(), description: description?.trim(), - isShared + isPinned: true, + isShared, + value: parent.getValue() }); } }