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 GitHub
parent 72e6343964
commit a16d006f89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View file

@ -14,6 +14,8 @@ const App = {
};
const renderComponent = createComponentRenderer(App);
let settingsStore: ReturnType<typeof useSettingsStore>;
describe('router', () => {
let server: ReturnType<typeof setupServer>;
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);
});
});

View file

@ -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',

View file

@ -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,
},
],