From 6a4a8b2828ec170b9876e1a02667087e6872f35b Mon Sep 17 00:00:00 2001 From: zipg Date: Tue, 30 Jun 2026 17:51:56 +0800 Subject: [PATCH] fix(grid): show empty state for condition history dropdown Co-authored-by: staff --- apps/desktop/src/components/grid/DataGrid.vue | 48 ++++++++++++++++--- apps/desktop/src/i18n/locales/en.ts | 2 + apps/desktop/src/i18n/locales/zh-CN.ts | 2 + 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 307bac1074..2c73ad6b4c 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -482,6 +482,7 @@ const suggestionLeft = ref(0); const whereSuggestions = ref([]); const whereSuggestionIndex = ref(-1); +const whereHistoryMenuOpen = ref(false); const whereFilterInputRef = ref(); const whereMeasureRef = ref(); const whereSuggestionLeft = ref(0); @@ -489,6 +490,7 @@ const whereSuggestionPosition = ref({ left: 0, top: 0 }); const orderBySuggestions = ref([]); const orderBySuggestionIndex = ref(-1); +const orderByHistoryMenuOpen = ref(false); const orderByInputRef = ref(); const orderByMeasureRef = ref(); const orderBySuggestionLeft = ref(0); @@ -522,11 +524,15 @@ const whereSuggestionStyle = computed(() => ({ left: `${whereSuggestionPosition.value.left}px`, top: `${whereSuggestionPosition.value.top}px`, })); +const showWhereSuggestionDropdown = computed(() => whereSuggestions.value.length > 0 || whereHistoryMenuOpen.value); +const whereHistoryEmptyText = computed(() => (whereFilterInput.value.trim() ? t("grid.conditionHistoryNoMatches") : t("grid.conditionHistoryEmpty"))); const orderBySuggestionStyle = computed(() => ({ left: `${orderBySuggestionPosition.value.left}px`, top: `${orderBySuggestionPosition.value.top}px`, })); +const showOrderBySuggestionDropdown = computed(() => orderBySuggestions.value.length > 0 || orderByHistoryMenuOpen.value); +const orderByHistoryEmptyText = computed(() => (orderByInput.value.trim() ? t("grid.conditionHistoryNoMatches") : t("grid.conditionHistoryEmpty"))); type LocalFilterMode = "local" | "server"; type LocalFilterOption = { @@ -1536,6 +1542,7 @@ function acceptWhereSuggestion() { whereFilterInput.value = sug.value; whereSuggestions.value = []; whereSuggestionIndex.value = -1; + whereHistoryMenuOpen.value = false; whereFilterInputRef.value?.focus(); return; } @@ -1547,12 +1554,14 @@ function acceptWhereSuggestion() { } whereSuggestions.value = []; whereSuggestionIndex.value = -1; + whereHistoryMenuOpen.value = false; whereFilterInputRef.value?.focus(); } function dismissWhereSuggestions() { whereSuggestions.value = []; whereSuggestionIndex.value = -1; + whereHistoryMenuOpen.value = false; } function navigateWhereSuggestion(delta: number) { @@ -1568,7 +1577,13 @@ function showWhereHistorySuggestions() { const history = loadDataGridConditionHistory("where", conditionHistoryScope.value, whereFilterInput.value); whereSuggestions.value = history.map((value) => ({ value, kind: "history" })); whereSuggestionIndex.value = -1; - if (whereSuggestions.value.length) updateWhereSuggestionPosition(); + updateWhereSuggestionPosition(); +} + +function openWhereHistoryMenu() { + whereHistoryMenuOpen.value = true; + showWhereHistorySuggestions(); + whereFilterInputRef.value?.focus(); } function deleteWhereHistorySuggestion(value: string) { @@ -1577,6 +1592,8 @@ function deleteWhereHistorySuggestion(value: string) { const filtered = query.trim() ? loadDataGridConditionHistory("where", conditionHistoryScope.value, query) : history; whereSuggestions.value = filtered.map((item) => ({ value: item, kind: "history" })); whereSuggestionIndex.value = whereSuggestions.value.length ? Math.min(whereSuggestionIndex.value, whereSuggestions.value.length - 1) : -1; + whereHistoryMenuOpen.value = true; + updateWhereSuggestionPosition(); } function onWhereFilterInput(event: Event) { @@ -1612,6 +1629,7 @@ watch(whereFilterInput, (val) => { persistStructuredFilterState(); previousWhereFilterInputValue = val; whereSuggestions.value = []; + whereHistoryMenuOpen.value = false; if (!props.tableMeta?.columns?.length) return; const trimmed = val.trim(); if (trimmed.length === 0) { @@ -1717,6 +1735,7 @@ function acceptOrderBySuggestion() { orderByInput.value = sug.value; orderBySuggestions.value = []; orderBySuggestionIndex.value = -1; + orderByHistoryMenuOpen.value = false; orderByInputRef.value?.focus(); return; } @@ -1728,12 +1747,14 @@ function acceptOrderBySuggestion() { } orderBySuggestions.value = []; orderBySuggestionIndex.value = -1; + orderByHistoryMenuOpen.value = false; orderByInputRef.value?.focus(); } function dismissOrderBySuggestions() { orderBySuggestions.value = []; orderBySuggestionIndex.value = -1; + orderByHistoryMenuOpen.value = false; } function navigateOrderBySuggestion(delta: number) { @@ -1749,7 +1770,13 @@ function showOrderByHistorySuggestions() { const history = loadDataGridConditionHistory("orderBy", conditionHistoryScope.value, orderByInput.value); orderBySuggestions.value = history.map((value) => ({ value, kind: "history" })); orderBySuggestionIndex.value = -1; - if (orderBySuggestions.value.length) updateOrderBySuggestionPosition(); + updateOrderBySuggestionPosition(); +} + +function openOrderByHistoryMenu() { + orderByHistoryMenuOpen.value = true; + showOrderByHistorySuggestions(); + orderByInputRef.value?.focus(); } function deleteOrderByHistorySuggestion(value: string) { @@ -1758,11 +1785,14 @@ function deleteOrderByHistorySuggestion(value: string) { const filtered = query.trim() ? loadDataGridConditionHistory("orderBy", conditionHistoryScope.value, query) : history; orderBySuggestions.value = filtered.map((item) => ({ value: item, kind: "history" })); orderBySuggestionIndex.value = orderBySuggestions.value.length ? Math.min(orderBySuggestionIndex.value, orderBySuggestions.value.length - 1) : -1; + orderByHistoryMenuOpen.value = true; + updateOrderBySuggestionPosition(); } watch(orderByInput, (val) => { emit("update:orderByInput", val); orderBySuggestions.value = []; + orderByHistoryMenuOpen.value = false; if (!props.tableMeta?.columns?.length) return; const trimmed = val.trim(); if (trimmed.length === 0) { @@ -7519,13 +7549,13 @@ const gridContextMenuItems = computed(() => { @click="updateWhereSuggestionPosition" @blur="dismissWhereSuggestions" /> -