Pull uncommitted work: new-task draft flow changes (worktree 4673f128)
Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
ad6c6c1a30
commit
9531885405
2 files changed
+67
-47
No files matched your search
@@ -66,28 +66,36 @@ export function NewTaskDraftScreen(props: {
|
||||
const { logicalProjects, selectedProject, setProject } = flow;
|
||||
const promptInputRef = useRef<ComposerEditorHandle>(null);
|
||||
const loadedBranchesProjectKeyRef = useRef<string | null>(null);
|
||||
const appliedInitialRefKeyRef = useRef<string | null>(null);
|
||||
|
||||
const borderColor = useThemeColor("--color-border");
|
||||
const sheetFadeOpaque = colorScheme === "dark" ? "rgba(14,14,14,0.98)" : "rgba(242,242,247,0.98)";
|
||||
const sheetFadeTransparent = colorScheme === "dark" ? "rgba(14,14,14,0)" : "rgba(242,242,247,0)";
|
||||
|
||||
useEffect(() => {
|
||||
if (props.initialProjectRef?.environmentId && props.initialProjectRef?.projectId) {
|
||||
const initialEnvironmentId = props.initialProjectRef?.environmentId;
|
||||
const initialProjectId = props.initialProjectRef?.projectId;
|
||||
if (initialEnvironmentId && initialProjectId) {
|
||||
const directProject =
|
||||
projects.find(
|
||||
(project) =>
|
||||
project.environmentId === props.initialProjectRef?.environmentId &&
|
||||
project.id === props.initialProjectRef?.projectId,
|
||||
project.environmentId === initialEnvironmentId && project.id === initialProjectId,
|
||||
) ?? null;
|
||||
|
||||
if (directProject) {
|
||||
if (
|
||||
selectedProject?.environmentId === directProject.environmentId &&
|
||||
selectedProject.id === directProject.id
|
||||
) {
|
||||
return;
|
||||
// Honor the route's project ref only once. Re-applying it on every
|
||||
// selection change would immediately revert a manual computer switch,
|
||||
// silently snapping back to the machine the draft was opened from.
|
||||
const initialKey = `${initialEnvironmentId}:${initialProjectId}`;
|
||||
if (appliedInitialRefKeyRef.current !== initialKey) {
|
||||
appliedInitialRefKeyRef.current = initialKey;
|
||||
if (
|
||||
selectedProject?.environmentId !== directProject.environmentId ||
|
||||
selectedProject.id !== directProject.id
|
||||
) {
|
||||
setProject(directProject);
|
||||
}
|
||||
}
|
||||
setProject(directProject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,40 +171,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
setExpandedProvider(null);
|
||||
}, []);
|
||||
|
||||
const environments = useMemo(
|
||||
() =>
|
||||
pipe(
|
||||
[
|
||||
...new Set(
|
||||
pipe(
|
||||
projects,
|
||||
Arr.map((project) => project.environmentId),
|
||||
),
|
||||
),
|
||||
],
|
||||
Arr.map((environmentId) => {
|
||||
const environment = savedConnectionsById[environmentId];
|
||||
if (!environment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
environmentId,
|
||||
environmentLabel: environment.environmentLabel,
|
||||
};
|
||||
}),
|
||||
Arr.filter(
|
||||
(
|
||||
entry,
|
||||
): entry is {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly environmentLabel: string;
|
||||
} => entry !== null,
|
||||
),
|
||||
),
|
||||
[projects, savedConnectionsById],
|
||||
);
|
||||
|
||||
const projectsForEnvironment = useMemo(
|
||||
() =>
|
||||
pipe(
|
||||
@@ -220,6 +186,40 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
) ??
|
||||
projectsForEnvironment[0] ??
|
||||
null;
|
||||
|
||||
// Only offer machines that actually host the currently selected repository, so
|
||||
// switching computers moves the same repo across machines instead of jumping to
|
||||
// whatever unrelated project happens to be first on the other machine.
|
||||
const selectedRepositoryKey = selectedProject?.repositoryIdentity?.canonicalKey ?? null;
|
||||
const environments = useMemo(() => {
|
||||
const seen = new Set<EnvironmentId>();
|
||||
const result: Array<{
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly environmentLabel: string;
|
||||
}> = [];
|
||||
for (const project of projects) {
|
||||
if (
|
||||
selectedRepositoryKey !== null &&
|
||||
(project.repositoryIdentity?.canonicalKey ?? null) !== selectedRepositoryKey
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (seen.has(project.environmentId)) {
|
||||
continue;
|
||||
}
|
||||
const environment = savedConnectionsById[project.environmentId];
|
||||
if (!environment) {
|
||||
continue;
|
||||
}
|
||||
seen.add(project.environmentId);
|
||||
result.push({
|
||||
environmentId: project.environmentId,
|
||||
environmentLabel: environment.environmentLabel,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}, [projects, savedConnectionsById, selectedRepositoryKey]);
|
||||
|
||||
const selectedEnvironmentServerConfig = useEnvironmentServerConfig(
|
||||
selectedProject?.environmentId ?? null,
|
||||
);
|
||||
@@ -384,10 +384,22 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
setSelectedProjectKey(nextProjectKey);
|
||||
}, []);
|
||||
|
||||
const selectEnvironment = useCallback((environmentId: EnvironmentId) => {
|
||||
setSelectedEnvironmentId(environmentId);
|
||||
setSelectedProjectKey(null);
|
||||
}, []);
|
||||
const selectEnvironment = useCallback(
|
||||
(environmentId: EnvironmentId) => {
|
||||
const repositoryKey = selectedProject?.repositoryIdentity?.canonicalKey ?? null;
|
||||
const match =
|
||||
repositoryKey === null
|
||||
? undefined
|
||||
: projects.find(
|
||||
(project) =>
|
||||
project.environmentId === environmentId &&
|
||||
(project.repositoryIdentity?.canonicalKey ?? null) === repositoryKey,
|
||||
);
|
||||
setSelectedEnvironmentId(environmentId);
|
||||
setSelectedProjectKey(match ? scopedProjectKey(match.environmentId, match.id) : null);
|
||||
},
|
||||
[projects, selectedProject?.repositoryIdentity?.canonicalKey],
|
||||
);
|
||||
|
||||
const setWorkspaceMode = useCallback(
|
||||
(mode: WorkspaceMode) => {
|
||||
|
||||
Reference in new issue
Block a user