UNPKG

gensx

Version:
106 lines 8.55 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Text, useApp } from "ink"; import { useEffect, useState } from "react"; import { ErrorMessage } from "../../components/ErrorMessage.js"; import { LoadingSpinner } from "../../components/LoadingSpinner.js"; import { useProjectName } from "../../hooks/useProjectName.js"; import { listEnvironments } from "../../models/environment.js"; import { listWorkflows } from "../../models/workflows.js"; import { getAuth } from "../../utils/config.js"; import { getSelectedEnvironment } from "../../utils/env-config.js"; function useShowProject(initialProjectName) { const { exit } = useApp(); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [selectedEnvironment, setSelectedEnvironment] = useState(null); const [environments, setEnvironments] = useState([]); const [workflows, setWorkflows] = useState([]); const { loading: projectLoading, error: projectError, projectName, } = useProjectName(initialProjectName); useEffect(() => { let mounted = true; async function showProjectFlow() { if (!projectName) return; try { // Check authentication first const authConfig = await getAuth(); if (!authConfig) { throw new Error("Not authenticated. Please run 'gensx login' first."); } // Fetch both selected environment and all environments const [selectedEnv, envs] = await Promise.all([ getSelectedEnvironment(projectName), listEnvironments(projectName), ]); if (mounted) { setSelectedEnvironment(selectedEnv); setEnvironments(envs); // If there's a selected environment, fetch workflows for it if (selectedEnv) { try { const workflowList = await listWorkflows(projectName, selectedEnv); setWorkflows(workflowList); } catch (workflowError) { // If workflow fetching fails, just set empty array but don't error the whole component console.warn("Failed to fetch workflows:", workflowError); setWorkflows([]); } } setLoading(false); } } catch (err) { if (mounted) { const error = err instanceof Error ? err : new Error(String(err)); setError(error); setLoading(false); setTimeout(() => { exit(); }, 100); } } } void showProjectFlow(); return () => { mounted = false; }; }, [projectName, exit]); return { loading: loading || projectLoading, error: error ?? projectError, projectName, selectedEnvironment, environments, workflows, }; } export function ShowProjectUI({ projectName: initialProjectName }) { const { loading, error, projectName, selectedEnvironment, environments, workflows, } = useShowProject(initialProjectName); if (error) { return _jsx(ErrorMessage, { message: error.message }); } if (loading || !projectName) { return _jsx(LoadingSpinner, {}); } return (_jsxs(Box, { flexDirection: "column", gap: 1, children: [_jsx(Box, { children: _jsxs(Text, { children: [_jsx(Text, { color: "blue", children: "\u2139\uFE0E" }), " Project:", " ", _jsx(Text, { bold: true, color: "cyan", children: projectName })] }) }), _jsxs(Box, { flexDirection: "column", gap: 0, paddingTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "white", children: "Environments" }), _jsxs(Text, { color: "gray", children: [" (", environments.length, ")"] })] }), environments.length > 0 ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "gray", children: "─".repeat(54) }), _jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { bold: true, children: [_jsx(Text, { color: "cyan", children: "NAME".padEnd(20) }), _jsx(Text, { color: "cyan", children: "SELECTED".padEnd(12) }), _jsx(Text, { color: "cyan", children: "UPDATED AT" })] }) }), _jsx(Text, { color: "gray", children: "─".repeat(54) }), _jsx(Box, { flexDirection: "column", children: environments.map((env) => (_jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { children: [_jsx(Text, { color: "green", children: env.name.padEnd(20) }), _jsx(Text, { color: env.name === selectedEnvironment ? "green" : "gray", children: (env.name === selectedEnvironment ? "✓" : "").padEnd(12) }), _jsx(Text, { dimColor: true, children: new Date(env.updatedAt) .toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: true, }) .replace(/,/, "") })] }) }, env.id))) }), _jsx(Text, { color: "gray", children: "─".repeat(54) })] })) : (_jsxs(Box, { paddingLeft: 1, children: [_jsx(Text, { dimColor: true, children: "No environments found" }), _jsxs(Text, { color: "gray", dimColor: true, children: ["\u203A Run", " ", _jsx(Text, { color: "yellow", children: "gensx env create <env-name>" }), " to create your first environment."] })] }))] }), selectedEnvironment && workflows.length > 0 && (_jsxs(Box, { flexDirection: "column", gap: 0, paddingTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "white", children: "Workflows in" }), _jsxs(Text, { color: "cyan", children: [" ", selectedEnvironment] }), _jsxs(Text, { color: "gray", children: [" (", workflows.length, ")"] })] }), _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "gray", children: "─".repeat(54) }), _jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { bold: true, children: [_jsx(Text, { color: "cyan", children: "NAME".padEnd(32) }), _jsx(Text, { color: "cyan", children: "UPDATED AT" })] }) }), _jsx(Text, { color: "gray", children: "─".repeat(54) }), _jsx(Box, { flexDirection: "column", children: workflows.map((workflow) => (_jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { children: [_jsx(Text, { color: "green", children: workflow.name.padEnd(32) }), _jsx(Text, { dimColor: true, children: new Date(workflow.updatedAt) .toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: true, }) .replace(/,/, "") })] }) }, workflow.id))) }), _jsx(Text, { color: "gray", children: "─".repeat(54) })] })] })), selectedEnvironment && workflows.length === 0 && (_jsxs(Box, { paddingTop: 1, gap: 1, flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { children: "No workflows found in" }), " ", _jsx(Text, { color: "cyan", children: selectedEnvironment }), _jsx(Text, { children: " environment." })] }), _jsxs(Text, { color: "gray", dimColor: true, children: ["\u203A Deploy a workflow with", " ", _jsx(Text, { color: "yellow", children: "gensx deploy <workflow-file>" })] })] })), environments.length > 0 && !selectedEnvironment && (_jsx(Box, { paddingTop: 1, children: _jsxs(Text, { color: "gray", dimColor: true, children: ["\u203A Run ", _jsx(Text, { color: "yellow", children: "gensx env select <env-name>" }), " ", "to activate an environment."] }) }))] })); } //# sourceMappingURL=show.js.map