Skip to content
Open
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 @@ -241,6 +241,7 @@ export function EnvironmentRow({
const createThreadInEnvironment = useCreateThreadInEnvironment({
projectId: thread.projectId,
environmentId: environment?.id ?? "",
sectionId: thread.sectionId,
});
const { providers } = useSystemEnvironmentProviders();
const { providers: machineProviders } = useSystemMachineProviders();
Expand Down
1 change: 1 addition & 0 deletions apps/app/src/components/sidebar/ProjectRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ const EnvironmentThreadGroupRow = memo(function EnvironmentThreadGroupRow({
const createThreadInEnvironment = useCreateThreadInEnvironment({
projectId,
environmentId,
sectionId: representativeThread.sectionId,
});
const threads = useMemo(() => nodes.map((node) => node.thread), [nodes]);
const { archiveThreadsPending, onArchiveThreads } =
Expand Down
35 changes: 22 additions & 13 deletions apps/app/src/hooks/useCreateThreadInEnvironment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import {
hasSingleUseRootComposeTargetState,
readRootComposeSectionTargetFromLocationState,
shouldStartComposingFromLocationState,
} from "@/views/RootComposeView";
import { useCreateThreadInEnvironment } from "./useCreateThreadInEnvironment";
Expand All @@ -19,19 +20,27 @@ vi.mock("@/lib/root-compose-selection", () => ({
}));

describe("useCreateThreadInEnvironment", () => {
it("navigates with state that opens the composer and seeds the environment", () => {
navigate.mockClear();
const { result } = renderHook(() =>
useCreateThreadInEnvironment({
projectId: "proj_personal",
environmentId: "env_1",
}),
);
it.each(["sec_a", null])(
"opens the composer in the source environment and section %s",
(sectionId) => {
navigate.mockClear();
const { result } = renderHook(() =>
useCreateThreadInEnvironment({
projectId: "proj_personal",
environmentId: "env_1",
sectionId,
}),
);

result.current();
result.current();

const state = navigate.mock.calls[0][1].state;
expect(shouldStartComposingFromLocationState(state)).toBe(true);
expect(hasSingleUseRootComposeTargetState(state)).toBe(true);
});
const state = navigate.mock.calls[0][1].state;
expect(state.reuseEnvironmentId).toBe("env_1");
expect(readRootComposeSectionTargetFromLocationState(state)).toEqual(
sectionId ? { kind: "set", sectionId } : { kind: "clear" },
);
expect(shouldStartComposingFromLocationState(state)).toBe(true);
expect(hasSingleUseRootComposeTargetState(state)).toBe(true);
},
);
});
10 changes: 8 additions & 2 deletions apps/app/src/hooks/useCreateThreadInEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ import { useSetRootComposeProjectId } from "@/lib/root-compose-selection";
interface UseCreateThreadInEnvironmentArgs {
projectId: string;
environmentId: string;
sectionId: string | null;
}

export function useCreateThreadInEnvironment({
projectId,
environmentId,
sectionId,
}: UseCreateThreadInEnvironmentArgs): () => void {
const navigate = useRouteNavigate();
const setRootComposeProjectId = useSetRootComposeProjectId();
return useCallback(() => {
setRootComposeProjectId(projectId);
navigate(getRootComposeRoutePath(), {
state: { focusPrompt: true, reuseEnvironmentId: environmentId },
state: {
focusPrompt: true,
reuseEnvironmentId: environmentId,
sectionId,
},
});
}, [environmentId, navigate, projectId, setRootComposeProjectId]);
}, [environmentId, navigate, projectId, sectionId, setRootComposeProjectId]);
}
1 change: 1 addition & 0 deletions apps/app/src/views/thread-detail/ThreadDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ function ThreadDetailViewInternal(props: ThreadRoutePathArgs) {
const createThreadInEnvironment = useCreateThreadInEnvironment({
projectId,
environmentId: thread?.environmentId ?? "",
sectionId: thread?.sectionId ?? null,
});
const { providers: registeredEnvironmentProviders } =
useSystemEnvironmentProviders();
Expand Down
Loading