refactor: unify tool-starting logic with shared useStartTool hook
- New useStartTool hook: calls working createInstance+startInstance API - WorkspacesPage: uses shared hook instead of inline createInstance logic - WorkspaceDetailPage ToolsTab: uses shared hook instead of broken createWorkspaceInstance - Both pages now use identical StartToolModal + identical start logic Quality gates: tsc --noEmit clean
This commit is contained in:
@@ -4,10 +4,10 @@ import { useState } from "react";
|
||||
import { Icon } from "../components/icon";
|
||||
import { useWorkspaces } from "../hooks/use-workspaces";
|
||||
import { useWorkspaceActions } from "../hooks/use-workspace-actions";
|
||||
import { useStartTool } from "../hooks/use-start-tool";
|
||||
import { WorkspaceCard } from "../components/workspace-card";
|
||||
import { WorkspaceCreateForm } from "../components/workspace-create-form";
|
||||
import { StartToolModal } from "../components/start-tool-modal";
|
||||
import { createInstance, startInstance } from "../api/sessions";
|
||||
import type { Workspace } from "../types/workspace";
|
||||
|
||||
export function WorkspacesPage() {
|
||||
@@ -16,6 +16,7 @@ export function WorkspacesPage() {
|
||||
|
||||
const { workspaces, loading, error, refresh } = useWorkspaces();
|
||||
const actions = useWorkspaceActions();
|
||||
const { startTool } = useStartTool();
|
||||
|
||||
const handleDelete = async (workspace: Workspace) => {
|
||||
await actions.delete(workspace, refresh);
|
||||
@@ -35,29 +36,15 @@ export function WorkspacesPage() {
|
||||
configProfileId?: string,
|
||||
) => {
|
||||
if (!startWorkspace) return;
|
||||
try {
|
||||
const instance = await createInstance(
|
||||
startWorkspace.project_id,
|
||||
startWorkspace.repo_id,
|
||||
toolTypeId,
|
||||
`${startWorkspace.name} - ${toolTypeId}`,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
configProfileId,
|
||||
[],
|
||||
startWorkspace.id,
|
||||
);
|
||||
await startInstance(
|
||||
startWorkspace.project_id,
|
||||
startWorkspace.repo_id,
|
||||
instance.id,
|
||||
configProfileId,
|
||||
);
|
||||
const instance = await startTool(
|
||||
startWorkspace,
|
||||
toolTypeId,
|
||||
undefined,
|
||||
configProfileId,
|
||||
);
|
||||
if (instance) {
|
||||
setStartWorkspace(null);
|
||||
await refresh();
|
||||
} catch (err) {
|
||||
alert(err instanceof Error ? err.message : "Failed to start tool");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user