From 1772596b59ee3cdccfe1e095e1586eaa43b4e764 Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Fri, 16 Feb 2024 07:03:27 +0100 Subject: [PATCH] fix: Fix routing --- .../src/features/projects/projects-routes.ts | 27 +++++++++---------- .../src/features/projects/views/Projects.vue | 18 ++++++++++--- packages/editor-ui/src/router.ts | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/packages/editor-ui/src/features/projects/projects-routes.ts b/packages/editor-ui/src/features/projects/projects-routes.ts index a92c26745d4a1..2ce0684ea66d6 100644 --- a/packages/editor-ui/src/features/projects/projects-routes.ts +++ b/packages/editor-ui/src/features/projects/projects-routes.ts @@ -24,14 +24,12 @@ const Projects = async () => await import('@/features/projects/views/Projects.vu export const projectsRoutes: Readonly = [ { path: projectsRoute, - name: VIEWS.PROJECTS, - component: Projects, meta: { middleware: ['authenticated'], }, children: [ { - path: '/credentials', + path: 'credentials', name: VIEWS.CREDENTIALS, components: { default: CredentialsView, @@ -42,7 +40,7 @@ export const projectsRoutes: Readonly = [ }, }, { - path: '/workflows/templates/:id', + path: 'workflows/templates/:id', name: VIEWS.TEMPLATE_IMPORT, components: { default: NodeView, @@ -57,7 +55,7 @@ export const projectsRoutes: Readonly = [ }, }, { - path: '/workflows', + path: 'workflows', name: VIEWS.WORKFLOWS, components: { default: WorkflowsView, @@ -68,7 +66,7 @@ export const projectsRoutes: Readonly = [ }, }, { - path: '/workflow/:name/debug/:executionId', + path: 'workflow/:name/debug/:executionId', name: VIEWS.EXECUTION_DEBUG, components: { default: NodeView, @@ -87,7 +85,7 @@ export const projectsRoutes: Readonly = [ }, }, { - path: '/workflow/:name/executions', + path: 'workflow/:name/executions', name: VIEWS.WORKFLOW_EXECUTIONS, components: { default: WorkflowExecutionsList, @@ -124,7 +122,7 @@ export const projectsRoutes: Readonly = [ ], }, { - path: '/workflow/:workflowId/history/:versionId?', + path: 'workflow/:workflowId/history/:versionId?', name: VIEWS.WORKFLOW_HISTORY, components: { default: WorkflowHistory, @@ -140,7 +138,7 @@ export const projectsRoutes: Readonly = [ }, }, { - path: '/workflow/new', + path: 'workflow/new', name: VIEWS.NEW_WORKFLOW, components: { default: NodeView, @@ -154,7 +152,7 @@ export const projectsRoutes: Readonly = [ }, }, { - path: '/workflow/:name', + path: 'workflow/:name', name: VIEWS.WORKFLOW, components: { default: NodeView, @@ -168,18 +166,19 @@ export const projectsRoutes: Readonly = [ }, }, { - path: '/workflow', - redirect: '/workflow/new', + path: 'workflow', + redirect: 'workflow/new', }, { - path: '/', - redirect: '/workflows', + path: '', + redirect: 'workflows', }, ], }, { path: projectsBaseRoute, component: Projects, + name: VIEWS.PROJECTS, meta: { middleware: ['authenticated'], }, diff --git a/packages/editor-ui/src/features/projects/views/Projects.vue b/packages/editor-ui/src/features/projects/views/Projects.vue index 7fcabf25892ed..d9a082a1f7ace 100644 --- a/packages/editor-ui/src/features/projects/views/Projects.vue +++ b/packages/editor-ui/src/features/projects/views/Projects.vue @@ -2,7 +2,11 @@ import { onBeforeMount, ref } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { getPathAsRegexPattern } from '@/utils/routeUtils'; -import { oldRoutesToRedirectToProjects } from '@/features/projects/projects-constants'; +import { + projectsBaseRoute, + oldRoutesToRedirectToProjects, +} from '@/features/projects/projects-constants'; +import { VIEWS } from '@/constants'; const router = useRouter(); const route = useRoute(); @@ -13,13 +17,19 @@ const projectId = ref('home'); onBeforeMount(async () => { // TODO: Get the project id from the store const oldRoutePatterns = oldRoutesToRedirectToProjects.map(getPathAsRegexPattern); - if (oldRoutePatterns.some((pattern) => pattern.test(route.path))) { + if ( + oldRoutePatterns.some((pattern) => pattern.test(route.path)) && + !route.path.includes(projectsBaseRoute) + ) { await router.replace({ - path: `/projects/${projectId.value}/${route.path}`, + path: `${projectsBaseRoute}/${projectId.value}${route.path}`, query: route.query, }); - redirectionSuccess.value = true; } + if (route.name === VIEWS.PROJECTS) { + await router.replace({ name: VIEWS.WORKFLOWS, params: { projectId: projectId.value } }); + } + redirectionSuccess.value = true; }); diff --git a/packages/editor-ui/src/router.ts b/packages/editor-ui/src/router.ts index 4044a2485fb46..97200fb4fb59c 100644 --- a/packages/editor-ui/src/router.ts +++ b/packages/editor-ui/src/router.ts @@ -62,7 +62,7 @@ export const routes = [ path: '/', name: VIEWS.HOMEPAGE, redirect: () => { - return { name: VIEWS.WORKFLOWS }; + return { name: VIEWS.PROJECTS }; }, meta: { middleware: ['authenticated'],