Browse Source

chore(nc-gui): properly close expanded form

pull/4141/head
braks 2 years ago
parent
commit
4a73bae955
  1. 8
      packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
  2. 21
      packages/nc-gui/components/virtual-cell/components/ListChildItems.vue
  3. 40
      packages/nc-gui/components/virtual-cell/components/ListItems.vue
  4. 11
      packages/nc-gui/composables/useExpandedFormDetached/index.ts

8
packages/nc-gui/components/smartsheet/expanded-form/Detached.vue

@ -1,7 +1,11 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useExpandedFormDetached } from '#imports' import { useExpandedFormDetached } from '#imports'
const { states } = useExpandedFormDetached() const { states, close } = useExpandedFormDetached()
const shouldClose = (isVisible: boolean, i: number) => {
if (!isVisible) close(i)
}
</script> </script>
<template> <template>
@ -15,6 +19,8 @@ const { states } = useExpandedFormDetached()
:state="state.state" :state="state.state"
:use-meta-fields="state.useMetaFields" :use-meta-fields="state.useMetaFields"
:view="state.view" :view="state.view"
@update:model-value="shouldClose($event, i)"
@cancel="close(i)"
/> />
</template> </template>
</template> </template>

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

@ -17,6 +17,7 @@ import {
useVModel, useVModel,
watch, watch,
} from '#imports' } from '#imports'
import type { Row } from '~/lib'
const props = defineProps<{ modelValue?: boolean; cellValue: any }>() const props = defineProps<{ modelValue?: boolean; cellValue: any }>()
@ -80,10 +81,6 @@ const container = computed(() =>
: Modal, : Modal,
) )
const expandedFormDlg = ref(false)
const expandedFormRow = ref()
/** reload children list whenever cell value changes and list is visible */ /** reload children list whenever cell value changes and list is visible */
watch( watch(
() => props.cellValue, () => props.cellValue,
@ -92,16 +89,16 @@ watch(
}, },
) )
function openExpandedForm() { function openExpandedForm(row: Row) {
if (expandedFormRow.value) { if (readonly) return
open({ open({
isOpen: true, isOpen: true,
row: { row: expandedFormRow.value, oldRow: expandedFormRow.value }, row: { row, oldRow: row, rowMeta: {} },
meta: relatedTableMeta.value, meta: relatedTableMeta.value,
loadRow: true, loadRow: true,
useMetaFields: true, useMetaFields: true,
}) })
}
} }
</script> </script>
@ -141,13 +138,7 @@ function openExpandedForm() {
v-for="(row, i) of childrenList?.list ?? state?.[column?.title] ?? []" v-for="(row, i) of childrenList?.list ?? state?.[column?.title] ?? []"
:key="i" :key="i"
class="!my-4 hover:(!bg-gray-200/50 shadow-md)" class="!my-4 hover:(!bg-gray-200/50 shadow-md)"
@click=" @click="openExpandedForm(row)"
() => {
if (readonly) return
expandedFormRow = row
expandedFormDlg = true
}
"
> >
<div class="flex items-center"> <div class="flex items-center">
<div class="flex-1 overflow-hidden min-w-0"> <div class="flex-1 overflow-hidden min-w-0">

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

@ -7,6 +7,7 @@ import {
computed, computed,
inject, inject,
ref, ref,
useExpandedFormDetached,
useLTARStoreOrThrow, useLTARStoreOrThrow,
useSmartsheetRowStoreOrThrow, useSmartsheetRowStoreOrThrow,
useVModel, useVModel,
@ -22,6 +23,8 @@ const vModel = useVModel(props, 'modelValue', emit)
const column = inject(ColumnInj) const column = inject(ColumnInj)
const { open, close } = useExpandedFormDetached()
const { const {
childrenExcludedList, childrenExcludedList,
loadChildrenExcludedList, loadChildrenExcludedList,
@ -57,8 +60,6 @@ watch(vModel, (nextVal, prevVal) => {
} }
}) })
const expandedFormDlg = ref(false)
/** populate initial state for a new row which is parent/child of current record */ /** populate initial state for a new row which is parent/child of current record */
const newRowState = computed(() => { const newRowState = computed(() => {
if (isNew.value) return {} if (isNew.value) return {}
@ -93,11 +94,23 @@ const newRowState = computed(() => {
} }
}) })
// if it's an existing record close the list function openExpandedForm() {
// after new record creation since it's already linking while creating // if it's an existing record close the list
watch(expandedFormDlg, (nexVal) => { // after new record creation since it's already linking while creating
if (!nexVal && !isNew.value) vModel.value = false if (!isNew.value) {
}) vModel.value = false
return close()
}
open({
isOpen: true,
row: { row: {}, oldRow: {}, rowMeta: { new: true } },
meta: relatedTableMeta.value,
loadRow: false,
useMetaFields: true,
state: newRowState.value,
})
}
</script> </script>
<template> <template>
@ -122,7 +135,7 @@ watch(expandedFormDlg, (nexVal) => {
<MdiReload class="cursor-pointer text-gray-500 nc-reload" @click="loadChildrenExcludedList" /> <MdiReload class="cursor-pointer text-gray-500 nc-reload" @click="loadChildrenExcludedList" />
<!-- Add new record --> <!-- Add new record -->
<a-button v-if="!isPublic" type="primary" size="small" @click="expandedFormDlg = true"> <a-button v-if="!isPublic" type="primary" size="small" @click="openExpandedForm">
{{ $t('activity.addNewRecord') }} {{ $t('activity.addNewRecord') }}
</a-button> </a-button>
</div> </div>
@ -156,17 +169,6 @@ watch(expandedFormDlg, (nexVal) => {
</template> </template>
<a-empty v-else class="my-10" :image="Empty.PRESENTED_IMAGE_SIMPLE" /> <a-empty v-else class="my-10" :image="Empty.PRESENTED_IMAGE_SIMPLE" />
<Suspense>
<LazySmartsheetExpandedForm
v-if="expandedFormDlg"
v-model="expandedFormDlg"
:meta="relatedTableMeta"
:row="{ row: {}, oldRow: {}, rowMeta: { new: true } }"
:state="newRowState"
use-meta-fields
/>
</Suspense>
</div> </div>
</a-modal> </a-modal>
</template> </template>

11
packages/nc-gui/composables/useExpandedFormDetached/index.ts

@ -1,5 +1,5 @@
import type { TableType, ViewType } from 'nocodb-sdk' import type { TableType, ViewType } from 'nocodb-sdk'
import { ref, useInjectionState } from '#imports' import { createEventHook, ref, useInjectionState } from '#imports'
import type { Row } from '~/lib' import type { Row } from '~/lib'
interface UseExpandedFormDetachedProps { interface UseExpandedFormDetachedProps {
@ -26,6 +26,8 @@ export function useExpandedFormDetached() {
states = setup() states = setup()
} }
const closeHook = createEventHook<void>()
const index = ref(-1) const index = ref(-1)
const open = (props: UseExpandedFormDetachedProps) => { const open = (props: UseExpandedFormDetachedProps) => {
@ -33,9 +35,10 @@ export function useExpandedFormDetached() {
index.value = states.value.length - 1 index.value = states.value.length - 1
} }
const close = () => { const close = (i?: number) => {
states.value.splice(index.value, 1) states.value.splice(i || index.value, 1)
if (index.value === i || !i) closeHook.trigger()
} }
return { states, open, close } return { states, open, close, onClose: closeHook.on }
} }

Loading…
Cancel
Save