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

@ -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);
@ -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>

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,
isCollapsed: currentStep !== 'selection',
onCollapsedClick: () => setCurrentStep('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')
} }