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

Signed-off-by: Nikolay Chunosov <Chunosov.N@gmail.com>
This commit is contained in:
Nikolay Chunosov 2024-12-25 13:11:07 +07:00
parent e676b75e7f
commit d7768adea2

View File

@ -31,8 +31,11 @@ export function isDropdownType (viewOption: ViewOptionModel): viewOption is Drop
return viewOption.type === 'dropdown'
}
function makeViewOptionsKey (viewlet: Viewlet, variant?: string): string {
const prefix = viewlet.viewOptions?.storageKey ?? viewlet._id + (variant !== undefined ? `-${variant}` : '')
function makeViewOptionsKey (viewlet: Viewlet, variant?: string, ignoreViewletKey = false): string {
const prefix =
viewlet.viewOptions?.storageKey !== undefined && !ignoreViewletKey
? viewlet.viewOptions.storageKey
: viewlet._id + (variant !== undefined ? `-${variant}` : '')
const loc = getCurrentResolvedLocation()
loc.fragment = undefined
loc.query = undefined
@ -57,8 +60,14 @@ function _getViewOptions (viewlet: Viewlet, viewOptionStore: Map<string, ViewOpt
if (store !== undefined) {
return store
}
const options = localStorage.getItem(key)
if (options === null) return null
let options = localStorage.getItem(key)
if (options === null) {
const key = makeViewOptionsKey(viewlet, viewlet.variant, true)
options = localStorage.getItem(key)
if (options === null) {
return null
}
}
const res = JSON.parse(options)
setStore(key, res)
return res