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.
79 lines
2.6 KiB
79 lines
2.6 KiB
2 years ago
|
<script lang="ts" setup>
|
||
2 years ago
|
import type { ColumnType, LinkToAnotherRecordType, LookupType } from 'nocodb-sdk'
|
||
2 years ago
|
import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk'
|
||
2 years ago
|
import type { Ref } from 'vue'
|
||
2 years ago
|
import { CellValueInj, ColumnInj, MetaInj, ReadonlyInj, computed, inject, provide, useColumn, useMetas } from '#imports'
|
||
3 years ago
|
|
||
2 years ago
|
const { metas, getMeta } = useMetas()
|
||
3 years ago
|
|
||
2 years ago
|
provide(ReadonlyInj, true)
|
||
2 years ago
|
|
||
2 years ago
|
const column = inject(ColumnInj)! as Ref<ColumnType & { colOptions: LookupType }>
|
||
2 years ago
|
|
||
2 years ago
|
const meta = inject(MetaInj)
|
||
2 years ago
|
|
||
2 years ago
|
const value = inject(CellValueInj)
|
||
2 years ago
|
|
||
|
const arrValue = computed(() => (Array.isArray(value?.value) ? value?.value : [value?.value]) ?? [])
|
||
2 years ago
|
|
||
2 years ago
|
const relationColumn = meta?.value.columns?.find((c) => c.id === column.value.colOptions?.fk_relation_column_id) as ColumnType & {
|
||
2 years ago
|
colOptions: LinkToAnotherRecordType
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
await getMeta(relationColumn.colOptions.fk_related_model_id!)
|
||
|
|
||
|
const lookupTableMeta = computed(() => metas.value[relationColumn.colOptions.fk_related_model_id!])
|
||
|
|
||
2 years ago
|
const lookupColumn = computed<any>(
|
||
2 years ago
|
() =>
|
||
|
lookupTableMeta.value.columns?.find(
|
||
|
(c: Record<string, any>) => c.id === column.value.colOptions?.fk_lookup_column_id,
|
||
|
) as ColumnType,
|
||
|
)
|
||
|
|
||
|
provide(MetaInj, lookupTableMeta)
|
||
2 years ago
|
|
||
|
const lookupColumnMetaProps = useColumn(lookupColumn)
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div class="h-full flex gap-1">
|
||
2 years ago
|
<template v-if="lookupColumn">
|
||
|
<!-- Render virtual cell -->
|
||
|
<div v-if="isVirtualCol(lookupColumn)">
|
||
|
<template
|
||
|
v-if="lookupColumn.uidt === UITypes.LinkToAnotherRecord && lookupColumn.colOptions.type === RelationTypes.BELONGS_TO"
|
||
|
>
|
||
|
<SmartsheetVirtualCell
|
||
|
v-for="(v, i) of arrValue"
|
||
|
:key="i"
|
||
|
:edit-enabled="false"
|
||
|
:model-value="v"
|
||
|
:column="lookupColumn"
|
||
|
/>
|
||
|
</template>
|
||
|
|
||
|
<SmartsheetVirtualCell v-else :edit-enabled="false" :model-value="arrValue" :column="lookupColumn" />
|
||
|
</div>
|
||
|
|
||
|
<!-- Render normal cell -->
|
||
|
<template v-else>
|
||
|
<!-- For attachment cell avoid adding chip style -->
|
||
2 years ago
|
<div
|
||
2 years ago
|
v-for="(v, i) of arrValue"
|
||
2 years ago
|
:key="i"
|
||
2 years ago
|
class="min-w-max"
|
||
2 years ago
|
:class="{
|
||
|
'bg-gray-100 px-1 rounded-full flex-1': !lookupColumnMetaProps.isAttachment,
|
||
|
' border-gray-200 rounded border-1': ![UITypes.Attachment, UITypes.MultiSelect, UITypes.SingleSelect].includes(
|
||
|
lookupColumn.uidt,
|
||
|
),
|
||
|
}"
|
||
2 years ago
|
>
|
||
2 years ago
|
<SmartsheetCell :model-value="v" :column="lookupColumn" :edit-enabled="false" :virtual="true" />
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
|
</template>
|
||
3 years ago
|
</div>
|
||
|
</template>
|