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.
95 lines
2.6 KiB
95 lines
2.6 KiB
2 years ago
|
<script lang="ts" setup>
|
||
2 years ago
|
import { Modal, message } from 'ant-design-vue'
|
||
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)
|
||
|
|
||
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
|
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)
|
||
|
} 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']">
|
||
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>
|