Use patches when updating homescreens
This commit is contained in:
parent
c24c5b2861
commit
6b85700fff
|
@ -21,6 +21,7 @@ import {
|
||||||
} from "../componentUtils"
|
} from "../componentUtils"
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
import { DefaultAppTheme, LAYOUT_NAMES } from "../../constants"
|
import { DefaultAppTheme, LAYOUT_NAMES } from "../../constants"
|
||||||
|
import { Utils } from "@budibase/frontend-core"
|
||||||
|
|
||||||
const INITIAL_FRONTEND_STATE = {
|
const INITIAL_FRONTEND_STATE = {
|
||||||
apps: [],
|
apps: [],
|
||||||
|
@ -228,14 +229,16 @@ export const getFrontendStore = () => {
|
||||||
})
|
})
|
||||||
return savedScreen
|
return savedScreen
|
||||||
},
|
},
|
||||||
patch: async (screenId, patch) => {
|
patch: Utils.sequential(async (screenId, patchFn) => {
|
||||||
const state = get(store)
|
const state = get(store)
|
||||||
const screen = state.screens.find(screen => screen._id === screenId)
|
const screen = state.screens.find(screen => screen._id === screenId)
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return store.actions.screens.save({ ...screen, ...patch })
|
let clone = cloneDeep(screen)
|
||||||
},
|
patchFn(clone)
|
||||||
|
return await store.actions.screens.save(clone)
|
||||||
|
}),
|
||||||
delete: async screens => {
|
delete: async screens => {
|
||||||
const screensToDelete = Array.isArray(screens) ? screens : [screens]
|
const screensToDelete = Array.isArray(screens) ? screens : [screens]
|
||||||
|
|
||||||
|
@ -291,14 +294,16 @@ export const getFrontendStore = () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if (existingHomeScreen) {
|
if (existingHomeScreen) {
|
||||||
existingHomeScreen.routing.homeScreen = false
|
const patchFn = screen => (screen.routing.homeScreen = false)
|
||||||
promises.push(store.actions.screens.save(existingHomeScreen))
|
promises.push(
|
||||||
|
store.actions.screens.patch(existingHomeScreen._id, patchFn)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the passed in screen
|
// Update the passed in screen
|
||||||
screen.routing.homeScreen = makeHomeScreen
|
const patchFn = screen => (screen.routing.homeScreen = makeHomeScreen)
|
||||||
promises.push(store.actions.screens.save(screen))
|
promises.push(store.actions.screens.patch(screen._id, patchFn))
|
||||||
return await Promise.all(promises)
|
return await Promise.all(promises)
|
||||||
},
|
},
|
||||||
removeCustomLayout: async screen => {
|
removeCustomLayout: async screen => {
|
||||||
|
|
Loading…
Reference in New Issue