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.
148 lines
4.3 KiB
148 lines
4.3 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import type { ColumnType, FormulaType, LinkToAnotherRecordType, LookupType, RollupType } from 'nocodb-sdk'
|
||
2 years ago
|
import { substituteColumnIdWithAliasInFormula } from 'nocodb-sdk'
|
||
|
import {
|
||
|
ColumnInj,
|
||
|
IsFormInj,
|
||
|
MetaInj,
|
||
|
computed,
|
||
|
inject,
|
||
|
provide,
|
||
|
ref,
|
||
|
toRef,
|
||
2 years ago
|
useI18n,
|
||
2 years ago
|
useMetas,
|
||
|
useUIPermission,
|
||
|
useVirtualCell,
|
||
|
} from '#imports'
|
||
2 years ago
|
|
||
2 years ago
|
const props = defineProps<{ column: ColumnType; hideMenu?: boolean; required?: boolean | number }>()
|
||
2 years ago
|
|
||
2 years ago
|
const { t } = useI18n()
|
||
|
|
||
2 years ago
|
const column = toRef(props, 'column')
|
||
2 years ago
|
|
||
2 years ago
|
const hideMenu = toRef(props, 'hideMenu')
|
||
2 years ago
|
|
||
2 years ago
|
const editColumnDropdown = ref(false)
|
||
|
|
||
2 years ago
|
provide(ColumnInj, column)
|
||
2 years ago
|
|
||
2 years ago
|
const { metas } = useMetas()
|
||
2 years ago
|
|
||
2 years ago
|
const { isUIAllowed } = useUIPermission()
|
||
|
|
||
2 years ago
|
const meta = inject(MetaInj, ref())
|
||
2 years ago
|
|
||
2 years ago
|
const isForm = inject(IsFormInj, ref(false))
|
||
2 years ago
|
|
||
2 years ago
|
const { isLookup, isBt, isRollup, isMm, isHm, isFormula } = useVirtualCell(column)
|
||
2 years ago
|
|
||
|
const colOptions = $computed(() => column.value?.colOptions)
|
||
2 years ago
|
|
||
2 years ago
|
const tableTile = $computed(() => meta?.value?.title)
|
||
2 years ago
|
|
||
2 years ago
|
const relationColumnOptions = $computed<LinkToAnotherRecordType | null>(() => {
|
||
|
if (isMm.value || isHm.value || isBt.value) {
|
||
2 years ago
|
return column.value?.colOptions as LinkToAnotherRecordType
|
||
|
} else if ((column?.value?.colOptions as LookupType | RollupType)?.fk_relation_column_id) {
|
||
|
return meta?.value?.columns?.find(
|
||
|
(c) => c.id === (column?.value?.colOptions as LookupType | RollupType)?.fk_relation_column_id,
|
||
|
)?.colOptions as LinkToAnotherRecordType
|
||
|
}
|
||
|
return null
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const relatedTableMeta = $computed(
|
||
2 years ago
|
() => relationColumnOptions?.fk_related_model_id && metas.value?.[relationColumnOptions?.fk_related_model_id as string],
|
||
2 years ago
|
)
|
||
|
|
||
|
const relatedTableTitle = $computed(() => relatedTableMeta?.title)
|
||
|
|
||
|
const childColumn = $computed(() => {
|
||
|
if (relatedTableMeta?.columns) {
|
||
2 years ago
|
if (isRollup.value) {
|
||
2 years ago
|
return relatedTableMeta?.columns.find((c: ColumnType) => c.id === (colOptions as RollupType).fk_rollup_column_id)
|
||
2 years ago
|
}
|
||
2 years ago
|
if (isLookup.value) {
|
||
2 years ago
|
return relatedTableMeta?.columns.find((c: ColumnType) => c.id === (colOptions as LookupType).fk_lookup_column_id)
|
||
2 years ago
|
}
|
||
|
}
|
||
|
return ''
|
||
|
})
|
||
|
|
||
|
const tooltipMsg = computed(() => {
|
||
|
if (!column.value) {
|
||
|
return ''
|
||
|
}
|
||
|
if (isHm.value) {
|
||
2 years ago
|
return `'${tableTile}' ${t('labels.hasMany')} '${relatedTableTitle}'`
|
||
2 years ago
|
} else if (isMm.value) {
|
||
2 years ago
|
return `'${tableTile}' & '${relatedTableTitle}' ${t('labels.manyToMany')}`
|
||
2 years ago
|
} else if (isBt.value) {
|
||
2 years ago
|
return `'${column?.value?.title}' ${t('labels.belongsTo')} '${relatedTableTitle}'`
|
||
2 years ago
|
} else if (isLookup.value) {
|
||
|
return `'${childColumn.title}' from '${relatedTableTitle}' (${childColumn.uidt})`
|
||
|
} else if (isFormula.value) {
|
||
|
const formula = substituteColumnIdWithAliasInFormula(
|
||
|
(column.value?.colOptions as FormulaType)?.formula,
|
||
|
meta?.value?.columns as ColumnType[],
|
||
|
(column.value?.colOptions as any)?.formula_raw,
|
||
|
)
|
||
|
return `Formula - ${formula}`
|
||
|
} else if (isRollup.value) {
|
||
|
return `'${childColumn.title}' of '${relatedTableTitle}' (${childColumn.uidt})`
|
||
|
}
|
||
|
return ''
|
||
|
})
|
||
2 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<template>
|
||
2 years ago
|
<div class="flex items-center w-full text-xs text-gray-500 font-weight-medium" :class="{ 'h-full': column }">
|
||
2 years ago
|
<SmartsheetHeaderVirtualCellIcon v-if="column" />
|
||
2 years ago
|
|
||
2 years ago
|
<a-tooltip placement="bottom">
|
||
|
<template #title>
|
||
|
{{ tooltipMsg }}
|
||
|
</template>
|
||
|
<span class="name" style="white-space: nowrap" :title="column.title"> {{ column.title }}</span>
|
||
|
</a-tooltip>
|
||
2 years ago
|
|
||
2 years ago
|
<span v-if="column.rqd || required" class="text-red-500"> *</span>
|
||
2 years ago
|
|
||
2 years ago
|
<template v-if="!hideMenu">
|
||
2 years ago
|
<div class="flex-1" />
|
||
2 years ago
|
<SmartsheetHeaderMenu v-if="!isForm && isUIAllowed('edit-column')" :virtual="true" @edit="editColumnDropdown = true" />
|
||
2 years ago
|
</template>
|
||
2 years ago
|
|
||
2 years ago
|
<a-dropdown
|
||
|
v-model:visible="editColumnDropdown"
|
||
|
class="h-full"
|
||
|
:trigger="['click']"
|
||
|
placement="bottomRight"
|
||
2 years ago
|
overlay-class-name="nc-dropdown-edit-column"
|
||
2 years ago
|
>
|
||
2 years ago
|
<div />
|
||
|
<template #overlay>
|
||
2 years ago
|
<SmartsheetColumnEditOrAddProvider
|
||
|
v-if="editColumnDropdown"
|
||
|
:column="column"
|
||
2 years ago
|
class="w-full"
|
||
2 years ago
|
@submit="editColumnDropdown = false"
|
||
|
@cancel="editColumnDropdown = false"
|
||
2 years ago
|
@click.stop
|
||
|
@keydown.stop
|
||
|
/>
|
||
|
</template>
|
||
|
</a-dropdown>
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<style scoped>
|
||
|
.name {
|
||
|
max-width: calc(100% - 40px);
|
||
|
overflow: hidden;
|
||
|
text-overflow: ellipsis;
|
||
|
}
|
||
|
</style>
|