Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@
<script setup lang="ts">
import type { AccHub } from '@speckle/shared/acc'
import type { LayoutDialogButton } from '@speckle/ui-components'
import { useMutation } from '@vue/apollo-composable'
import { useForm } from 'vee-validate'
import { useAccAuthManager } from '~/lib/acc/composables/useAccAuthManager'
import {
useAcc,
type AccFolder,
type AccItemVersion
} from '~/lib/acc/composables/useAccFiles'
import { accSyncItemCreateMutation } from '~/lib/acc/graphql/mutations'
import { useCreateNewModel } from '~/lib/projects/composables/modelManagement'
import { useCreateAccSyncItem } from '~/lib/acc/composables/useCreateAccSyncItem'

type FormValues = { feedback: string }

Expand All @@ -68,21 +66,26 @@ const props = defineProps<{

const isOpen = defineModel<boolean>('open', { required: true })

const isCreatingSyncItem = ref(false)
const disableCreateButton = computed(() => !!isCreatingSyncItem.value)

const { handleSubmit } = useForm<FormValues>()

const dialogButtons = computed((): LayoutDialogButton[] => [
{
text: 'Create',
props: { color: 'primary' },
props: { color: 'primary', loading: isCreatingSyncItem.value },
onClick: () => {
onSubmit()
},
disabled: disableCreateButton.value,
disabledMessage: 'Creating ACC sync...',
id: 'createAccSync'
}
])

const { triggerNotification } = useGlobalToast()
const createModel = useCreateNewModel()
const createAccSyncItem = useCreateAccSyncItem()

const dialogTitle = computed(() => props.title || 'Create sync from ACC')

Expand Down Expand Up @@ -132,39 +135,28 @@ const onFileSelected = (fileId: string, fileVersion: AccItemVersion) => {
selectedFileVersion.value = fileVersion
}

const { mutate: createAccSyncItem } = useMutation(accSyncItemCreateMutation)

const addSync = async () => {
try {
if (!selectedFileVersion.value || !selectedFileVersion.value.fileType) {
return
}
isCreatingSyncItem.value = true

const fileVersion = selectedFileVersion.value.versionNumber

const accFileViewName = revitViewName.value === '' ? undefined : revitViewName.value

const res = await createModel({
name: selectedFileVersion.value.name,
description: '',
projectId: props.projectId as string
})

await createAccSyncItem({
input: {
projectId: props.projectId as string,
modelId: res?.id as string,
accRegion: selectedHub.value?.attributes?.region as string,
accFileExtension: selectedFileVersion.value.fileType,
accHubId: selectedHubId.value!,
accProjectId: selectedProjectId.value as string,
accRootProjectFolderUrn: rootProjectFolderId.value!,
accFileLineageUrn: selectedFileId.value as string,
accFileName: selectedFileVersion.value.name,
accFileVersionIndex: fileVersion,
accFileVersionUrn: selectedFileVersion.value.id,
accFileViewName
}
projectId: props.projectId as string,
accRegion: selectedHub.value?.attributes?.region as string,
accFileExtension: selectedFileVersion.value.fileType,
accHubId: selectedHubId.value!,
accProjectId: selectedProjectId.value as string,
accRootProjectFolderUrn: rootProjectFolderId.value!,
accFileLineageUrn: selectedFileId.value as string,
accFileName: selectedFileVersion.value.name,
accFileVersionIndex: fileVersion,
accFileVersionUrn: selectedFileVersion.value.id,
accFileViewName
})
} catch (error) {
triggerNotification({
Expand All @@ -173,6 +165,7 @@ const addSync = async () => {
description: error instanceof Error ? error.message : 'Unexpected error'
})
} finally {
isCreatingSyncItem.value = false
revitViewName.value = undefined
}
}
Expand Down
80 changes: 80 additions & 0 deletions packages/frontend-2/lib/acc/composables/useCreateAccSyncItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useApolloClient } from '@vue/apollo-composable'
import { accSyncItemCreateMutation } from '~/lib/acc/graphql/mutations'
import { useCreateNewModel } from '~/lib/projects/composables/modelManagement'

export const useCreateAccSyncItem = () => {
const apollo = useApolloClient().client
const { triggerNotification } = useGlobalToast()
const createModel = useCreateNewModel()

return async (args: {
projectId: string
accRegion: string
accFileExtension: string
accHubId: string
accProjectId: string
accRootProjectFolderUrn: string
accFileLineageUrn: string
accFileName: string
accFileVersionIndex: number
accFileVersionUrn: string
accFileViewName?: string
}) => {
try {
const model = await createModel({
name: args.accFileName,
description: '',
projectId: args.projectId
})

if (!model) {
throw new Error('Failed to create model')
}

await apollo.mutate({
mutation: accSyncItemCreateMutation,
variables: {
input: {
projectId: args.projectId,
modelId: model.id,
accHubId: args.accHubId,
accRegion: args.accRegion,
accProjectId: args.accProjectId,
accRootProjectFolderUrn: args.accRootProjectFolderUrn,
accFileLineageUrn: args.accFileLineageUrn,
accFileVersionUrn: args.accFileVersionUrn,
accFileName: args.accFileName,
accFileExtension: args.accFileExtension,
accFileVersionIndex: args.accFileVersionIndex,
accFileViewName: args.accFileViewName
}
},
update: (cache, { data }) => {
if (!data?.accSyncItemMutations.create) return
const newSyncItem = data.accSyncItemMutations.create
cache.modify({
id: getCacheId('Model', model.id),
fields: {
accSyncItem: () => newSyncItem
}
})
cache.modify({
id: getCacheId('Project', args.projectId),
fields: {
accSyncItems: (value) => {
const syncItems = value ?? []
return [newSyncItem, ...syncItems]
}
}
})
}
})
} catch (e) {
triggerNotification({
type: ToastNotificationType.Danger,
title: 'Failed to sync with ACC',
description: e instanceof Error ? e.message : 'Unexpected error'
})
}
}
}
10 changes: 10 additions & 0 deletions packages/frontend-2/lib/acc/graphql/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ export const accSyncItemCreateMutation = graphql(`
accSyncItemMutations {
create(input: $input) {
id
model {
id
name
}
author {
id
name
}
accFileName
accFileLineageUrn
accFileViewName
status
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend-2/lib/common/generated/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ type Documents = {
"\n fragment WorkspaceWizardStepRegion_ServerInfo on ServerInfo {\n multiRegion {\n regions {\n id\n ...SettingsWorkspacesRegionsSelect_ServerRegionItem\n }\n }\n }\n": typeof types.WorkspaceWizardStepRegion_ServerInfoFragmentDoc,
"\n fragment AccFolderContents on AccFolder {\n id\n name\n contents {\n items {\n id\n name\n latestVersion {\n id\n name\n versionNumber\n fileType\n }\n }\n }\n children {\n items {\n id\n name\n }\n }\n }\n ": typeof types.AccFolderContentsFragmentDoc,
"\n fragment ProjectAccSyncItem on AccSyncItem {\n id\n project {\n id\n }\n model {\n id\n }\n accRegion\n accHubId\n accProjectId\n accRootProjectFolderUrn\n accFileLineageUrn\n accFileName\n accFileExtension\n accFileVersionIndex\n accFileViewName\n updatedAt\n status\n author {\n name\n avatar\n }\n }\n": typeof types.ProjectAccSyncItemFragmentDoc,
"\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n accFileLineageUrn\n status\n }\n }\n }\n": typeof types.CreateAccSyncItemDocument,
"\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n model {\n id\n name\n }\n author {\n id\n name\n }\n accFileName\n accFileLineageUrn\n accFileViewName\n status\n }\n }\n }\n": typeof types.CreateAccSyncItemDocument,
"\n mutation DeleteAccSyncItem($input: DeleteAccSyncItemInput!) {\n accSyncItemMutations {\n delete(input: $input)\n }\n }\n": typeof types.DeleteAccSyncItemDocument,
"\n mutation UpdateAccSyncItem($input: UpdateAccSyncItemInput!) {\n accSyncItemMutations {\n update(input: $input) {\n id\n status\n }\n }\n }\n": typeof types.UpdateAccSyncItemDocument,
"\n query ProjectAccSyncItems($id: String!) {\n project(id: $id) {\n accSyncItems {\n items {\n ...ProjectAccSyncItem\n }\n }\n }\n }\n": typeof types.ProjectAccSyncItemsDocument,
Expand Down Expand Up @@ -776,7 +776,7 @@ const documents: Documents = {
"\n fragment WorkspaceWizardStepRegion_ServerInfo on ServerInfo {\n multiRegion {\n regions {\n id\n ...SettingsWorkspacesRegionsSelect_ServerRegionItem\n }\n }\n }\n": types.WorkspaceWizardStepRegion_ServerInfoFragmentDoc,
"\n fragment AccFolderContents on AccFolder {\n id\n name\n contents {\n items {\n id\n name\n latestVersion {\n id\n name\n versionNumber\n fileType\n }\n }\n }\n children {\n items {\n id\n name\n }\n }\n }\n ": types.AccFolderContentsFragmentDoc,
"\n fragment ProjectAccSyncItem on AccSyncItem {\n id\n project {\n id\n }\n model {\n id\n }\n accRegion\n accHubId\n accProjectId\n accRootProjectFolderUrn\n accFileLineageUrn\n accFileName\n accFileExtension\n accFileVersionIndex\n accFileViewName\n updatedAt\n status\n author {\n name\n avatar\n }\n }\n": types.ProjectAccSyncItemFragmentDoc,
"\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n accFileLineageUrn\n status\n }\n }\n }\n": types.CreateAccSyncItemDocument,
"\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n model {\n id\n name\n }\n author {\n id\n name\n }\n accFileName\n accFileLineageUrn\n accFileViewName\n status\n }\n }\n }\n": types.CreateAccSyncItemDocument,
"\n mutation DeleteAccSyncItem($input: DeleteAccSyncItemInput!) {\n accSyncItemMutations {\n delete(input: $input)\n }\n }\n": types.DeleteAccSyncItemDocument,
"\n mutation UpdateAccSyncItem($input: UpdateAccSyncItemInput!) {\n accSyncItemMutations {\n update(input: $input) {\n id\n status\n }\n }\n }\n": types.UpdateAccSyncItemDocument,
"\n query ProjectAccSyncItems($id: String!) {\n project(id: $id) {\n accSyncItems {\n items {\n ...ProjectAccSyncItem\n }\n }\n }\n }\n": types.ProjectAccSyncItemsDocument,
Expand Down Expand Up @@ -1983,7 +1983,7 @@ export function graphql(source: "\n fragment ProjectAccSyncItem on AccSyncItem
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n accFileLineageUrn\n status\n }\n }\n }\n"): (typeof documents)["\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n accFileLineageUrn\n status\n }\n }\n }\n"];
export function graphql(source: "\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n model {\n id\n name\n }\n author {\n id\n name\n }\n accFileName\n accFileLineageUrn\n accFileViewName\n status\n }\n }\n }\n"): (typeof documents)["\n mutation CreateAccSyncItem($input: CreateAccSyncItemInput!) {\n accSyncItemMutations {\n create(input: $input) {\n id\n model {\n id\n name\n }\n author {\n id\n name\n }\n accFileName\n accFileLineageUrn\n accFileViewName\n status\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading
Loading