Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View state storage #746

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions client-app/src/admin/tests/viewmanager/ViewManagerTestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ export class ViewManagerTestModel extends HoistModel {
.map(it => it.name);
return [
'type',
'instance',
'typeDisplayName',
'globalDisplayName',
'localStorageKey',
'sessionStorageKey',
'manageGlobal',
'enableGlobal',
'enableSharing',
Expand All @@ -96,10 +95,9 @@ export class ViewManagerTestModel extends HoistModel {
this.configFormModel = new FormModel({
fields: [
{name: 'type', rules: [required], initialValue: 'testView'},
{name: 'instance', rules: [required], initialValue: 'default'},
{name: 'typeDisplayName', initialValue: 'view'},
{name: 'globalDisplayName', initialValue: 'global'},
{name: 'localStorageKey', initialValue: 'viewManagerTest'},
{name: 'sessionStorageKey', initialValue: 'viewManagerTest'},
{name: 'manageGlobal', initialValue: true},
{name: 'enableGlobal', initialValue: true},
{name: 'enableSharing', initialValue: true},
Expand Down Expand Up @@ -129,10 +127,9 @@ export class ViewManagerTestModel extends HoistModel {
const data = configFormModel.getData(),
{
type,
instance,
typeDisplayName,
globalDisplayName,
localStorageKey,
sessionStorageKey,
manageGlobal,
enableGlobal,
enableSharing,
Expand All @@ -142,23 +139,16 @@ export class ViewManagerTestModel extends HoistModel {
settleTime
} = data;

const persistWith = localStorageKey
? {
localStorageKey,
persistPendingValue: sessionStorageKey ? {sessionStorageKey} : false
}
: null;

const newModel = await ViewManagerModel.createAsync({
type,
instance,
typeDisplayName,
globalDisplayName,
manageGlobal,
enableGlobal,
enableSharing,
enableDefault,
enableAutoSave,
persistWith,
settleTime,
initialViewSpec: views => views.find(v => v.name == initialViewName) ?? views[0]
});
Expand Down Expand Up @@ -186,10 +176,7 @@ export class ViewManagerTestModel extends HoistModel {
const persistWith = {viewManagerModel: this.viewManagerModel};

this.groupingChooserModel = createGroupingChooserModel(persistWith);
this.filterChooserModel = createFilterChooserModel(
persistWith,
this.configFormModel.values.localStorageKey
);
this.filterChooserModel = createFilterChooserModel(persistWith);

this.tabContainerModel = new TabContainerModel({
persistWith,
Expand Down Expand Up @@ -320,10 +307,6 @@ class BaseWidgetModel extends HoistModel {
return this.vmtModel.viewManagerModel;
}

get localStorageKey(): string {
return this.vmtModel.configFormModel.values.localStorageKey;
}

override onLinked() {
super.onLinked();
this.persistWith = {dashViewModel: this.dashViewModel};
Expand Down Expand Up @@ -359,7 +342,7 @@ class FilterChooserWidgetModel extends BaseWidgetModel {

override onLinked() {
super.onLinked();
this.filterChooserModel = createFilterChooserModel(this.persistWith, this.localStorageKey);
this.filterChooserModel = createFilterChooserModel(this.persistWith);
}
}

Expand All @@ -370,11 +353,11 @@ const filterChooserWidget = hoistCmp.factory({
}
});

const createFilterChooserModel = (persistWith: PersistOptions, localStorageKey: string) => {
const createFilterChooserModel = (persistWith: PersistOptions) => {
return new FilterChooserModel({
persistWith: {
persistValue: persistWith,
persistFavorites: localStorageKey ? {localStorageKey: localStorageKey} : null
persistFavorites: {localStorageKey: 'filterChooserFavorites'}
},
fieldSpecs: [
{field: 'color', values: ['green', 'blue', 'red']},
Expand Down
13 changes: 4 additions & 9 deletions client-app/src/admin/tests/viewmanager/ViewManagerTestPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,15 @@ const modelConfig = hoistCmp.factory({
item: textInput()
}),
formField({
field: 'typeDisplayName',
item: textInput({enableClear: true})
}),
formField({
field: 'globalDisplayName',
item: textInput({enableClear: true})
field: 'instance',
item: textInput()
}),
formField({
field: 'localStorageKey',
field: 'typeDisplayName',
item: textInput({enableClear: true})
}),
formField({
field: 'sessionStorageKey',
info: 'If set, will persist pendingValue',
field: 'globalDisplayName',
item: textInput({enableClear: true})
}),
formField({
Expand Down
3 changes: 1 addition & 2 deletions client-app/src/examples/portfolio/AppModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export class AppModel extends BaseAppModel {
type: 'portfolioLayout',
typeDisplayName: 'Layout',
enableDefault: true,
manageGlobal: true,
persistWith: {localStorageKey: 'portfolioViewManager'}
manageGlobal: XH.getUser().isHoistAdmin
});

this.addReaction({
Expand Down
Loading