Skip to content

Commit

Permalink
fix: Fix routing
Browse files Browse the repository at this point in the history
  • Loading branch information
cstuncsik committed Feb 17, 2024
1 parent 36c2a2c commit 1772596
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
27 changes: 13 additions & 14 deletions packages/editor-ui/src/features/projects/projects-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ const Projects = async () => await import('@/features/projects/views/Projects.vu
export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
{
path: projectsRoute,
name: VIEWS.PROJECTS,
component: Projects,
meta: {
middleware: ['authenticated'],
},
children: [
{
path: '/credentials',
path: 'credentials',
name: VIEWS.CREDENTIALS,
components: {
default: CredentialsView,
Expand All @@ -42,7 +40,7 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
},
},
{
path: '/workflows/templates/:id',
path: 'workflows/templates/:id',
name: VIEWS.TEMPLATE_IMPORT,
components: {
default: NodeView,
Expand All @@ -57,7 +55,7 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
},
},
{
path: '/workflows',
path: 'workflows',
name: VIEWS.WORKFLOWS,
components: {
default: WorkflowsView,
Expand All @@ -68,7 +66,7 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
},
},
{
path: '/workflow/:name/debug/:executionId',
path: 'workflow/:name/debug/:executionId',
name: VIEWS.EXECUTION_DEBUG,
components: {
default: NodeView,
Expand All @@ -87,7 +85,7 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
},
},
{
path: '/workflow/:name/executions',
path: 'workflow/:name/executions',
name: VIEWS.WORKFLOW_EXECUTIONS,
components: {
default: WorkflowExecutionsList,
Expand Down Expand Up @@ -124,7 +122,7 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
],
},
{
path: '/workflow/:workflowId/history/:versionId?',
path: 'workflow/:workflowId/history/:versionId?',
name: VIEWS.WORKFLOW_HISTORY,
components: {
default: WorkflowHistory,
Expand All @@ -140,7 +138,7 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
},
},
{
path: '/workflow/new',
path: 'workflow/new',
name: VIEWS.NEW_WORKFLOW,
components: {
default: NodeView,
Expand All @@ -154,7 +152,7 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
},
},
{
path: '/workflow/:name',
path: 'workflow/:name',
name: VIEWS.WORKFLOW,
components: {
default: NodeView,
Expand All @@ -168,18 +166,19 @@ export const projectsRoutes: Readonly<RouteRecordRaw[]> = [
},
},
{
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'],
},
Expand Down
18 changes: 14 additions & 4 deletions packages/editor-ui/src/features/projects/views/Projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const routes = [
path: '/',
name: VIEWS.HOMEPAGE,
redirect: () => {
return { name: VIEWS.WORKFLOWS };
return { name: VIEWS.PROJECTS };
},
meta: {
middleware: ['authenticated'],
Expand Down

0 comments on commit 1772596

Please sign in to comment.