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

fix: ensures containers exist #842

Merged
merged 3 commits into from
Aug 22, 2022
Merged
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
26 changes: 8 additions & 18 deletions src/store/layout/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,16 @@ export const mutations: MutationTree<LayoutState> = {

for (const layout of migratableLayouts) {
const defaultComponents = defaultState.layouts[layout]
const existingComponents = Object.values(defaultComponents).flat().map(card => card.id)
const componentsInDB = Object.values(payload.layouts[layout]).flat().map(card => card.id)
const defaultComponentIds = Object.values(defaultComponents).flat().map(card => card.id)
const currentComponentIds = Object.values(payload.layouts[layout]).flat().map(card => card.id)

// add missing components
for (const [container, components] of Object.entries(defaultComponents)) {
for (const component of components) {
if (!componentsInDB.includes(component.id)) {
payload.layouts[layout][container].push(component)
}
}
}
for (const [container, defaultContainerComponents] of Object.entries(defaultComponents)) {
const currentContainerComponents = payload.layouts[layout][container] || []

// remove outdated components
for (const [container, components] of Object.entries(payload.layouts[layout])) {
for (const component of components) {
if (!existingComponents.includes(component.id)) {
const payloadContainer = payload.layouts[layout][container]
payloadContainer.splice(payloadContainer.indexOf(component), 1)
}
}
payload.layouts[layout][container] = [
...currentContainerComponents.filter(component => defaultComponentIds.includes(component.id)),
...defaultContainerComponents.filter(component => !currentComponentIds.includes(component.id))
]
}
}

Expand Down