From 7b32836f27424bd91c328060e854b149553f4310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E4=B8=AB=E8=AE=B2=E6=A2=B5?= Date: Fri, 11 Sep 2026 10:52:57 +0800 Subject: [PATCH] feat(grid): support applying a single structured filter condition --- apps/desktop/src/components/grid/DataGrid.vue | 46 +++++++++++++++++-- .../components/grid/DataGridFilterBuilder.vue | 8 +++- .../grid/DataGridFilterWorkbench.vue | 5 ++ .../components/grid/DataGridQueryControls.vue | 5 ++ .../grid/DataGridTextFilterWorkbench.vue | 5 ++ .../grid/__tests__/DataGridSurfaces.spec.ts | 29 ++++++++++++ .../dataGridFilterBuilderPointerDrag.spec.ts | 2 +- .../useDataGridFilterBuilder.spec.ts | 23 ++++++++++ .../composables/useDataGridFilterBuilder.ts | 6 ++- apps/desktop/src/i18n/locales/az.ts | 2 + apps/desktop/src/i18n/locales/en.ts | 2 + apps/desktop/src/i18n/locales/es.ts | 2 + apps/desktop/src/i18n/locales/it.ts | 2 + apps/desktop/src/i18n/locales/ja.ts | 2 + apps/desktop/src/i18n/locales/ko.ts | 2 + apps/desktop/src/i18n/locales/pt-BR.ts | 2 + apps/desktop/src/i18n/locales/tr.ts | 2 + apps/desktop/src/i18n/locales/zh-CN.ts | 2 + apps/desktop/src/i18n/locales/zh-TW.ts | 2 + 19 files changed, 143 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 94d8573b1a..baa6158c25 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -1595,13 +1595,47 @@ function buildGroupedWhere(conditions: string[], rules: StructuredFilterRule[]): return result; } -async function applyStructuredFilters() { - if (!canUseWhereSearch.value) return; - appliedStructuredWhereInput.value = await buildStructuredWhereFromRules(structuredFilterRules.value); +async function applyStructuredWhere(where: string) { + appliedStructuredWhereInput.value = where; if (!isFilterEditorPinnedOpen.value) filterBuilderOpen.value = false; await applyWhereFilter(); } +async function applyStructuredFilters() { + if (!canUseWhereSearch.value) return; + await applyStructuredWhere(await buildStructuredWhereFromRules(structuredFilterRules.value)); +} + +const applyingOnlyStructuredFilter = ref(false); +async function applyOnlyStructuredFilter(ruleId: string) { + if (!canUseWhereSearch.value || applyingOnlyStructuredFilter.value || isApplyingWhere.value) return; + const rule = structuredFilterRules.value.find((item) => item.id === ruleId); + if (!rule) return; + if (!rule.columnName || !isStructuredFilterRuleComplete(rule)) { + toast(t("grid.filterBuilderCompleteRuleFirst")); + return; + } + applyingOnlyStructuredFilter.value = true; + const scopeKey = structuredFilterScopeKey.value; + const cacheKey = structuredFilterCacheKey.value; + const rulesSnapshot = JSON.stringify(structuredFilterRules.value); + try { + // Build before changing enabled states so an invalid condition cannot clear the filter. + const where = await buildStructuredWhereFromRules([{ ...rule, disabled: false }]); + if (scopeKey !== structuredFilterScopeKey.value || cacheKey !== structuredFilterCacheKey.value || rulesSnapshot !== JSON.stringify(structuredFilterRules.value)) return; + if (!where) { + toast(t("grid.filterBuilderCompleteRuleFirst")); + return; + } + filterBuilder.enableOnlyRule(ruleId); + await applyStructuredWhere(where); + } catch (error: unknown) { + toast(error instanceof Error ? error.message : String(error)); + } finally { + applyingOnlyStructuredFilter.value = false; + } +} + let structuredFilterPreviewRequestId = 0; async function refreshStructuredFilterPreview() { const requestId = ++structuredFilterPreviewRequestId; @@ -11521,6 +11555,8 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val @ensure-rule="ensureStructuredFilterRule" @add-rule="addStructuredFilterRule" @apply-filters="applyStructuredFilters" + :apply-only-busy="applyingOnlyStructuredFilter || isApplyingWhere" + @apply-only="applyOnlyStructuredFilter" @reset-filters="resetStructuredFilters" @clear-filters="clearAllFilters" @remove-rule="removeStructuredFilterRule" @@ -11659,6 +11695,8 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val @ensure-rule="ensureStructuredFilterRule" @add-rule="addStructuredFilterRule" @apply="applyStructuredFilters" + :apply-only-busy="applyingOnlyStructuredFilter || isApplyingWhere" + @apply-only="applyOnlyStructuredFilter" @reset="resetStructuredFilters" @clear="clearAllFilters" @copy-sql="copyFilterSqlPreview" @@ -11681,6 +11719,8 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val @ensure-rule="ensureStructuredFilterRule" @add-rule="addStructuredFilterRule" @apply="applyStructuredFilters" + :apply-only-busy="applyingOnlyStructuredFilter || isApplyingWhere" + @apply-only="applyOnlyStructuredFilter" @reset="resetStructuredFilters" @clear="clearAllFilters" @copy-sql="copyFilterSqlPreview" diff --git a/apps/desktop/src/components/grid/DataGridFilterBuilder.vue b/apps/desktop/src/components/grid/DataGridFilterBuilder.vue index 405377eb78..63f31f6d5b 100644 --- a/apps/desktop/src/components/grid/DataGridFilterBuilder.vue +++ b/apps/desktop/src/components/grid/DataGridFilterBuilder.vue @@ -1,6 +1,6 @@