1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-24 13:04:06 +00:00
bramw_baserow/web-frontend/modules/database/components/field/ChooseSingleSelectField.vue
Jonathan Adeline 4321aaea9a Replace icons
2023-09-28 13:39:41 +00:00

100 lines
2.4 KiB
Vue

<template>
<div>
<slot
v-if="canCreateSingleSelectField || singleSelectFields.length > 0"
></slot>
<div v-else class="warning">
{{ $t('chooseSingleSelectField.warningWhenNothingToChooseOrCreate') }}
</div>
<Radio
v-for="field in singleSelectFields"
:key="field.id"
:value="field.id"
:model-value="value"
:loading="loading && field.id === value"
:disabled="loading || readOnly"
@input="$emit('input', $event)"
>{{ field.name }}</Radio
>
<div v-if="canCreateSingleSelectField" class="margin-top-2">
<a
ref="createFieldContextLink"
class="choose-select-field__link margin-right-auto"
@click="$refs.createFieldContext.toggle($refs.createFieldContextLink)"
>
<i class="choose-select-field__link-icon iconoir-plus"></i>
{{ $t('chooseSingleSelectField.addSelectField') }}
</a>
<CreateFieldContext
ref="createFieldContext"
:table="table"
:forced-type="singleSelectFieldType"
@field-created="$event.callback()"
></CreateFieldContext>
</div>
</div>
</template>
<script>
import { SingleSelectFieldType } from '@baserow/modules/database/fieldTypes'
import CreateFieldContext from '@baserow/modules/database/components/field/CreateFieldContext'
export default {
name: 'ChooseSingleSelectField',
components: { CreateFieldContext },
props: {
table: {
type: Object,
required: true,
},
workspace: {
type: Object,
required: true,
},
view: {
type: Object,
required: true,
},
fields: {
type: Array,
required: true,
},
readOnly: {
type: Boolean,
required: false,
default: false,
},
value: {
required: true,
validator() {
return true
},
},
loading: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
canCreateSingleSelectField() {
return (
!this.readOnly &&
this.$hasPermission(
'database.table.create_field',
this.table,
this.workspace.id
)
)
},
singleSelectFieldType() {
return SingleSelectFieldType.getType()
},
singleSelectFields() {
return this.fields.filter(
(field) => field.type === this.singleSelectFieldType
)
},
},
}
</script>