Restructure automate

This commit is contained in:
Connor Yoh 2025-08-20 18:47:34 +01:00
parent 775723f560
commit 50afa105ce
2 changed files with 48 additions and 47 deletions

View File

@ -1,11 +1,11 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { import {
Button, Button,
Text, Text,
Title, Title,
Stack, Stack,
Group, Group,
ActionIcon, ActionIcon,
Progress, Progress,
Card, Card,
@ -17,7 +17,7 @@ import CheckIcon from '@mui/icons-material/Check';
import ErrorIcon from '@mui/icons-material/Error'; import ErrorIcon from '@mui/icons-material/Error';
import { useFileContext } from '../../../contexts/FileContext'; import { useFileContext } from '../../../contexts/FileContext';
interface ToolSequenceProps { interface AutomationRunProps {
automation: any; automation: any;
onBack: () => void; onBack: () => void;
onComplete: () => void; onComplete: () => void;
@ -31,7 +31,7 @@ interface ExecutionStep {
error?: string; error?: string;
} }
export default function ToolSequence({ automation, onBack, onComplete }: ToolSequenceProps) { export default function AutomationRun({ automation, onBack, onComplete }: AutomationRunProps) {
const { t } = useTranslation(); const { t } = useTranslation();
const { activeFiles } = useFileContext(); const { activeFiles } = useFileContext();
const [isExecuting, setIsExecuting] = useState(false); const [isExecuting, setIsExecuting] = useState(false);
@ -63,28 +63,28 @@ export default function ToolSequence({ automation, onBack, onComplete }: ToolSeq
try { try {
for (let i = 0; i < executionSteps.length; i++) { for (let i = 0; i < executionSteps.length; i++) {
setCurrentStepIndex(i); setCurrentStepIndex(i);
// Update step status to running // Update step status to running
setExecutionSteps(prev => prev.map((step, idx) => setExecutionSteps(prev => prev.map((step, idx) =>
idx === i ? { ...step, status: 'running' } : step idx === i ? { ...step, status: 'running' } : step
)); ));
// Simulate step execution (replace with actual tool execution) // Simulate step execution (replace with actual tool execution)
await new Promise(resolve => setTimeout(resolve, 2000)); await new Promise(resolve => setTimeout(resolve, 2000));
// Update step status to completed // Update step status to completed
setExecutionSteps(prev => prev.map((step, idx) => setExecutionSteps(prev => prev.map((step, idx) =>
idx === i ? { ...step, status: 'completed' } : step idx === i ? { ...step, status: 'completed' } : step
)); ));
} }
setCurrentStepIndex(-1); setCurrentStepIndex(-1);
setIsExecuting(false); setIsExecuting(false);
// All steps completed - show success // All steps completed - show success
} catch (error) { } catch (error) {
// Handle error // Handle error
setExecutionSteps(prev => prev.map((step, idx) => setExecutionSteps(prev => prev.map((step, idx) =>
idx === currentStepIndex ? { ...step, status: 'error', error: error?.toString() } : step idx === currentStepIndex ? { ...step, status: 'error', error: error?.toString() } : step
)); ));
setIsExecuting(false); setIsExecuting(false);
@ -114,15 +114,6 @@ export default function ToolSequence({ automation, onBack, onComplete }: ToolSeq
return ( return (
<div> <div>
<Group justify="space-between" align="center" mb="md">
<Title order={3} size="h4" fw={600} style={{ color: 'var(--mantine-color-text)' }}>
{t('automate.sequence.title', 'Tool Sequence')}
</Title>
<ActionIcon variant="subtle" onClick={onBack}>
<ArrowBackIcon />
</ActionIcon>
</Group>
<Stack gap="md"> <Stack gap="md">
{/* Automation Info */} {/* Automation Info */}
<Card padding="md" withBorder> <Card padding="md" withBorder>
@ -145,9 +136,9 @@ export default function ToolSequence({ automation, onBack, onComplete }: ToolSeq
{isExecuting && ( {isExecuting && (
<div> <div>
<Text size="sm" mb="xs"> <Text size="sm" mb="xs">
{t('automate.sequence.progress', 'Progress: {{current}}/{{total}}', { {t('automate.sequence.progress', 'Progress: {{current}}/{{total}}', {
current: currentStepIndex + 1, current: currentStepIndex + 1,
total: executionSteps.length total: executionSteps.length
})} })}
</Text> </Text>
<Progress value={getProgress()} size="lg" /> <Progress value={getProgress()} size="lg" />
@ -161,11 +152,11 @@ export default function ToolSequence({ automation, onBack, onComplete }: ToolSeq
<Text size="xs" c="dimmed" style={{ minWidth: '1rem', textAlign: 'center' }}> <Text size="xs" c="dimmed" style={{ minWidth: '1rem', textAlign: 'center' }}>
{index + 1} {index + 1}
</Text> </Text>
{getStepIcon(step)} {getStepIcon(step)}
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<Text size="sm" style={{ <Text size="sm" style={{
color: step.status === 'running' ? 'var(--mantine-color-blue-6)' : 'var(--mantine-color-text)', color: step.status === 'running' ? 'var(--mantine-color-blue-6)' : 'var(--mantine-color-text)',
fontWeight: step.status === 'running' ? 500 : 400 fontWeight: step.status === 'running' ? 500 : 400
}}> }}>
@ -189,8 +180,8 @@ export default function ToolSequence({ automation, onBack, onComplete }: ToolSeq
disabled={isExecuting || !activeFiles || activeFiles.length === 0} disabled={isExecuting || !activeFiles || activeFiles.length === 0}
loading={isExecuting} loading={isExecuting}
> >
{isExecuting {isExecuting
? t('automate.sequence.running', 'Running Automation...') ? t('automate.sequence.running', 'Running Automation...')
: t('automate.sequence.run', 'Run Automation') : t('automate.sequence.run', 'Run Automation')
} }
</Button> </Button>
@ -216,4 +207,4 @@ export default function ToolSequence({ automation, onBack, onComplete }: ToolSeq
</style> </style>
</div> </div>
); );
} }

View File

@ -6,7 +6,7 @@ import { useToolFileSelection } from "../contexts/FileSelectionContext";
import { createToolFlow } from "../components/tools/shared/createToolFlow"; import { createToolFlow } from "../components/tools/shared/createToolFlow";
import AutomationSelection from "../components/tools/automate/AutomationSelection"; import AutomationSelection from "../components/tools/automate/AutomationSelection";
import AutomationCreation, { AutomationMode } from "../components/tools/automate/AutomationCreation"; import AutomationCreation, { AutomationMode } from "../components/tools/automate/AutomationCreation";
import ToolSequence from "../components/tools/automate/ToolSequence"; import AutomationRun from "../components/tools/automate/AutomationRun";
import { useAutomateOperation } from "../hooks/tools/automate/useAutomateOperation"; import { useAutomateOperation } from "../hooks/tools/automate/useAutomateOperation";
import { BaseToolProps } from "../types/tool"; import { BaseToolProps } from "../types/tool";
@ -18,11 +18,12 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
const { setCurrentMode } = useFileContext(); const { setCurrentMode } = useFileContext();
const { selectedFiles } = useToolFileSelection(); const { selectedFiles } = useToolFileSelection();
const [currentStep, setCurrentStep] = useState<'selection' | 'creation' | 'sequence'>('selection'); const [currentStep, setCurrentStep] = useState<'selection' | 'creation' | 'run'>('selection');
const [stepData, setStepData] = useState<any>({}); const [stepData, setStepData] = useState<any>({});
const automateOperation = useAutomateOperation(); const automateOperation = useAutomateOperation();
const toolRegistry = useFlatToolRegistry(); const toolRegistry = useFlatToolRegistry();
const hasResults = automateOperation.files.length > 0 || automateOperation.downloadUrl !== null;
const { savedAutomations, deleteAutomation } = useSavedAutomations(); const { savedAutomations, deleteAutomation } = useSavedAutomations();
const handleStepChange = (data: any) => { const handleStepChange = (data: any) => {
@ -44,7 +45,7 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
<AutomationSelection <AutomationSelection
savedAutomations={savedAutomations} savedAutomations={savedAutomations}
onCreateNew={() => handleStepChange({ step: 'creation', mode: AutomationMode.CREATE })} onCreateNew={() => handleStepChange({ step: 'creation', mode: AutomationMode.CREATE })}
onRun={(automation: any) => handleStepChange({ step: 'sequence', automation })} onRun={(automation: any) => handleStepChange({ step: 'run', automation })}
onEdit={(automation: any) => handleStepChange({ step: 'creation', mode: AutomationMode.EDIT, automation })} onEdit={(automation: any) => handleStepChange({ step: 'creation', mode: AutomationMode.EDIT, automation })}
onDelete={async (automation: any) => { onDelete={async (automation: any) => {
try { try {
@ -63,16 +64,16 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
mode={stepData.mode} mode={stepData.mode}
existingAutomation={stepData.automation} existingAutomation={stepData.automation}
onBack={() => handleStepChange({ step: 'selection' })} onBack={() => handleStepChange({ step: 'selection' })}
onComplete={(automation: any) => handleStepChange({ step: 'sequence', automation })} onComplete={() => handleStepChange({ step: 'selection' })}
toolRegistry={toolRegistry} toolRegistry={toolRegistry}
/> />
); );
case 'sequence': case 'run':
return ( return (
<ToolSequence <AutomationRun
automation={stepData.automation} automation={stepData.automation}
onBack={() => handleStepChange({ step: 'creation', mode: stepData.mode, automation: stepData.automation })} onBack={() => handleStepChange({ step: 'selection'})}
onComplete={handleComplete} onComplete={handleComplete}
/> />
); );
@ -85,24 +86,33 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
return createToolFlow({ return createToolFlow({
files: { files: {
selectedFiles: [], selectedFiles: [],
isCollapsed: true, // Hide files step for automate tool isCollapsed: hasResults, // Hide files step for automate tool
placeholder: t('automate.filesHidden', 'Files will be selected during automation execution')
}, },
steps: [ steps: [
{ {
title: t('automate.stepTitle', 'Automations'), title: t('automate.selection.title', 'Automation Selection'),
isVisible: true, isVisible: true,
onCollapsedClick: ()=> setCurrentStep('selection'), isCollapsed: currentStep !== 'selection',
onCollapsedClick: () => setCurrentStep('selection'),
content: currentStep === 'selection' ? renderCurrentStep() : null content: currentStep === 'selection' ? renderCurrentStep() : null
}, },
{ {
title: t('automate.sequenceTitle', 'Tool Sequence'), title: stepData.mode === AutomationMode.EDIT
isVisible: currentStep === 'creation' || currentStep === 'sequence', ? t('automate.creation.editTitle', 'Edit Automation')
content: currentStep === 'creation' || currentStep === 'sequence' ? renderCurrentStep() : null : t('automate.creation.createTitle', 'Create Automation'),
isVisible: currentStep === 'creation',
isCollapsed: false,
content: currentStep === 'creation' ? renderCurrentStep() : null
},
{
title: t('automate.run.title', 'Run Automation'),
isVisible: currentStep === 'run',
isCollapsed: false,
content: currentStep === 'run' ? renderCurrentStep() : null
} }
], ],
review: { review: {
isVisible: false, // Hide review step for automate tool isVisible: hasResults, // Hide review step for automate tool
operation: automateOperation, operation: automateOperation,
title: t('automate.reviewTitle', 'Automation Results') title: t('automate.reviewTitle', 'Automation Results')
} }