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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface PromptGroupAdvancedOptionsProps {
onSelectBaseBranch: (branchName: string) => void;
runSetupScript: boolean;
onRunSetupScriptChange: (checked: boolean) => void;
hideSetupScript?: boolean;
}

export function PromptGroupAdvancedOptions({
Expand All @@ -69,6 +70,7 @@ export function PromptGroupAdvancedOptions({
onSelectBaseBranch,
runSetupScript,
onRunSetupScriptChange,
hideSetupScript,
}: PromptGroupAdvancedOptionsProps) {
return (
<Collapsible open={showAdvanced} onOpenChange={onShowAdvancedChange}>
Expand Down Expand Up @@ -184,19 +186,21 @@ export function PromptGroupAdvancedOptions({
)}
</div>

<div className="flex items-center justify-between">
<Label
htmlFor="run-setup-script"
className="text-xs text-muted-foreground"
>
Run setup script
</Label>
<Switch
id="run-setup-script"
checked={runSetupScript}
onCheckedChange={onRunSetupScriptChange}
/>
</div>
{!hideSetupScript && (
<div className="flex items-center justify-between">
<Label
htmlFor="run-setup-script"
className="text-xs text-muted-foreground"
>
Run setup script
</Label>
<Switch
id="run-setup-script"
checked={runSetupScript}
onCheckedChange={onRunSetupScriptChange}
/>
</div>
)}
</CollapsibleContent>
</Collapsible>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@superset/ui/dialog";
import {
useCloseNewWorkspaceModal,
useNewWorkspaceModalOpen,
usePreSelectedProjectId,
} from "renderer/stores/new-workspace-modal";
import { V2NewWorkspaceModalContent } from "./components/V2NewWorkspaceModalContent";
import { V2NewWorkspaceModalDraftProvider } from "./V2NewWorkspaceModalDraftContext";

export function V2NewWorkspaceModal() {
const isOpen = useNewWorkspaceModalOpen();
const closeModal = useCloseNewWorkspaceModal();
const preSelectedProjectId = usePreSelectedProjectId();

return (
<V2NewWorkspaceModalDraftProvider onClose={closeModal}>
<Dialog open={isOpen} onOpenChange={(open) => !open && closeModal()}>
Comment on lines +22 to +23
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 | 🟠 Major

Manual dismiss should reset the modal draft.

V2NewWorkspaceModalDraftProvider only clears state through closeAndResetDraft() or runAsyncAction() in V2NewWorkspaceModalDraftContext.tsx. Here backdrop clicks and Esc only call the store's closeModal, so reopening the modal reuses the previous project/query/prompt instead of starting fresh.

Proposed fix
 import { V2NewWorkspaceModalContent } from "./components/V2NewWorkspaceModalContent";
-import { V2NewWorkspaceModalDraftProvider } from "./V2NewWorkspaceModalDraftContext";
+import {
+	useV2NewWorkspaceModalDraft,
+	V2NewWorkspaceModalDraftProvider,
+} from "./V2NewWorkspaceModalDraftContext";

 export function V2NewWorkspaceModal() {
 	const isOpen = useNewWorkspaceModalOpen();
 	const closeModal = useCloseNewWorkspaceModal();
 	const preSelectedProjectId = usePreSelectedProjectId();

 	return (
 		<V2NewWorkspaceModalDraftProvider onClose={closeModal}>
-			<Dialog open={isOpen} onOpenChange={(open) => !open && closeModal()}>
-				<DialogHeader className="sr-only">
-					<DialogTitle>New Workspace</DialogTitle>
-					<DialogDescription>
-						Create a new workspace from a PR, branch, issue, or prompt.
-					</DialogDescription>
-				</DialogHeader>
-				<DialogContent
-					showCloseButton={false}
-					className="bg-popover text-popover-foreground sm:max-w-[560px] max-h-[min(70vh,600px)] !top-[calc(50%-min(35vh,300px))] !-translate-y-0 flex flex-col overflow-hidden p-0"
-				>
-					<V2NewWorkspaceModalContent
-						isOpen={isOpen}
-						preSelectedProjectId={preSelectedProjectId}
-					/>
-				</DialogContent>
-			</Dialog>
+			<V2NewWorkspaceModalDialog
+				isOpen={isOpen}
+				preSelectedProjectId={preSelectedProjectId}
+			/>
 		</V2NewWorkspaceModalDraftProvider>
 	);
 }
+
+function V2NewWorkspaceModalDialog({
+	isOpen,
+	preSelectedProjectId,
+}: {
+	isOpen: boolean;
+	preSelectedProjectId: string | null;
+}) {
+	const { closeAndResetDraft } = useV2NewWorkspaceModalDraft();
+
+	return (
+		<Dialog
+			open={isOpen}
+			onOpenChange={(open) => !open && closeAndResetDraft()}
+		>
+			<DialogHeader className="sr-only">
+				<DialogTitle>New Workspace</DialogTitle>
+				<DialogDescription>
+					Create a new workspace from a PR, branch, issue, or prompt.
+				</DialogDescription>
+			</DialogHeader>
+			<DialogContent
+				showCloseButton={false}
+				className="bg-popover text-popover-foreground sm:max-w-[560px] max-h-[min(70vh,600px)] !top-[calc(50%-min(35vh,300px))] !-translate-y-0 flex flex-col overflow-hidden p-0"
+			>
+				<V2NewWorkspaceModalContent
+					isOpen={isOpen}
+					preSelectedProjectId={preSelectedProjectId}
+				/>
+			</DialogContent>
+		</Dialog>
+	);
+}
📝 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
<V2NewWorkspaceModalDraftProvider onClose={closeModal}>
<Dialog open={isOpen} onOpenChange={(open) => !open && closeModal()}>
import { V2NewWorkspaceModalContent } from "./components/V2NewWorkspaceModalContent";
import {
useV2NewWorkspaceModalDraft,
V2NewWorkspaceModalDraftProvider,
} from "./V2NewWorkspaceModalDraftContext";
export function V2NewWorkspaceModal() {
const isOpen = useNewWorkspaceModalOpen();
const closeModal = useCloseNewWorkspaceModal();
const preSelectedProjectId = usePreSelectedProjectId();
return (
<V2NewWorkspaceModalDraftProvider onClose={closeModal}>
<V2NewWorkspaceModalDialog
isOpen={isOpen}
preSelectedProjectId={preSelectedProjectId}
/>
</V2NewWorkspaceModalDraftProvider>
);
}
function V2NewWorkspaceModalDialog({
isOpen,
preSelectedProjectId,
}: {
isOpen: boolean;
preSelectedProjectId: string | null;
}) {
const { closeAndResetDraft } = useV2NewWorkspaceModalDraft();
return (
<Dialog
open={isOpen}
onOpenChange={(open) => !open && closeAndResetDraft()}
>
<DialogHeader className="sr-only">
<DialogTitle>New Workspace</DialogTitle>
<DialogDescription>
Create a new workspace from a PR, branch, issue, or prompt.
</DialogDescription>
</DialogHeader>
<DialogContent
showCloseButton={false}
className="bg-popover text-popover-foreground sm:max-w-[560px] max-h-[min(70vh,600px)] !top-[calc(50%-min(35vh,300px))] !-translate-y-0 flex flex-col overflow-hidden p-0"
>
<V2NewWorkspaceModalContent
isOpen={isOpen}
preSelectedProjectId={preSelectedProjectId}
/>
</DialogContent>
</Dialog>
);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/desktop/src/renderer/components/V2NewWorkspaceModal/V2NewWorkspaceModal.tsx`
around lines 22 - 23, The modal is being closed via the Dialog onOpenChange
(backdrop/Esc) which only calls closeModal, so the
V2NewWorkspaceModalDraftProvider’s draft state isn't reset; update the
onOpenChange handler inside V2NewWorkspaceModal (the Dialog line) to call the
draft provider's reset API (e.g., closeAndResetDraft() or runAsyncAction()
exposed from V2NewWorkspaceModalDraftContext) when open becomes false, or call
both closeModal() and closeAndResetDraft() so manual dismisses clear the draft
stored by V2NewWorkspaceModalDraftProvider.

<DialogHeader className="sr-only">
<DialogTitle>New Workspace</DialogTitle>
<DialogDescription>
Create a new workspace from a PR, branch, issue, or prompt.
</DialogDescription>
</DialogHeader>
<DialogContent
showCloseButton={false}
className="bg-popover text-popover-foreground sm:max-w-[560px] max-h-[min(70vh,600px)] !top-[calc(50%-min(35vh,300px))] !-translate-y-0 flex flex-col overflow-hidden p-0"
>
<V2NewWorkspaceModalContent
isOpen={isOpen}
preSelectedProjectId={preSelectedProjectId}
/>
</DialogContent>
</Dialog>
</V2NewWorkspaceModalDraftProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { toast } from "@superset/ui/sonner";
import {
createContext,
type PropsWithChildren,
useCallback,
useContext,
useMemo,
useState,
} from "react";

export type V2NewWorkspaceModalTab =
| "prompt"
| "issues"
| "pull-requests"
| "branches";

export interface V2NewWorkspaceModalDraft {
activeTab: V2NewWorkspaceModalTab;
selectedProjectId: string | null;
selectedDeviceId: string | null;
prompt: string;
branchName: string;
branchNameEdited: boolean;
baseBranch: string | null;
showAdvanced: boolean;
branchSearch: string;
issuesQuery: string;
pullRequestsQuery: string;
branchesQuery: string;
}

interface V2NewWorkspaceModalDraftState extends V2NewWorkspaceModalDraft {
draftVersion: number;
}

const initialDraft: V2NewWorkspaceModalDraft = {
activeTab: "prompt",
selectedProjectId: null,
selectedDeviceId: null,
prompt: "",
branchName: "",
branchNameEdited: false,
baseBranch: null,
showAdvanced: false,
branchSearch: "",
issuesQuery: "",
pullRequestsQuery: "",
branchesQuery: "",
};

function buildInitialDraftState(): V2NewWorkspaceModalDraftState {
return {
...initialDraft,
draftVersion: 0,
};
}

interface V2NewWorkspaceModalActionMessages {
loading: string;
success: string;
error: (err: unknown) => string;
}

interface V2NewWorkspaceModalDraftContextValue {
draft: V2NewWorkspaceModalDraft;
draftVersion: number;
closeModal: () => void;
closeAndResetDraft: () => void;
runAsyncAction: <T>(
promise: Promise<T>,
messages: V2NewWorkspaceModalActionMessages,
) => Promise<T>;
updateDraft: (patch: Partial<V2NewWorkspaceModalDraft>) => void;
resetDraft: () => void;
resetDraftIfVersion: (draftVersion: number) => void;
}

const V2NewWorkspaceModalDraftContext =
createContext<V2NewWorkspaceModalDraftContextValue | null>(null);

export function V2NewWorkspaceModalDraftProvider({
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Mar 12, 2026

Choose a reason for hiding this comment

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

P2: Extract shared draft-context behavior instead of duplicating this provider logic; keeping two near-identical implementations will make fixes/features drift between legacy and V2 modal flows.

(Based on your team's feedback about avoiding duplicated business logic across components.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/components/V2NewWorkspaceModal/V2NewWorkspaceModalDraftContext.tsx, line 81:

<comment>Extract shared draft-context behavior instead of duplicating this provider logic; keeping two near-identical implementations will make fixes/features drift between legacy and V2 modal flows.

(Based on your team's feedback about avoiding duplicated business logic across components.) </comment>

<file context>
@@ -0,0 +1,190 @@
+const V2NewWorkspaceModalDraftContext =
+	createContext<V2NewWorkspaceModalDraftContextValue | null>(null);
+
+export function V2NewWorkspaceModalDraftProvider({
+	children,
+	onClose,
</file context>
Fix with Cubic

children,
onClose,
}: PropsWithChildren<{ onClose: () => void }>) {
const [state, setState] = useState(buildInitialDraftState);

const updateDraft = useCallback(
(patch: Partial<V2NewWorkspaceModalDraft>) => {
setState((state) => ({
...state,
...patch,
draftVersion: state.draftVersion + 1,
}));
},
[],
);

const resetDraft = useCallback(() => {
setState((state) => ({
...initialDraft,
draftVersion: state.draftVersion + 1,
}));
}, []);

const resetDraftIfVersion = useCallback((draftVersion: number) => {
setState((state) =>
state.draftVersion !== draftVersion
? state
: {
...initialDraft,
draftVersion: state.draftVersion + 1,
},
);
}, []);

const closeAndResetDraft = useCallback(() => {
resetDraft();
onClose();
}, [onClose, resetDraft]);

const runAsyncAction = useCallback(
<T,>(promise: Promise<T>, messages: V2NewWorkspaceModalActionMessages) => {
const submitDraftVersion = state.draftVersion;
onClose();
toast.promise(promise, {
loading: messages.loading,
success: messages.success,
error: (err) => messages.error(err),
});
void promise
.then(() => {
resetDraftIfVersion(submitDraftVersion);
})
.catch(() => undefined);
return promise;
},
[onClose, resetDraftIfVersion, state.draftVersion],
);

const value = useMemo<V2NewWorkspaceModalDraftContextValue>(
() => ({
draft: {
activeTab: state.activeTab,
selectedProjectId: state.selectedProjectId,
selectedDeviceId: state.selectedDeviceId,
prompt: state.prompt,
branchName: state.branchName,
branchNameEdited: state.branchNameEdited,
baseBranch: state.baseBranch,
showAdvanced: state.showAdvanced,
branchSearch: state.branchSearch,
issuesQuery: state.issuesQuery,
pullRequestsQuery: state.pullRequestsQuery,
branchesQuery: state.branchesQuery,
},
draftVersion: state.draftVersion,
closeModal: onClose,
closeAndResetDraft,
runAsyncAction,
updateDraft,
resetDraft,
resetDraftIfVersion,
}),
[
closeAndResetDraft,
onClose,
resetDraft,
resetDraftIfVersion,
runAsyncAction,
state,
updateDraft,
],
);

return (
<V2NewWorkspaceModalDraftContext.Provider value={value}>
{children}
</V2NewWorkspaceModalDraftContext.Provider>
);
}

export function useV2NewWorkspaceModalDraft() {
const context = useContext(V2NewWorkspaceModalDraftContext);
if (!context) {
throw new Error(
"useV2NewWorkspaceModalDraft must be used within V2NewWorkspaceModalDraftProvider",
);
}
return context;
}
Loading
Loading