Files
speckle-server/packages/frontend-2/components/automate/function/EditDialog.vue
T
Chuck Driesler e312110933 Automate Public Beta (#3472)
* feat(automate): query active user functions

* fix(automate): show automations to non-stream-owners

* feat(automate): associate function with workspace

* fix(automate): split functions page between user and example functions

* fix(automate): ugh

* fix(functions): use correct query type in different places

* fix(automate): workspace functions page

* feat(automate): query specific categories of functions

* fix(automate): checkpoint

* fix(workspaces): successful queries w local env

* fix(automate): createFunctionWithoutVersion

* fix(automate): successful associate function with workspace

* fix(automate): query and return workspaces on functions

* fix(automate): show current function workspace

* fix(automate): query functions in automation create dialog

* fix(automate): audit non-owner automation access

* refactor(automate): logs api can get the projectId from the path

* fix(automate): multiregion gql resolvers

* fix(automate): multiregion event listeners

* fix(automate): drop automationCount

* fix(automate): multiregion run status

* fix(automate): correctness

* fix(automate): successful usage of multiregion results

* fix(automate): actually finish event listeners

* chore(automate): fix tests fix tests

* fix(automate): fix tests but make it multiregion flavor

* fix(automate): logs endpoint

* fix(automate): inject projectid correctly

* fix(automate): drop user-source functions

* fix(automate): owners edit, others can view

* fix(automate): simplify queries, auto workspace association

* chore(automate): appease

* chore(automate): fix function types

* fix(automate): get to workspace functions from empty state

* chore(automate): death to all slugs

* fix(automate): no create automation from function

* fix(automate): hide workspace change, tweak role access

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2024-11-29 17:33:14 +01:00

95 lines
2.5 KiB
Vue

<template>
<LayoutDialog
v-model:open="open"
title="Edit function"
:buttons="buttons"
max-width="md"
buttons-wrapper-classes="justify-between"
:on-submit="onSubmit"
prevent-close-on-click-outside
>
<AutomateFunctionCreateDialogDetailsStep />
</LayoutDialog>
</template>
<script setup lang="ts">
import type { LayoutDialogButton } from '@speckle/ui-components'
import { useMutationLoading } from '@vue/apollo-composable'
import { difference, differenceBy } from 'lodash-es'
import { useForm } from 'vee-validate'
import { useUpdateAutomateFunction } from '~/lib/automate/composables/management'
import type { FunctionDetailsFormValues } from '~/lib/automate/helpers/functions'
import type { Workspace } from '~/lib/common/generated/gql/graphql'
const props = defineProps<{
model: FunctionDetailsFormValues
fnId: string
workspaces?: Pick<Workspace, 'id' | 'name'>[]
}>()
const open = defineModel<boolean>('open', { required: true })
const { handleSubmit, setValues } = useForm<FunctionDetailsFormValues>()
const mutationLoading = useMutationLoading()
const updateFunction = useUpdateAutomateFunction()
const buttons = computed((): LayoutDialogButton[] => [
{
text: 'Cancel',
props: {
color: 'outline',
class: '!text-primary'
},
onClick: () => (open.value = false)
},
{
text: 'Save',
submit: true,
disabled: mutationLoading.value
}
])
const onSubmit = handleSubmit(async (values) => {
const res = await updateFunction({
input: {
id: props.fnId,
name: values.name !== props.model.name ? values.name : null,
description:
values.description !== props.model.description ? values.description : null,
logo: values.image !== props.model.image ? values.image : null,
tags: difference(values.tags, props.model.tags || []).length ? values.tags : null,
workspaceIds: values.workspace ? [values.workspace.id] : [],
supportedSourceApps: differenceBy(
values.allowedSourceApps,
props.model.allowedSourceApps || [],
(i) => i.name
)
? (values.allowedSourceApps || []).map((a) => a.name)
: null
}
})
if (res?.id) {
open.value = false
}
})
const reset = () => {
// Temp hack while FormSelectBase has a bug where it rewrites form value with initialValue
nextTick(() => {
setValues(props.model)
})
}
watch(
() => props.model,
() => {
reset()
},
{ immediate: true }
)
watch(open, (newVal, oldVal) => {
if (newVal && !oldVal) {
reset()
}
})
</script>