Files
speckle-server/packages/frontend-2/components/project/page/team/PermissionSelect.vue
T
Kristaps Fabians Geikins 83d8035dc2 chore: upgrade to eslint 9 (#2348)
* root + server

* frontend

* frontend-2

* dui3

* dui3

* tailwind theme

* ui-components

* preview service

* viewer

* viewer-sandbox

* fileimport-service

* webhook service

* objectloader

* shared

* ui-components-nuxt

* WIP full config

* WIP full linter

* eslint projectwide util

* minor fix

* removing redundant ci

* clean up test errors

* fixed prettier formatting

* CI improvements

* TSC lint fix

* 'buildBatch' needs to be async since some batch types (like Text) require it. Removed a disabled liniting rule from ObjLoader

* removed unnecessary void

---------

Co-authored-by: AlexandruPopovici <alexandrupopoviciioan@gmail.com>
2024-06-12 14:38:02 +03:00

95 lines
2.2 KiB
Vue

<template>
<FormSelectBase
v-model="selectValue"
:items="Object.values(items)"
label="Project access level"
button-style="simple"
:show-label="showLabel"
:name="name || 'role'"
:allow-unset="false"
:disabled="disabled"
:label-id="labelId"
:button-id="buttonId"
hide-checkmarks
by="id"
class="min-w-[85px]"
mount-menu-on-body
>
<template #something-selected="{ value }">
<div class="text-normal text-right">
{{ isArray(value) ? value[0].title : value.title }}
</div>
</template>
<template #option="{ item, selected }">
<div class="flex flex-col">
<div
:class="[
'text-normal',
selected ? 'text-primary' : '',
item.id === 'delete' ? 'text-danger' : ''
]"
>
{{ item.title }}
</div>
</div>
</template>
</FormSelectBase>
</template>
<script setup lang="ts">
import { roleSelectItems } from '~~/lib/projects/helpers/components'
import { Roles } from '@speckle/shared'
import type { StreamRoles } from '@speckle/shared'
import { reduce, isArray } from 'lodash-es'
const emit = defineEmits<{
(e: 'update:modelValue', v: StreamRoles): void
(e: 'delete'): void
}>()
const props = defineProps<{
modelValue: StreamRoles | string
showLabel?: boolean
name?: string
disabled?: boolean
hideRemove?: boolean
hideOwner?: boolean
}>()
const labelId = useId()
const buttonId = useId()
const items = ref(
reduce(
roleSelectItems,
(results, item) => {
if (item.id === 'delete') {
if (!props.hideRemove) {
results[item.id] = item
}
} else if (item.id === Roles.Stream.Owner) {
if (!props.hideOwner) {
results[item.id] = item
}
} else {
results[item.id] = item
}
return results
},
{} as typeof roleSelectItems
)
)
const selectedValue = computed({
get: () => props.modelValue as StreamRoles,
set: (newVal) => emit('update:modelValue', newVal)
})
const selectValue = computed({
get: () => items.value[selectedValue.value],
set: (newVal) => {
if (newVal.id === 'delete') return emit('delete')
selectedValue.value = newVal.id
}
})
</script>