Browse Source

feat(gui-v2): filter auto-save disable/enable option

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2860/head
Pranav C 2 years ago
parent
commit
5eb38b9520
  1. 27
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue
  2. 31
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue
  3. 21
      packages/nc-gui-v2/composables/useViewFilters.ts

27
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue

@ -2,7 +2,6 @@
import type { FilterType } from 'nocodb-sdk' import type { FilterType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue' import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue'
import Smartsheet from '~/components/tabs/Smartsheet.vue'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { inject, useViewFilters, watchEffect } from '#imports' import { inject, useViewFilters, watchEffect } from '#imports'
import { comparisonOpList } from '~/utils/filterUtils' import { comparisonOpList } from '~/utils/filterUtils'
@ -10,7 +9,7 @@ import { ActiveViewInj, MetaInj, ReloadViewDataHookInj } from '~/context'
import MdiDeleteIcon from '~icons/mdi/close-box' import MdiDeleteIcon from '~icons/mdi/close-box'
import MdiAddIcon from '~icons/mdi/plus' import MdiAddIcon from '~icons/mdi/plus'
const { nested = false, parentId } = defineProps<{ nested?: boolean; parentId?: string }>() const { nested = false, parentId, autoSave = true } = defineProps<{ nested?: boolean; parentId?: string; autoSave: boolean }>()
const emit = defineEmits(['update:filters-length']) const emit = defineEmits(['update:filters-length'])
@ -20,9 +19,10 @@ const reloadDataHook = inject(ReloadViewDataHookInj)
const { $e } = useNuxtApp() const { $e } = useNuxtApp()
const { filters, deleteFilter, saveOrUpdate, loadFilters, addFilter, addFilterGroup } = useViewFilters( const { filters, deleteFilter, saveOrUpdate, loadFilters, addFilter, addFilterGroup, sync } = useViewFilters(
activeView, activeView,
parentId, parentId,
computed(() => autoSave),
() => { () => {
reloadDataHook?.trigger() reloadDataHook?.trigger()
}, },
@ -30,7 +30,6 @@ const { filters, deleteFilter, saveOrUpdate, loadFilters, addFilter, addFilterGr
const filterUpdateCondition = (filter: FilterType, i: number) => { const filterUpdateCondition = (filter: FilterType, i: number) => {
saveOrUpdate(filter, i) saveOrUpdate(filter, i)
$e('a:filter:update', { $e('a:filter:update', {
logical: filter.logical_op, logical: filter.logical_op,
comparison: filter.comparison_op, comparison: filter.comparison_op,
@ -79,7 +78,7 @@ watch(
{ immediate: true }, { immediate: true },
) )
const nestedFilter = ref() const nestedFilters = ref()
const logicalOps = [ const logicalOps = [
{ value: 'and', text: 'AND' }, { value: 'and', text: 'AND' },
@ -92,6 +91,22 @@ watch(
emit('update:filters-length', length ?? 0) emit('update:filters-length', length ?? 0)
}, },
) )
const applyChanges = async () => {
console.log('hello')
// sync()
// $e('a:filter:apply')
for (const nestedFilter of nestedFilters?.value || []) {
if (nestedFilter.parentId) {
await nestedFilter.applyChanges(true);
}
}
}
defineExpose({
applyChanges, parentId
})
</script> </script>
<template> <template>
@ -128,7 +143,7 @@ watch(
<div class="col-span-5"> <div class="col-span-5">
<SmartsheetToolbarColumnFilter <SmartsheetToolbarColumnFilter
v-if="filter.id || shared" v-if="filter.id || shared"
ref="nestedFilter" ref="nestedFilters"
v-model="filter.children" v-model="filter.children"
:parent-id="filter.id" :parent-id="filter.id"
nested nested

31
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue

@ -4,15 +4,22 @@ import { useState } from '#app'
import { IsLockedInj } from '~/context' import { IsLockedInj } from '~/context'
import MdiFilterIcon from '~icons/mdi/filter-outline' import MdiFilterIcon from '~icons/mdi/filter-outline'
import MdiMenuDownIcon from '~icons/mdi/menu-down' import MdiMenuDownIcon from '~icons/mdi/menu-down'
import ColumnFilter from './ColumnFilter.vue'
const autoApplyFilter = useState('autoApplyFilter', () => false) const autoApplyFilter = useState('autoApplyFilter', () => false)
const isLocked = inject(IsLockedInj) const isLocked = inject(IsLockedInj)
// todo: emit from child // todo: emit from child
const filtersLength = ref(0) const filtersLength = ref(0)
// todo: sync with store
const autosave = ref(true)
const filterComp = ref<typeof ColumnFilter>()
// todo: implement // todo: implement
const applyChanges = () => {} const applyChanges = async () => {
await filterComp?.value?.applyChanges()
}
</script> </script>
<template> <template>
@ -28,7 +35,27 @@ const applyChanges = () => {}
</a-button> </a-button>
</div> </div>
<template #overlay> <template #overlay>
<SmartsheetToolbarColumnFilter class="nc-table-toolbar-menu" @update:filters-length="filtersLength = $event" /> <SmartsheetToolbarColumnFilter ref="filterComp" class="nc-table-toolbar-menu" @update:filters-length="filtersLength = $event" :auto-save="autosave" >
<div class="d-flex align-end mt-2 min-h-[30px]" @click.stop>
<a-checkbox
id="col-filter-checkbox"
v-model:checked="autosave"
class="col-filter-checkbox"
hide-details
dense
>
<span class="text-grey text-xs">
{{ $t('msg.info.filterAutoApply') }}
<!-- Auto apply -->
</span>
</a-checkbox>
<div class="flex-1"/>
<a-button v-show="!autosave" size="small" class="text-xs ml-2" @click="applyChanges">
Apply changes
</a-button>
</div>
</SmartsheetToolbarColumnFilter>
</template> </template>
</a-dropdown> </a-dropdown>
</template> </template>

21
packages/nc-gui-v2/composables/useViewFilters.ts

@ -1,10 +1,11 @@
import type { FilterType, GalleryType, GridType, KanbanType } from 'nocodb-sdk' import type { FilterType, GalleryType, GridType, KanbanType } from 'nocodb-sdk'
import type { Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { useNuxtApp } from '#imports' import { useNuxtApp } from '#imports'
export function useViewFilters( export function useViewFilters(
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined,
parentId?: string, parentId?: string,
autoApply?: ComputedRef<boolean>,
reloadData?: () => void, reloadData?: () => void,
) { ) {
// todo: update swagger // todo: update swagger
@ -39,20 +40,20 @@ export function useViewFilters(
reloadData?.() reloadData?.()
} }
const deleteFilter = async (filter: FilterType, i: number) => { const deleteFilter = async (filter: FilterType & { status: string }, i: number) => {
// if (this.shared || !this._isUIAllowed('filterSync')) { // if (this.shared || !this._isUIAllowed('filterSync')) {
// this.filters.splice(i, 1) // this.filters.splice(i, 1)
// this.$emit('updated') // this.$emit('updated')
// } else // } else
if (filter.id) { if (filter.id) {
// if (!this.autoApply) { if (!autoApply?.value) {
// this.$set(filter, 'status', 'delete') filter.status = 'delete'
// } else { } else {
await $api.dbTableFilter.delete(filter.id) /**/ await $api.dbTableFilter.delete(filter.id) /**/
// await this.loadFilter() // await this.loadFilter()
// this.$emit('updated') // this.$emit('updated')
// } }
} else { } else {
// this.$emit('updated') // this.$emit('updated')
} }
@ -64,16 +65,16 @@ export function useViewFilters(
reloadData?.() reloadData?.()
} }
const saveOrUpdate = async (filter: FilterType, i: number) => { const saveOrUpdate = async (filter: FilterType & { status?: string }, i: number) => {
if (!view?.value) return if (!view?.value) return
// if (this.shared || !this._isUIAllowed('filterSync')) { // if (this.shared || !this._isUIAllowed('filterSync')) {
// this.$emit('input', this.filters.filter(f => f.fk_column_id && f.comparison_op)) // this.$emit('input', this.filters.filter(f => f.fk_column_id && f.comparison_op))
// this.$emit('updated') // this.$emit('updated')
// } else if (!this.autoApply) {
// filter.status = 'update'
// } else // } else
if (filter.id) { if (!autoApply?.value) {
filter.status = 'update'
} else if (filter.id) {
await $api.dbTableFilter.update(filter.id, { await $api.dbTableFilter.update(filter.id, {
...filter, ...filter,
fk_parent_id: parentId, fk_parent_id: parentId,

Loading…
Cancel
Save