Skip to content

Commit 17c54aa

Browse files
authored
Merge pull request #16634 from Budibase/revert-16611-BUDI-9294/navigation-from-workspace
Revert "Navigation from workspace app"
2 parents d5cb7ad + 13fc94e commit 17c54aa

File tree

8 files changed

+139
-21
lines changed

8 files changed

+139
-21
lines changed

packages/builder/src/stores/builder/app.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
UpdateAppRequest,
1212
} from "@budibase/types"
1313
import { get } from "svelte/store"
14-
import { initialise, navigationStore, workspaceAppStore } from "."
14+
import { initialise, navigationStore } from "."
1515

1616
interface ClientFeatures {
1717
spectrumThemes: boolean
@@ -206,15 +206,9 @@ export class AppMetaStore extends BudiStore<AppMetaState> {
206206
}
207207

208208
async refreshAppNav() {
209-
const { selectedWorkspaceApp } = get(workspaceAppStore)
210-
if (!selectedWorkspaceApp) {
211-
return
212-
}
213-
214-
const { navigation } = await API.workspaceApp.find(
215-
selectedWorkspaceApp._id!
216-
)
217-
navigationStore.syncAppNavigation(navigation)
209+
const { appId } = get(this.store)
210+
const { application } = await API.fetchAppPackage(appId)
211+
navigationStore.syncAppNavigation(application?.navigation)
218212
}
219213
}
220214

packages/builder/src/stores/builder/screens.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
appStore,
88
componentStore,
99
layoutStore,
10+
navigationStore,
1011
previewStore,
1112
selectedComponent,
1213
workspaceAppStore,
@@ -18,13 +19,15 @@ import {
1819
Component,
1920
ComponentDefinition,
2021
DeleteScreenResponse,
22+
FeatureFlag,
2123
FetchAppPackageResponse,
2224
SaveScreenRequest,
2325
SaveScreenResponse,
2426
Screen,
2527
ScreenVariant,
2628
WithRequired,
2729
} from "@budibase/types"
30+
import { featureFlag } from "@/helpers"
2831

2932
interface ScreenState {
3033
screens: Screen[]
@@ -265,6 +268,17 @@ export class ScreenStore extends BudiStore<ScreenState> {
265268
return state
266269
})
267270

271+
if (
272+
!featureFlag.isEnabled(FeatureFlag.WORKSPACE_APPS) &&
273+
navigationLinkLabel
274+
) {
275+
await navigationStore.addLink({
276+
url: screen.routing.route,
277+
title: navigationLinkLabel,
278+
roleId: screen.routing.roleId,
279+
})
280+
}
281+
268282
await appStore.refreshAppNav()
269283

270284
return savedScreen

packages/frontend-core/src/api/workspaceApps.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
FetchWorkspaceAppResponse,
3-
FindWorkspaceAppResponse,
43
InsertWorkspaceAppRequest,
54
InsertWorkspaceAppResponse,
65
UpdateWorkspaceAppRequest,
@@ -9,7 +8,6 @@ import {
98
import { BaseAPIClient } from "./types"
109

1110
export interface WorkspaceAppEndpoints {
12-
find: (id: string) => Promise<FindWorkspaceAppResponse>
1311
fetch: () => Promise<FetchWorkspaceAppResponse>
1412
create: (
1513
workspaceApp: InsertWorkspaceAppRequest
@@ -23,11 +21,6 @@ export interface WorkspaceAppEndpoints {
2321
export const buildWorkspaceAppEndpoints = (
2422
API: BaseAPIClient
2523
): WorkspaceAppEndpoints => ({
26-
find: async id => {
27-
return await API.get({
28-
url: `/api/workspaceApp/${id}`,
29-
})
30-
},
3124
fetch: async () => {
3225
return await API.get({
3326
url: "/api/workspaceApp",

packages/server/src/api/controllers/application.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
docIds,
2727
env as envCore,
2828
events,
29+
features,
2930
objectStore,
3031
roles,
3132
tenancy,
@@ -68,6 +69,7 @@ import {
6869
AddAppSampleDataResponse,
6970
UnpublishAppResponse,
7071
ErrorCode,
72+
FeatureFlag,
7173
FetchPublishedAppsResponse,
7274
} from "@budibase/types"
7375
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
@@ -202,6 +204,29 @@ async function addSampleDataScreen() {
202204

203205
const screen = createSampleDataTableScreen(workspaceApp._id!)
204206
await sdk.screens.create(screen)
207+
208+
{
209+
// TODO: remove when cleaning the flag FeatureFlag.WORKSPACE_APPS
210+
const db = context.getAppDB()
211+
let app = await sdk.applications.metadata.get()
212+
if (!app.navigation) {
213+
return
214+
}
215+
if (!app.navigation.links) {
216+
app.navigation.links = []
217+
}
218+
app.navigation.links.push({
219+
text: "Inventory",
220+
url: "/inventory",
221+
type: "link",
222+
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
223+
})
224+
225+
await db.put(app)
226+
227+
// remove any cached metadata, so that it will be updated
228+
await cache.app.invalidateAppMetadata(app.appId)
229+
}
205230
}
206231

207232
export const addSampleData = async (
@@ -295,7 +320,10 @@ export async function fetchAppPackage(
295320
screens = await accessController.checkScreensAccess(screens, userRoleId)
296321
}
297322

298-
if (!isBuilder) {
323+
if (
324+
(await features.flags.isEnabled(FeatureFlag.WORKSPACE_APPS)) &&
325+
!isBuilder
326+
) {
299327
const urlPath = ctx.headers.referer
300328
? new URL(ctx.headers.referer).pathname
301329
: ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as controller from "../controllers/navigation"
22
import { builderRoutes } from "./endpointGroups"
33

4+
// TODO: remove when cleaning the flag FeatureFlag.WORKSPACE_APPS
45
builderRoutes.put("/api/navigation/:workspaceAppId", controller.update)

packages/server/src/api/routes/tests/navigation.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { structures } from "@budibase/backend-core/tests"
12
import * as setup from "./utilities"
23
import { AppNavigation, WithRequired, WorkspaceApp } from "@budibase/types"
34

@@ -44,6 +45,15 @@ describe("/navigation", () => {
4445
expect(updatedApp!.navigation).toEqual(sampleNavigation)
4546
})
4647

48+
it("should update both workspace app and default app navigation for default workspaceApps", async () => {
49+
await config.api.navigation.update(workspaceApp._id, {
50+
navigation: sampleNavigation,
51+
})
52+
53+
const appMetadata = await config.api.application.get(config.getAppId())
54+
expect(appMetadata.navigation).toEqual(sampleNavigation)
55+
})
56+
4757
it("should return 400 for invalid workspace app id", async () => {
4858
await config.api.navigation.update(
4959
"invalid_id",
@@ -52,6 +62,26 @@ describe("/navigation", () => {
5262
)
5363
})
5464

65+
it("should not update app navigation app navigation when updating not default workspaces", async () => {
66+
const { workspaceApp: otherWorkspaceApp } =
67+
await config.api.workspaceApp.create({
68+
...structures.workspaceApps.createRequest(),
69+
})
70+
expect(otherWorkspaceApp.isDefault).toBe(false)
71+
72+
await config.api.navigation.update(otherWorkspaceApp._id, {
73+
navigation: sampleNavigation,
74+
})
75+
76+
const updatedWorkspaceApp = await config.api.workspaceApp.find(
77+
otherWorkspaceApp._id
78+
)
79+
expect(updatedWorkspaceApp.navigation).toEqual(sampleNavigation)
80+
81+
const appMetadata = await config.api.application.get(config.getAppId())
82+
expect(appMetadata.navigation).not.toEqual(sampleNavigation)
83+
})
84+
5585
it("should handle empty navigation links", async () => {
5686
const emptyNavigation: AppNavigation = { navigation: "Left", links: [] }
5787

@@ -62,6 +92,9 @@ describe("/navigation", () => {
6292
const updatedApp = await config.api.workspaceApp.find(workspaceApp._id)
6393
expect(updatedApp).toBeDefined()
6494
expect(updatedApp!.navigation).toEqual(emptyNavigation)
95+
96+
const appMetadata = await config.api.application.get(config.getAppId())
97+
expect(appMetadata.navigation).toEqual(emptyNavigation)
6598
})
6699
})
67100
})

packages/server/src/sdk/app/navigation/index.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { HTTPError } from "@budibase/backend-core"
1+
import { context, HTTPError } from "@budibase/backend-core"
22
import sdk from "../.."
3-
import { AppNavigation } from "@budibase/types"
3+
import { App, AppNavigation } from "@budibase/types"
44

55
export async function addLink({
66
label,
@@ -26,6 +26,24 @@ export async function addLink({
2626
})
2727

2828
await sdk.workspaceApps.update(workspaceApp)
29+
30+
if (workspaceApp.isDefault) {
31+
// TODO: remove when cleaning the flag FeatureFlag.WORKSPACE_APPS
32+
const appMetadata = await sdk.applications.metadata.get()
33+
appMetadata.navigation ??= {
34+
navigation: "Top",
35+
}
36+
appMetadata.navigation.links ??= []
37+
appMetadata.navigation.links.push({
38+
text: label,
39+
url,
40+
roleId,
41+
type: "link",
42+
})
43+
44+
const db = context.getAppDB()
45+
await db.put(appMetadata)
46+
}
2947
}
3048

3149
export async function deleteLink(route: string, workspaceAppId: string) {
@@ -48,6 +66,35 @@ export async function deleteLink(route: string, workspaceAppId: string) {
4866
...workspaceApp,
4967
navigation: { ...workspaceApp.navigation, links: updatedLinks },
5068
})
69+
70+
if (workspaceApp.isDefault) {
71+
// TODO: remove when cleaning the flag FeatureFlag.WORKSPACE_APPS
72+
const appMetadata = await sdk.applications.metadata.get()
73+
const navigation = appMetadata.navigation
74+
if (!navigation || !navigation.links?.length) {
75+
return
76+
}
77+
78+
// Filter out top level links pointing to these URLs
79+
const updatedLinks = navigation.links.filter(link => link.url !== route)
80+
81+
// Filter out nested links pointing to these URLs
82+
updatedLinks.forEach(link => {
83+
if (link.type === "sublinks" && link.subLinks?.length) {
84+
link.subLinks = link.subLinks.filter(subLink => subLink.url !== route)
85+
}
86+
})
87+
88+
const db = context.getAppDB()
89+
const updatedMetadata: App = {
90+
...appMetadata,
91+
navigation: {
92+
...navigation,
93+
links: updatedLinks,
94+
},
95+
}
96+
await db.put(updatedMetadata)
97+
}
5198
}
5299

53100
export async function update(
@@ -59,4 +106,12 @@ export async function update(
59106
throw new HTTPError("Workspace app not found", 400)
60107
}
61108
await sdk.workspaceApps.update({ ...workspaceApp, navigation })
109+
110+
if (workspaceApp.isDefault) {
111+
const appMetadata = await sdk.applications.metadata.get()
112+
appMetadata.navigation = navigation
113+
114+
const db = context.getAppDB()
115+
await db.put(appMetadata)
116+
}
62117
}

packages/types/src/documents/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface App extends Document {
1919
revertableVersion?: string
2020
lockedBy?: User
2121
sessions?: SocketSession[]
22-
/** @deprecated use workspace app navigation instead */
22+
// @deprecated use workspace app navigation instead
2323
navigation?: AppNavigation
2424
automationErrors?: AppMetadataErrors
2525
backupErrors?: AppMetadataErrors

0 commit comments

Comments
 (0)