Browse Source

Nc fix/links followup (#8994)

* fix: avoid using title as key since it's going to re-render on field name change

* fix: delete fk column only if type id ForeignKey

* fix: mark custom link as virtual and disable

* chore: lint

* refactor: on edit show relation information

* refactor: on edit show relation information
pull/9000/head
Pranav C 4 months ago committed by GitHub
parent
commit
346b1cc392
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      packages/nc-gui/components/smartsheet/column/EditOrAdd.vue
  2. 36
      packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue
  3. 7
      packages/nocodb/src/services/columns.service.ts

2
packages/nc-gui/components/smartsheet/column/EditOrAdd.vue

@ -492,7 +492,7 @@ const isFullUpdateAllowed = computed(() => {
<SmartsheetColumnRollupOptions v-if="formState.uidt === UITypes.Rollup" v-model:value="formState" /> <SmartsheetColumnRollupOptions v-if="formState.uidt === UITypes.Rollup" v-model:value="formState" />
<SmartsheetColumnLinkedToAnotherRecordOptions <SmartsheetColumnLinkedToAnotherRecordOptions
v-if="formState.uidt === UITypes.LinkToAnotherRecord || formState.uidt === UITypes.Links" v-if="formState.uidt === UITypes.LinkToAnotherRecord || formState.uidt === UITypes.Links"
:key="`${formState.uidt}-${formState.id || formState.title}`" :key="`${formState.uidt}-${formState.id || 'new'}`"
v-model:value="formState" v-model:value="formState"
:is-edit="isEdit" :is-edit="isEdit"
/> />

36
packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ModelTypes, MssqlUi, RelationTypes, SqliteUi, UITypes, ViewTypes } from 'nocodb-sdk' import { type LinkToAnotherRecordType, ModelTypes, MssqlUi, RelationTypes, SqliteUi, UITypes, ViewTypes } from 'nocodb-sdk'
const props = defineProps<{ const props = defineProps<{
value: any value: any
@ -48,12 +48,33 @@ if (!isEdit.value) {
if (!vModel.value.virtual) vModel.value.virtual = sqlUi === SqliteUi // appInfo.isCloud || sqlUi === SqliteUi if (!vModel.value.virtual) vModel.value.virtual = sqlUi === SqliteUi // appInfo.isCloud || sqlUi === SqliteUi
if (!vModel.value.alias) vModel.value.alias = vModel.value.column_name if (!vModel.value.alias) vModel.value.alias = vModel.value.column_name
} else { } else {
if (!vModel.value.childId) const colOptions = vModel.value?.colOptions as LinkToAnotherRecordType
vModel.custom = { if (vModel.value?.meta?.custom && isEeUI) {
ref_model_id: vModel.value?.colOptions?.fk_related_model_id, let ref_column_id = colOptions.fk_child_column_id
let column_id = colOptions.fk_parent_column_id
// extract ref column id from colOptions
if (
colOptions.type === RelationTypes.MANY_TO_MANY ||
colOptions.type === RelationTypes.BELONGS_TO ||
vModel?.value?.meta?.bt
) {
ref_column_id = colOptions.fk_parent_column_id
column_id = colOptions.fk_child_column_id
}
vModel.value.custom = {
ref_model_id: colOptions?.fk_related_model_id,
base_id: meta.value?.base_id, base_id: meta.value?.base_id,
junc_base_id: meta.value?.base_id, junc_base_id: meta.value?.base_id,
junc_model_id: colOptions?.fk_mm_model_id,
junc_ref_column_id: colOptions?.fk_mm_parent_column_id,
junc_column_id: colOptions?.fk_mm_child_column_id,
ref_column_id,
column_id,
} }
}
vModel.value.is_custom_link = vModel.value?.meta?.custom
if (!vModel.value.childViewId) vModel.value.childViewId = vModel.value?.colOptions?.fk_target_view_id || null if (!vModel.value.childViewId) vModel.value.childViewId = vModel.value?.colOptions?.fk_target_view_id || null
} }
if (!vModel.value.childId) vModel.value.childId = vModel.value?.colOptions?.fk_related_model_id || null if (!vModel.value.childId) vModel.value.childId = vModel.value?.colOptions?.fk_related_model_id || null
@ -182,13 +203,14 @@ const cusJuncTableValidations = {
} }
const onCustomSwitchToggle = () => { const onCustomSwitchToggle = () => {
if (vModel.value?.is_custom_link) if (vModel.value?.is_custom_link) {
setAdditionalValidations({ setAdditionalValidations({
childId: [], childId: [],
...cusValidators, ...cusValidators,
...(vModel.value.type === RelationTypes.MANY_TO_MANY ? cusJuncTableValidations : {}), ...(vModel.value.type === RelationTypes.MANY_TO_MANY ? cusJuncTableValidations : {}),
}) })
else vModel.value.virtual = true
} else
setAdditionalValidations({ setAdditionalValidations({
childId: [{ required: true, message: t('general.required') }], childId: [{ required: true, message: t('general.required') }],
}) })
@ -413,7 +435,7 @@ const handleShowAdvanceOptions = () => {
<div class="flex flex-row"> <div class="flex flex-row">
<a-form-item> <a-form-item>
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
<NcSwitch v-model:checked="vModel.virtual" @change="onDataTypeChange"> <NcSwitch v-model:checked="vModel.virtual" :disabled="vModel.is_custom_link" @change="onDataTypeChange">
<div class="text-sm text-gray-800 select-none"> <div class="text-sm text-gray-800 select-none">
{{ $t('title.virtualRelation') }} {{ $t('title.virtualRelation') }}
</div> </div>

7
packages/nocodb/src/services/columns.service.ts

@ -2396,7 +2396,8 @@ export class ColumnsService {
} }
} }
if (mmTable) { // delete m2m table if it is made for mm relation
if (mmTable?.mm) {
// retrieve columns in m2m table again // retrieve columns in m2m table again
await mmTable.getColumns(context, ncMeta); await mmTable.getColumns(context, ncMeta);
@ -2597,7 +2598,7 @@ export class ColumnsService {
await Column.delete(context, relationColOpt.fk_column_id, ncMeta); await Column.delete(context, relationColOpt.fk_column_id, ncMeta);
if (custom) return; if (custom) return;
if (!ignoreFkDelete) { if (!ignoreFkDelete && childColumn.uidt === UITypes.ForeignKey) {
const cTable = await Model.getWithInfo( const cTable = await Model.getWithInfo(
context, context,
{ {
@ -2758,7 +2759,7 @@ export class ColumnsService {
if (custom) return; if (custom) return;
if (!ignoreFkDelete) { if (!ignoreFkDelete && childColumn.uidt === UITypes.ForeignKey) {
const cTable = await Model.getWithInfo( const cTable = await Model.getWithInfo(
context, context,
{ {

Loading…
Cancel
Save