Skip to content

Commit 5ce89ca

Browse files
satellite/admin-ui: clean up routing
Related: #7601 Change-Id: Idc6dc0eff6e59e78e186de53d7801e86550ad982
1 parent 10a3f04 commit 5ce89ca

File tree

7 files changed

+66
-30
lines changed

7 files changed

+66
-30
lines changed

satellite/admin/back-office/ui/src/components/AccountProjectsTableComponent.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ const projects = computed<ProjectTableItem[]>(() => {
219219
*/
220220
async function selectProject(id: string): Promise<void> {
221221
await appStore.selectProject(id);
222-
router.push(`${router.currentRoute.value.path}/projects/${id}`);
222+
router.push({
223+
name: ROUTES.AccountProject.name,
224+
params: { email: appStore.state.userAccount?.email, id },
225+
});
223226
}
224227
225228
function getPercentColor(percent: number) {

satellite/admin/back-office/ui/src/router/index.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
import { watch } from 'vue';
55
import { createRouter, createWebHistory } from 'vue-router';
66

7+
import { NavigationLink } from '@/router/navigation';
8+
9+
export abstract class ROUTES {
10+
public static AccountSearch = new NavigationLink('/account-search', 'Account Search');
11+
public static Accounts = new NavigationLink('/accounts', 'Accounts');
12+
public static Account = new NavigationLink(':email', 'Account');
13+
public static AccountProject = new NavigationLink('projects/:id', 'Account Project');
14+
15+
public static Projects = new NavigationLink('/projects', 'Projects');
16+
public static ProjectDetail = new NavigationLink('/projects-details', 'Project Details');
17+
18+
public static BucketDetail = new NavigationLink('/bucket-details', 'Bucket Details');
19+
public static AdminSettings = new NavigationLink('/admin-settings', 'Admin Settings');
20+
}
21+
722
const routes = [
823
{
924
path: '/',
@@ -18,7 +33,7 @@ const routes = [
1833
// ],
1934
// TODO: once the switch satellite feature is implemented, remove the redirection below and
2035
// uncomment the above code.
21-
redirect: '/account-search', // directly redirect
36+
redirect: ROUTES.AccountSearch.path, // directly redirect
2237
},
2338
{
2439
path: '/admin',
@@ -30,53 +45,53 @@ const routes = [
3045
component: () => import(/* webpackChunkName: "Dashboard" */ '@/views/Dashboard.vue'),
3146
},
3247
{
33-
path: '/accounts',
48+
path: ROUTES.Accounts.path,
3449
children: [
3550
{
3651
path: '',
37-
name: 'Accounts',
52+
name: ROUTES.Accounts.name,
3853
component: () => import(/* webpackChunkName: "Users" */ '@/views/Accounts.vue'),
3954
},
4055
{
41-
path: ':email',
56+
path: ROUTES.Account.path,
4257
children: [
4358
{
4459
path: '',
45-
name: 'Account Details',
60+
name: ROUTES.Account.name,
4661
component: () => import(/* webpackChunkName: "Users" */ '@/views/AccountDetails.vue'),
4762
},
4863
{
49-
path: 'projects/:id',
50-
name: 'User Project Details',
64+
path: ROUTES.AccountProject.path,
65+
name: ROUTES.AccountProject.name,
5166
component: () => import(/* webpackChunkName: "Users" */ '@/views/ProjectDetails.vue'),
5267
},
5368
],
5469
},
5570
],
5671
},
5772
{
58-
path: '/account-search',
59-
name: 'Search Account',
73+
path: ROUTES.AccountSearch.path,
74+
name: ROUTES.AccountSearch.name,
6075
component: () => import(/* webpackChunkName: "Users" */ '@/views/AccountSearch.vue'),
6176
},
6277
{
63-
path: '/projects',
64-
name: 'Projects',
78+
path: ROUTES.Projects.path,
79+
name: ROUTES.Projects.name,
6580
component: () => import(/* webpackChunkName: "Projects" */ '@/views/Projects.vue'),
6681
},
6782
{
68-
path: '/project-details',
69-
name: 'Project Details',
83+
path: ROUTES.ProjectDetail.path,
84+
name: ROUTES.ProjectDetail.name,
7085
component: () => import(/* webpackChunkName: "ProjectDetails" */ '@/views/ProjectDetails.vue'),
7186
},
7287
{
73-
path: '/bucket-details',
74-
name: 'Bucket Details',
88+
path: ROUTES.BucketDetail.path,
89+
name: ROUTES.BucketDetail.name,
7590
component: () => import(/* webpackChunkName: "BucketDetails" */ '@/views/BucketDetails.vue'),
7691
},
7792
{
78-
path: '/admin-settings',
79-
name: 'Admin Settings',
93+
path: ROUTES.AdminSettings.path,
94+
name: ROUTES.AdminSettings.name,
8095
component: () => import(/* webpackChunkName: "AdminSettings" */ '@/views/AdminSettings.vue'),
8196
},
8297
],
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2025 Storj Labs, Inc.
2+
// See LICENSE for copying information.
3+
4+
export class NavigationLink {
5+
private readonly _path: string;
6+
private readonly _name: string;
7+
8+
public constructor(path: string, name: string) {
9+
this._path = path;
10+
this._name = name;
11+
}
12+
13+
public get path(): string {
14+
return this._path;
15+
}
16+
17+
public get name(): string {
18+
return this._name;
19+
}
20+
}

satellite/admin/back-office/ui/src/store/app.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ export const useAppStore = defineStore('app', () => {
2727
return state.userAccount;
2828
}
2929

30-
async function getProject(id: string): Promise<Project> {
31-
state.selectedProject = await projectApi.getProject(id);
32-
33-
return state.selectedProject;
34-
}
35-
3630
function clearUser(): void {
3731
state.userAccount = null;
3832
}
@@ -53,8 +47,10 @@ export const useAppStore = defineStore('app', () => {
5347
return `Unknown (${code})`;
5448
}
5549

56-
async function selectProject(id: string): Promise<void> {
50+
async function selectProject(id: string): Promise<Project> {
5751
state.selectedProject = await projectApi.getProject(id);
52+
53+
return state.selectedProject;
5854
}
5955

6056
async function updateProjectLimits(id: string, limits: ProjectLimitsUpdate): Promise<void> {
@@ -84,7 +80,6 @@ export const useAppStore = defineStore('app', () => {
8480
return {
8581
state,
8682
getUserByEmail,
87-
getProject,
8883
clearUser,
8984
getPlacements,
9085
getPlacementText,

satellite/admin/back-office/ui/src/views/AccountDetails.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ import {
192192
import { FeatureFlags, UserAccount } from '@/api/client.gen';
193193
import { useAppStore } from '@/store/app';
194194
import { sizeToBase10String } from '@/utils/memory';
195+
import { ROUTES } from '@/router';
195196
196197
import PageTitleComponent from '@/components/PageTitleComponent.vue';
197198
import AccountProjectsTableComponent from '@/components/AccountProjectsTableComponent.vue';
@@ -275,7 +276,7 @@ onBeforeMount(async () => {
275276
const email = router.currentRoute.value.params.email as string;
276277
await appStore.getUserByEmail(email);
277278
} catch {
278-
router.push('/account-search');
279+
router.push({ name: ROUTES.AccountSearch.name });
279280
}
280281
});
281282

satellite/admin/back-office/ui/src/views/AccountSearch.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { VContainer, VRow, VCol, VBtn, VCard, VCardText, VForm, VTextField } fro
5959
import { FeatureFlags } from '@/api/client.gen';
6060
import { useAppStore } from '@/store/app';
6161
import { useNotificationsStore } from '@/store/notifications';
62+
import { ROUTES } from '@/router';
6263
6364
import PageTitleComponent from '@/components/PageTitleComponent.vue';
6465
import PageSubtitleComponent from '@/components/PageSubtitleComponent.vue';
@@ -91,7 +92,7 @@ async function goToUser(): Promise<void> {
9192
for (let attempt = 0; attempt < maxAttempts; attempt++) {
9293
try {
9394
const user = await appStore.getUserByEmail(email.value);
94-
router.push(`/accounts/${user.email}`);
95+
router.push({ name: ROUTES.Account.name, params: { email: user.email } });
9596
isLoading.value = false;
9697
return;
9798
} catch (error) {

satellite/admin/back-office/ui/src/views/ProjectDetails.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ import { useRouter } from 'vue-router';
189189
190190
import { FeatureFlags, Project, UserAccount } from '@/api/client.gen';
191191
import { useAppStore } from '@/store/app';
192+
import { ROUTES } from '@/router';
192193
193194
import PageTitleComponent from '@/components/PageTitleComponent.vue';
194195
import UsageProgressComponent from '@/components/UsageProgressComponent.vue';
@@ -229,12 +230,12 @@ onMounted(async () => {
229230
230231
try {
231232
await Promise.all([
232-
appStore.getProject(projectID),
233+
appStore.selectProject(projectID),
233234
appStore.getUserByEmail(userEmail),
234235
]);
235236
// eslint-disable-next-line @typescript-eslint/no-unused-vars
236237
} catch (error) {
237-
router.push('/account-search');
238+
router.push({ name: ROUTES.AccountSearch.name });
238239
}
239240
});
240241
</script>

0 commit comments

Comments
 (0)