diff --git a/packages/nc-gui/components/virtual-cell/components/ListChildItems.vue b/packages/nc-gui/components/virtual-cell/components/ListChildItems.vue index b909374a25..f8319e7467 100644 --- a/packages/nc-gui/components/virtual-cell/components/ListChildItems.vue +++ b/packages/nc-gui/components/virtual-cell/components/ListChildItems.vue @@ -47,7 +47,7 @@ const { displayValueProp, } = useLTARStoreOrThrow() -const { isNew, state, removeLTARRef } = useSmartsheetRowStoreOrThrow() +const { isNew, state, removeLTARRef, addLTARRef } = useSmartsheetRowStoreOrThrow() watch( [vModel, isForm], @@ -67,6 +67,14 @@ const unlinkRow = async (row: Record, id: number) => { } } +const linkRow = async (row: Record, id: number) => { + if (isNew.value) { + await addLTARRef(row, injectedColumn?.value as ColumnType) + } else { + await link(row, {}, false, id) + } +} + const attachmentCol = computedInject(FieldsInj, (_fields) => { return (relatedTableMeta.value.columns ?? []).filter((col) => isAttachment(col))[0] }) @@ -160,7 +168,7 @@ watch(expandedFormDlg, () => { isChildrenListLinked[Number.parseInt(id)] ? unlinkRow(refRow, Number.parseInt(id)) - : link(refRow, {}, false, Number.parseInt(id)) + : linkRow(refRow, Number.parseInt(id)) } " /> diff --git a/packages/nc-gui/components/virtual-cell/components/ListItems.vue b/packages/nc-gui/components/virtual-cell/components/ListItems.vue index 10c5637e0d..0df6fb17ab 100644 --- a/packages/nc-gui/components/virtual-cell/components/ListItems.vue +++ b/packages/nc-gui/components/virtual-cell/components/ListItems.vue @@ -41,7 +41,7 @@ const { row, } = useLTARStoreOrThrow() -const { addLTARRef, isNew } = useSmartsheetRowStoreOrThrow() +const { addLTARRef, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow() const isPublic = inject(IsPublicInj, ref(false)) @@ -56,12 +56,23 @@ const isFocused = ref(false) const linkRow = async (row: Record, id: number) => { if (isNew.value) { addLTARRef(row, injectedColumn?.value as ColumnType) + isChildrenExcludedListLinked.value[id] = true saveRow!() } else { await link(row, {}, false, id) } } +const unlinkRow = async (row: Record, id: number) => { + if (isNew.value) { + removeLTARRef(row, injectedColumn?.value as ColumnType) + isChildrenExcludedListLinked.value[id] = false + saveRow!() + } else { + await unlink(row, {}, false, id) + } +} + /** reload list on modal open */ watch(vModel, (nextVal, prevVal) => { if (nextVal && !prevVal) { @@ -212,7 +223,7 @@ watch(expandedFormDlg, () => { " @click=" () => { - if (isChildrenExcludedListLinked[Number.parseInt(id)]) unlink(refRow, {}, false, Number.parseInt(id)) + if (isChildrenExcludedListLinked[Number.parseInt(id)]) unlinkRow(refRow, Number.parseInt(id)) else linkRow(refRow, Number.parseInt(id)) } " @@ -244,7 +255,7 @@ watch(expandedFormDlg, () => { show-less-items /> - Close + Close