Browse Source

Merge pull request #2692 from nocodb/fix/2690-grouped-filter-local-state

fix: handle nested group save in filter manual sync
pull/2693/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
aee8799795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      packages/nc-gui/components/project/spreadsheet/components/ColumnFilter.vue
  2. 16
      packages/nocodb/src/lib/models/Filter.ts

46
packages/nc-gui/components/project/spreadsheet/components/ColumnFilter.vue

@ -10,16 +10,16 @@
<template v-if="filter.is_group"> <template v-if="filter.is_group">
<v-icon <v-icon
v-if="!filter.readOnly" v-if="!filter.readOnly"
:key="i + '_1'"
small small
class="nc-filter-item-remove-btn" class="nc-filter-item-remove-btn"
@click.stop="deleteFilter(filter, i)" @click.stop="deleteFilter(filter, i)"
:key="i + '_1'"
> >
mdi-close-box mdi-close-box
</v-icon> </v-icon>
<span v-else :key="i + '_1'" /> <span v-else :key="i + '_1'" />
<span :key="i + '_2'" v-if="!i" class="caption d-flex align-center">{{ $t('labels.where') }}</span> <span v-if="!i" :key="i + '_2'" class="caption d-flex align-center">{{ $t('labels.where') }}</span>
<v-select <v-select
v-else v-else
:key="i + '_2'" :key="i + '_2'"
@ -38,12 +38,12 @@
<span class="caption font-weight-regular">{{ item }}</span> <span class="caption font-weight-regular">{{ item }}</span>
</template> </template>
</v-select> </v-select>
<span :key="i + '_3'" style="grid-column: span 3"></span> <span :key="i + '_3'" style="grid-column: span 3" />
</template> </template>
<div v-if="filter.is_group" :key="i + '_4'" style="grid-column: span 5; padding: 6px" class="elevation-4"> <div v-if="filter.is_group" :key="i + '_4'" style="grid-column: span 5; padding: 6px" class="elevation-4">
<column-filter <column-filter
v-if="filter.id || shared" v-if="filter.id || shared || !autoApply"
ref="nestedFilter" ref="nestedFilter"
v-model="filter.children" v-model="filter.children"
:parent-id="filter.id" :parent-id="filter.id"
@ -100,12 +100,12 @@
/> />
<v-select <v-select
v-if="filter && filter.fk_column_id"
:key="i + '_8'" :key="i + '_8'"
v-model="filter.comparison_op" v-model="filter.comparison_op"
class="flex-shrink-1 flex-grow-0 caption nc-filter-operation-select" class="flex-shrink-1 flex-grow-0 caption nc-filter-operation-select"
:items="filterComparisonOp(filter)" :items="filterComparisonOp(filter)"
:placeholder="$t('labels.operation')" :placeholder="$t('labels.operation')"
v-if="filter && filter.fk_column_id"
solo solo
flat flat
style="max-width: 120px" style="max-width: 120px"
@ -120,7 +120,7 @@
<span class="caption font-weight-regular">{{ item.text }}</span> <span class="caption font-weight-regular">{{ item.text }}</span>
</template> </template>
</v-select> </v-select>
<span v-else :key="i + '_8'"></span> <span v-else :key="i + '_8'" />
<span v-if="['null', 'notnull', 'empty', 'notempty'].includes(filter.comparison_op)" :key="i + '_5'" /> <span v-if="['null', 'notnull', 'empty', 'notempty'].includes(filter.comparison_op)" :key="i + '_5'" />
<v-checkbox <v-checkbox
v-else-if="types[filter.field] === 'boolean'" v-else-if="types[filter.field] === 'boolean'"
@ -143,19 +143,19 @@
@click.stop @click.stop
@input="saveOrUpdate(filter, i)" @input="saveOrUpdate(filter, i)"
/> />
<span v-else :key="i + '_9'"></span> <span v-else :key="i + '_9'" />
</template> </template>
</template> </template>
</template> </template>
</div> </div>
<v-btn small class="elevation-0 grey--text my-3" @click.stop="addFilter"> <v-btn small class="elevation-0 grey--text my-3" @click.stop="addFilter">
<v-icon small color="grey"> mdi-plus</v-icon> <v-icon small color="grey"> mdi-plus </v-icon>
<!-- Add Filter --> <!-- Add Filter -->
{{ $t('activity.addFilter') }} {{ $t('activity.addFilter') }}
</v-btn> </v-btn>
<v-btn v-if="!webHook" small class="elevation-0 grey--text my-3" @click.stop="addFilterGroup"> <v-btn v-if="!webHook" small class="elevation-0 grey--text my-3" @click.stop="addFilterGroup">
<v-icon small color="grey"> mdi-plus</v-icon> <v-icon small color="grey"> mdi-plus </v-icon>
Add Filter Group Add Filter Group
<!-- todo: add i18n {{ $t('activity.addFilterGroup') }}--> <!-- todo: add i18n {{ $t('activity.addFilterGroup') }}-->
</v-btn> </v-btn>
@ -297,11 +297,22 @@ export default {
}, },
}, },
watch: { watch: {
async viewId(v) { viewId: {
async handler(v) {
if (v) { if (v) {
await this.loadFilter(); await this.loadFilter();
} }
}, },
immediate: true,
},
hookId: {
async handler(v) {
if (v) {
await this.loadFilter();
}
},
immediate: true,
},
filters: { filters: {
handler(v) { handler(v) {
this.$emit('input', v && v.filter(f => (f.fk_column_id && f.comparison_op) || f.is_group)); this.$emit('input', v && v.filter(f => (f.fk_column_id && f.comparison_op) || f.is_group));
@ -309,9 +320,6 @@ export default {
deep: true, deep: true,
}, },
}, },
created() {
this.loadFilter();
},
methods: { methods: {
filterComparisonOp(f) { filterComparisonOp(f) {
return this.comparisonOp.filter(op => { return this.comparisonOp.filter(op => {
@ -348,11 +356,15 @@ export default {
await this.$api.dbTableFilter.update(filter.id, { await this.$api.dbTableFilter.update(filter.id, {
...filter, ...filter,
fk_parent_id: this.parentId, fk_parent_id: this.parentId,
children: undefined,
status: undefined,
}); });
} else { } else {
await this.$api.dbTableFilter.update(filter.id, { await this.$api.dbTableFilter.update(filter.id, {
...filter, ...filter,
fk_parent_id: this.parentId, fk_parent_id: this.parentId,
children: undefined,
status: undefined,
}); });
} }
} else if (this.hookId || hookId) { } else if (this.hookId || hookId) {
@ -362,6 +374,7 @@ export default {
await this.$api.dbTableWebhookFilter.create(this.hookId || hookId, { await this.$api.dbTableWebhookFilter.create(this.hookId || hookId, {
...filter, ...filter,
fk_parent_id: this.parentId, fk_parent_id: this.parentId,
status: undefined,
}) })
); );
} else { } else {
@ -371,6 +384,7 @@ export default {
await this.$api.dbTableFilter.create(this.viewId, { await this.$api.dbTableFilter.create(this.viewId, {
...filter, ...filter,
fk_parent_id: this.parentId, fk_parent_id: this.parentId,
status: undefined,
}) })
); );
} }
@ -378,9 +392,11 @@ export default {
} }
if (this.$refs.nestedFilter) { if (this.$refs.nestedFilter) {
for (const nestedFilter of this.$refs.nestedFilter) { for (const nestedFilter of this.$refs.nestedFilter) {
if (nestedFilter.parentId) {
await nestedFilter.applyChanges(true); await nestedFilter.applyChanges(true);
} }
} }
}
this.loadFilter(); this.loadFilter();
if (!nested) { if (!nested) {
this.$emit('updated'); this.$emit('updated');
@ -389,12 +405,12 @@ export default {
async loadFilter() { async loadFilter() {
let filters = []; let filters = [];
if (this.viewId && this._isUIAllowed('filterSync')) { if (this.viewId && this._isUIAllowed('filterSync')) {
filters = this.parentId filters = this.nested
? await this.$api.dbTableFilter.childrenRead(this.parentId) ? await this.$api.dbTableFilter.childrenRead(this.parentId)
: await this.$api.dbTableFilter.read(this.viewId); : await this.$api.dbTableFilter.read(this.viewId);
} }
if (this.hookId && this._isUIAllowed('filterSync')) { if (this.hookId && this._isUIAllowed('filterSync')) {
filters = this.parentId filters = this.nested
? await this.$api.dbTableFilter.childrenRead(this.parentId) ? await this.$api.dbTableFilter.childrenRead(this.parentId)
: await this.$api.dbTableWebhookFilter.read(this.hookId); : await this.$api.dbTableWebhookFilter.read(this.hookId);
} }

16
packages/nocodb/src/lib/models/Filter.ts

@ -104,7 +104,15 @@ export default class Filter {
if (filter?.children?.length) { if (filter?.children?.length) {
await Promise.all( await Promise.all(
filter.children.map((f) => filter.children.map((f) =>
this.insert({ ...f, fk_parent_id: row.id }, ncMeta) this.insert(
{
...f,
fk_parent_id: row.id,
[filter.fk_hook_id ? 'fk_hook_id' : 'fk_view_id']:
filter.fk_hook_id ? filter.fk_hook_id : filter.fk_view_id,
},
ncMeta
)
) )
); );
} }
@ -373,6 +381,7 @@ export default class Filter {
}; };
await deleteRecursively(filter); await deleteRecursively(filter);
} }
static async deleteAllByHook(hookId: string, ncMeta = Noco.ncMeta) { static async deleteAllByHook(hookId: string, ncMeta = Noco.ncMeta) {
const filter = await this.getFilterObject({ hookId }, ncMeta); const filter = await this.getFilterObject({ hookId }, ncMeta);
@ -421,7 +430,9 @@ export default class Filter {
}); });
await NocoCache.setList(CacheScope.FILTER_EXP, [viewId], filterObjs); await NocoCache.setList(CacheScope.FILTER_EXP, [viewId], filterObjs);
} }
return filterObjs?.filter(f => !f.fk_parent_id)?.map((f) => new Filter(f)); return filterObjs
?.filter((f) => !f.fk_parent_id)
?.map((f) => new Filter(f));
} }
static async rootFilterListByHook( static async rootFilterListByHook(
@ -464,6 +475,7 @@ export default class Filter {
} }
return filterObjs?.map((f) => new Filter(f)); return filterObjs?.map((f) => new Filter(f));
} }
static async parentFilterListByHook( static async parentFilterListByHook(
{ {
hookId, hookId,

Loading…
Cancel
Save