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

Add storage key for viewlet view options #7545

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 8 additions & 4 deletions models/recruit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ export function createModel (builder: Builder): void {
viewOptions: {
groupBy: [],
orderBy: [],
other: [vacancyHideArchivedOption]
other: [vacancyHideArchivedOption],
storageKey: 'vacancyViewOptions'
}
},
recruit.viewlet.TableVacancy
Expand Down Expand Up @@ -502,7 +503,8 @@ export function createModel (builder: Builder): void {
viewOptions: {
groupBy: [],
orderBy: [],
other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption]
other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption],
storageKey: 'applicantViewOptions'
}
},
recruit.viewlet.ApplicantTable
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions plugins/view-resources/src/viewOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ export function isDropdownType (viewOption: ViewOptionModel): viewOption is Drop
return viewOption.type === 'dropdown'
}

export function makeViewOptionsKey (viewlet: Ref<Viewlet>, variant?: string): string {
const prefix = viewlet + (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
return `viewOptions:${prefix}:${locationToUrl(loc)}`
}

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)
}
Expand All @@ -52,13 +55,19 @@ function setStore (key: string, options: ViewOptions): void {
}

function _getViewOptions (viewlet: Viewlet, viewOptionStore: Map<string, ViewOptions>): ViewOptions | null {
const key = makeViewOptionsKey(viewlet._id, viewlet.variant)
haiodo marked this conversation as resolved.
Show resolved Hide resolved
const key = makeViewOptionsKey(viewlet, viewlet.variant)
const store = viewOptionStore.get(key)
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
Expand Down
1 change: 1 addition & 0 deletions plugins/view/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ export interface ViewOptionsModel {
orderBy: OrderOption[]
other: ViewOptionModel[]
groupDepth?: number
storageKey?: string
}

/**
Expand Down
Loading