Browse Source

fix(nc-gui): Add detached expanded form

pull/4141/head
braks 2 years ago
parent
commit
7c326ce118
  1. 20
      packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
  2. 6
      packages/nc-gui/components/smartsheet/expanded-form/index.vue
  3. 4
      packages/nc-gui/components/tabs/Smartsheet.vue
  4. 39
      packages/nc-gui/components/virtual-cell/components/ItemChip.vue
  5. 58
      packages/nc-gui/composables/useExpandedFormDetached/index.ts

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

@ -0,0 +1,20 @@
<script lang="ts" setup>
import { useExpandedFormDetached } from '#imports'
const { isOpen, state, row, rowId, loadRow: shouldLoadRow, meta, useMetaFields, view, close } = 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>

6
packages/nc-gui/components/smartsheet/expanded-form/index.vue

@ -9,7 +9,10 @@ import {
MetaInj, MetaInj,
ReloadRowDataHookInj, ReloadRowDataHookInj,
computedInject, computedInject,
createEventHook,
inject,
message, message,
onBeforeMount,
provide, provide,
ref, ref,
toRef, toRef,
@ -57,6 +60,7 @@ provide(MetaInj, meta)
const { commentsDrawer, changedColumns, state: rowState, isNew, loadRow } = useProvideExpandedFormStore(meta, row) const { commentsDrawer, changedColumns, state: rowState, isNew, loadRow } = useProvideExpandedFormStore(meta, row)
onBeforeMount(async () => {
if (props.loadRow) { if (props.loadRow) {
await loadRow() await loadRow()
} }
@ -72,6 +76,7 @@ if (props.rowId) {
} else throw e } else throw e
} }
} }
})
useProvideSmartsheetStore(ref({}) as Ref<ViewType>, meta) useProvideSmartsheetStore(ref({}) as Ref<ViewType>, meta)
@ -134,6 +139,7 @@ export default {
width="min(90vw,1000px)" width="min(90vw,1000px)"
:body-style="{ 'padding': 0, 'display': 'flex', 'flex-direction': 'column' }" :body-style="{ 'padding': 0, 'display': 'flex', 'flex-direction': 'column' }"
:closable="false" :closable="false"
destroy-on-close
class="nc-drawer-expanded-form" class="nc-drawer-expanded-form"
> >
<SmartsheetExpandedFormHeader :view="props.view" @cancel="onClose" /> <SmartsheetExpandedFormHeader :view="props.view" @cancel="onClose" />

4
packages/nc-gui/components/tabs/Smartsheet.vue

@ -7,6 +7,7 @@ import {
IsLockedInj, IsLockedInj,
MetaInj, MetaInj,
OpenNewRecordFormHookInj, OpenNewRecordFormHookInj,
ReadonlyInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
ReloadViewMetaHookInj, ReloadViewMetaHookInj,
TabMetaInj, TabMetaInj,
@ -55,6 +56,7 @@ provide(OpenNewRecordFormHookInj, openNewRecordFormHook)
provide(FieldsInj, fields) provide(FieldsInj, fields)
provide(IsFormInj, isForm) provide(IsFormInj, isForm)
provide(TabMetaInj, activeTab) provide(TabMetaInj, activeTab)
provide(ReadonlyInj, false)
</script> </script>
<template> <template>
@ -79,6 +81,8 @@ provide(TabMetaInj, activeTab)
</Transition> </Transition>
</div> </div>
<LazySmartsheetExpandedFormDetached />
<!-- Lazy loading the sidebar causes issues when deleting elements, i.e. it appears as if multiple elements are removed when they are not --> <!-- Lazy loading the sidebar causes issues when deleting elements, i.e. it appears as if multiple elements are removed when they are not -->
<SmartsheetSidebar v-if="meta" class="nc-right-sidebar" /> <SmartsheetSidebar v-if="meta" class="nc-right-sidebar" />
</div> </div>

39
packages/nc-gui/components/virtual-cell/components/ItemChip.vue

@ -1,5 +1,15 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ActiveCellInj, IsFormInj, IsLockedInj, ReadonlyInj, inject, ref, useLTARStoreOrThrow, useUIPermission } from '#imports' import {
ActiveCellInj,
IsFormInj,
IsLockedInj,
ReadonlyInj,
inject,
ref,
useExpandedFormDetached,
useLTARStoreOrThrow,
useUIPermission,
} from '#imports'
interface Props { interface Props {
value?: string | number | boolean value?: string | number | boolean
@ -22,7 +32,19 @@ const isForm = inject(IsFormInj)!
const isLocked = inject(IsLockedInj, ref(false)) const isLocked = inject(IsLockedInj, ref(false))
const expandedFormDlg = ref(false) const { open } = useExpandedFormDetached()
function openExpandedForm() {
if (!readOnly && !isLocked.value) {
open({
isOpen: true,
row: { row: item, rowMeta: {}, oldRow: { ...item } },
meta: relatedTableMeta.value,
loadRow: true,
useMetaFields: true,
})
}
}
</script> </script>
<script lang="ts"> <script lang="ts">
@ -35,24 +57,13 @@ export default {
<div <div
class="chip group py-1 px-2 mr-1 my-1 flex items-center bg-blue-100/60 hover:bg-blue-100/40 rounded-[2px]" class="chip group py-1 px-2 mr-1 my-1 flex items-center bg-blue-100/60 hover:bg-blue-100/40 rounded-[2px]"
:class="{ active }" :class="{ active }"
@click="expandedFormDlg = true" @click="openExpandedForm"
> >
<span class="name">{{ value }}</span> <span class="name">{{ value }}</span>
<div v-show="active || isForm" v-if="!readOnly && !isLocked && isUIAllowed('xcDatatableEditable')" class="flex items-center"> <div v-show="active || isForm" v-if="!readOnly && !isLocked && isUIAllowed('xcDatatableEditable')" class="flex items-center">
<MdiCloseThick class="unlink-icon text-xs text-gray-500/50 group-hover:text-gray-500" @click.stop="emit('unlink')" /> <MdiCloseThick class="unlink-icon text-xs text-gray-500/50 group-hover:text-gray-500" @click.stop="emit('unlink')" />
</div> </div>
<Suspense>
<SmartsheetExpandedForm
v-if="!readOnly && !isLocked && expandedFormDlg"
v-model="expandedFormDlg"
:row="{ row: item, rowMeta: {}, oldRow: { ...item } }"
:meta="relatedTableMeta"
load-row
use-meta-fields
/>
</Suspense>
</div> </div>
</template> </template>

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

@ -0,0 +1,58 @@
import type { TableType, ViewType } from 'nocodb-sdk'
import { reactive, toRefs, 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
}
const [setup, use] = useInjectionState(() => {
const state = reactive<UseExpandedFormDetachedProps>({
isOpen: false,
state: null,
loadRow: false,
useMetaFields: false,
row: null,
meta: null as any,
})
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
}
const close = () => {
state.isOpen = false
}
return {
...toRefs(state),
open,
close,
}
})
export function useExpandedFormDetached() {
const state = use()
if (!state) {
return setup()
}
return state
}
Loading…
Cancel
Save