Browse Source

feat(nc-gui): open a separate form for each composable caller

pull/4141/head
braks 2 years ago
parent
commit
bcff62b834
  1. 26
      packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
  2. 26
      packages/nc-gui/components/virtual-cell/components/ListChildItems.vue
  3. 67
      packages/nc-gui/composables/useExpandedFormDetached/index.ts

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

@ -1,20 +1,20 @@
<script lang="ts" setup>
import { useExpandedFormDetached } from '#imports'
const { isOpen, state, row, rowId, loadRow: shouldLoadRow, meta, useMetaFields, view, close } = useExpandedFormDetached()
const { states } = useExpandedFormDetached()
</script>
<template>
<LazySmartsheetExpandedForm
v-if="!!row && !!meta"
v-model="isOpen"
:row="row"
:load-row="shouldLoadRow"
:meta="meta"
:row-id="rowId"
:state="state"
:use-meta-fields="useMetaFields"
:view="view"
@cancel="close"
/>
<template v-for="(state, i) of states" :key="`expanded-form-${i}`">
<LazySmartsheetExpandedForm
v-model="state.isOpen"
:row="state.row"
:load-row="state.loadRow"
:meta="state.meta"
:row-id="state.rowId"
:state="state.state"
:use-meta-fields="state.useMetaFields"
:view="state.view"
/>
</template>
</template>

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

@ -11,6 +11,7 @@ import {
h,
inject,
ref,
useExpandedFormDetached,
useLTARStoreOrThrow,
useSmartsheetRowStoreOrThrow,
useVModel,
@ -31,6 +32,8 @@ const column = inject(ColumnInj)
const readonly = inject(ReadonlyInj, false)
const { open } = useExpandedFormDetached()
const {
childrenList,
deleteRelatedRow,
@ -88,6 +91,18 @@ watch(
if (!isNew.value && vModel.value) loadChildrenList()
},
)
function openExpandedForm() {
if (expandedFormRow.value) {
open({
isOpen: true,
row: { row: expandedFormRow.value, oldRow: expandedFormRow.value },
meta: relatedTableMeta.value,
loadRow: true,
useMetaFields: true,
})
}
}
</script>
<template>
@ -176,17 +191,6 @@ watch(
:image-style="isForm ? { height: '20px' } : {}"
/>
</div>
<Suspense>
<LazySmartsheetExpandedForm
v-if="expandedFormRow && expandedFormDlg"
v-model="expandedFormDlg"
:row="{ row: expandedFormRow }"
:meta="relatedTableMeta"
load-row
use-meta-fields
/>
</Suspense>
</component>
</template>

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

@ -1,58 +1,41 @@
import type { TableType, ViewType } from 'nocodb-sdk'
import { reactive, toRefs, useInjectionState } from '#imports'
import { ref, useInjectionState } from '#imports'
import type { Row } from '~/lib'
interface UseExpandedFormDetachedProps {
isOpen?: boolean
row: Row | null
state?: Record<string, any> | null
meta: TableType
loadRow?: boolean
useMetaFields?: boolean
rowId?: string
view?: ViewType
'isOpen'?: boolean
'row': Row | null
'state'?: Record<string, any> | null
'meta': TableType
'loadRow'?: boolean
'useMetaFields'?: boolean
'rowId'?: string
'view'?: ViewType
'onCancel'?: Function
'onUpdate:modelValue'?: Function
}
const [setup, use] = useInjectionState(() => {
const state = reactive<UseExpandedFormDetachedProps>({
isOpen: false,
state: null,
loadRow: false,
useMetaFields: false,
row: null,
meta: null as any,
})
return ref<UseExpandedFormDetachedProps[]>([])
})
const open = (props: UseExpandedFormDetachedProps) => {
state.state = props.state
state.loadRow = props.loadRow
state.useMetaFields = props.useMetaFields
state.rowId = props.rowId
state.row = props.row
state.loadRow = props.loadRow
state.meta = props.meta
state.isOpen = props.isOpen
state.isOpen = true
}
export function useExpandedFormDetached() {
let states = use()!
const close = () => {
state.isOpen = false
if (!states) {
states = setup()
}
return {
...toRefs(state),
open,
close,
}
})
const index = ref(-1)
export function useExpandedFormDetached() {
const state = use()
const open = (props: UseExpandedFormDetachedProps) => {
states.value.push(props)
index.value = states.value.length - 1
}
if (!state) {
return setup()
const close = () => {
states.value.splice(index.value, 1)
}
return state
return { states, open, close }
}

Loading…
Cancel
Save