fix(editor): Redirect Settings to the proper sub page depending on the instance type (cloud or not) (#12053)

This commit is contained in:
Csaba Tuncsik 2024-12-05 08:47:55 +01:00 committed by Iván Ovejero
parent 137a1e761f
commit 7a0a9e4a7b
No known key found for this signature in database
3 changed files with 20 additions and 3 deletions

View file

@ -14,6 +14,8 @@ const App = {
}; };
const renderComponent = createComponentRenderer(App); const renderComponent = createComponentRenderer(App);
let settingsStore: ReturnType<typeof useSettingsStore>;
describe('router', () => { describe('router', () => {
let server: ReturnType<typeof setupServer>; let server: ReturnType<typeof setupServer>;
const initializeAuthenticatedFeaturesSpy = vi.spyOn(init, 'initializeAuthenticatedFeatures'); const initializeAuthenticatedFeaturesSpy = vi.spyOn(init, 'initializeAuthenticatedFeatures');
@ -28,6 +30,7 @@ describe('router', () => {
}); });
beforeEach(() => { beforeEach(() => {
settingsStore = useSettingsStore();
initializeAuthenticatedFeaturesSpy.mockImplementation(async () => await Promise.resolve()); initializeAuthenticatedFeaturesSpy.mockImplementation(async () => await Promise.resolve());
}); });
@ -114,7 +117,6 @@ describe('router', () => {
])( ])(
'should resolve %s to %s with %s user permissions', 'should resolve %s to %s with %s user permissions',
async (path, name, scopes) => { async (path, name, scopes) => {
const settingsStore = useSettingsStore();
const rbacStore = useRBACStore(); const rbacStore = useRBACStore();
settingsStore.settings.communityNodesEnabled = true; settingsStore.settings.communityNodesEnabled = true;
@ -126,4 +128,13 @@ describe('router', () => {
}, },
10000, 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);
});
}); });

View file

@ -483,7 +483,13 @@ export const routes: RouteRecordRaw[] = [
name: VIEWS.SETTINGS, name: VIEWS.SETTINGS,
component: SettingsView, component: SettingsView,
props: true, props: true,
redirect: { name: VIEWS.USAGE }, redirect: () => {
const settingsStore = useSettingsStore();
if (settingsStore.settings.hideUsagePage) {
return { name: VIEWS.PERSONAL_SETTINGS };
}
return { name: VIEWS.USAGE };
},
children: [ children: [
{ {
path: 'usage', path: 'usage',

View file

@ -50,7 +50,7 @@ const router = createRouter({
name: VIEWS.SETTINGS, name: VIEWS.SETTINGS,
component: SettingsView, component: SettingsView,
props: true, props: true,
redirect: { name: VIEWS.USAGE }, redirect: { name: VIEWS.PERSONAL_SETTINGS },
children: settingsRouteChildren, children: settingsRouteChildren,
}, },
], ],