mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
6.6 KiB
199 lines
6.6 KiB
2 years ago
|
<script lang="ts" setup>
|
||
2 years ago
|
import { UITypes, isVirtualCol } from 'nocodb-sdk'
|
||
2 years ago
|
import { message } from 'ant-design-vue'
|
||
2 years ago
|
import { computed, inject, useMetas, watchEffect } from '#imports'
|
||
2 years ago
|
import { MetaInj, ReloadViewDataHookInj } from '~/context'
|
||
2 years ago
|
import { uiTypes } from '~/utils/columnUtils'
|
||
|
import MdiPlusIcon from '~icons/mdi/plus-circle-outline'
|
||
|
import MdiMinusIcon from '~icons/mdi/minus-circle-outline'
|
||
2 years ago
|
import MdiIdentifierIcon from '~icons/mdi/identifier'
|
||
2 years ago
|
|
||
2 years ago
|
const emit = defineEmits(['submit', 'cancel'])
|
||
2 years ago
|
|
||
2 years ago
|
const { formState, generateNewColumnMeta, addOrUpdate, onAlter, onUidtOrIdTypeChange, validateInfos, isEdit } =
|
||
|
useColumnCreateStoreOrThrow()
|
||
|
|
||
2 years ago
|
const { getMeta } = useMetas()
|
||
|
|
||
|
const { t } = useI18n()
|
||
|
|
||
|
const meta = inject(MetaInj)
|
||
|
|
||
2 years ago
|
const reloadDataTrigger = inject(ReloadViewDataHookInj)
|
||
2 years ago
|
|
||
2 years ago
|
const advancedOptions = ref(false)
|
||
2 years ago
|
|
||
2 years ago
|
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber]
|
||
|
|
||
2 years ago
|
const onlyNameUpdateOnEditColumns = [UITypes.LinkToAnotherRecord, UITypes.Lookup, UITypes.Rollup]
|
||
|
|
||
2 years ago
|
const uiTypesOptions = computed<typeof uiTypes>(() => {
|
||
|
return [
|
||
2 years ago
|
...uiTypes.filter((t) => !isEdit.value || !t.virtual),
|
||
|
...(!isEdit.value && meta?.value?.columns?.every((c) => !c.pk)
|
||
2 years ago
|
? [
|
||
|
{
|
||
2 years ago
|
name: UITypes.ID,
|
||
|
icon: MdiIdentifierIcon,
|
||
|
virtual: 0,
|
||
2 years ago
|
},
|
||
|
]
|
||
|
: []),
|
||
|
]
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const reloadMetaAndData = async () => {
|
||
|
await getMeta(meta?.value.id as string, true)
|
||
2 years ago
|
reloadDataTrigger?.trigger()
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async function onSubmit() {
|
||
|
await addOrUpdate(reloadMetaAndData)
|
||
2 years ago
|
|
||
|
// add delay to complete the minimize transition
|
||
|
setTimeout(() => {
|
||
|
advancedOptions.value = false
|
||
|
}, 500)
|
||
2 years ago
|
emit('submit')
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
// focus and select the column name field
|
||
|
const antInput = ref()
|
||
|
watchEffect(() => {
|
||
|
if (antInput.value && formState.value) {
|
||
|
// todo: replace setTimeout
|
||
|
setTimeout(() => {
|
||
2 years ago
|
antInput.value?.focus()
|
||
|
antInput.value?.select()
|
||
2 years ago
|
}, 300)
|
||
|
}
|
||
2 years ago
|
advancedOptions.value = false
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
onMounted(() => {
|
||
|
if (isEdit.value === false) {
|
||
|
generateNewColumnMeta()
|
||
2 years ago
|
} else {
|
||
|
if (formState.value.pk) {
|
||
|
message.info(t('msg.info.editingPKnotSupported'))
|
||
|
emit('cancel')
|
||
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
// for cases like formula
|
||
|
if (formState.value && !formState.value.column_name) {
|
||
|
formState.value.column_name = formState.value?.title
|
||
|
}
|
||
|
})
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div
|
||
|
class="w-[400px] max-h-[95vh] bg-gray-50 shadow-lg p-6 overflow-auto !border"
|
||
|
:class="{ '!w-[600px]': formState.uidt === UITypes.Formula }"
|
||
|
@click.stop
|
||
|
>
|
||
2 years ago
|
<a-form v-if="formState" v-model="formState" name="column-create-or-edit" layout="vertical">
|
||
2 years ago
|
<div class="flex flex-col gap-2">
|
||
|
<a-form-item :label="$t('labels.columnName')" v-bind="validateInfos.title">
|
||
|
<a-input ref="antInput" v-model:value="formState.title" class="nc-column-name-input" @input="onAlter(8)" />
|
||
|
</a-form-item>
|
||
|
|
||
|
<a-form-item
|
||
2 years ago
|
v-if="!(isEdit && !!onlyNameUpdateOnEditColumns.find((col) => col === formState.uidt))"
|
||
2 years ago
|
:label="$t('labels.columnType')"
|
||
2 years ago
|
>
|
||
2 years ago
|
<a-select v-model:value="formState.uidt" show-search class="nc-column-type-input" @change="onUidtOrIdTypeChange">
|
||
|
<a-select-option v-for="opt of uiTypesOptions" :key="opt.name" :value="opt.name" v-bind="validateInfos.uidt">
|
||
2 years ago
|
<div class="flex gap-1 items-center">
|
||
2 years ago
|
<component :is="opt.icon" class="text-grey" />
|
||
|
{{ opt.name }}
|
||
|
</div>
|
||
|
</a-select-option>
|
||
|
</a-select>
|
||
|
</a-form-item>
|
||
2 years ago
|
<SmartsheetColumnFormulaOptions v-if="formState.uidt === UITypes.Formula" v-model:value="formState" />
|
||
2 years ago
|
<SmartsheetColumnCurrencyOptions v-if="formState.uidt === UITypes.Currency" v-model:value="formState" />
|
||
|
<SmartsheetColumnDurationOptions v-if="formState.uidt === UITypes.Duration" v-model:value="formState" />
|
||
|
<SmartsheetColumnRatingOptions v-if="formState.uidt === UITypes.Rating" v-model:value="formState" />
|
||
|
<SmartsheetColumnCheckboxOptions v-if="formState.uidt === UITypes.Checkbox" v-model:value="formState" />
|
||
|
<SmartsheetColumnLookupOptions v-if="!isEdit && formState.uidt === UITypes.Lookup" v-model:value="formState" />
|
||
|
<SmartsheetColumnDateOptions v-if="formState.uidt === UITypes.Date" v-model:value="formState" />
|
||
|
<SmartsheetColumnRollupOptions v-if="!isEdit && formState.uidt === UITypes.Rollup" v-model:value="formState" />
|
||
2 years ago
|
<SmartsheetColumnLinkedToAnotherRecordOptions
|
||
2 years ago
|
v-if="!isEdit && formState.uidt === UITypes.LinkToAnotherRecord"
|
||
|
v-model:value="formState"
|
||
2 years ago
|
/>
|
||
|
<SmartsheetColumnSpecificDBTypeOptions v-if="formState.uidt === UITypes.SpecificDBType" />
|
||
2 years ago
|
<SmartsheetColumnSelectOptions
|
||
|
v-if="formState.uidt === UITypes.SingleSelect || formState.uidt === UITypes.MultiSelect"
|
||
|
v-model:value="formState"
|
||
|
/>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<div
|
||
|
v-if="!isVirtualCol(formState.uidt)"
|
||
2 years ago
|
class="text-xs cursor-pointer text-grey nc-more-options mb-1 mt-4 flex items-center gap-1 justify-end"
|
||
2 years ago
|
@click="advancedOptions = !advancedOptions"
|
||
|
>
|
||
|
{{ advancedOptions ? $t('general.hideAll') : $t('general.showMore') }}
|
||
|
<component :is="advancedOptions ? MdiMinusIcon : MdiPlusIcon" />
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
2 years ago
|
<div class="overflow-hidden" :class="advancedOptions ? 'h-min mb-2' : 'h-0'">
|
||
2 years ago
|
<a-checkbox
|
||
|
v-if="formState.meta && columnToValidate.includes(formState.uidt)"
|
||
|
v-model:checked="formState.meta.validate"
|
||
|
class="ml-1 mb-1"
|
||
|
>
|
||
2 years ago
|
<span class="text-[10px] text-gray-600">
|
||
2 years ago
|
{{ `Accept only valid ${formState.uidt}` }}
|
||
|
</span>
|
||
|
</a-checkbox>
|
||
2 years ago
|
<SmartsheetColumnAdvancedOptions v-model:value="formState" />
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<a-form-item>
|
||
|
<div class="flex justify-end gap-1 mt-4">
|
||
2 years ago
|
<a-button html-type="button" @click="emit('cancel')">
|
||
2 years ago
|
<!-- Cancel -->
|
||
|
{{ $t('general.cancel') }}
|
||
|
</a-button>
|
||
2 years ago
|
<a-button html-type="submit" type="primary" @click.prevent="onSubmit">
|
||
2 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
|
</a-button>
|
||
|
</div>
|
||
|
</a-form-item>
|
||
2 years ago
|
</a-form>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<style scoped>
|
||
|
:deep(.ant-form-item-label > label) {
|
||
|
@apply !text-xs;
|
||
|
}
|
||
|
|
||
|
:deep(.ant-form-item-label) {
|
||
|
@apply !pb-0;
|
||
|
}
|
||
|
|
||
|
:deep(.ant-form-item-control-input) {
|
||
|
@apply !min-h-min;
|
||
|
}
|
||
|
|
||
|
:deep(.ant-form-item) {
|
||
|
@apply !mb-1;
|
||
|
}
|
||
|
|
||
|
:deep(.ant-select-selection-item) {
|
||
2 years ago
|
@apply flex items-center;
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
:deep(.ant-form-item-explain-error) {
|
||
|
@apply !text-[10px];
|
||
|
}
|
||
|
|
||
|
:deep(.ant-form-item-explain) {
|
||
|
@apply !min-h-[15px];
|
||
|
}
|
||
2 years ago
|
</style>
|