From a16d006f893cac927d674fa447b08c1205b67c54 Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Thu, 5 Dec 2024 08:47:55 +0100 Subject: [PATCH] fix(editor): Redirect Settings to the proper sub page depending on the instance type (cloud or not) (#12053) --- packages/editor-ui/src/router.test.ts | 13 ++++++++++++- packages/editor-ui/src/router.ts | 8 +++++++- packages/editor-ui/src/views/SettingsView.test.ts | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/editor-ui/src/router.test.ts b/packages/editor-ui/src/router.test.ts index f67399d6345b4..8af15d9da5dca 100644 --- a/packages/editor-ui/src/router.test.ts +++ b/packages/editor-ui/src/router.test.ts @@ -14,6 +14,8 @@ const App = { }; const renderComponent = createComponentRenderer(App); +let settingsStore: ReturnType; + describe('router', () => { let server: ReturnType; const initializeAuthenticatedFeaturesSpy = vi.spyOn(init, 'initializeAuthenticatedFeatures'); @@ -28,6 +30,7 @@ describe('router', () => { }); beforeEach(() => { + settingsStore = useSettingsStore(); initializeAuthenticatedFeaturesSpy.mockImplementation(async () => await Promise.resolve()); }); @@ -114,7 +117,6 @@ describe('router', () => { ])( 'should resolve %s to %s with %s user permissions', async (path, name, scopes) => { - const settingsStore = useSettingsStore(); const rbacStore = useRBACStore(); settingsStore.settings.communityNodesEnabled = true; @@ -126,4 +128,13 @@ describe('router', () => { }, 10000, ); + + test.each([ + [VIEWS.PERSONAL_SETTINGS, true], + [VIEWS.USAGE, false], + ])('should redirect Settings to %s', async (name, hideUsagePage) => { + settingsStore.settings.hideUsagePage = hideUsagePage; + await router.push('/settings'); + expect(router.currentRoute.value.name).toBe(name); + }); }); diff --git a/packages/editor-ui/src/router.ts b/packages/editor-ui/src/router.ts index ad8193a9dc454..472114a1c973e 100644 --- a/packages/editor-ui/src/router.ts +++ b/packages/editor-ui/src/router.ts @@ -482,7 +482,13 @@ export const routes: RouteRecordRaw[] = [ name: VIEWS.SETTINGS, component: SettingsView, props: true, - redirect: { name: VIEWS.USAGE }, + redirect: () => { + const settingsStore = useSettingsStore(); + if (settingsStore.settings.hideUsagePage) { + return { name: VIEWS.PERSONAL_SETTINGS }; + } + return { name: VIEWS.USAGE }; + }, children: [ { path: 'usage', diff --git a/packages/editor-ui/src/views/SettingsView.test.ts b/packages/editor-ui/src/views/SettingsView.test.ts index 87875147f86a0..00178caffb2e0 100644 --- a/packages/editor-ui/src/views/SettingsView.test.ts +++ b/packages/editor-ui/src/views/SettingsView.test.ts @@ -50,7 +50,7 @@ const router = createRouter({ name: VIEWS.SETTINGS, component: SettingsView, props: true, - redirect: { name: VIEWS.USAGE }, + redirect: { name: VIEWS.PERSONAL_SETTINGS }, children: settingsRouteChildren, }, ],