From 56dca1166a71ae87a9279764176666298ed2be1b Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 6 Aug 2022 17:36:04 +0530 Subject: [PATCH] feat(gui-v2): keep row level state Signed-off-by: Pranav C --- packages/nc-gui-v2/components.d.ts | 2 + .../nc-gui-v2/components/smartsheet/Grid.vue | 9 +++ .../nc-gui-v2/components/smartsheet/Row.vue | 79 +++++++++++++++++++ .../smartsheet/expanded-form/index.vue | 1 - .../components/virtual-cell/HasMany.vue | 2 + .../composables/useExpandedFormStore.ts | 14 ++-- .../composables/useSmartsheetRowStore.ts | 28 +++++++ 7 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 packages/nc-gui-v2/components/smartsheet/Row.vue create mode 100644 packages/nc-gui-v2/composables/useSmartsheetRowStore.ts diff --git a/packages/nc-gui-v2/components.d.ts b/packages/nc-gui-v2/components.d.ts index cd5b18371e..ad183207f6 100644 --- a/packages/nc-gui-v2/components.d.ts +++ b/packages/nc-gui-v2/components.d.ts @@ -80,6 +80,8 @@ declare module '@vue/runtime-core' { MdiApi: typeof import('~icons/mdi/api')['default'] MdiArrowExpand: typeof import('~icons/mdi/arrow-expand')['default'] MdiArrowLeftBold: typeof import('~icons/mdi/arrow-left-bold')['default'] + MdiArrowExpand: typeof import('~icons/mdi/arrow-expand')['default'] + MdiArrowExpandIcon: typeof import('~icons/mdi/arrow-expand-icon')['default'] MdiAt: typeof import('~icons/mdi/at')['default'] MdiCalculator: typeof import('~icons/mdi/calculator')['default'] MdiCardsHeart: typeof import('~icons/mdi/cards-heart')['default'] diff --git a/packages/nc-gui-v2/components/smartsheet/Grid.vue b/packages/nc-gui-v2/components/smartsheet/Grid.vue index d342221f36..e7827e1239 100644 --- a/packages/nc-gui-v2/components/smartsheet/Grid.vue +++ b/packages/nc-gui-v2/components/smartsheet/Grid.vue @@ -329,6 +329,14 @@ const expandForm = (row: Row) => { +
@@ -388,6 +396,7 @@ const expandForm = (row: Row) => {
+
+import { isVirtualCol } from 'nocodb-sdk' +import type { Row } from '~/composables' +import { useSmartsheetStoreOrThrow } from '~/composables' +import { useProvideSmartsheetRowStore } from '~/composables/useSmartsheetRowStore' +import { FieldsInj } from '~/context' + +interface Props { + row: Row + selected: { col?: number; row?: number } + rowIndex: number + editEnabled: boolean +} + +const props = defineProps() + +const emit = defineEmits(['expandForm', 'selectCell', 'updateOrSaveRow', 'navigate']) + +const row = toRef(props, 'row') +const rowIndex = toRef(props, 'rowIndex') +const editEnabled = toRef(props, 'editEnabled') + +// todo : from props / inject +const isPublicView = false + +const fields = inject(FieldsInj, ref([])) +const { meta } = useSmartsheetStoreOrThrow() + +const { isNew } = useProvideSmartsheetRowStore(meta, row) + + + diff --git a/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue b/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue index a04a1a3e8a..566d29982f 100644 --- a/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue +++ b/packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue @@ -43,7 +43,6 @@ const isExpanded = useVModel(props, 'modelValue', emits)
- >, row, diff --git a/packages/nc-gui-v2/composables/useExpandedFormStore.ts b/packages/nc-gui-v2/composables/useExpandedFormStore.ts index eb5dcd411d..c6b9d2a9fa 100644 --- a/packages/nc-gui-v2/composables/useExpandedFormStore.ts +++ b/packages/nc-gui-v2/composables/useExpandedFormStore.ts @@ -3,15 +3,16 @@ import type { ColumnType, TableType } from 'nocodb-sdk' import type { Ref } from 'vue' import { message, notification } from 'ant-design-vue' import dayjs from 'dayjs' -import { NOCO } from '~/lib' import getPlainText from '../../nc-gui/components/project/spreadsheet/helpers/getPlainText' +import { useProvideSmartsheetRowStore } from '~/composables/useSmartsheetRowStore' +import { NOCO } from '~/lib' import { useNuxtApp } from '#app' -import { useInjectionState,useProject } from '#imports' +import { useInjectionState, useProject } from '#imports' import { useApi } from '~/composables/useApi' import type { Row } from '~/composables/useViewData' import { extractPkFromRow, extractSdkResponseErrorMsg } from '~/utils' -const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((meta: Ref, row: Ref, ) => { +const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((meta: Ref, row: Ref) => { const { $e, $state, $api } = useNuxtApp() const { api, isLoading: isCommentsLoading, error: commentsError } = useApi() // { useGlobalInstance: true }, @@ -22,6 +23,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m const commentsDrawer = ref(false) const changedColumns = ref(new Set()) const { project } = useProject() + const rowStore = useProvideSmartsheetRowStore(meta, row) // todo // const activeView = inject(ActiveViewInj) @@ -72,7 +74,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m )?.reverse?.() || [] } - const isYou = (email:string) => { + const isYou = (email: string) => { return $state.user?.value?.email === email } @@ -151,8 +153,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m value: getPlainText(updateOrInsertObj[key]), prev_value: getPlainText(row.value.oldRow[key]), }) - .then(() => { - }) + .then(() => {}) } } else { return message.info('No columns to update') @@ -176,6 +177,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m } return { + ...rowStore, commentsOnly, loadCommentsAndLogs, commentsAndLogs, diff --git a/packages/nc-gui-v2/composables/useSmartsheetRowStore.ts b/packages/nc-gui-v2/composables/useSmartsheetRowStore.ts new file mode 100644 index 0000000000..67bb0f78b3 --- /dev/null +++ b/packages/nc-gui-v2/composables/useSmartsheetRowStore.ts @@ -0,0 +1,28 @@ +import type { TableType } from 'nocodb-sdk' +import type { Ref } from 'vue' +import { useInjectionState } from '#imports' +import type { Row } from '~/composables/useViewData' + +const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState((meta: Ref, row: Ref) => { + // state + const localState = reactive({}) + + // getters + const isNew = computed(() => row.value?.rowMeta?.new) + + // actions + + return { + row, + localState, + isNew, + } +}, 'smartsheet-row-store') + +export { useProvideSmartsheetRowStore } + +export function useSmartsheetRowStoreOrThrow() { + const smartsheetRowStore = useSmartsheetRowStore() + if (smartsheetRowStore == null) throw new Error('Please call `useSmartsheetRowStore` on the appropriate parent component') + return smartsheetRowStore +}