Browse Source

fix: update link for new records

pull/6360/head
DarkPhoenix2704 1 year ago
parent
commit
733da2e3a5
  1. 12
      packages/nc-gui/components/virtual-cell/components/ListChildItems.vue
  2. 17
      packages/nc-gui/components/virtual-cell/components/ListItems.vue

12
packages/nc-gui/components/virtual-cell/components/ListChildItems.vue

@ -47,7 +47,7 @@ const {
displayValueProp, displayValueProp,
} = useLTARStoreOrThrow() } = useLTARStoreOrThrow()
const { isNew, state, removeLTARRef } = useSmartsheetRowStoreOrThrow() const { isNew, state, removeLTARRef, addLTARRef } = useSmartsheetRowStoreOrThrow()
watch( watch(
[vModel, isForm], [vModel, isForm],
@ -67,6 +67,14 @@ const unlinkRow = async (row: Record<string, any>, id: number) => {
} }
} }
const linkRow = async (row: Record<string, any>, id: number) => {
if (isNew.value) {
await addLTARRef(row, injectedColumn?.value as ColumnType)
} else {
await link(row, {}, false, id)
}
}
const attachmentCol = computedInject(FieldsInj, (_fields) => { const attachmentCol = computedInject(FieldsInj, (_fields) => {
return (relatedTableMeta.value.columns ?? []).filter((col) => isAttachment(col))[0] return (relatedTableMeta.value.columns ?? []).filter((col) => isAttachment(col))[0]
}) })
@ -160,7 +168,7 @@ watch(expandedFormDlg, () => {
isChildrenListLinked[Number.parseInt(id)] isChildrenListLinked[Number.parseInt(id)]
? unlinkRow(refRow, Number.parseInt(id)) ? unlinkRow(refRow, Number.parseInt(id))
: link(refRow, {}, false, Number.parseInt(id)) : linkRow(refRow, Number.parseInt(id))
} }
" "
/> />

17
packages/nc-gui/components/virtual-cell/components/ListItems.vue

@ -41,7 +41,7 @@ const {
row, row,
} = useLTARStoreOrThrow() } = useLTARStoreOrThrow()
const { addLTARRef, isNew } = useSmartsheetRowStoreOrThrow() const { addLTARRef, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow()
const isPublic = inject(IsPublicInj, ref(false)) const isPublic = inject(IsPublicInj, ref(false))
@ -56,12 +56,23 @@ const isFocused = ref(false)
const linkRow = async (row: Record<string, any>, id: number) => { const linkRow = async (row: Record<string, any>, id: number) => {
if (isNew.value) { if (isNew.value) {
addLTARRef(row, injectedColumn?.value as ColumnType) addLTARRef(row, injectedColumn?.value as ColumnType)
isChildrenExcludedListLinked.value[id] = true
saveRow!() saveRow!()
} else { } else {
await link(row, {}, false, id) await link(row, {}, false, id)
} }
} }
const unlinkRow = async (row: Record<string, any>, 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 */ /** reload list on modal open */
watch(vModel, (nextVal, prevVal) => { watch(vModel, (nextVal, prevVal) => {
if (nextVal && !prevVal) { if (nextVal && !prevVal) {
@ -212,7 +223,7 @@ watch(expandedFormDlg, () => {
" "
@click=" @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)) else linkRow(refRow, Number.parseInt(id))
} }
" "
@ -244,7 +255,7 @@ watch(expandedFormDlg, () => {
show-less-items show-less-items
/> />
</div> </div>
<NcButton class="nc-close-btn" @click="vModel = false"> Close </NcButton> <NcButton class="nc-close-btn ml-auto" @click="vModel = false"> Close </NcButton>
</div> </div>
<Suspense> <Suspense>
<LazySmartsheetExpandedForm <LazySmartsheetExpandedForm

Loading…
Cancel
Save