From e676b75e7fdcf136d06d95e5cc0d29b8dc40237a Mon Sep 17 00:00:00 2001 From: Nikolay Chunosov Date: Tue, 24 Dec 2024 23:48:15 +0700 Subject: [PATCH] add storage key for viewlet view options Signed-off-by: Nikolay Chunosov --- models/recruit/src/index.ts | 12 ++++++++---- plugins/view-resources/src/viewOptions.ts | 8 ++++---- plugins/view/src/types.ts | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index 003de31209..0d01744fff 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -361,7 +361,8 @@ export function createModel (builder: Builder): void { viewOptions: { groupBy: [], orderBy: [], - other: [vacancyHideArchivedOption] + other: [vacancyHideArchivedOption], + storageKey: 'vacancyViewOptions' } }, recruit.viewlet.TableVacancy @@ -502,7 +503,8 @@ export function createModel (builder: Builder): void { viewOptions: { groupBy: [], orderBy: [], - other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption] + other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption], + storageKey: 'applicantViewOptions' } }, recruit.viewlet.ApplicantTable @@ -559,7 +561,8 @@ export function createModel (builder: Builder): void { action: view.function.ShowEmptyGroups, label: view.string.ShowEmptyGroups } - ] + ], + storageKey: 'applicantViewOptions' } if (colors) { model.other.push(showColorsViewOption) @@ -784,7 +787,8 @@ export function createModel (builder: Builder): void { ['modifiedOn', SortingOrder.Descending], ['createdOn', SortingOrder.Descending] ], - other: [vacancyHideArchivedOption] + other: [vacancyHideArchivedOption], + storageKey: 'vacancyViewOptions' } }, recruit.viewlet.ListVacancy diff --git a/plugins/view-resources/src/viewOptions.ts b/plugins/view-resources/src/viewOptions.ts index 6ca0e42bb4..dec09cddbb 100644 --- a/plugins/view-resources/src/viewOptions.ts +++ b/plugins/view-resources/src/viewOptions.ts @@ -31,8 +31,8 @@ export function isDropdownType (viewOption: ViewOptionModel): viewOption is Drop return viewOption.type === 'dropdown' } -export function makeViewOptionsKey (viewlet: Ref, variant?: string): string { - const prefix = viewlet + (variant !== undefined ? `-${variant}` : '') +function makeViewOptionsKey (viewlet: Viewlet, variant?: string): string { + const prefix = viewlet.viewOptions?.storageKey ?? viewlet._id + (variant !== undefined ? `-${variant}` : '') const loc = getCurrentResolvedLocation() loc.fragment = undefined loc.query = undefined @@ -40,7 +40,7 @@ export function makeViewOptionsKey (viewlet: Ref, variant?: string): st } export function setViewOptions (viewlet: Viewlet, options: ViewOptions): void { - const key = makeViewOptionsKey(viewlet._id, viewlet.variant) + const key = makeViewOptionsKey(viewlet, viewlet.variant) localStorage.setItem(key, JSON.stringify(options)) setStore(key, options) } @@ -52,7 +52,7 @@ function setStore (key: string, options: ViewOptions): void { } function _getViewOptions (viewlet: Viewlet, viewOptionStore: Map): ViewOptions | null { - const key = makeViewOptionsKey(viewlet._id, viewlet.variant) + const key = makeViewOptionsKey(viewlet, viewlet.variant) const store = viewOptionStore.get(key) if (store !== undefined) { return store diff --git a/plugins/view/src/types.ts b/plugins/view/src/types.ts index 3e343c6308..15586de1f6 100644 --- a/plugins/view/src/types.ts +++ b/plugins/view/src/types.ts @@ -794,6 +794,7 @@ export interface ViewOptionsModel { orderBy: OrderOption[] other: ViewOptionModel[] groupDepth?: number + storageKey?: string } /**