Skip to content

Commit d42eacf

Browse files
vdhieuclaude
andcommitted
fix: improve sidebar starred items handling and cache management
- Exclude starred items from their original sections to prevent duplicates - Update section counts to reflect non-starred items only - Switch to resetQueries() for proper cache invalidation and refetch - Add cmd+k as quickOpen shortcut, remove unused chord keybindings - Add aria-label to CommandDialog for accessibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 96d4ef8 commit d42eacf

6 files changed

Lines changed: 53 additions & 50 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ui/command.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as React from "react";
44
import { type DialogProps } from "@radix-ui/react-dialog";
55
import { Command as CommandPrimitive } from "cmdk";
66
import { cn } from "@/lib/cn";
7-
import { Dialog, DialogContent } from "@/components/ui/dialog";
7+
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
88
import { MagnifyingGlassIcon } from "@radix-ui/react-icons";
99

1010
const Command = React.forwardRef<
@@ -43,7 +43,9 @@ const CommandDialog = ({
4343
showCloseButton={false}
4444
className="overflow-hidden p-0 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-top-[48%] data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200 top-[20%] translate-y-0"
4545
onKeyDown={onKeyDown}
46+
aria-describedby={undefined}
4647
>
48+
<DialogTitle className="sr-only">Command Palette</DialogTitle>
4749
<Command
4850
value={value}
4951
onValueChange={onValueChange}

src/data/defaultCommands.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { useWorkspaceSelectionStore } from "@/stores/workspaceSelectionStore";
1212
import { tabGroupRegistry } from "@/services/tabGroupRegistry";
1313
import { clearAllCaches } from "@/lib/cacheManager";
1414
import { useCrudStore } from "@/stores/crudStore";
15-
import { queryClient } from "@/lib/react-query-client";
1615
import { toast } from "sonner";
1716
import React from "react";
1817
import { ConfirmationToast } from "@/components/ConfirmationToast";
@@ -311,13 +310,9 @@ export const defaultCommands: Command[] = [
311310
crudStore.discardAll();
312311
}
313312

314-
// Clear all caches (React Query + Zustand)
315-
logger.info("[RefreshAll] Clearing all caches");
316-
clearAllCaches();
317-
318-
// Invalidate all queries to trigger refetch
319-
logger.info("[RefreshAll] Invalidating queries");
320-
await queryClient.invalidateQueries();
313+
// Reset all caches and trigger refetch for active queries
314+
logger.info("[RefreshAll] Resetting all caches and refetching");
315+
await clearAllCaches();
321316

322317
// Show success toast
323318
logger.info("[RefreshAll] Showing success toast");
@@ -347,13 +342,9 @@ export const defaultCommands: Command[] = [
347342
logger.info("[DiscardAllChanges] Discarding all changes");
348343
crudStore.discardAll();
349344

350-
// Clear all caches
351-
logger.info("[DiscardAllChanges] Clearing all caches");
352-
clearAllCaches();
353-
354-
// Invalidate all queries to trigger refetch
355-
logger.info("[DiscardAllChanges] Invalidating queries");
356-
await queryClient.invalidateQueries();
345+
// Reset all caches and trigger refetch for active queries
346+
logger.info("[DiscardAllChanges] Resetting all caches and refetching");
347+
await clearAllCaches();
357348

358349
// Show success toast
359350
logger.info("[DiscardAllChanges] Showing success toast");

src/data/defaultKeybindings.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export const defaultKeybindings: Keybinding[] = [
55
command: 'commandPalette.open',
66
key: 'cmd+shift+p',
77
},
8+
{
9+
command: 'quickOpen.show',
10+
key: 'cmd+k',
11+
},
812
{
913
command: 'quickOpen.show',
1014
key: 'cmd+p',
@@ -13,10 +17,6 @@ export const defaultKeybindings: Keybinding[] = [
1317
command: 'commandPalette.open',
1418
key: 'f1',
1519
},
16-
{
17-
command: 'commandPalette.toggle',
18-
key: 'cmd+k cmd+p',
19-
},
2020
{
2121
command: 'commandPalette.close',
2222
key: 'escape',
@@ -26,10 +26,6 @@ export const defaultKeybindings: Keybinding[] = [
2626
command: 'preferences.open',
2727
key: 'cmd+,',
2828
},
29-
{
30-
command: 'preferences.openKeyboardShortcuts',
31-
key: 'cmd+k cmd+s',
32-
},
3329
{
3430
command: 'help.keyboardShortcuts',
3531
key: 'cmd+shift+/',
@@ -155,10 +151,6 @@ export const defaultKeybindings: Keybinding[] = [
155151
key: 'cmd+shift+z',
156152
when: '!editorTextFocus && !editingCell',
157153
},
158-
{
159-
command: 'workbench.action.discardAllChanges',
160-
key: 'cmd+r',
161-
},
162154
{
163155
command: 'workbench.action.reloadWindow',
164156
key: 'cmd+shift+r',

src/lib/cacheManager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ export function clearConnectionCache(connectionId: string): void {
4343

4444
/**
4545
* Clear all query caches globally (used for Cmd+R refresh)
46+
* Uses resetQueries() to properly reset and refetch active queries
4647
*/
47-
export function clearAllCaches(): void {
48-
// Clear React Query cache
49-
queryClient.clear();
48+
export async function clearAllCaches(): Promise<void> {
49+
// Reset all React Query queries - this marks them as stale AND triggers refetch for active ones
50+
await queryClient.resetQueries();
5051

5152
// Clear all Zustand tab state
5253
const tabStateStore = useTabStateStore.getState();

src/screens/workspace/components/DatabaseSidebar.tsx

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ export function DatabaseSidebar({
109109
return set;
110110
}, [starredItemsRaw]);
111111

112+
// Compute non-starred counts for section headers
113+
const nonStarredCounts = useMemo(() => ({
114+
tables: tables.filter((t) => !starredSet.has(`table:${t.schema}.${t.name}`)).length,
115+
views: views.filter((v) => !starredSet.has(`view:${v.schema}.${v.name}`)).length,
116+
functions: functions.filter((f) => !starredSet.has(`function:${f.schema}.${f.name}`)).length,
117+
}), [tables, views, functions, starredSet]);
118+
112119
// Pre-compute pending changes set for O(1) lookups
113120
const pendingChangesSet = useMemo(() => {
114121
const set = new Set<string>();
@@ -205,21 +212,21 @@ export function DatabaseSidebar({
205212

206213
// Add tables if expanded
207214
if (expandedNodes.has("tables")) {
208-
filterItems(tables).forEach((table) => {
215+
filterItems(tables, "table").forEach((table) => {
209216
allItems.push(getItemKey("table", table.name, table.schema));
210217
});
211218
}
212219

213220
// Add views if expanded
214221
if (expandedNodes.has("views")) {
215-
filterItems(views).forEach((view) => {
222+
filterItems(views, "view").forEach((view) => {
216223
allItems.push(getItemKey("view", view.name, view.schema));
217224
});
218225
}
219226

220227
// Add functions if expanded
221228
if (expandedNodes.has("functions")) {
222-
filterItems(functions).forEach((func) => {
229+
filterItems(functions, "function").forEach((func) => {
223230
allItems.push(getItemKey("function", func.name, func.schema));
224231
});
225232
}
@@ -516,12 +523,22 @@ export function DatabaseSidebar({
516523
// Use pre-computed starred items
517524
const starredItems = starredItemsRaw;
518525

519-
// IconFilter items based on search
520-
const filterItems = <T extends { name: string }>(items: T[]): T[] => {
521-
if (!searchQuery) return items;
522-
return items.filter((item) =>
523-
item.name.toLowerCase().includes(searchQuery.toLowerCase()),
524-
);
526+
// Filter items based on search and exclude starred items from original groups
527+
const filterItems = <T extends { name: string; schema: string }>(
528+
items: T[],
529+
type: "table" | "view" | "function",
530+
): T[] => {
531+
return items.filter((item) => {
532+
// Exclude starred items from their original group
533+
if (starredSet.has(`${type}:${item.schema}.${item.name}`)) {
534+
return false;
535+
}
536+
// Apply search filter
537+
if (searchQuery && !item.name.toLowerCase().includes(searchQuery.toLowerCase())) {
538+
return false;
539+
}
540+
return true;
541+
});
525542
};
526543

527544
// IconCheck if a table/view is currently active in the active panel
@@ -810,10 +827,10 @@ export function DatabaseSidebar({
810827
)}
811828

812829
{/* Tables Section */}
813-
{(tables.length > 0 || isLoadingData) && (
830+
{(nonStarredCounts.tables > 0 || isLoadingData) && (
814831
<SidebarSection
815832
title="Tables"
816-
count={tables.length}
833+
count={nonStarredCounts.tables}
817834
isExpanded={expandedNodes.has("tables")}
818835
onToggle={() => {
819836
toggleNode("tables");
@@ -822,7 +839,7 @@ export function DatabaseSidebar({
822839
onAdd={handleCreateTable}
823840
addTooltip="Create new table"
824841
>
825-
{filterItems(tables).map((table) => {
842+
{filterItems(tables, "table").map((table) => {
826843
const itemKey = getItemKey("table", table.name, table.schema);
827844
return (
828845
<SidebarItem
@@ -882,18 +899,18 @@ export function DatabaseSidebar({
882899
)}
883900

884901
{/* Views Section */}
885-
{views.length > 0 && (
902+
{nonStarredCounts.views > 0 && (
886903
<SidebarSection
887904
title="Views"
888-
count={views.length}
905+
count={nonStarredCounts.views}
889906
isExpanded={expandedNodes.has("views")}
890907
onToggle={() => {
891908
toggleNode("views");
892909
}}
893910
onAdd={handleCreateView}
894911
addTooltip="Create new view"
895912
>
896-
{filterItems(views).map((view) => {
913+
{filterItems(views, "view").map((view) => {
897914
const itemKey = getItemKey("view", view.name, view.schema);
898915
return (
899916
<SidebarItem
@@ -960,10 +977,10 @@ export function DatabaseSidebar({
960977
)}
961978

962979
{/* Functions Section */}
963-
{functions.length > 0 && (
980+
{nonStarredCounts.functions > 0 && (
964981
<SidebarSection
965982
title="Functions"
966-
count={functions.length}
983+
count={nonStarredCounts.functions}
967984
isExpanded={expandedNodes.has("functions")}
968985
onToggle={() => {
969986
toggleNode("functions");
@@ -972,7 +989,7 @@ export function DatabaseSidebar({
972989
onAdd={handleCreateFunction}
973990
addTooltip="Create new function"
974991
>
975-
{filterItems(functions).map((func) => {
992+
{filterItems(functions, "function").map((func) => {
976993
const itemKey = getItemKey("function", func.name, func.schema);
977994
return (
978995
<SidebarItem

0 commit comments

Comments
 (0)