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
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import type { ColumnType } from 'nocodb-sdk'
|
||
2 years ago
|
import type { Ref } from 'vue'
|
||
2 years ago
|
import {
|
||
|
ActiveCellInj,
|
||
|
CellValueInj,
|
||
|
ColumnInj,
|
||
2 years ago
|
ReadonlyInj,
|
||
2 years ago
|
ReloadViewDataHookInj,
|
||
|
RowInj,
|
||
2 years ago
|
defineAsyncComponent,
|
||
2 years ago
|
inject,
|
||
|
ref,
|
||
|
useProvideLTARStore,
|
||
|
useSmartsheetRowStoreOrThrow,
|
||
2 years ago
|
useUIPermission,
|
||
2 years ago
|
} from '#imports'
|
||
2 years ago
|
import MdiArrowExpand from '~icons/mdi/arrow-expand'
|
||
|
import MdiPlus from '~icons/mdi/plus'
|
||
2 years ago
|
|
||
2 years ago
|
const ItemChip = defineAsyncComponent(() => import('./components/ItemChip.vue'))
|
||
|
|
||
|
const ListItems = defineAsyncComponent(() => import('./components/ListItems.vue'))
|
||
|
|
||
2 years ago
|
const column = inject(ColumnInj)!
|
||
2 years ago
|
|
||
|
const reloadTrigger = inject(ReloadViewDataHookInj)!
|
||
|
|
||
2 years ago
|
const cellValue = inject(CellValueInj, ref<any>(null))
|
||
2 years ago
|
|
||
2 years ago
|
const row = inject(RowInj)!
|
||
2 years ago
|
|
||
2 years ago
|
const active = inject(ActiveCellInj)!
|
||
2 years ago
|
|
||
2 years ago
|
const readOnly = inject(ReadonlyInj, false)
|
||
2 years ago
|
|
||
2 years ago
|
const isForm = inject(IsFormInj, ref(false))
|
||
|
|
||
2 years ago
|
const isLocked = inject(IsLockedInj)
|
||
|
|
||
2 years ago
|
const { isUIAllowed } = useUIPermission()
|
||
2 years ago
|
|
||
2 years ago
|
const listItemsDlg = ref(false)
|
||
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
|
)
|
||
2 years ago
|
|
||
2 years ago
|
await loadRelatedTableMeta()
|
||
2 years ago
|
|
||
2 years ago
|
const addIcon = computed(() => (cellValue?.value ? MdiArrowExpand : MdiPlus))
|
||
|
|
||
2 years ago
|
const value = computed(() => {
|
||
|
if (cellValue?.value) {
|
||
|
return cellValue?.value
|
||
|
} else if (isNew.value) {
|
||
|
return state?.value?.[column?.value.title as string]
|
||
|
}
|
||
|
return null
|
||
|
})
|
||
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 w-full chips-wrapper items-center" :class="{ active }">
|
||
|
<div class="chips flex items-center flex-1">
|
||
2 years ago
|
<template v-if="value && relatedTablePrimaryValueProp">
|
||
2 years ago
|
<ItemChip :item="value" :value="value[relatedTablePrimaryValueProp]" @unlink="unlinkRef(value)" />
|
||
2 years ago
|
</template>
|
||
|
</div>
|
||
2 years ago
|
<div
|
||
2 years ago
|
v-if="!readOnly && !isLocked && (isUIAllowed('xcDatatableEditable') || isForm)"
|
||
2 years ago
|
class="flex justify-end gap-1 min-h-[30px] items-center"
|
||
2 years ago
|
>
|
||
2 years ago
|
<component
|
||
|
:is="addIcon"
|
||
2 years ago
|
class="text-sm nc-action-icon text-gray-500/50 hover:text-gray-500 select-none group-hover:(text-gray-500) nc-plus"
|
||
2 years ago
|
@click="listItemsDlg = true"
|
||
|
/>
|
||
|
</div>
|
||
2 years ago
|
<ListItems v-model="listItemsDlg" @attach-record="listItemsDlg = true" />
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
2 years ago
|
|
||
2 years ago
|
<style scoped lang="scss">
|
||
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,
|
||
|
.chips-wrapper.active {
|
||
|
.nc-action-icon {
|
||
|
@apply inline-block;
|
||
|
}
|
||
2 years ago
|
}
|
||
|
</style>
|