Skip to content

Commit

Permalink
Minor fixes to Views (#3879)
Browse files Browse the repository at this point in the history
* Checkpoint

* Checkpoint
  • Loading branch information
lbwexler authored Dec 30, 2024
1 parent fad641c commit 0ee190e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
32 changes: 5 additions & 27 deletions cmp/viewmanager/DataAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean>;
autoSave: boolean;
}
import {ViewManagerModel, ViewUserState, ViewUpdateSpec, ViewCreateSpec} from './ViewManagerModel';

/**
* Supporting class for accessing and updating ViewManager and View data.
Expand Down Expand Up @@ -100,7 +78,7 @@ export class DataAccess<T> {
try {
this.ensureEditable(view);
const raw = await XH.postJson({
url: 'xhView/updateViewInfo',
url: 'xhView/updateInfo',
params: {token: view.token},
body: updates
});
Expand Down Expand Up @@ -157,9 +135,9 @@ export class DataAccess<T> {
//--------------------------
// State related changes
//--------------------------
async updateStateAsync(update: Partial<ViewUserState>) {
async updateStateAsync(update: Partial<ViewUserState>): Promise<ViewUserState> {
const {type, instance} = this.model;
await XH.postJson({
return XH.postJson({
url: 'xhView/updateState',
params: {type, viewInstance: instance},
body: update
Expand Down
32 changes: 25 additions & 7 deletions cmp/viewmanager/ViewManagerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean>;
autoSave: boolean;
}

export interface ViewManagerConfig {
/**
Expand Down Expand Up @@ -338,9 +361,8 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
}

async saveAsAsync(spec: ViewCreateSpec): Promise<void> {
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);
}

Expand Down Expand Up @@ -404,10 +426,6 @@ export class ViewManagerModel<T = PlainObject> 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};
Expand Down
2 changes: 0 additions & 2 deletions desktop/cmp/viewmanager/ViewMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function getOtherMenuItems(model: ViewManagerLocalModel): ReactNode[] {
autoSaveUnavailableReason,
autoSave,
isViewSavable,
views,
isValueDirty,
typeDisplayName
} = parent;
Expand Down Expand Up @@ -119,7 +118,6 @@ function getOtherMenuItems(model: ViewManagerLocalModel): ReactNode[] {
menuDivider(),
menuItem({
icon: Icon.gear(),
disabled: isEmpty(views),
text: `Manage ${pluralName}...`,
onClick: () => model.manageDialogModel.open()
})
Expand Down
4 changes: 3 additions & 1 deletion desktop/cmp/viewmanager/dialog/SaveAsDialogModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});
}
}

0 comments on commit 0ee190e

Please sign in to comment.