Files
speckle-server/packages/frontend-2/components/form/select/SavedViewGroup.vue
T
Kristaps Fabians Geikins f87edcb50f feat: saved view update dialog (#5196)
* view update BE foundation

* WIP update service call

* a bunch of tests

* WIP edit view dialog

* fix for auto submit

* frontend works
2025-08-08 13:27:15 +03:00

117 lines
2.9 KiB
Vue

<template>
<FormSelectBase
v-model="selectedValue"
:name="name || 'savedViewGroup'"
:label="label || 'Group'"
:label-id="labelId"
:button-id="buttonId"
mount-menu-on-body
:show-label="showLabel"
:fully-control-value="fullyControlValue"
:disabled="disabled"
:clearable="clearable"
:get-search-results="getSearchResults"
:allow-unset="allowUnset"
search
>
<template #nothing-selected>Select a group</template>
<template #something-selected="{ value }">
<div class="truncate text-foreground capitalize">
{{ isArrayValue(value) ? value.map((v) => v.title).join(', ') : value.title }}
</div>
</template>
<template #option="{ item }">
<div class="flex flex-col space-y-0.5">
<span class="truncate capitalize">{{ item.title }}</span>
</div>
</template>
</FormSelectBase>
</template>
<script setup lang="ts">
import { useFormSelectChildInternals } from '@speckle/ui-components'
import { useApolloClient } from '@vue/apollo-composable'
import { graphql } from '~/lib/common/generated/gql'
import type { FormSelectSavedViewGroup_SavedViewGroupFragment } from '~/lib/common/generated/gql/graphql'
graphql(`
fragment FormSelectSavedViewGroup_SavedViewGroup on SavedViewGroup {
id
title
isUngroupedViewsGroup
}
`)
const searchItemsQuery = graphql(`
query FormSelectSavedViewGroup_SavedViewGroups(
$projectId: String!
$input: SavedViewGroupsInput!
) {
project(id: $projectId) {
id
savedViewGroups(input: $input) {
items {
id
...FormSelectSavedViewGroup_SavedViewGroup
}
totalCount
cursor
}
}
}
`)
type ItemType = FormSelectSavedViewGroup_SavedViewGroupFragment
type ValueType = ItemType | ItemType[] | undefined
const emit = defineEmits<{
(e: 'update:modelValue', v: ValueType): void
}>()
const props = withDefaults(
defineProps<{
projectId: string
resourceIdString: string
modelValue?: ValueType
fullyControlValue?: boolean
label?: string
disabled?: boolean
showLabel?: boolean
clearable?: boolean
allowUnset?: boolean
name?: string
}>(),
{
clearable: false,
allowUnset: false
}
)
const apollo = useApolloClient().client
const labelId = useId()
const buttonId = useId()
const { selectedValue, isArrayValue } = useFormSelectChildInternals<ItemType>({
props: toRefs(props),
emit
})
const getSearchResults = async (search: string): Promise<ItemType[]> => {
const res = await apollo
.query({
query: searchItemsQuery,
variables: {
projectId: props.projectId,
input: {
resourceIdString: props.resourceIdString,
search,
limit: 10
}
}
})
.catch(convertThrowIntoFetchResult)
const items = res.data?.project.savedViewGroups.items || []
return items
}
</script>