Files
speckle-server/packages/frontend-2/lib/common/helpers/route.ts
T
Kristaps Fabians Geikins 83d8035dc2 chore: upgrade to eslint 9 (#2348)
* root + server

* frontend

* frontend-2

* dui3

* dui3

* tailwind theme

* ui-components

* preview service

* viewer

* viewer-sandbox

* fileimport-service

* webhook service

* objectloader

* shared

* ui-components-nuxt

* WIP full config

* WIP full linter

* eslint projectwide util

* minor fix

* removing redundant ci

* clean up test errors

* fixed prettier formatting

* CI improvements

* TSC lint fix

* 'buildBatch' needs to be async since some batch types (like Text) require it. Removed a disabled liniting rule from ObjLoader

* removed unnecessary void

---------

Co-authored-by: AlexandruPopovici <alexandrupopoviciioan@gmail.com>
2024-06-12 14:38:02 +03:00

125 lines
4.0 KiB
TypeScript

import type { LocationQueryRaw } from 'vue-router'
import { deserializeHashState, serializeHashState } from '~~/lib/common/composables/url'
import type { ViewerHashStateKeys } from '~~/lib/viewer/composables/setup/urlHashState'
export const profileRoute = '/profile'
export const authBlockedDueToVerificationRoute = '/error-email-verify'
export const homeRoute = '/'
export const loginRoute = '/authn/login'
export const registerRoute = '/authn/register'
export const forgottenPasswordRoute = '/authn/forgotten-password'
export const onboardingRoute = '/onboarding'
export const downloadManagerRoute = '/download-manager'
export const serverManagementRoute = '/server-management'
export const projectRoute = (
id: string,
tab?: 'models' | 'discussions' | 'automations' | 'settings'
) => {
let res = `/projects/${id}`
if (tab && tab !== 'models') {
res += `/${tab}`
}
return res
}
export const projectAutomationRoute = (projectId: string, automationId: string) => {
return `${projectRoute(projectId, 'automations')}/${automationId}`
}
export const modelRoute = (
projectId: string,
resourceIdString: string,
hashState?: Partial<Record<ViewerHashStateKeys, string>>
) =>
`/projects/${projectId}/models/${encodeURIComponent(resourceIdString)}${
hashState ? serializeHashState(hashState) || '' : ''
}`
export const modelVersionsRoute = (projectId: string, modelId: string) =>
`/projects/${projectId}/models/${modelId}/versions`
// Temp change to allProjectModelsRoute until tab routing is implemented
export const allProjectModelsRoute = (projectId: string) => `/projects/${projectId}`
// Temp change to projectDiscussionsRoute until tab routing is implemented
export const projectDiscussionsRoute = (projectId: string) => `/projects/${projectId}`
export const projectSettingsRoute = (projectId: string) =>
`/projects/${projectId}/settings`
export const projectCollaboratorsRoute = (projectId: string) =>
`/projects/${projectId}/settings/collaborators`
export const projectWebhooksRoute = (projectId: string) =>
`/projects/${projectId}/settings/webhooks`
export const threadRedirectRoute = (projectId: string, threadId: string) =>
`/projects/${projectId}/threads/${threadId}`
export const automateGithubAppAuthorizationRoute = '/api/automate/auth/githubapp'
export const automationFunctionsRoute = '/functions'
export const automationFunctionRoute = (functionId: string) =>
`${automationFunctionsRoute}/${functionId}`
const buildNavigationComposable = (route: string) => () => {
const router = useRouter()
return (params?: { query?: LocationQueryRaw }) => {
const { query } = params || {}
return router.push({ path: route, query })
}
}
export const useNavigateToHome = buildNavigationComposable(homeRoute)
export const useNavigateToLogin = buildNavigationComposable(loginRoute)
export const useNavigateToRegistration = buildNavigationComposable(registerRoute)
export const useNavigateToForgottenPassword =
buildNavigationComposable(forgottenPasswordRoute)
export const useNavigateToProject = () => {
const router = useRouter()
return (params: { query?: LocationQueryRaw; id: string }) => {
const { query, id } = params || {}
return router.push({ path: projectRoute(id), query })
}
}
/**
* Check that fullPathA fits fullPathB (not necessarily the inverse)
*/
export const doesRouteFitTarget = (fullPathA: string, fullPathB: string) => {
const fakeOrigin = 'https://test.com'
let urlA: URL
let urlB: URL
try {
urlA = new URL(fullPathA, fakeOrigin)
urlB = new URL(fullPathB, fakeOrigin)
} catch (e) {
useLogger().warn('Failed to parse URLs', e)
return false
}
if (urlA.pathname !== urlB.pathname) {
return false
}
const queryKeysA = urlA.searchParams.keys()
for (const key of queryKeysA) {
if (urlB.searchParams.get(key) !== urlA.searchParams.get(key)) {
return false
}
}
const hashA = deserializeHashState(urlA.hash)
const hashB = deserializeHashState(urlB.hash)
for (const [key, value] of Object.entries(hashA)) {
if (hashB[key] !== value) {
return false
}
}
return true
}