Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { LuPlus } from "react-icons/lu";
import { trpc } from "renderer/lib/trpc";
import { useOpenNewWorkspaceModal } from "renderer/stores/new-workspace-modal";

export function NewWorkspaceButton() {
const openModal = useOpenNewWorkspaceModal();
const { data: activeWorkspace, isLoading } =
trpc.workspaces.getActive.useQuery();

const handleClick = () => {
// projectId may be undefined if no workspace is active or query failed
// openModal handles undefined by opening without a pre-selected project
const projectId = activeWorkspace?.projectId;
openModal(projectId);
};
Comment on lines +5 to +15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Check if the file exists and read its content
cat -n "apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarHeader/NewWorkspaceButton.tsx"

Repository: superset-sh/superset

Length of output: 1337


🏁 Script executed:

# Search for similar tRPC query patterns in renderer components to understand error handling practices
rg "trpc\." apps/desktop/src/renderer --type tsx --type ts -A 3 -B 1 | head -100

Repository: superset-sh/superset

Length of output: 91


🏁 Script executed:

# Check how isError is used in other components
rg "isError" apps/desktop/src/renderer --type tsx --type ts -B 2 -A 2 | head -80

Repository: superset-sh/superset

Length of output: 91


🏁 Script executed:

# Search for error handling patterns in renderer components
rg "isError" apps/desktop/src/renderer -A 2 -B 2

Repository: superset-sh/superset

Length of output: 3490


🏁 Script executed:

# Check for trpc query error handling patterns
rg "useQuery.*error" apps/desktop/src/renderer -A 3 -B 1

Repository: superset-sh/superset

Length of output: 46


🏁 Script executed:

# Look at the trpc configuration to understand what's available
cat -n "apps/desktop/src/renderer/lib/trpc.ts" 2>/dev/null || cat -n "src/lib/trpc.ts"

Repository: superset-sh/superset

Length of output: 375


🏁 Script executed:

# Search for similar error logging patterns with context
rg "console\.error.*\[" apps/desktop/src/renderer | head -20

Repository: superset-sh/superset

Length of output: 1422


Add error handling for tRPC query failures

The component destructures isLoading from the query result but ignores isError. When trpc.workspaces.getActive fails, the button remains enabled and passes undefined to openModal.

Per the coding guideline "Never swallow errors silently - at minimum log them with context", destructure isError and log the error:

export function NewWorkspaceButton() {
	const openModal = useOpenNewWorkspaceModal();
-	const { data: activeWorkspace, isLoading } =
+	const { data: activeWorkspace, isLoading, isError, error } =
		trpc.workspaces.getActive.useQuery();

+	if (isError) {
+		console.error('[NewWorkspaceButton/getActive]', error);
+	}
+
	const handleClick = () => {
		// projectId may be undefined if no workspace is active or query failed
		// openModal handles undefined by opening without a pre-selected project
		const projectId = activeWorkspace?.projectId;
		openModal(projectId);
	};

Alternatively or additionally, disable the button on error by changing the button's disabled attribute to disabled={isLoading || isError}.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function NewWorkspaceButton() {
const openModal = useOpenNewWorkspaceModal();
const { data: activeWorkspace, isLoading } =
trpc.workspaces.getActive.useQuery();
const handleClick = () => {
// projectId may be undefined if no workspace is active or query failed
// openModal handles undefined by opening without a pre-selected project
const projectId = activeWorkspace?.projectId;
openModal(projectId);
};
export function NewWorkspaceButton() {
const openModal = useOpenNewWorkspaceModal();
const { data: activeWorkspace, isLoading, isError, error } =
trpc.workspaces.getActive.useQuery();
if (isError) {
console.error('[NewWorkspaceButton/getActive]', error);
}
const handleClick = () => {
// projectId may be undefined if no workspace is active or query failed
// openModal handles undefined by opening without a pre-selected project
const projectId = activeWorkspace?.projectId;
openModal(projectId);
};
🤖 Prompt for AI Agents
In
@apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarHeader/NewWorkspaceButton.tsx
around lines 5-15, NewWorkspaceButton is not handling trpc.workspaces.getActive
errors: destructure isError and error from trpc.workspaces.getActive.useQuery()
in the NewWorkspaceButton component, log the error with context (e.g., "Failed
to load active workspace" plus the error) when isError is true, and update the
button's disabled prop to disabled={isLoading || isError} so the button is
disabled on query failures; keep passing activeWorkspace?.projectId to openModal
when not errored.


return (
<button
type="button"
onClick={handleClick}
disabled={isLoading}
className="flex items-center gap-2 px-2 py-1.5 text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-accent/50 rounded-md transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
<div className="flex items-center justify-center size-5 rounded bg-accent">
<LuPlus className="size-3" />
</div>
<span>New Workspace</span>
</button>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LuLayers } from "react-icons/lu";
import { NewWorkspaceButton } from "./NewWorkspaceButton";

export function WorkspaceSidebarHeader() {
return (
<div className="flex flex-col border-b border-border px-2 pt-2 pb-2">
<div className="flex items-center gap-2 px-2 py-1.5">
<div className="flex items-center justify-center size-5">
<LuLayers className="size-4 text-muted-foreground" />
</div>
<span className="text-sm font-medium text-muted-foreground">
Workspaces
</span>
</div>
<NewWorkspaceButton />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WorkspaceSidebarHeader } from "./WorkspaceSidebarHeader";
Loading