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.
109 lines
2.7 KiB
109 lines
2.7 KiB
<script setup lang="ts"> |
|
import type { ColumnReqType, ColumnType } from 'nocodb-sdk' |
|
import { ColumnInj, IsFormInj, IsKanbanInj, inject, provide, ref, toRef, useUIPermission } from '#imports' |
|
|
|
interface Props { |
|
column: ColumnType |
|
required?: boolean | number |
|
hideMenu?: boolean |
|
} |
|
|
|
const props = defineProps<Props>() |
|
|
|
const hideMenu = toRef(props, 'hideMenu') |
|
|
|
const isForm = inject(IsFormInj, ref(false)) |
|
|
|
const isDropDownOpen = ref(false) |
|
|
|
const isKanban = inject(IsKanbanInj, ref(false)) |
|
|
|
const column = toRef(props, 'column') |
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
provide(ColumnInj, column) |
|
|
|
const editColumnDropdown = ref(false) |
|
|
|
const columnOrder = ref<Pick<ColumnReqType, 'column_order'> | null>(null) |
|
|
|
const addField = async (payload: any) => { |
|
columnOrder.value = payload |
|
editColumnDropdown.value = true |
|
} |
|
|
|
const closeAddColumnDropdown = () => { |
|
columnOrder.value = null |
|
editColumnDropdown.value = false |
|
} |
|
|
|
const openHeaderMenu = () => { |
|
if (!isForm.value && isUIAllowed('edit-column')) { |
|
editColumnDropdown.value = true |
|
} |
|
} |
|
</script> |
|
|
|
<template> |
|
<div |
|
class="flex items-center w-full text-xs text-gray-500 font-weight-medium" |
|
:class="{ 'h-full': column, '!text-gray-400': isKanban }" |
|
@dblclick="openHeaderMenu" |
|
@click.right="isDropDownOpen = !isDropDownOpen" |
|
@click="isDropDownOpen = false" |
|
> |
|
<SmartsheetHeaderCellIcon v-if="column" /> |
|
<div |
|
v-if="column" |
|
class="name pl-1 !truncate" |
|
:class="{ 'cursor-pointer pt-0.25': !isForm && isUIAllowed('edit-column') && !hideMenu }" |
|
style="white-space: pre-line" |
|
:title="column.title" |
|
> |
|
{{ column.title }} |
|
</div> |
|
|
|
<span v-if="(column.rqd && !column.cdf) || required" class="text-red-500"> *</span> |
|
|
|
<template v-if="!hideMenu"> |
|
<div class="flex-1" /> |
|
<LazySmartsheetHeaderMenu |
|
v-if="!isForm && isUIAllowed('edit-column')" |
|
v-model:is-open="isDropDownOpen" |
|
@add-column="addField" |
|
@edit="openHeaderMenu" |
|
/> |
|
</template> |
|
|
|
<a-dropdown |
|
v-model:visible="editColumnDropdown" |
|
class="h-full" |
|
:trigger="['click']" |
|
placement="bottomRight" |
|
overlay-class-name="nc-dropdown-edit-column" |
|
> |
|
<div /> |
|
|
|
<template #overlay> |
|
<SmartsheetColumnEditOrAddProvider |
|
v-if="editColumnDropdown" |
|
:column="columnOrder ? null : column" |
|
:column-position="columnOrder" |
|
class="w-full" |
|
@submit="closeAddColumnDropdown" |
|
@cancel="closeAddColumnDropdown" |
|
@click.stop |
|
@keydown.stop |
|
/> |
|
</template> |
|
</a-dropdown> |
|
</div> |
|
</template> |
|
|
|
<style scoped> |
|
.name { |
|
max-width: calc(100% - 40px); |
|
word-break: break-all; |
|
} |
|
</style>
|
|
|