From f2a3bcb4b7816338c43bf2aa22eda4813fda60a8 Mon Sep 17 00:00:00 2001 From: andrewwallacespeckle Date: Wed, 2 Apr 2025 16:49:55 +0200 Subject: [PATCH] Move composables to their own file --- .../projects/MoveToWorkspaceDialog.vue | 2 +- .../viewer/anchored-point/thread/Comment.vue | 2 + .../thread/CommentLimitAlert.vue | 6 +- .../workspace/MoveProjectsDialog.vue | 6 +- .../lib/workspaces/composables/limits.ts | 53 +++++++++++ .../lib/workspaces/composables/plan.ts | 87 +------------------ .../lib/workspaces/composables/usage.ts | 30 +++++++ 7 files changed, 94 insertions(+), 92 deletions(-) create mode 100644 packages/frontend-2/lib/workspaces/composables/limits.ts create mode 100644 packages/frontend-2/lib/workspaces/composables/usage.ts diff --git a/packages/frontend-2/components/projects/MoveToWorkspaceDialog.vue b/packages/frontend-2/components/projects/MoveToWorkspaceDialog.vue index 7234dfd88..d2c5ed276 100644 --- a/packages/frontend-2/components/projects/MoveToWorkspaceDialog.vue +++ b/packages/frontend-2/components/projects/MoveToWorkspaceDialog.vue @@ -76,7 +76,7 @@ import { useWorkspaceCustomDataResidencyDisclaimer, RegionStaticDataDisclaimerVariant } from '~/lib/workspaces/composables/region' -import { useWorkspacePlanLimits } from '~/lib/workspaces/composables/plan' +import { useWorkspacePlanLimits } from '~/lib/workspaces/composables/limits' graphql(` fragment ProjectsMoveToWorkspaceDialog_Workspace on Workspace { diff --git a/packages/frontend-2/components/viewer/anchored-point/thread/Comment.vue b/packages/frontend-2/components/viewer/anchored-point/thread/Comment.vue index 46f9d054f..50958e3d9 100644 --- a/packages/frontend-2/components/viewer/anchored-point/thread/Comment.vue +++ b/packages/frontend-2/components/viewer/anchored-point/thread/Comment.vue @@ -30,7 +30,9 @@ readonly @created="emit('mounted')" /> + + diff --git a/packages/frontend-2/components/workspace/MoveProjectsDialog.vue b/packages/frontend-2/components/workspace/MoveProjectsDialog.vue index 22b4ac1b3..e24694b93 100644 --- a/packages/frontend-2/components/workspace/MoveProjectsDialog.vue +++ b/packages/frontend-2/components/workspace/MoveProjectsDialog.vue @@ -89,10 +89,8 @@ import type { import { usePaginatedQuery } from '~/lib/common/composables/graphql' import { moveProjectsDialogQuery } from '~~/lib/workspaces/graphql/queries' import { Roles } from '@speckle/shared' -import { - useWorkspacePlanLimits, - useGetWorkspacePlanUsage -} from '~/lib/workspaces/composables/plan' +import { useWorkspacePlanLimits } from '~/lib/workspaces/composables/limits' +import { useGetWorkspacePlanUsage } from '~/lib/workspaces/composables/usage' graphql(` fragment MoveProjectsDialog_Workspace on Workspace { diff --git a/packages/frontend-2/lib/workspaces/composables/limits.ts b/packages/frontend-2/lib/workspaces/composables/limits.ts new file mode 100644 index 000000000..b25aec7ca --- /dev/null +++ b/packages/frontend-2/lib/workspaces/composables/limits.ts @@ -0,0 +1,53 @@ +export const useWorkspacePlanLimits = ( + projectCount: ComputedRef, + modelCount: ComputedRef +) => { + const projectLimit = computed(() => 3) + const modelLimit = computed(() => 8) + + const remainingProjects = computed(() => { + return projectLimit.value - projectCount.value + }) + + const remainingModels = computed(() => { + return modelLimit.value - modelCount.value + }) + + const limitType = computed(() => { + if (projectCount.value > projectLimit.value) { + return 'project' + } + if (modelCount.value > modelLimit.value) { + return 'model' + } + return null + }) + + const activeLimit = computed(() => { + const limit = + limitType.value === 'project' + ? projectLimit.value + : limitType.value === 'model' + ? modelLimit.value + : null + return limit + }) + + const canAddProject = computed( + () => remainingProjects.value !== null && remainingProjects.value > 0 + ) + const canAddModels = computed( + () => remainingModels.value !== null && remainingModels.value > 0 + ) + + return { + projectLimit, + modelLimit, + remainingProjects, + remainingModels, + canAddProject, + canAddModels, + limitType, + activeLimit + } +} diff --git a/packages/frontend-2/lib/workspaces/composables/plan.ts b/packages/frontend-2/lib/workspaces/composables/plan.ts index f137799ce..ded0776e5 100644 --- a/packages/frontend-2/lib/workspaces/composables/plan.ts +++ b/packages/frontend-2/lib/workspaces/composables/plan.ts @@ -1,8 +1,5 @@ import { graphql } from '~~/lib/common/generated/gql' -import { - workspacePlanLimitsQuery, - workspacePlanQuery -} from '~~/lib/workspaces/graphql/queries' +import { workspacePlanQuery } from '~~/lib/workspaces/graphql/queries' import { useQuery } from '@vue/apollo-composable' import { isNewWorkspacePlan, @@ -158,85 +155,3 @@ graphql(` } } `) - -export const useGetWorkspacePlanUsage = (slug: string) => { - const { result } = useQuery( - workspacePlanLimitsQuery, - () => ({ - slug - }), - () => ({ - enabled: !!slug - }) - ) - - const projectCount = computed( - () => result.value?.workspaceBySlug?.projects?.totalCount ?? 0 - ) - const modelCount = computed( - () => - result.value?.workspaceBySlug?.projects?.items?.reduce( - (total, project) => total + (project?.models?.totalCount ?? 0), - 0 - ) ?? 0 - ) - - return { - projectCount, - modelCount - } -} - -export const useWorkspacePlanLimits = ( - projectCount: ComputedRef, - modelCount: ComputedRef -) => { - const projectLimit = computed(() => 3) - const modelLimit = computed(() => 8) - - const remainingProjects = computed(() => { - return projectLimit.value - projectCount.value - }) - - const remainingModels = computed(() => { - return modelLimit.value - modelCount.value - }) - - const limitType = computed(() => { - if (projectCount.value > projectLimit.value) { - return 'project' - } - if (modelCount.value > modelLimit.value) { - return 'model' - } - return null - }) - - const activeLimit = computed(() => { - const limit = - limitType.value === 'project' - ? projectLimit.value - : limitType.value === 'model' - ? modelLimit.value - : null - return limit - }) - - const canAddProject = computed( - () => remainingProjects.value !== null && remainingProjects.value > 0 - ) - const canAddModels = computed( - () => remainingModels.value !== null && remainingModels.value > 0 - ) - - return { - projectLimit, - modelLimit, - remainingProjects, - remainingModels, - canAddProject, - canAddModels, - limitType, - activeLimit - } -} diff --git a/packages/frontend-2/lib/workspaces/composables/usage.ts b/packages/frontend-2/lib/workspaces/composables/usage.ts new file mode 100644 index 000000000..5ab365806 --- /dev/null +++ b/packages/frontend-2/lib/workspaces/composables/usage.ts @@ -0,0 +1,30 @@ +import { useQuery } from '@vue/apollo-composable' +import { workspacePlanLimitsQuery } from '~/lib/workspaces/graphql/queries' + +export const useGetWorkspacePlanUsage = (slug: string) => { + const { result } = useQuery( + workspacePlanLimitsQuery, + () => ({ + slug + }), + () => ({ + enabled: !!slug + }) + ) + + const projectCount = computed( + () => result.value?.workspaceBySlug?.projects?.totalCount ?? 0 + ) + const modelCount = computed( + () => + result.value?.workspaceBySlug?.projects?.items?.reduce( + (total, project) => total + (project?.models?.totalCount ?? 0), + 0 + ) ?? 0 + ) + + return { + projectCount, + modelCount + } +}