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.
134 lines
3.4 KiB
134 lines
3.4 KiB
2 years ago
|
<script setup lang="ts">
|
||
|
import type { ColumnType } from 'nocodb-sdk'
|
||
2 years ago
|
import type { Ref } from 'vue'
|
||
2 years ago
|
import {
|
||
|
CellValueInj,
|
||
|
ColumnInj,
|
||
|
IsFormInj,
|
||
2 years ago
|
IsLockedInj,
|
||
2 years ago
|
ReadonlyInj,
|
||
2 years ago
|
ReloadViewDataHookInj,
|
||
|
RowInj,
|
||
|
computed,
|
||
|
defineAsyncComponent,
|
||
|
inject,
|
||
|
ref,
|
||
|
useProvideLTARStore,
|
||
|
useSmartsheetRowStoreOrThrow,
|
||
2 years ago
|
useUIPermission,
|
||
2 years ago
|
} from '#imports'
|
||
|
|
||
|
const ItemChip = defineAsyncComponent(() => import('./components/ItemChip.vue'))
|
||
|
|
||
|
const ListItems = defineAsyncComponent(() => import('./components/ListItems.vue'))
|
||
|
|
||
|
const ListChildItems = defineAsyncComponent(() => import('./components/ListChildItems.vue'))
|
||
2 years ago
|
|
||
2 years ago
|
const column = inject(ColumnInj)!
|
||
|
|
||
|
const cellValue = inject(CellValueInj)!
|
||
|
|
||
|
const row = inject(RowInj)!
|
||
|
|
||
|
const reloadTrigger = inject(ReloadViewDataHookInj)!
|
||
2 years ago
|
|
||
2 years ago
|
const isForm = inject(IsFormInj)
|
||
|
|
||
2 years ago
|
const readOnly = inject(ReadonlyInj, false)
|
||
2 years ago
|
|
||
2 years ago
|
const isLocked = inject(IsLockedInj)
|
||
|
|
||
2 years ago
|
const listItemsDlg = ref(false)
|
||
2 years ago
|
|
||
2 years ago
|
const childListDlg = ref(false)
|
||
|
|
||
2 years ago
|
const { isUIAllowed } = useUIPermission()
|
||
2 years ago
|
|
||
2 years ago
|
const { state, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow()
|
||
2 years ago
|
|
||
2 years ago
|
const { loadRelatedTableMeta, relatedTablePrimaryValueProp, unlink } = useProvideLTARStore(
|
||
2 years ago
|
column as Ref<Required<ColumnType>>,
|
||
2 years ago
|
row,
|
||
2 years ago
|
isNew,
|
||
2 years ago
|
reloadTrigger.trigger,
|
||
2 years ago
|
)
|
||
|
await loadRelatedTableMeta()
|
||
2 years ago
|
|
||
2 years ago
|
const localCellValue = computed(() => {
|
||
|
if (cellValue?.value) {
|
||
2 years ago
|
return cellValue?.value ?? []
|
||
2 years ago
|
} else if (isNew.value) {
|
||
2 years ago
|
return state?.value?.[column?.value.title as string] ?? []
|
||
2 years ago
|
}
|
||
|
return []
|
||
|
})
|
||
|
|
||
2 years ago
|
const cells = computed(() =>
|
||
2 years ago
|
localCellValue.value.reduce((acc: any[], curr: any) => {
|
||
2 years ago
|
if (!relatedTablePrimaryValueProp.value) return acc
|
||
|
|
||
|
const value = curr[relatedTablePrimaryValueProp.value]
|
||
|
|
||
|
if (!value) return acc
|
||
|
|
||
|
return [...acc, { value, item: curr }]
|
||
|
}, [] as any[]),
|
||
|
)
|
||
2 years ago
|
|
||
|
const unlinkRef = async (rec: Record<string, any>) => {
|
||
|
if (isNew.value) {
|
||
|
removeLTARRef(rec, column?.value as ColumnType)
|
||
|
} else {
|
||
|
await unlink(rec)
|
||
|
}
|
||
|
}
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div class="flex items-center items-center gap-1 w-full chips-wrapper">
|
||
2 years ago
|
<template v-if="!isForm">
|
||
2 years ago
|
<div class="chips flex items-center img-container flex-1 hm-items flex-nowrap min-w-0 overflow-hidden">
|
||
2 years ago
|
<template v-if="cells">
|
||
2 years ago
|
<ItemChip v-for="(cell, i) of cells" :key="i" :item="cell.item" :value="cell.value" @unlink="unlinkRef(cell.item)" />
|
||
2 years ago
|
<span v-if="cellValue?.length === 10" class="caption pointer ml-1 grey--text" @click="childListDlg = true">
|
||
|
more...
|
||
2 years ago
|
</span>
|
||
|
</template>
|
||
|
</div>
|
||
2 years ago
|
<div v-if="!isLocked" class="flex justify-end gap-1 min-h-[30px] items-center">
|
||
2 years ago
|
<MdiArrowExpand
|
||
2 years ago
|
class="select-none transform text-sm nc-action-icon text-gray-500/50 hover:text-gray-500 nc-arrow-expand"
|
||
2 years ago
|
@click="childListDlg = true"
|
||
|
/>
|
||
2 years ago
|
<MdiPlus
|
||
2 years ago
|
v-if="!readOnly && isUIAllowed('xcDatatableEditable')"
|
||
2 years ago
|
class="select-none text-sm nc-action-icon text-gray-500/50 hover:text-gray-500 nc-plus"
|
||
2 years ago
|
@click="listItemsDlg = true"
|
||
|
/>
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
2 years ago
|
|
||
2 years ago
|
<ListItems v-model="listItemsDlg" />
|
||
2 years ago
|
|
||
2 years ago
|
<ListChildItems
|
||
|
v-model="childListDlg"
|
||
|
@attach-record="
|
||
|
() => {
|
||
|
childListDlg = false
|
||
|
listItemsDlg = true
|
||
|
}
|
||
|
"
|
||
|
/>
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
2 years ago
|
|
||
2 years ago
|
<style scoped>
|
||
2 years ago
|
.nc-action-icon {
|
||
2 years ago
|
@apply hidden cursor-pointer;
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
.chips-wrapper:hover .nc-action-icon {
|
||
2 years ago
|
@apply flex;
|
||
2 years ago
|
}
|
||
|
</style>
|