Browse Source

refactor(gui-v2): replace pain object with Map

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3370/head
Pranav C 2 years ago
parent
commit
86586fd1a9
  1. 36
      packages/nc-gui/components/tabs/Smartsheet.vue
  2. 1
      packages/nc-gui/composables/useTabs.ts

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

@ -1,5 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType, TableType, ViewType } from 'nocodb-sdk' import type { ColumnType, TableType, ViewType } from 'nocodb-sdk'
import type { Ref } from 'vue'
import { useUIPermission } from '#imports'
import SmartsheetGrid from '../smartsheet/Grid.vue'
import { import {
ActiveViewInj, ActiveViewInj,
FieldsInj, FieldsInj,
@ -45,25 +48,38 @@ const reloadViewMetaEventHook = createEventHook()
useProvideKanbanViewStore(meta, activeView) useProvideKanbanViewStore(meta, activeView)
const { isUIAllowed } = useUIPermission()
/** keep view level state in tabMeta and restore on view change */ /** keep view level state in tabMeta and restore on view change */
watch(nestedFilters, (newFilters) => { watch(nestedFilters, (newFilters) => {
activeTab.value.state = activeTab.value.state || {} activeTab.value.state = activeTab.value.state || new Map()
activeTab.value.state[activeView.value.id] = activeTab.value.state[activeView.value.id] || {} if (!activeTab.value.state.has(activeView.value.id)) {
activeTab.value.state[activeView.value.id].filters = newFilters activeTab.value.state.set(activeView.value.id, new Map())
}
activeTab.value.state.get(activeView.value.id)!.set('filters', newFilters)
}) })
watch(sorts, (newSorts) => { watch(sorts, (newSorts) => {
activeTab.value.state = activeTab.value.state || {} activeTab.value.state = activeTab.value.state || new Map()
activeTab.value.state[activeView.value.id] = activeTab.value.state[activeView.value.id] || {} if (!activeTab.value.state.has(activeView.value.id)) {
activeTab.value.state[activeView.value.id].sorts = newSorts activeTab.value.state.set(activeView.value.id, new Map())
}
activeTab.value.state.get(activeView.value.id)!.set('sorts', newSorts)
}) })
watch(activeView, (newView: ViewType) => { watch(activeView, (newView: ViewType) => {
if (activeTab.value.state?.[newView.id!]?.filters) if(!newView || !activeTab.value?.state?.get(newView.id as string)) return
nestedFilters.value = activeTab.value.state?.[newView.id!]?.filters || []
if (activeTab.value.state?.[newView.id!]?.sorts) if (
sorts.value = activeTab.value.state?.[newView.id!]?.sorts || [] activeTab.value?.state?.get(newView.id as string)?.has('filters') &&
!isUIAllowed('filterSync') &&
!isUIAllowed('filterChildrenRead')
) {
nestedFilters.value = activeTab.value?.state?.get(newView.id as string)?.get('filters') || []
}
if (activeTab.value?.state?.get(newView.id as string)?.has('sorts') && !isUIAllowed('sortSync')) {
nestedFilters.value = activeTab.value?.state?.get(newView.id as string)?.get('sorts') || []
}
}) })
// todo: move to store // todo: move to store

1
packages/nc-gui/composables/useTabs.ts

@ -38,6 +38,7 @@ const [setup, use] = useInjectionState(() => {
let index = tabs.value.findIndex((t) => t.id === tab.id) let index = tabs.value.findIndex((t) => t.id === tab.id)
if (index === -1) { if (index === -1) {
tab.state = tab.state || new Map()
tabs.value.push(tab) tabs.value.push(tab)
index = tabs.value.length - 1 index = tabs.value.length - 1
} }

Loading…
Cancel
Save