Skip to content
Merged
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 @@ -27,7 +27,6 @@ import {
SelectValue,
} from "@superset/ui/select";
import { toast } from "@superset/ui/sonner";
import debounce from "lodash/debounce";
import { useEffect, useMemo, useRef, useState } from "react";
import { GoGitBranch } from "react-icons/go";
import { HiCheck, HiChevronDown, HiChevronUpDown } from "react-icons/hi2";
Expand Down Expand Up @@ -63,8 +62,6 @@ export function NewWorkspaceModal() {
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(
null,
);
// Use local title for immediate input feedback, debounce updates to derived state
const [localTitle, setLocalTitle] = useState("");
const [title, setTitle] = useState("");
const [branchName, setBranchName] = useState("");
const [branchNameEdited, setBranchNameEdited] = useState(false);
Expand All @@ -75,25 +72,6 @@ export function NewWorkspaceModal() {
const [showAdvanced, setShowAdvanced] = useState(false);
const titleInputRef = useRef<HTMLInputElement>(null);

// Debounced title update to reduce re-renders from derived state calculations
const debouncedSetTitle = useMemo(
() => debounce((value: string) => setTitle(value), 150),
[],
);

// Cleanup debounced function on unmount
useEffect(() => {
return () => {
debouncedSetTitle.cancel();
};
}, [debouncedSetTitle]);

const handleTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setLocalTitle(value); // Immediate update for responsive typing
debouncedSetTitle(value); // Debounced update for derived state
};

const { data: recentProjects = [] } =
electronTrpc.projects.getRecents.useQuery();
const {
Expand Down Expand Up @@ -141,7 +119,6 @@ export function NewWorkspaceModal() {

const resetForm = () => {
setSelectedProjectId(null);
setLocalTitle("");
setTitle("");
setBranchName("");
setBranchNameEdited(false);
Expand Down Expand Up @@ -188,8 +165,7 @@ export function NewWorkspaceModal() {
const handleCreateWorkspace = async () => {
if (!selectedProjectId) return;

// Use localTitle for the actual value (in case debounce hasn't fired yet)
const workspaceName = localTitle.trim() || undefined;
const workspaceName = title.trim() || undefined;
const customBranchName = branchName.trim() || undefined;

try {
Expand Down Expand Up @@ -285,15 +261,15 @@ export function NewWorkspaceModal() {
id="title"
className="h-9 text-sm"
placeholder="Feature name (press Enter to create)"
value={localTitle}
onChange={handleTitleChange}
value={title}
onChange={(e) => setTitle(e.target.value)}
/>

{localTitle && !showAdvanced && (
{title && !showAdvanced && (
<p className="text-xs text-muted-foreground flex items-center gap-1.5">
<GoGitBranch className="size-3" />
<span className="font-mono">
{branchName || generateBranchFromTitle(localTitle)}
{branchName || generateBranchFromTitle(title)}
</span>
<span className="text-muted-foreground/60">
from {effectiveBaseBranch}
Expand Down Expand Up @@ -323,8 +299,8 @@ export function NewWorkspaceModal() {
id="branch"
className="h-8 text-sm font-mono"
placeholder={
localTitle
? generateBranchFromTitle(localTitle)
title
? generateBranchFromTitle(title)
: "auto-generated"
}
value={branchName}
Expand Down
Loading