25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(grid): add a custom filter entry to the cell context menu
HARRISONf5f58d4ae586
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex 51a0b7be76..a0c523e53e 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -1340,6 +1340,7 @@ watch([conditionalBulkEditConditionSource, conditionalBulkEditCurrentWhereInput,const structuredFilterRules = filterBuilder.rules;const filterBuilderOpen = filterBuilder.open;+const filterWorkbenchRef = ref<{ focusRuleValue: (ruleId: string) => void }>();const filterBuilderColumnSearch = filterBuilder.columnSearch;const filteredFilterBuilderColumnOptions = filterBuilder.filteredColumns;const appliedStructuredWhereInput = filterBuilder.appliedWhereInput;@@ -7294,6 +7295,24 @@ async function applyContextFilter(mode: FilterMode) {}}+async function openContextCustomFilter() {+ if (!canUseWhereSearch.value) return;+ const target = contextFilterTarget.value;+ if (!target) return;+ const rule = filterBuilder.addRule({+ columnName: target.columnName,+ rawValue: target.requiresHydration ? "" : formatFilterRawValue(target.sourceValue),+ });+ // The quick and text views only expose a raw WHERE string, so a hand-tuned+ // condition needs the rule builder; select it and open its panel.+ settingsStore.updateEditorSettings({ dataGridFilterEditorView: "conditions" });+ await nextTick();+ filterBuilderOpen.value = true;+ await nextTick();+ filterWorkbenchRef.value?.focusRuleValue(rule.id);+ if (contextFilterTarget.value?.id === target.id) contextFilterTarget.value = null;+}+async function clearContextFilter() {await clearAllFilters();}@@ -13165,11 +13184,13 @@ function filterSubmenu(): ContextMenuItem {notLike: t("grid.filterNotLike"),lessThan: t("grid.filterLessThan"),greaterThan: t("grid.filterGreaterThan"),+ custom: t("grid.filterCustom"),isNull: t("grid.filterIsNull"),isNotNull: t("grid.filterIsNotNull"),clear: t("grid.clearFilter"),},apply: applyContextFilter,+ applyCustom: openContextCustomFilter,clear: clearContextFilter,});}@@ -13943,6 +13964,7 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val</div><DataGridFilterWorkbenchv-if="canUseWhereSearch && filterEditorView === 'conditions' && filterBuilderOpen"+ ref="filterWorkbenchRef":sql-preview="filterSqlPreview":rules="structuredFilterRules":columns="filterBuilderColumnOptions"diff --git a/apps/desktop/src/components/grid/DataGridFilterBuilder.vue b/apps/desktop/src/components/grid/DataGridFilterBuilder.vueindex 298998adc8..15da812dc4 100644--- a/apps/desktop/src/components/grid/DataGridFilterBuilder.vue+++ b/apps/desktop/src/components/grid/DataGridFilterBuilder.vue@@ -379,7 +379,7 @@ async function openFirstEmptyRuleColumnSearch() {if (rule) await handleColumnSelectOpen(rule, true);}-defineExpose({ openFirstEmptyRuleColumnSearch });+defineExpose({ openFirstEmptyRuleColumnSearch, focusFilterRuleValue });function handleColumnCloseAutoFocus(id: string, event: Event) {if (pendingKeyboardAddFocus.delete(id)) {diff --git a/apps/desktop/src/components/grid/DataGridFilterWorkbench.vue b/apps/desktop/src/components/grid/DataGridFilterWorkbench.vueindex bfb7d634bd..02505d56d7 100644--- a/apps/desktop/src/components/grid/DataGridFilterWorkbench.vue+++ b/apps/desktop/src/components/grid/DataGridFilterWorkbench.vue@@ -45,6 +45,13 @@ const emit = defineEmits<{const { t } = useI18n();const rulesScrollerRef = ref<HTMLElement>();+const filterBuilderRef = ref<InstanceType<typeof DataGridFilterBuilder>>();++function focusRuleValue(ruleId: string) {+ filterBuilderRef.value?.focusFilterRuleValue(ruleId);+}++defineExpose({ focusRuleValue });const previewText = computed(() => props.sqlPreview || t("grid.filterSqlPreviewEmpty"));onMounted(() => emit("ensureRule"));@@ -66,6 +73,7 @@ watch(<section data-grid-filter-workbench class="shrink-0 border-b bg-muted/10 text-foreground"><div ref="rulesScrollerRef" data-filter-rules-scroll class="filter-rules-scroll min-h-11 overflow-auto px-3 py-2"><DataGridFilterBuilder+ ref="filterBuilderRef"class="min-w-[560px]":rules="rules":show-apply-only="true"diff --git a/apps/desktop/src/components/grid/__tests__/DataGridFilterEditorState.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridFilterEditorState.spec.tsindex c9dba148fe..eac155df8c 100644--- a/apps/desktop/src/components/grid/__tests__/DataGridFilterEditorState.spec.ts+++ b/apps/desktop/src/components/grid/__tests__/DataGridFilterEditorState.spec.ts@@ -13,6 +13,7 @@ const backendMocks = vi.hoisted(() => ({buildTableSelectSql: vi.fn(async ({ tableName, whereInput }: { tableName: string; whereInput?: string }) => `SELECT * FROM ${tableName}${whereInput ? ` WHERE ${whereInput}` : ""}`),loadEditorSettings: vi.fn().mockResolvedValue({}),saveEditorSettings: vi.fn().mockResolvedValue(undefined),+ buildDataGridContextFilterCondition: vi.fn(async ({ columnName, value }: { columnName: string; value: unknown }) => `\`${columnName}\` = ${String(value)}`),}));vi.mock("@/lib/backend/api", async (importOriginal) => {@@ -20,6 +21,7 @@ vi.mock("@/lib/backend/api", async (importOriginal) => {return {...actual,buildTableSelectSql: backendMocks.buildTableSelectSql,+ buildDataGridContextFilterCondition: backendMocks.buildDataGridContextFilterCondition,loadEditorSettings: backendMocks.loadEditorSettings,saveEditorSettings: backendMocks.saveEditorSettings,};@@ -151,11 +153,33 @@ async function settle() {await nextTick();}+function contextMenuButton(label: string): HTMLButtonElement {+ const button = [...document.querySelectorAll<HTMLButtonElement>("[data-dbx-context-menu] button")].find((candidate) => candidate.textContent?.trim() === label);+ if (!button) throw new Error(`Context menu item not found: ${label}`);+ return button;+}++async function openCellCustomFilter(host: HTMLElement) {+ // Canvas rendering has no per-cell DOM, so switch to the DOM grid before+ // driving the cell context menu.+ useSettingsStore().updateEditorSettings({ dataGridRenderMode: "dom" });+ await settle();+ const cell = host.querySelector<HTMLElement>('[data-row-index="0"] [data-visible-col-index="0"]');+ if (!cell) throw new Error("Grid cell not found");+ cell.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: 12, clientY: 12 }));+ await settle();+ contextMenuButton("Filter").dispatchEvent(new MouseEvent("mouseenter", { bubbles: true }));+ await settle();+ contextMenuButton("Custom Filter").click();+ await settle();+}+afterEach(() => {for (const { app, host } of mountedApps.splice(0)) {app.unmount();host.remove();}+ document.querySelectorAll("[data-dbx-context-menu]").forEach((menu) => menu.remove());clearDataGridStructuredFilterStates();});@@ -214,6 +238,21 @@ describe.each(["conditions", "text"] as const)("DataGrid %s filter editor state"});});+describe("DataGrid custom filter menu", () => {+ it.each(["quick", "conditions", "text"] as const)("opens the rule builder seeded from the right-clicked cell in %s view", async (view) => {+ const { host } = mountGrid(view, false);+ await settle();++ await openCellCustomFilter(host);++ expect(host.querySelector("[data-grid-filter-workbench]")).not.toBeNull();+ const valueEditor = [...host.querySelectorAll<HTMLInputElement>("[data-filter-value-editor]")].find((input) => input.value === "1");+ expect(valueEditor, "seeded value editor").toBeDefined();+ await vi.waitFor(() => expect(document.activeElement).toBe(valueEditor));+ await vi.waitFor(() => expect(host.querySelector("[data-grid-filter-workbench]")?.textContent).toContain("`id` = 1"));+ });+});+describe("DataGrid quick filter editor state", () => {it("continues to close its popover after apply", async () => {const { host, onExecuteSql } = mountGrid("quick", true);diff --git a/apps/desktop/src/composables/useDataGridFilterBuilder.ts b/apps/desktop/src/composables/useDataGridFilterBuilder.tsindex ca7de1bacf..08bf3cd10a 100644--- a/apps/desktop/src/composables/useDataGridFilterBuilder.ts+++ b/apps/desktop/src/composables/useDataGridFilterBuilder.ts@@ -88,8 +88,10 @@ export function useDataGridFilterBuilder(options: UseDataGridFilterBuilderOptionfunction ensureRule() {if (!rules.value.length && toValue(options.columns).length) rules.value = [defaultRule()];}- function addRule() {- rules.value = [...rules.value, defaultRule()];+ function addRule(patch?: Partial<Omit<DataGridStructuredFilterRule, "id">>): DataGridStructuredFilterRule {+ const rule = { ...defaultRule(), ...patch };+ rules.value = [...rules.value, rule];+ return rule;}function removeRule(id: string) {rules.value = rules.value.filter((rule) => rule.id !== id);diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.tsindex 41de1d22d4..bdb7bcb077 100644--- a/apps/desktop/src/i18n/locales/az.ts+++ b/apps/desktop/src/i18n/locales/az.ts@@ -2194,6 +2194,7 @@ export default withEnglishFallback({filterNotLike: "Ehtiva etmir",filterLessThan: "Dəyərdən kiçikdir",filterGreaterThan: "Dəyərdən böyükdür",+ filterCustom: "Fərdi süzgəc",filterIsNull: "NULL dəyərləri göstər",filterIsNotNull: "NULL olmayan dəyərləri göstər",clearFilter: "Süzgəci təmizlə",diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex a0a11e4d6b..ae4c217335 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -2656,6 +2656,7 @@ export default {filterNotLike: "Does Not Contain",filterLessThan: "Less Than Value",filterGreaterThan: "Greater Than Value",+ filterCustom: "Custom Filter",filterIsNull: "Show NULL Values",filterIsNotNull: "Show Non-NULL Values",clearFilter: "Clear Filter",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex 12c593de28..423ade9c7c 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -2492,6 +2492,7 @@ export default withEnglishFallback({filterNotLike: "No contiene este valor",filterLessThan: "Menor que este valor",filterGreaterThan: "Mayor que este valor",+ filterCustom: "Filtro personalizado",filterIsNull: "Mostrar valores NULL",filterIsNotNull: "Mostrar valores no NULL",clearFilter: "Limpiar filtro",diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.tsindex 1a5adf51eb..296eeecf5c 100644--- a/apps/desktop/src/i18n/locales/id.ts+++ b/apps/desktop/src/i18n/locales/id.ts@@ -2490,6 +2490,7 @@ export default withEnglishFallback({filterNotLike: "Tidak Mengandung",filterLessThan: "Kurang dari Nilai",filterGreaterThan: "Lebih dari Nilai",+ filterCustom: "Filter khusus",filterIsNull: "Tampilkan Nilai NULL",filterIsNotNull: "Tampilkan Nilai Non-NULL",clearFilter: "Bersihkan Filter",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex 3baaebfc91..8ef981cb81 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -2386,6 +2386,7 @@ export default withEnglishFallback({filterNotLike: "Non Contiene il Valore",filterLessThan: "Minore del Valore",filterGreaterThan: "Maggiore del Valore",+ filterCustom: "Filtro personalizzato",filterIsNull: "Mostra Valori NULL",filterIsNotNull: "Mostra Valori Non-NULL",clearFilter: "Cancella Filtro",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 2629e42bd2..9d0f16bb1a 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -2392,6 +2392,7 @@ export default withEnglishFallback({filterNotLike: "値を含まない",filterLessThan: "値より小さい",filterGreaterThan: "値より大きい",+ filterCustom: "カスタムフィルター",filterIsNull: "NULL値を表示",filterIsNotNull: "非NULL値を表示",clearFilter: "フィルターをクリア",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex b5a55d633a..7f1b2cc714 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -2433,6 +2433,7 @@ export default withEnglishFallback({filterNotLike: "포함하지 않음",filterLessThan: "값보다 작음",filterGreaterThan: "값보다 큼",+ filterCustom: "사용자 지정 필터",filterIsNull: "NULL 값 표시",filterIsNotNull: "NULL이 아닌 값 표시",clearFilter: "필터 지우기",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex bea3f4b894..893e7cdac6 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -2387,6 +2387,7 @@ export default withEnglishFallback({filterNotLike: "Não Contém",filterLessThan: "Menor Que o Valor",filterGreaterThan: "Maior Que o Valor",+ filterCustom: "Filtro personalizado",filterIsNull: "Mostrar Valores NULL",filterIsNotNull: "Mostrar Valores Não NULL",clearFilter: "Limpar Filtro",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex fec51e211f..dce0819a83 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -2549,6 +2549,7 @@ export default withEnglishFallback({filterNotLike: "Не содержит",filterLessThan: "Меньше значения",filterGreaterThan: "Больше значения",+ filterCustom: "Пользовательский фильтр",filterIsNull: "Показать значения NULL",filterIsNotNull: "Показать значения, отличные от NULL",clearFilter: "Очистить фильтр",diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.tsindex d2d53c3809..7d4615280d 100644--- a/apps/desktop/src/i18n/locales/tr.ts+++ b/apps/desktop/src/i18n/locales/tr.ts@@ -2187,6 +2187,7 @@ export default withEnglishFallback({filterNotLike: "İçermez",filterLessThan: "Değerden Küçük",filterGreaterThan: "Değerden Büyük",+ filterCustom: "Özel filtre",filterIsNull: "NULL Değerleri Göster",filterIsNotNull: "NULL Olmayan Değerleri Göster",clearFilter: "Filtreyi Temizle",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex fe9461d57a..82d1aa5da3 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -2591,6 +2591,7 @@ export default withEnglishFallback({filterNotLike: "不包含此值",filterLessThan: "小于此值",filterGreaterThan: "大于此值",+ filterCustom: "自定义筛选",filterIsNull: "仅显示 NULL",filterIsNotNull: "仅显示非 NULL",clearFilter: "清除筛选",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex b9d6e5421c..ee4ff07835 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -2387,6 +2387,7 @@ export default withEnglishFallback({filterNotLike: "不包含此值",filterLessThan: "小於此值",filterGreaterThan: "大於此值",+ filterCustom: "自訂篩選",filterIsNull: "僅顯示 NULL",filterIsNotNull: "僅顯示非 NULL",clearFilter: "清除篩選",diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridContextMenu.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridContextMenu.spec.tsindex 244a4e86bb..0e3db1f4c1 100644--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridContextMenu.spec.ts+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridContextMenu.spec.ts@@ -47,8 +47,9 @@ describe("dataGridContextMenu", () => {const filter = createDataGridFilterSubmenu({label: "filter",icon,- labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", isNull: "null", isNotNull: "not null", clear: "clear" },+ labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", custom: "custom", isNull: "null", isNotNull: "not null", clear: "clear" },apply: action,+ applyCustom: action,clear: action,});const items = createDataGridColumnContextMenuItems({@@ -98,8 +99,9 @@ describe("dataGridContextMenu", () => {const filter = createDataGridFilterSubmenu({label: "filter",icon,- labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", isNull: "null", isNotNull: "not null", clear: "clear" },+ labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", custom: "custom", isNull: "null", isNotNull: "not null", clear: "clear" },apply: action,+ applyCustom: action,clear: action,});const columnItems = createDataGridColumnContextMenuItems({@@ -153,8 +155,9 @@ describe("dataGridContextMenu", () => {const filter = createDataGridFilterSubmenu({label: "filter",icon,- labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", isNull: "null", isNotNull: "not null", clear: "clear" },+ labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", custom: "custom", isNull: "null", isNotNull: "not null", clear: "clear" },apply: action,+ applyCustom: action,clear: action,});return createDataGridColumnContextMenuItems({@@ -296,13 +299,33 @@ describe("dataGridContextMenu", () => {expect(clear).toHaveBeenCalledTimes(1);});+ it("lists the custom filter entry after the value comparison entries", () => {+ const apply = vi.fn();+ const applyCustom = vi.fn();+ const submenu = createDataGridFilterSubmenu({+ label: "filter",+ icon,+ labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", custom: "custom", isNull: "null", isNotNull: "not null", clear: "clear" },+ apply,+ applyCustom,+ clear: vi.fn(),+ });++ expect(submenu.children?.map((item) => item.label)).toEqual(["equals", "not equals", "like", "not like", "less", "greater", "custom", "", "null", "not null", "", "clear"]);++ submenu.children?.[6]?.action?.();+ expect(applyCustom).toHaveBeenCalledTimes(1);+ expect(apply).not.toHaveBeenCalled();+ });+it("includes highlight submenu in header and context column items", () => {const action = vi.fn();const filter = createDataGridFilterSubmenu({label: "filter",icon,- labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", isNull: "null", isNotNull: "not null", clear: "clear" },+ labels: { equals: "equals", notEquals: "not equals", like: "like", notLike: "not like", lessThan: "less", greaterThan: "greater", custom: "custom", isNull: "null", isNotNull: "not null", clear: "clear" },apply: action,+ applyCustom: action,clear: action,});const highlightSubmenu = createDataGridHighlightSubmenu({diff --git a/apps/desktop/src/lib/dataGrid/dataGridContextMenu.ts b/apps/desktop/src/lib/dataGrid/dataGridContextMenu.tsindex d49e6974dc..be64126f6a 100644--- a/apps/desktop/src/lib/dataGrid/dataGridContextMenu.ts+++ b/apps/desktop/src/lib/dataGrid/dataGridContextMenu.ts@@ -46,8 +46,9 @@ export type DataGridContextMenuIcons = {export function createDataGridFilterSubmenu(options: {label: string;icon: Component;- labels: Record<"equals" | "notEquals" | "like" | "notLike" | "lessThan" | "greaterThan" | "isNull" | "isNotNull" | "clear", string>;+ labels: Record<"equals" | "notEquals" | "like" | "notLike" | "lessThan" | "greaterThan" | "custom" | "isNull" | "isNotNull" | "clear", string>;apply: (mode: "equals" | "not-equals" | "like" | "not-like" | "less-than" | "greater-than" | "is-null" | "is-not-null") => void;+ applyCustom: () => void;clear: () => void;}): DataGridContextMenuItem {const { labels } = options;@@ -61,6 +62,7 @@ export function createDataGridFilterSubmenu(options: {{ label: labels.notLike, action: () => options.apply("not-like") },{ label: labels.lessThan, action: () => options.apply("less-than") },{ label: labels.greaterThan, action: () => options.apply("greater-than") },+ { label: labels.custom, action: () => options.applyCustom() },{ label: "", separator: true },{ label: labels.isNull, action: () => options.apply("is-null") },{ label: labels.isNotNull, action: () => options.apply("is-not-null") },