Revert changes to updateAppPackage and attempt to do it another way
This commit is contained in:
parent
3d2f75d00d
commit
9059cf83c5
|
@ -199,26 +199,25 @@ async function addSampleDataScreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addSampleDataNavLinks() {
|
async function addSampleDataNavLinks() {
|
||||||
const appId = context.getAppId()
|
const db = context.getAppDB()
|
||||||
if (!appId) {
|
let app = await sdk.applications.metadata.get()
|
||||||
throw "Missing app ID"
|
if (!app.navigation) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
const addLinks = (app: App) => {
|
if (!app.navigation.links) {
|
||||||
if (!app.navigation) {
|
app.navigation.links = []
|
||||||
return app
|
|
||||||
}
|
|
||||||
if (!app.navigation.links) {
|
|
||||||
app.navigation.links = []
|
|
||||||
}
|
|
||||||
app.navigation.links.push({
|
|
||||||
text: "Inventory",
|
|
||||||
url: "/inventory",
|
|
||||||
type: "link",
|
|
||||||
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
|
||||||
})
|
|
||||||
return app
|
|
||||||
}
|
}
|
||||||
await updateAppPackage(addLinks, appId)
|
app.navigation.links.push({
|
||||||
|
text: "Inventory",
|
||||||
|
url: "/inventory",
|
||||||
|
type: "link",
|
||||||
|
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
||||||
|
})
|
||||||
|
|
||||||
|
await db.put(app)
|
||||||
|
|
||||||
|
// remove any cached metadata, so that it will be updated
|
||||||
|
await cache.app.invalidateAppMetadata(app.appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addSampleData = async (
|
export const addSampleData = async (
|
||||||
|
@ -854,20 +853,17 @@ export async function duplicateApp(
|
||||||
// which is required to update anything deeper than the top level without
|
// which is required to update anything deeper than the top level without
|
||||||
// overwriting more than intended.
|
// overwriting more than intended.
|
||||||
export async function updateAppPackage(
|
export async function updateAppPackage(
|
||||||
update: Partial<App> | ((app: App) => App),
|
appPackage: Partial<App>,
|
||||||
appId: string
|
appId: string
|
||||||
) {
|
) {
|
||||||
return context.doInAppContext(appId, async () => {
|
return context.doInAppContext(appId, async () => {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const application = await sdk.applications.metadata.get()
|
const application = await sdk.applications.metadata.get()
|
||||||
|
|
||||||
const newAppPackage: App =
|
const newAppPackage: App = { ...application, ...appPackage }
|
||||||
typeof update === "function"
|
if (appPackage._rev !== application._rev) {
|
||||||
? update(application)
|
newAppPackage._rev = application._rev
|
||||||
: { ...application, ...update }
|
}
|
||||||
|
|
||||||
// Ensure our rev stays the same
|
|
||||||
newAppPackage._rev = application._rev
|
|
||||||
|
|
||||||
// the locked by property is attached by server but generated from
|
// the locked by property is attached by server but generated from
|
||||||
// Redis, shouldn't ever store it
|
// Redis, shouldn't ever store it
|
||||||
|
|
Loading…
Reference in New Issue