Browse Source

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

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

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

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

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

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

Loading…
Cancel
Save