|
|
@ -1,28 +1,26 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
<script lang="ts" setup> |
|
|
|
import { UITypes, isVirtualCol } from 'nocodb-sdk' |
|
|
|
import { UITypes, isVirtualCol } from 'nocodb-sdk' |
|
|
|
import { computed, inject, useColumnCreateStoreOrThrow, useMetas, watchEffect } from '#imports' |
|
|
|
import { computed, inject, useMetas, watchEffect } from '#imports' |
|
|
|
import { MetaInj, ReloadViewDataHookInj } from '~/context' |
|
|
|
import { MetaInj, ReloadViewDataHookInj } from '~/context' |
|
|
|
import { uiTypes } from '~/utils/columnUtils' |
|
|
|
import { uiTypes } from '~/utils/columnUtils' |
|
|
|
import MdiPlusIcon from '~icons/mdi/plus-circle-outline' |
|
|
|
import MdiPlusIcon from '~icons/mdi/plus-circle-outline' |
|
|
|
import MdiMinusIcon from '~icons/mdi/minus-circle-outline' |
|
|
|
import MdiMinusIcon from '~icons/mdi/minus-circle-outline' |
|
|
|
import MdiIdentifierIcon from '~icons/mdi/identifier' |
|
|
|
import MdiIdentifierIcon from '~icons/mdi/identifier' |
|
|
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
const emit = defineEmits(['submit', 'cancel']) |
|
|
|
editColumnDropdown?: boolean |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { editColumnDropdown } = defineProps<Props>() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['cancel', 'submit']) |
|
|
|
|
|
|
|
const meta = inject(MetaInj) |
|
|
|
const meta = inject(MetaInj) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { formState, generateNewColumnMeta, addOrUpdate, onAlter, onUidtOrIdTypeChange, validateInfos, isEdit } = |
|
|
|
|
|
|
|
useColumnCreateStoreOrThrow() |
|
|
|
|
|
|
|
|
|
|
|
const reloadDataTrigger = inject(ReloadViewDataHookInj) |
|
|
|
const reloadDataTrigger = inject(ReloadViewDataHookInj) |
|
|
|
|
|
|
|
|
|
|
|
const advancedOptions = ref(false) |
|
|
|
const advancedOptions = ref(false) |
|
|
|
const { getMeta } = useMetas() |
|
|
|
const { getMeta } = useMetas() |
|
|
|
|
|
|
|
|
|
|
|
const formulaOptionsRef = ref() |
|
|
|
const formulaOptionsRef = ref() |
|
|
|
|
|
|
|
const editOrAddRef = ref<HTMLElement>() |
|
|
|
const { formState, validateInfos, onUidtOrIdTypeChange, onAlter, addOrUpdate, generateNewColumnMeta, isEdit } = |
|
|
|
|
|
|
|
useColumnCreateStoreOrThrow() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber] |
|
|
|
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber] |
|
|
|
|
|
|
|
|
|
|
@ -44,18 +42,8 @@ const uiTypesOptions = computed<typeof uiTypes>(() => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const reloadMetaAndData = async () => { |
|
|
|
const reloadMetaAndData = async () => { |
|
|
|
emit('cancel') |
|
|
|
|
|
|
|
await getMeta(meta?.value.id as string, true) |
|
|
|
await getMeta(meta?.value.id as string, true) |
|
|
|
reloadDataTrigger?.trigger() |
|
|
|
reloadDataTrigger?.trigger() |
|
|
|
emit('submit') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onCancel() { |
|
|
|
|
|
|
|
emit('cancel') |
|
|
|
|
|
|
|
if (formState.value.uidt === UITypes.Formula) { |
|
|
|
|
|
|
|
// close formula drawer |
|
|
|
|
|
|
|
formulaOptionsRef.value.formulaSuggestionDrawer = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function onSubmit() { |
|
|
|
async function onSubmit() { |
|
|
@ -65,55 +53,69 @@ async function onSubmit() { |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
advancedOptions.value = false |
|
|
|
advancedOptions.value = false |
|
|
|
}, 500) |
|
|
|
}, 500) |
|
|
|
|
|
|
|
emit('submit') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// create column meta if it's a new column |
|
|
|
|
|
|
|
watchEffect(() => { |
|
|
|
|
|
|
|
if (!isEdit.value && formState.value.altered !== 1) { |
|
|
|
|
|
|
|
generateNewColumnMeta() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// focus and select the column name field |
|
|
|
// focus and select the column name field |
|
|
|
const antInput = ref() |
|
|
|
const antInput = ref() |
|
|
|
watchEffect(() => { |
|
|
|
watchEffect(() => { |
|
|
|
if (antInput.value && formState.value) { |
|
|
|
if (antInput.value && formState.value) { |
|
|
|
// todo: replace setTimeout |
|
|
|
// todo: replace setTimeout |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
antInput.value.focus() |
|
|
|
antInput.value?.focus() |
|
|
|
antInput.value.select() |
|
|
|
antInput.value?.select() |
|
|
|
}, 300) |
|
|
|
}, 300) |
|
|
|
} |
|
|
|
} |
|
|
|
advancedOptions.value = false |
|
|
|
advancedOptions.value = false |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
onMounted(() => { |
|
|
|
() => editColumnDropdown, |
|
|
|
if (isEdit.value === false) { |
|
|
|
(v) => { |
|
|
|
generateNewColumnMeta() |
|
|
|
if (v) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (formState.value.uidt === UITypes.Formula) { |
|
|
|
if (formState.value.uidt === UITypes.Formula) { |
|
|
|
formulaOptionsRef.value.formulaSuggestionDrawer = true |
|
|
|
formulaOptionsRef.value.formulaSuggestionDrawer = true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for cases like formula |
|
|
|
// for cases like formula |
|
|
|
if (!formState.value?.column_name) { |
|
|
|
if (formState.value && !formState.value.column_name) { |
|
|
|
formState.value.column_name = formState.value?.title |
|
|
|
formState.value.column_name = formState.value?.title |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => { |
|
|
|
|
|
|
|
if (formState.value.uidt === UITypes.Formula) { |
|
|
|
|
|
|
|
// close formula drawer |
|
|
|
|
|
|
|
formulaOptionsRef.value.formulaSuggestionDrawer = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleClose = (e: MouseEvent) => { |
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
e.target && |
|
|
|
|
|
|
|
editOrAddRef?.value && |
|
|
|
|
|
|
|
!editOrAddRef.value.contains(e.target) && |
|
|
|
|
|
|
|
!e.target.closest('.ant-dropdown') && |
|
|
|
|
|
|
|
!e.target.closest('.ant-select') && |
|
|
|
|
|
|
|
!e.target.closest('.ant-select-item') |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
emit('cancel') |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
useEventListener(document, 'click', handleClose) |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div class="min-w-[400px] max-h-[95vh] bg-white shadow p-6 overflow-auto" @click.stop> |
|
|
|
<div ref="editOrAddRef" class="min-w-[400px] max-h-[95vh] bg-white shadow p-6 overflow-auto" @click.stop> |
|
|
|
<a-form v-model="formState" name="column-create-or-edit" layout="vertical"> |
|
|
|
<a-form v-if="formState" v-model="formState" name="column-create-or-edit" layout="vertical"> |
|
|
|
<div class="flex flex-col gap-2"> |
|
|
|
<div class="flex flex-col gap-2"> |
|
|
|
<a-form-item :label="$t('labels.columnName')" v-bind="validateInfos.title"> |
|
|
|
<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-input ref="antInput" v-model:value="formState.title" class="nc-column-name-input" @input="onAlter(8)" /> |
|
|
|
</a-form-item> |
|
|
|
</a-form-item> |
|
|
|
|
|
|
|
|
|
|
|
<a-form-item |
|
|
|
<a-form-item |
|
|
|
v-if="!(editColumnDropdown && !!onlyNameUpdateOnEditColumns.find((col) => col === formState.uidt))" |
|
|
|
v-if="!(isEdit && !!onlyNameUpdateOnEditColumns.find((col) => col === formState.uidt))" |
|
|
|
:label="$t('labels.columnType')" |
|
|
|
:label="$t('labels.columnType')" |
|
|
|
> |
|
|
|
> |
|
|
|
<a-select v-model:value="formState.uidt" show-search class="nc-column-type-input" @change="onUidtOrIdTypeChange"> |
|
|
|
<a-select v-model:value="formState.uidt" show-search class="nc-column-type-input" @change="onUidtOrIdTypeChange"> |
|
|
@ -125,20 +127,28 @@ if (!formState.value?.column_name) { |
|
|
|
</a-select-option> |
|
|
|
</a-select-option> |
|
|
|
</a-select> |
|
|
|
</a-select> |
|
|
|
</a-form-item> |
|
|
|
</a-form-item> |
|
|
|
<SmartsheetColumnFormulaOptions v-if="formState.uidt === UITypes.Formula" ref="formulaOptionsRef" /> |
|
|
|
<SmartsheetColumnFormulaOptions |
|
|
|
<SmartsheetColumnCurrencyOptions v-if="formState.uidt === UITypes.Currency" /> |
|
|
|
v-if="formState.uidt === UITypes.Formula" |
|
|
|
<SmartsheetColumnDurationOptions v-if="formState.uidt === UITypes.Duration" /> |
|
|
|
ref="formulaOptionsRef" |
|
|
|
<SmartsheetColumnRatingOptions v-if="formState.uidt === UITypes.Rating" /> |
|
|
|
v-model:value="formState" |
|
|
|
<SmartsheetColumnCheckboxOptions v-if="formState.uidt === UITypes.Checkbox" /> |
|
|
|
/> |
|
|
|
<SmartsheetColumnLookupOptions v-if="!editColumnDropdown && formState.uidt === UITypes.Lookup" /> |
|
|
|
<SmartsheetColumnCurrencyOptions v-if="formState.uidt === UITypes.Currency" v-model:value="formState" /> |
|
|
|
<SmartsheetColumnDateOptions v-if="formState.uidt === UITypes.Date" /> |
|
|
|
<SmartsheetColumnDurationOptions v-if="formState.uidt === UITypes.Duration" v-model:value="formState" /> |
|
|
|
<SmartsheetColumnRollupOptions v-if="!editColumnDropdown && formState.uidt === UITypes.Rollup" /> |
|
|
|
<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" /> |
|
|
|
<SmartsheetColumnLinkedToAnotherRecordOptions |
|
|
|
<SmartsheetColumnLinkedToAnotherRecordOptions |
|
|
|
v-if="!editColumnDropdown && formState.uidt === UITypes.LinkToAnotherRecord" |
|
|
|
v-if="!isEdit && formState.uidt === UITypes.LinkToAnotherRecord" |
|
|
|
|
|
|
|
v-model:value="formState" |
|
|
|
/> |
|
|
|
/> |
|
|
|
<SmartsheetColumnSpecificDBTypeOptions v-if="formState.uidt === UITypes.SpecificDBType" /> |
|
|
|
<SmartsheetColumnSpecificDBTypeOptions v-if="formState.uidt === UITypes.SpecificDBType" /> |
|
|
|
<SmartsheetColumnPercentOptions v-if="formState.uidt === UITypes.Percent" /> |
|
|
|
<SmartsheetColumnPercentOptions v-if="formState.uidt === UITypes.Percent" v-model:value="formState" /> |
|
|
|
<SmartsheetColumnSelectOptions v-if="formState.uidt === UITypes.SingleSelect || formState.uidt === UITypes.MultiSelect" /> |
|
|
|
<SmartsheetColumnSelectOptions |
|
|
|
|
|
|
|
v-if="formState.uidt === UITypes.SingleSelect || formState.uidt === UITypes.MultiSelect" |
|
|
|
|
|
|
|
v-model:value="formState" |
|
|
|
|
|
|
|
/> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div |
|
|
|
<div |
|
|
|
v-if="!isVirtualCol(formState.uidt)" |
|
|
|
v-if="!isVirtualCol(formState.uidt)" |
|
|
@ -159,15 +169,15 @@ if (!formState.value?.column_name) { |
|
|
|
{{ `Accept only valid ${formState.uidt}` }} |
|
|
|
{{ `Accept only valid ${formState.uidt}` }} |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</a-checkbox> |
|
|
|
</a-checkbox> |
|
|
|
<SmartsheetColumnAdvancedOptions /> |
|
|
|
<SmartsheetColumnAdvancedOptions v-model:value="formState" /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<a-form-item> |
|
|
|
<a-form-item> |
|
|
|
<div class="flex justify-end gap-1 mt-4"> |
|
|
|
<div class="flex justify-end gap-1 mt-4"> |
|
|
|
<a-button html-type="button" @click="onCancel"> |
|
|
|
<a-button html-type="button" @click="emit('cancel')"> |
|
|
|
<!-- Cancel --> |
|
|
|
<!-- Cancel --> |
|
|
|
{{ $t('general.cancel') }} |
|
|
|
{{ $t('general.cancel') }} |
|
|
|
</a-button> |
|
|
|
</a-button> |
|
|
|
<a-button html-type="submit" type="primary" @click="onSubmit"> |
|
|
|
<a-button html-type="submit" type="primary" @click.prevent="onSubmit"> |
|
|
|
<!-- Save --> |
|
|
|
<!-- Save --> |
|
|
|
{{ $t('general.save') }} |
|
|
|
{{ $t('general.save') }} |
|
|
|
</a-button> |
|
|
|
</a-button> |
|
|
|