Add storage key for viewlet view options (#7545)

* add storage key for viewlet view options

Signed-off-by: Nikolay Chunosov <Chunosov.N@gmail.com>

* load view options from old key when there is no new one

Signed-off-by: Nikolay Chunosov <Chunosov.N@gmail.com>

---------

Signed-off-by: Nikolay Chunosov <Chunosov.N@gmail.com>
This commit is contained in:
Chunosov 2024-12-25 14:43:25 +07:00 committed by GitHub
parent 9672f5064e
commit 118ede7388
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 10 deletions

View File

@ -361,7 +361,8 @@ export function createModel (builder: Builder): void {
viewOptions: { viewOptions: {
groupBy: [], groupBy: [],
orderBy: [], orderBy: [],
other: [vacancyHideArchivedOption] other: [vacancyHideArchivedOption],
storageKey: 'vacancyViewOptions'
} }
}, },
recruit.viewlet.TableVacancy recruit.viewlet.TableVacancy
@ -502,7 +503,8 @@ export function createModel (builder: Builder): void {
viewOptions: { viewOptions: {
groupBy: [], groupBy: [],
orderBy: [], orderBy: [],
other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption] other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption],
storageKey: 'applicantViewOptions'
} }
}, },
recruit.viewlet.ApplicantTable recruit.viewlet.ApplicantTable
@ -559,7 +561,8 @@ export function createModel (builder: Builder): void {
action: view.function.ShowEmptyGroups, action: view.function.ShowEmptyGroups,
label: view.string.ShowEmptyGroups label: view.string.ShowEmptyGroups
} }
] ],
storageKey: 'applicantViewOptions'
} }
if (colors) { if (colors) {
model.other.push(showColorsViewOption) model.other.push(showColorsViewOption)
@ -784,7 +787,8 @@ export function createModel (builder: Builder): void {
['modifiedOn', SortingOrder.Descending], ['modifiedOn', SortingOrder.Descending],
['createdOn', SortingOrder.Descending] ['createdOn', SortingOrder.Descending]
], ],
other: [vacancyHideArchivedOption] other: [vacancyHideArchivedOption],
storageKey: 'vacancyViewOptions'
} }
}, },
recruit.viewlet.ListVacancy recruit.viewlet.ListVacancy

View File

@ -31,8 +31,11 @@ export function isDropdownType (viewOption: ViewOptionModel): viewOption is Drop
return viewOption.type === 'dropdown' return viewOption.type === 'dropdown'
} }
export function makeViewOptionsKey (viewlet: Ref<Viewlet>, variant?: string): string { function makeViewOptionsKey (viewlet: Viewlet, variant?: string, ignoreViewletKey = false): string {
const prefix = viewlet + (variant !== undefined ? `-${variant}` : '') const prefix =
viewlet.viewOptions?.storageKey !== undefined && !ignoreViewletKey
? viewlet.viewOptions.storageKey
: viewlet._id + (variant !== undefined ? `-${variant}` : '')
const loc = getCurrentResolvedLocation() const loc = getCurrentResolvedLocation()
loc.fragment = undefined loc.fragment = undefined
loc.query = undefined loc.query = undefined
@ -40,7 +43,7 @@ export function makeViewOptionsKey (viewlet: Ref<Viewlet>, variant?: string): st
} }
export function setViewOptions (viewlet: Viewlet, options: ViewOptions): void { 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)) localStorage.setItem(key, JSON.stringify(options))
setStore(key, options) setStore(key, options)
} }
@ -52,13 +55,19 @@ function setStore (key: string, options: ViewOptions): void {
} }
function _getViewOptions (viewlet: Viewlet, viewOptionStore: Map<string, ViewOptions>): ViewOptions | null { function _getViewOptions (viewlet: Viewlet, viewOptionStore: Map<string, ViewOptions>): ViewOptions | null {
const key = makeViewOptionsKey(viewlet._id, viewlet.variant) const key = makeViewOptionsKey(viewlet, viewlet.variant)
const store = viewOptionStore.get(key) const store = viewOptionStore.get(key)
if (store !== undefined) { if (store !== undefined) {
return store return store
} }
const options = localStorage.getItem(key) let options = localStorage.getItem(key)
if (options === null) return null if (options === null) {
const key = makeViewOptionsKey(viewlet, viewlet.variant, true)
options = localStorage.getItem(key)
if (options === null) {
return null
}
}
const res = JSON.parse(options) const res = JSON.parse(options)
setStore(key, res) setStore(key, res)
return res return res

View File

@ -794,6 +794,7 @@ export interface ViewOptionsModel {
orderBy: OrderOption[] orderBy: OrderOption[]
other: ViewOptionModel[] other: ViewOptionModel[]
groupDepth?: number groupDepth?: number
storageKey?: string
} }
/** /**