Files
speckle-server/packages/frontend-2/lib/viewer/composables/resources.ts
T
Kristaps Fabians Geikins 596312ab0e feat(frontend): personal project limit disclaimers & prompts (#4822)
* ProjectsAdd wrapper

* WorkspaceMoveProject wrapper added

* move wrapper finalized

* passing through location

* more cleanup

* model add wrapper

* permissions cleanup

* add invite wrapper

* vue-tippy bugfix

* ViewerLimitsDialog prep

* upgrade limit alert prep

* limit alerts

* movemanager fix

* new add flow

* slug update fix

* add model flow

* invites?

* some extra fixes

* move unmount fix?

* more fixes

* vue-tsc update

* style: remove h-32 for smaller screens

* vue-tsc parser fix

* prep for new viewer limits dialog

* updated viewer dialogs

* comment variant cleanup

* CR comments

---------

Co-authored-by: michalspeckle <michal@speckle.systems>
2025-05-28 12:12:18 +03:00

73 lines
2.1 KiB
TypeScript

import type { MaybeNullOrUndefined } from '@speckle/shared'
import {
createGetParamFromResources,
isModelResource,
parseUrlParameters
} from '@speckle/shared/viewer/route'
import type { LayoutDialogButton } from '@speckle/ui-components'
import { graphql } from '~/lib/common/generated/gql'
import type { UseLoadLatestVersion_ProjectFragment } from '~/lib/common/generated/gql/graphql'
import { modelRoute } from '~/lib/common/helpers/route'
import { useMixpanel } from '~/lib/core/composables/mp'
graphql(`
fragment UseLoadLatestVersion_Project on Project {
id
workspace {
slug
}
}
`)
export const useLoadLatestVersion = (params: {
project: Ref<MaybeNullOrUndefined<UseLoadLatestVersion_ProjectFragment>>
resourceIdString: Ref<string>
}) => {
const mixpanel = useMixpanel()
const workspaceSlug = computed(() => unref(params.project)?.workspace?.slug)
const projectId = computed(() => unref(params.project)?.id)
const stripVersionIds = (resourceIdString: string) => {
const resources2 = parseUrlParameters(resourceIdString)
return createGetParamFromResources(
resources2.map((r) => {
if (isModelResource(r)) {
r.versionId = undefined // Remove versionId from the resource
}
return r
})
)
}
const load = async () => {
if (!projectId.value) return
mixpanel.track('Load Latest Version Button Clicked', {
location: 'viewer',
...(workspaceSlug.value
? {
// eslint-disable-next-line camelcase
workspace_id: workspaceSlug.value
}
: {})
})
const latestResourceIdString = stripVersionIds(unref(params.resourceIdString))
// Use the modelRoute but with the cleaned resource string that has no version IDs
navigateTo(modelRoute(projectId.value, latestResourceIdString))
}
const createButton = (isPrimary = true): LayoutDialogButton => ({
text: 'Load latest version',
props: {
color: isPrimary ? 'primary' : 'outline'
},
disabled: !projectId.value?.length || !unref(params.resourceIdString)?.length,
onClick: load
})
return { createButton, load }
}