From b88517d696e244394cf4041bc6faa4ad8902cb4c Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 8 Aug 2022 17:51:15 +0530 Subject: [PATCH] fix(gui-v2): pass isNewRow reference to LTAR store Signed-off-by: Pranav C --- packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue | 3 ++- packages/nc-gui-v2/components/virtual-cell/HasMany.vue | 9 +++------ .../nc-gui-v2/components/virtual-cell/ManyToMany.vue | 4 ++-- .../components/virtual-cell/components/ListItems.vue | 2 +- packages/nc-gui-v2/composables/useLTARStore.ts | 8 ++++---- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue b/packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue index 2bbeb3cf85..a894fbd2cb 100644 --- a/packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue +++ b/packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue @@ -23,14 +23,15 @@ const listItemsDlg = ref(false) const isForm = inject(IsFormInj) +const { state, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow() const { relatedTableMeta, loadRelatedTableMeta, relatedTablePrimaryValueProp, unlink } = useProvideLTARStore( column as Ref>, row, + isNew, reloadTrigger.trigger, ) await loadRelatedTableMeta() -const { state, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow() const value = computed(() => { if (cellValue?.value) { diff --git a/packages/nc-gui-v2/components/virtual-cell/HasMany.vue b/packages/nc-gui-v2/components/virtual-cell/HasMany.vue index 2b4924e2bf..ebe91458fe 100644 --- a/packages/nc-gui-v2/components/virtual-cell/HasMany.vue +++ b/packages/nc-gui-v2/components/virtual-cell/HasMany.vue @@ -4,10 +4,9 @@ import type { Ref } from 'vue' import ItemChip from './components/ItemChip.vue' import ListChildItems from './components/ListChildItems.vue' import ListItems from './components/ListItems.vue' -import { useProvideSmartsheetRowStore, useSmartsheetRowStoreOrThrow } from '~/composables/useSmartsheetRowStore' +import { useSmartsheetRowStoreOrThrow } from '~/composables/useSmartsheetRowStore' import { computed, inject, ref, useProvideLTARStore } from '#imports' import { CellValueInj, ColumnInj, IsFormInj, ReloadViewDataHookInj, RowInj } from '~/context' - import { useProvideLTARStore } from '#imports' import { CellValueInj, ColumnInj, IsFormInj, ReloadViewDataHookInj, RowInj } from '~/context' @@ -27,17 +26,15 @@ const listItemsDlg = ref(false) const childListDlg = ref(false) -const { state, isNew } = useSmartsheetRowStoreOrThrow() - +const { state, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow() const { relatedTableMeta, loadRelatedTableMeta, relatedTablePrimaryValueProp, unlink } = useProvideLTARStore( column as Ref>, row, + isNew, reloadTrigger.trigger, ) await loadRelatedTableMeta() -const { state, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow() - const localCellValue = computed(() => { if (cellValue?.value) { return cellValue?.value diff --git a/packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue b/packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue index 9bd8e8abed..b5c793ddc1 100644 --- a/packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue +++ b/packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue @@ -24,16 +24,16 @@ const listItemsDlg = ref(false) const childListDlg = ref(false) +const { state, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow() const { loadRelatedTableMeta, relatedTablePrimaryValueProp, unlink } = useProvideLTARStore( column as Ref>, row, + isNew, reloadTrigger.trigger, ) await loadRelatedTableMeta() -const { state, isNew, removeLTARRef } = useSmartsheetRowStoreOrThrow() - const localCellValue = computed(() => { if (cellValue?.value) { return cellValue?.value diff --git a/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue b/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue index 696e196fad..dde6acad7e 100644 --- a/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue +++ b/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue @@ -34,7 +34,7 @@ const linkRow = async (row: Record) => { watch(vModel, () => { if (vModel.value) { - loadChildrenExcludedList(isNew.value) + loadChildrenExcludedList() } }) diff --git a/packages/nc-gui-v2/composables/useLTARStore.ts b/packages/nc-gui-v2/composables/useLTARStore.ts index 436a1b40ea..d3928940bf 100644 --- a/packages/nc-gui-v2/composables/useLTARStore.ts +++ b/packages/nc-gui-v2/composables/useLTARStore.ts @@ -1,5 +1,5 @@ import type { ColumnType, LinkToAnotherRecordType, PaginatedType, TableType } from 'nocodb-sdk' -import type { Ref } from 'vue' +import type { ComputedRef, Ref } from 'vue' import { Modal, notification } from 'ant-design-vue' import { useInjectionState, useMetas, useProject } from '#imports' import { NOCO } from '~/lib' @@ -13,7 +13,7 @@ interface DataApiResponse { /** Store for managing Link to another cells */ const [useProvideLTARStore, useLTARStore] = useInjectionState( - (column: Ref>, row?: Ref, reloadData = () => {}) => { + (column: Ref>, row?: Ref, isNewRow: ComputedRef, reloadData = () => {}) => { // state const { metas, getMeta } = useMetas() const { project } = useProject() @@ -69,10 +69,10 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState( return (meta?.value?.columns?.find((c: Required) => c.pv) || relatedTableMeta?.value?.columns?.[0])?.title }) - const loadChildrenExcludedList = async (isNewRow = false) => { + const loadChildrenExcludedList = async () => { try { /** if new row load all records */ - if (isNewRow) { + if (isNewRow?.value) { childrenExcludedList.value = await $api.dbTableRow.list( NOCO, project.value.id as string,