|
|
@ -1,92 +1,94 @@ |
|
|
|
<script setup lang="ts"> |
|
|
|
<script setup lang="ts"> |
|
|
|
import { onMounted, watchEffect } from '@vue/runtime-core' |
|
|
|
import { onMounted, watchEffect } from "@vue/runtime-core"; |
|
|
|
import { Form } from 'ant-design-vue' |
|
|
|
import { Form } from "ant-design-vue"; |
|
|
|
import type { TableType } from 'nocodb-sdk' |
|
|
|
import type { TableType } from "nocodb-sdk"; |
|
|
|
import { useToast } from 'vue-toastification' |
|
|
|
import { useToast } from "vue-toastification"; |
|
|
|
import { useProject, useTableCreate, useTabs } from '#imports' |
|
|
|
import { useProject, useTableCreate, useTabs } from "#imports"; |
|
|
|
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' |
|
|
|
import { extractSdkResponseErrorMsg } from "~/utils/errorUtils"; |
|
|
|
import { validateTableName } from '~/utils/validation' |
|
|
|
import { validateTableName } from "~/utils/validation"; |
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
import { useNuxtApp } from "#app"; |
|
|
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
interface Props { |
|
|
|
modelValue?: boolean |
|
|
|
modelValue?: boolean; |
|
|
|
tableMeta: TableType |
|
|
|
tableMeta: TableType; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { modelValue = false, tableMeta } = defineProps<Props>() |
|
|
|
const { modelValue = false, tableMeta } = defineProps<Props>(); |
|
|
|
const emit = defineEmits(['update:modelValue', 'updated']) |
|
|
|
const emit = defineEmits(["update:modelValue", "updated"]); |
|
|
|
const { $e, $api } = useNuxtApp() |
|
|
|
const { $e, $api } = useNuxtApp(); |
|
|
|
const toast = useToast() |
|
|
|
const toast = useToast(); |
|
|
|
const dialogShow = computed({ |
|
|
|
const dialogShow = computed({ |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
return modelValue |
|
|
|
return modelValue; |
|
|
|
}, |
|
|
|
}, |
|
|
|
set(v) { |
|
|
|
set(v) { |
|
|
|
emit('update:modelValue', v) |
|
|
|
emit("update:modelValue", v); |
|
|
|
}, |
|
|
|
} |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const { addTab } = useTabs() |
|
|
|
const { addTab } = useTabs(); |
|
|
|
const { loadTables } = useProject() |
|
|
|
const { loadTables } = useProject(); |
|
|
|
const { project, tables } = useProject() |
|
|
|
const { project, tables } = useProject(); |
|
|
|
|
|
|
|
|
|
|
|
const prefix = computed(() => project?.value?.prefix || '') |
|
|
|
const prefix = computed(() => project?.value?.prefix || ""); |
|
|
|
const validateDuplicateAlias = (v: string) => { |
|
|
|
const validateDuplicateAlias = (v: string) => { |
|
|
|
return (tables?.value || []).every((t) => t.title !== (v || '')) || 'Duplicate table alias' |
|
|
|
return (tables?.value || []).every((t) => t.title !== (v || "")) || "Duplicate table alias"; |
|
|
|
} |
|
|
|
}; |
|
|
|
const validateLeadingOrTrailingWhiteSpace = (v: string) => { |
|
|
|
const validateLeadingOrTrailingWhiteSpace = (v: string) => { |
|
|
|
return !/^\s+|\s+$/.test(v) || 'Leading or trailing whitespace not allowed in table name' |
|
|
|
return !/^\s+|\s+$/.test(v) || "Leading or trailing whitespace not allowed in table name"; |
|
|
|
} |
|
|
|
}; |
|
|
|
const validateDuplicate = (v: string) => { |
|
|
|
const validateDuplicate = (v: string) => { |
|
|
|
return (tables?.value || []).every((t) => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name' |
|
|
|
return (tables?.value || []).every((t) => t.table_name.toLowerCase() !== (v || "").toLowerCase()) || "Duplicate table name"; |
|
|
|
} |
|
|
|
}; |
|
|
|
const inputEl = ref<any>() |
|
|
|
const inputEl = $ref<any>(); |
|
|
|
const useForm = Form.useForm |
|
|
|
const useForm = Form.useForm; |
|
|
|
const formState = reactive({ |
|
|
|
const formState = reactive({ |
|
|
|
title: '', |
|
|
|
title: "" |
|
|
|
}) |
|
|
|
}); |
|
|
|
const validators = computed(() => { |
|
|
|
const validators = computed(() => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
title: [validateTableName, validateDuplicateAlias], |
|
|
|
title: [validateTableName, validateDuplicateAlias], |
|
|
|
table_name: [validateTableName], |
|
|
|
table_name: [validateTableName] |
|
|
|
} |
|
|
|
}; |
|
|
|
}) |
|
|
|
}); |
|
|
|
const { resetFields, validate, validateInfos } = useForm(formState, validators) |
|
|
|
const { resetFields, validate, validateInfos } = useForm(formState, validators); |
|
|
|
onMounted(() => { |
|
|
|
|
|
|
|
// todo: focus input |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
|
|
|
|
() => tableMeta?.title, |
|
|
|
watchEffect(() => { |
|
|
|
(title) => { |
|
|
|
if (tableMeta?.title) formState.title = tableMeta?.title; |
|
|
|
if (title) formState.title = title |
|
|
|
// todo: replace setTimeout and follow better approach |
|
|
|
}, |
|
|
|
nextTick(() => { |
|
|
|
) |
|
|
|
const input = inputEl?.$el; |
|
|
|
|
|
|
|
input.setSelectionRange(0, formState.title.length); |
|
|
|
|
|
|
|
input.focus(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const renameTable = async () => { |
|
|
|
const renameTable = async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
await $api.dbTable.update(tableMeta?.id as string, { |
|
|
|
await $api.dbTable.update(tableMeta?.id as string, { |
|
|
|
title: formState.title, |
|
|
|
title: formState.title |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
loadTables() |
|
|
|
loadTables(); |
|
|
|
toast.success('Table renamed successfully') |
|
|
|
toast.success("Table renamed successfully"); |
|
|
|
$e('a:table:rename') |
|
|
|
$e("a:table:rename"); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<a-modal v-model:visible="dialogShow" @keydown.esc="dialogShow = false" @finish="renameTable"> |
|
|
|
<a-modal v-model:visible="dialogShow" @keydown.esc="dialogShow = false" @finish="renameTable"> |
|
|
|
<template #footer> |
|
|
|
<template #footer> |
|
|
|
<a-button key="back" @click="dialogShow = false">{{ $t('general.cancel') }}</a-button> |
|
|
|
<a-button key="back" @click="dialogShow = false">{{ $t("general.cancel") }}</a-button> |
|
|
|
<a-button key="submit" type="primary" @click="renameTable">{{ $t('general.submit') }}</a-button> |
|
|
|
<a-button key="submit" type="primary" @click="renameTable">{{ $t("general.submit") }}</a-button> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<div class="pl-10 pr-10 pt-5"> |
|
|
|
<div class="pl-10 pr-10 pt-5"> |
|
|
|
<a-form :model="formState" name="create-new-table-form"> |
|
|
|
<a-form :model="formState" name="create-new-table-form"> |
|
|
|
<!-- Create A New Table --> |
|
|
|
<!-- Rename Table --> |
|
|
|
<div class="prose-xl font-bold text-center my-4">Rename Table</div> |
|
|
|
<div class="prose-xl font-bold text-center my-4">Rename Table</div> |
|
|
|
<!-- hint="Enter table name" --> |
|
|
|
<!-- hint="Enter table name" --> |
|
|
|
<div class="mb-2">Table Name</div> |
|
|
|
<div class="mb-2">Table Name</div> |
|
|
@ -97,8 +99,9 @@ const renameTable = async () => { |
|
|
|
size="large" |
|
|
|
size="large" |
|
|
|
hide-details |
|
|
|
hide-details |
|
|
|
:placeholder="$t('msg.info.enterTableName')" |
|
|
|
:placeholder="$t('msg.info.enterTableName')" |
|
|
|
/> </a-form-item |
|
|
|
/> |
|
|
|
></a-form> |
|
|
|
</a-form-item> |
|
|
|
|
|
|
|
</a-form> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</a-modal> |
|
|
|
</a-modal> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|