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.
88 lines
3.0 KiB
88 lines
3.0 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
|
||
2 years ago
|
import { UITypes, isSystemColumn } from 'nocodb-sdk'
|
||
2 years ago
|
import { MetaInj } from '#imports'
|
||
2 years ago
|
|
||
2 years ago
|
interface Props {
|
||
|
value: Record<string, any>
|
||
|
}
|
||
|
|
||
|
const props = defineProps<Props>()
|
||
|
const emit = defineEmits(['update:value'])
|
||
|
const vModel = useVModel(props, 'value', emit)
|
||
|
|
||
2 years ago
|
const meta = $(inject(MetaInj)!)
|
||
2 years ago
|
|
||
|
const { setAdditionalValidations, validateInfos, onDataTypeChange } = useColumnCreateStoreOrThrow()
|
||
|
|
||
|
const { tables } = $(useProject())
|
||
|
|
||
2 years ago
|
const { metas } = $(useMetas())
|
||
|
|
||
|
setAdditionalValidations({
|
||
|
fk_relation_column_id: [{ required: true, message: 'Required' }],
|
||
|
fk_lookup_column_id: [{ required: true, message: 'Required' }],
|
||
|
})
|
||
|
|
||
2 years ago
|
if (!vModel.value.fk_relation_column_id) vModel.value.fk_relation_column_id = null
|
||
|
if (!vModel.value.fk_lookup_column_id) vModel.value.fk_lookup_column_id = null
|
||
2 years ago
|
|
||
|
const relationNames = {
|
||
|
mm: 'Many To Many',
|
||
|
hm: 'Has Many',
|
||
|
bt: 'Belongs To',
|
||
|
}
|
||
|
|
||
|
const refTables = $computed(() => {
|
||
|
if (!tables || !tables.length) {
|
||
|
return []
|
||
|
}
|
||
|
|
||
2 years ago
|
return meta.columns
|
||
2 years ago
|
?.filter((c: any) => c.uidt === UITypes.LinkToAnotherRecord && !c.system)
|
||
|
.map((c: ColumnType) => ({
|
||
2 years ago
|
col: c.colOptions,
|
||
|
column: c,
|
||
2 years ago
|
...tables.find((t) => t.id === (c.colOptions as LinkToAnotherRecordType).fk_related_model_id),
|
||
2 years ago
|
}))
|
||
2 years ago
|
.filter((table: any) => table.col.fk_related_model_id === table.id && !table.mm)
|
||
2 years ago
|
})
|
||
|
|
||
|
const columns = $computed(() => {
|
||
2 years ago
|
const selectedTable = refTables?.find((t) => t.column.id === vModel.value.fk_relation_column_id)
|
||
2 years ago
|
if (!selectedTable?.id) {
|
||
|
return []
|
||
|
}
|
||
|
|
||
2 years ago
|
return metas[selectedTable.id].columns.filter((c: any) => !isSystemColumn(c))
|
||
2 years ago
|
})
|
||
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div class="p-6 w-full flex flex-col border-2 mb-2 mt-4">
|
||
2 years ago
|
<div class="w-full flex flex-row space-x-2">
|
||
|
<a-form-item class="flex w-1/2 pb-2" :label="$t('labels.childTable')" v-bind="validateInfos.fk_relation_column_id">
|
||
2 years ago
|
<a-select v-model:value="vModel.fk_relation_column_id" dropdown-class-name="!w-64" @change="onDataTypeChange">
|
||
2 years ago
|
<a-select-option v-for="(table, index) in refTables" :key="index" :value="table.col.fk_column_id">
|
||
|
<div class="flex flex-row space-x-0.5 h-full pb-0.5 items-center justify-between">
|
||
|
<div class="font-semibold text-xs">{{ table.column.title }}</div>
|
||
|
<div class="text-[0.65rem] text-gray-600">
|
||
|
{{ relationNames[table.col.type] }} {{ table.title || table.table_name }}
|
||
|
</div>
|
||
2 years ago
|
</div>
|
||
|
</a-select-option>
|
||
|
</a-select>
|
||
|
</a-form-item>
|
||
|
<a-form-item class="flex w-1/2" :label="$t('labels.childColumn')" v-bind="validateInfos.fk_lookup_column_id">
|
||
2 years ago
|
<a-select v-model:value="vModel.fk_lookup_column_id" name="fk_lookup_column_id" @change="onDataTypeChange">
|
||
2 years ago
|
<a-select-option v-for="(column, index) of columns" :key="index" :value="column.id">
|
||
2 years ago
|
{{ column.title }}
|
||
|
</a-select-option>
|
||
|
</a-select>
|
||
|
</a-form-item>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<style scoped></style>
|