Browse Source

Merge pull request #9051 from nocodb/nc-fix/3368-links-followup

Nc fix/3368 links followup
pull/9056/head
Pranav C 5 months ago committed by GitHub
parent
commit
e34d9029c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 40
      packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue
  2. 4
      packages/nc-gui/composables/useMultiSelect/index.ts
  3. 29
      packages/nocodb/src/db/BaseModelSqlv2.ts

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

@ -92,8 +92,10 @@ const refTables = computed(() => {
})
const refViews = computed(() => {
if (!vModel.value.childId) return []
const views = viewsByTable.value.get(vModel.value.childId)
const childId = vModel.value?.is_custom_link ? vModel.value?.custom?.ref_model_id : vModel.value?.childId
if (!childId) return []
const views = viewsByTable.value.get(childId)
return (views || []).filter((v) => v.type !== ViewTypes.FORM)
})
@ -105,7 +107,7 @@ const isLinks = computed(() => vModel.value.uidt === UITypes.Links && vModel.val
const { metas, getMeta } = useMetas()
watch(
() => vModel.value.childId,
() => (vModel.value?.is_custom_link ? vModel.value?.custom?.ref_model_id : vModel.value?.childId),
async (tableId) => {
if (tableId) {
getMeta(tableId).catch(() => {
@ -146,7 +148,10 @@ const onLimitRecToViewChange = (value: boolean) => {
provide(
MetaInj,
computed(() => metas.value[vModel.value.childId] || {}),
computed(() => {
const childId = vModel.value?.is_custom_link ? vModel.value?.custom?.ref_model_id : vModel.value?.childId
return metas.value[childId] || {}
}),
)
onMounted(() => {
@ -223,6 +228,23 @@ const handleShowAdvanceOptions = () => {
vModel.value.is_custom_link = false
}
}
const onCustomSwitchLabelClick = () => {
vModel.value.is_custom_link = !vModel.value.is_custom_link
onCustomSwitchToggle()
}
const onViewLabelClick = () => {
if (!vModel.value.childId && !(vModel.value.is_custom_link && vModel.value.custom?.ref_model_id)) return
limitRecToView.value = !limitRecToView.value
onLimitRecToViewChange()
}
const onFilterLabelClick = () => {
if (!vModel.value.childId && !(vModel.value.is_custom_link && vModel.value.custom?.ref_model_id)) return
limitRecToCond.value = !limitRecToCond.value
}
</script>
<template>
@ -260,7 +282,7 @@ const handleShowAdvanceOptions = () => {
name="Custom"
@change="onCustomSwitchToggle"
/>
<span class="ml-3">Advanced Link</span>
<span class="ml-3 cursor-pointer" @click="onCustomSwitchLabelClick">Advanced Link</span>
</div>
<div v-if="isEeUI && vModel.is_custom_link">
<LazySmartsheetColumnLinkAdvancedOptions v-model:value="vModel" :is-edit="isEdit" :meta="meta" />
@ -300,14 +322,14 @@ const handleShowAdvanceOptions = () => {
v-model:checked="limitRecToView"
v-e="['c:link:limit-record-by-view', { status: limitRecToView }]"
size="small"
:disabled="!vModel.childId"
:disabled="!vModel.childId && !(vModel.is_custom_link && vModel.custom?.ref_model_id)"
@change="onLimitRecToViewChange"
></a-switch>
<span
v-e="['c:link:limit-record-by-view', { status: limitRecToView }]"
class="text-s"
data-testid="nc-limit-record-view"
@click="limitRecToView = !!vModel.childId && !limitRecToView"
@click="onViewLabelClick"
>Limit record selection to a view</span
>
</div>
@ -337,13 +359,13 @@ const handleShowAdvanceOptions = () => {
<a-switch
v-model:checked="limitRecToCond"
v-e="['c:link:limit-record-by-filter', { status: limitRecToCond }]"
:disabled="!vModel.childId"
:disabled="!vModel.childId && !(vModel.is_custom_link && vModel.custom?.ref_model_id)"
size="small"
></a-switch>
<span
v-e="['c:link:limit-record-by-filter', { status: limitRecToCond }]"
data-testid="nc-limit-record-filters"
@click="limitRecToCond = !!vModel.childId && !limitRecToCond"
@click="onFilterLabelClick"
>
Limit record selection to filters
</span>

4
packages/nc-gui/composables/useMultiSelect/index.ts

@ -907,8 +907,8 @@ export function useMultiSelect(
const rowObj = unref(data)[activeCell.row]
const columnObj = unref(fields)[activeCell.col]
// handle belongs to column
if (isBt(columnObj)) {
// handle belongs to column, skip custom links
if (isBt(columnObj) && !columnObj.meta?.custom) {
const pasteVal = convertCellData(
{
value: clipboardData,

29
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -4320,10 +4320,25 @@ class BaseModelSqlv2 {
);
insertObj[childCol.column_name] = nestedData?.[parentCol.title];
} else {
const parentCol = await colOptions.getParentColumn(
this.context,
);
const parentModel = await parentCol.getModel(this.context);
await parentModel.getColumns(this.context);
postInsertOps.push(async (rowId) => {
let refId = rowId;
if (parentModel.primaryKey.id !== parentCol.id) {
refId = this.dbDriver(
this.getTnPath(parentModel.table_name),
)
.select(parentCol.column_name)
.where(parentModel.primaryKey.column_name, rowId)
.first();
}
return this.dbDriver(this.getTnPath(childModel.table_name))
.update({
[childCol.column_name]: rowId,
[childCol.column_name]: refId,
})
.where(
childModel.primaryKey.column_name,
@ -4338,13 +4353,23 @@ class BaseModelSqlv2 {
{
if (!Array.isArray(nestedData)) continue;
const childCol = await colOptions.getChildColumn(this.context);
const parentCol = await colOptions.getParentColumn(this.context);
const childModel = await childCol.getModel(this.context);
const parentModel = await parentCol.getModel(this.context);
await childModel.getColumns(this.context);
await parentModel.getColumns(this.context);
postInsertOps.push(async (rowId) => {
let refId = rowId;
if (parentModel.primaryKey.id !== parentCol.id) {
refId = this.dbDriver(this.getTnPath(parentModel.table_name))
.select(parentCol.column_name)
.where(parentModel.primaryKey.column_name, rowId)
.first();
}
return this.dbDriver(this.getTnPath(childModel.table_name))
.update({
[childCol.column_name]: rowId,
[childCol.column_name]: refId,
})
.whereIn(
childModel.primaryKey.column_name,

Loading…
Cancel
Save