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.
105 lines
3.2 KiB
105 lines
3.2 KiB
2 years ago
|
<script lang="ts" setup>
|
||
2 years ago
|
import { Modal, message } from 'ant-design-vue'
|
||
2 years ago
|
import type { LinkToAnotherRecordType } from 'nocodb-sdk'
|
||
|
import { UITypes } from 'nocodb-sdk'
|
||
2 years ago
|
import { ColumnInj, IsLockedInj, MetaInj, extractSdkResponseErrorMsg, inject, useI18n, useMetas, useNuxtApp } from '#imports'
|
||
2 years ago
|
|
||
2 years ago
|
const { virtual = false } = defineProps<{ virtual?: boolean }>()
|
||
2 years ago
|
|
||
2 years ago
|
const emit = defineEmits(['edit'])
|
||
2 years ago
|
|
||
|
const column = inject(ColumnInj)
|
||
2 years ago
|
|
||
2 years ago
|
const meta = inject(MetaInj, ref())
|
||
2 years ago
|
|
||
2 years ago
|
const isLocked = inject(IsLockedInj)
|
||
|
|
||
2 years ago
|
const { $api, $e } = useNuxtApp()
|
||
2 years ago
|
|
||
2 years ago
|
const { t } = useI18n()
|
||
2 years ago
|
|
||
2 years ago
|
const { getMeta } = useMetas()
|
||
|
|
||
|
const deleteColumn = () =>
|
||
|
Modal.confirm({
|
||
2 years ago
|
title: h('div', ['Do you want to delete ', h('span', { class: 'font-weight-bold' }, [column?.value?.title]), ' column ?']),
|
||
2 years ago
|
wrapClassName: 'nc-modal-column-delete',
|
||
2 years ago
|
okText: t('general.delete'),
|
||
|
okType: 'danger',
|
||
|
cancelText: t('general.cancel'),
|
||
|
async onOk() {
|
||
|
try {
|
||
2 years ago
|
await $api.dbTableColumn.delete(column?.value?.id as string)
|
||
2 years ago
|
|
||
|
await getMeta(meta?.value?.id as string, true)
|
||
2 years ago
|
|
||
|
/** force-reload related table meta if deleted column is a LTAR and not linked to same table */
|
||
|
if (column?.value?.uidt === UITypes.LinkToAnotherRecord && column.value?.colOptions) {
|
||
|
await getMeta((column.value?.colOptions as LinkToAnotherRecordType).fk_related_model_id!, true)
|
||
|
}
|
||
|
|
||
2 years ago
|
$e('a:column:delete')
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
},
|
||
|
})
|
||
|
|
||
|
const setAsPrimaryValue = async () => {
|
||
|
try {
|
||
2 years ago
|
await $api.dbTableColumn.primaryColumnSet(column?.value?.id as string)
|
||
2 years ago
|
|
||
|
await getMeta(meta?.value?.id as string, true)
|
||
|
|
||
2 years ago
|
// Successfully updated as primary column
|
||
|
message.success(t('msg.success.primaryColumnUpdated'))
|
||
2 years ago
|
|
||
2 years ago
|
$e('a:column:set-primary')
|
||
2 years ago
|
} catch (e) {
|
||
2 years ago
|
message.error(t('msg.error.primaryColumnUpdateFailed'))
|
||
2 years ago
|
}
|
||
|
}
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<a-dropdown v-if="!isLocked" placement="bottomRight" :trigger="['click']" overlay-class-name="nc-dropdown-column-operations">
|
||
2 years ago
|
<MdiMenuDown class="h-full text-grey nc-ui-dt-dropdown cursor-pointer outline-0" />
|
||
|
|
||
2 years ago
|
<template #overlay>
|
||
2 years ago
|
<a-menu class="shadow bg-white">
|
||
2 years ago
|
<a-menu-item @click="emit('edit')">
|
||
2 years ago
|
<div class="nc-column-edit nc-header-menu-item">
|
||
2 years ago
|
<MdiPencil class="text-primary" />
|
||
2 years ago
|
<!-- Edit -->
|
||
|
{{ $t('general.edit') }}
|
||
|
</div>
|
||
|
</a-menu-item>
|
||
2 years ago
|
|
||
2 years ago
|
<a-menu-item v-if="!virtual" @click="setAsPrimaryValue">
|
||
2 years ago
|
<div class="nc-column-set-primary nc-header-menu-item">
|
||
2 years ago
|
<MdiStar class="text-primary" />
|
||
2 years ago
|
|
||
2 years ago
|
<!-- todo : tooltip -->
|
||
|
<!-- Set as Primary value -->
|
||
|
{{ $t('activity.setPrimary') }}
|
||
|
</div>
|
||
|
</a-menu-item>
|
||
2 years ago
|
|
||
2 years ago
|
<a-menu-item @click="deleteColumn">
|
||
|
<div class="nc-column-delete nc-header-menu-item">
|
||
2 years ago
|
<MdiDeleteOutline class="text-error" />
|
||
2 years ago
|
<!-- Delete -->
|
||
|
{{ $t('general.delete') }}
|
||
|
</div>
|
||
|
</a-menu-item>
|
||
|
</a-menu>
|
||
2 years ago
|
</template>
|
||
|
</a-dropdown>
|
||
|
</template>
|
||
2 years ago
|
|
||
|
<style scoped>
|
||
|
.nc-header-menu-item {
|
||
|
@apply text-xs flex items-center px-1 py-2 gap-1;
|
||
|
}
|
||
|
</style>
|