Files
speckle-server/packages/frontend-2/components/viewer/resources/add-model/DialogObjectTab.vue
T
Benjamin Ottensten fc76fd9f4f Various polishing around the product (#2427)
* Update header navigation

Logo, share button color, breadcrumb colors, spacings

* Updates to main button component

Shadows, border on secondary button, less spacings to icons

* Update spacings in dialog after bew button styling

* Use secondary button in embed dialog

* Update select inputs

Spacing, icon, border on dropdown, smaller avatars

* Update inputs to use the new styling

* Various copy updates

* Update icons

Smaller icons, outline instead of solid, removed some icons that were unnecessary

* Switch order of actions in Delete dialog

* Update styling of inline New model action

* Remove strange BG effect on comments component

* Update styling of hide/isolate actions in viewer

Was necessary after the button styling change. But new copy also makes it more usable.

* Fix alignment issue in selection info panel

* Align styling in Viewer panel component

* Clean up measure usage tips

A permanent "Right click to cancel measurement" tip isn't needed

* Panel spacing

* Update actions in the add model to viewer dialog

* Update permissions input in new project dialog

* Two minor things

* Remove unnecessary flex classes

---------

Co-authored-by: andrewwallacespeckle <andrew@speckle.systems>
2024-06-25 14:43:50 +02:00

87 lines
2.8 KiB
Vue

<template>
<div class="flex flex-col gap-y-4">
<div class="text-foreground normal text-sm sm:text-base">
Add objects from the current project by their IDs or an Object URL.
</div>
<form
class="flex flex-col gap-y-4 sm:space-y-0 sm:flex-row sm:space-x-4 w-full"
@submit="onSubmit"
>
<FormTextInput
name="objectIdsOrUrl"
label="Value"
full-width
:custom-icon="LinkIcon"
:rules="[isRequired, isValidValue]"
placeholder="Comma-delimited object IDs/URLs"
color="foundation"
auto-focus
/>
<FormButton :icon-left="PlusIcon" submit>Add</FormButton>
</form>
</div>
</template>
<script setup lang="ts">
import { useForm } from 'vee-validate'
import type { RuleExpression } from 'vee-validate'
import { PlusIcon, LinkIcon } from '@heroicons/vue/20/solid'
import { isRequired } from '~~/lib/common/helpers/validation'
import { isObjectId } from '~~/lib/common/helpers/resources'
import { useInjectedViewerLoadedResources } from '~~/lib/viewer/composables/setup'
import { difference } from 'lodash-es'
const emit = defineEmits<{
(e: 'chosen', val: { objectIds: string[] }): void
}>()
type FormPayload = { objectIdsOrUrl: string }
const urlRegexp = /\/models\/([a-zA-Z0-_9,@$]+)$/i
const { handleSubmit } = useForm<FormPayload>()
const { resourceItems } = useInjectedViewerLoadedResources()
const explodeValidatedObjectIds = (commaDelimitedIdList: string) => {
const idParts = commaDelimitedIdList.split(',')
const areIdsValid = !idParts.some((id) => !isObjectId(id))
if (areIdsValid) return idParts
return null
}
const extractObjectIds = (urlOrObjectIds: string) => {
const [, idsString] = urlOrObjectIds.match(urlRegexp) || []
if (idsString) {
const listedIds = explodeValidatedObjectIds(idsString)
if (listedIds?.length) return listedIds
} else {
const listedIds = explodeValidatedObjectIds(urlOrObjectIds)
if (listedIds?.length) return listedIds
}
return null
}
const removeRedundantIds = (objectIds: string[]) => {
const loadedObjectIds = resourceItems.value.map((i) => i.objectId)
const newIds = difference(objectIds, loadedObjectIds)
return newIds.length ? newIds : null
}
const isValidValue: RuleExpression<string> = (newVal) => {
const ids = extractObjectIds(newVal)
if (!ids)
return 'Value must consist of comma-delimited object IDs or an URL to an object viewer page'
const newIds = removeRedundantIds(ids)
if (!newIds) return 'All specified objects are already loaded in the viewer'
return true
}
const onSubmit = handleSubmit((payload) => {
const { objectIdsOrUrl } = payload
const ids = removeRedundantIds(extractObjectIds(objectIdsOrUrl) || [])
if (!ids?.length) return
emit('chosen', { objectIds: ids })
})
</script>