mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 09:04:07 -08:00
67a88914f2
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Csaba Tuncsik <csaba@n8n.io>
33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
import type { RouteLocationNormalized } from 'vue-router';
|
|
import type { Resource } from '@n8n/permissions';
|
|
|
|
export function inferProjectIdFromRoute(to: RouteLocationNormalized): string {
|
|
const routeParts = to.path.split('/');
|
|
const projectsIndex = routeParts.indexOf('projects');
|
|
const projectIdIndex = projectsIndex !== -1 ? projectsIndex + 1 : -1;
|
|
|
|
return routeParts[projectIdIndex];
|
|
}
|
|
|
|
export function inferResourceTypeFromRoute(to: RouteLocationNormalized): Resource | undefined {
|
|
const routeParts = to.path.split('/');
|
|
const routeMap = {
|
|
workflow: 'workflows',
|
|
credential: 'credentials',
|
|
user: 'users',
|
|
variable: 'variables',
|
|
sourceControl: 'source-control',
|
|
externalSecretsStore: 'external-secrets',
|
|
};
|
|
|
|
for (const resource of Object.keys(routeMap) as Array<keyof typeof routeMap>) {
|
|
if (routeParts.includes(routeMap[resource])) {
|
|
return resource;
|
|
}
|
|
}
|
|
}
|
|
|
|
export function inferResourceIdFromRoute(to: RouteLocationNormalized): string | undefined {
|
|
return (to.params.id as string | undefined) ?? (to.params.name as string | undefined);
|
|
}
|