Skip to content

Commit

Permalink
fix(editor): Redirect Settings to the proper sub page depending on th…
Browse files Browse the repository at this point in the history
…e instance type (cloud or not) (#12053)
  • Loading branch information
cstuncsik authored and ivov committed Dec 6, 2024
1 parent 137a1e7 commit 7a0a9e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
13 changes: 12 additions & 1 deletion packages/editor-ui/src/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -28,6 +30,7 @@ describe('router', () => {
});

beforeEach(() => {
settingsStore = useSettingsStore();
initializeAuthenticatedFeaturesSpy.mockImplementation(async () => await Promise.resolve());
});

Expand Down Expand Up @@ -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;
Expand All @@ -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);
});
});
8 changes: 7 additions & 1 deletion packages/editor-ui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,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',
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/views/SettingsView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
Expand Down

0 comments on commit 7a0a9e4

Please # to comment.