Browse Source

fix(gui-v2): handle linked row delete in proper way if it's a new record

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3169/head
Pranav C 2 years ago
parent
commit
44897b363b
  1. 8
      packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue
  2. 2
      packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue
  3. 9
      packages/nc-gui-v2/composables/useLTARStore.ts

8
packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue

@ -59,6 +59,12 @@ const unlinkRow = async (row: Record<string, any>) => {
}
}
const unlinkIfNewRow = async (row: Record<string, any>) => {
if (isNew.value) {
removeLTARRef(row, column?.value as ColumnType)
}
}
const container = computed(() =>
isForm?.value
? h('div', {
@ -112,7 +118,7 @@ const expandedFormRow = ref()
/>
<MdiDeleteOutline
class="text-xs text-grey hover:(!text-red-500) cursor-pointer"
@click.stop="deleteRelatedRow(row)"
@click.stop="deleteRelatedRow(row, unlinkIfNewRow)"
/>
</div>
</div>

2
packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue

@ -47,8 +47,10 @@ const linkRow = async (row: Record<string, any>) => {
vModel.value = false
}
/** reload list on modal open */
watch(vModel, (nextVal, prevVal) => {
if (nextVal && !prevVal) {
/** reset query and limit */
childrenExcludedListPagination.query = ''
childrenExcludedListPagination.page = 1
loadChildrenExcludedList()

9
packages/nc-gui-v2/composables/useLTARStore.ts

@ -139,7 +139,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
}
}
const deleteRelatedRow = async (row: Record<string, any>) => {
const deleteRelatedRow = async (row: Record<string, any>, onSuccess?: (row: Record<string, any>) => void) => {
Modal.confirm({
title: 'Do you want to delete the record?',
type: 'warning',
@ -148,7 +148,12 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
try {
$api.dbTableRow.delete(NOCO, project.value.id as string, relatedTableMeta.value.id as string, id as string)
reloadData?.()
await loadChildrenList()
/** reload child list if not a new row */
if (!isNewRow?.value) {
await loadChildrenList()
}
onSuccess?.(row)
} catch (e: any) {
message.error(`Delete failed: ${await extractSdkResponseErrorMsg(e)}`)
}

Loading…
Cancel
Save