Type errors

This commit is contained in:
Connor Yoh 2025-08-22 13:04:28 +01:00
parent ea7c8ee1c7
commit 577a866bf0
6 changed files with 62 additions and 31 deletions

View File

@ -38,7 +38,7 @@ export default function AutomationRun({ automation, onComplete, automateOperatio
id: `${op.operation}-${index}`, id: `${op.operation}-${index}`,
operation: op.operation, operation: op.operation,
name: tool?.name || op.operation, name: tool?.name || op.operation,
status: EXECUTION_STATUS.PENDING as const status: EXECUTION_STATUS.PENDING
}; };
}); });
setExecutionSteps(steps); setExecutionSteps(steps);
@ -69,7 +69,7 @@ export default function AutomationRun({ automation, onComplete, automateOperatio
// Reset progress tracking // Reset progress tracking
setCurrentStepIndex(0); setCurrentStepIndex(0);
setExecutionSteps(prev => prev.map(step => ({ ...step, status: EXECUTION_STATUS.PENDING as const, error: undefined }))); setExecutionSteps(prev => prev.map(step => ({ ...step, status: EXECUTION_STATUS.PENDING, error: undefined })));
try { try {
// Use the automateOperation.executeOperation to handle file consumption properly // Use the automateOperation.executeOperation to handle file consumption properly
@ -79,17 +79,17 @@ export default function AutomationRun({ automation, onComplete, automateOperatio
onStepStart: (stepIndex: number, operationName: string) => { onStepStart: (stepIndex: number, operationName: string) => {
setCurrentStepIndex(stepIndex); setCurrentStepIndex(stepIndex);
setExecutionSteps(prev => prev.map((step, idx) => setExecutionSteps(prev => prev.map((step, idx) =>
idx === stepIndex ? { ...step, status: EXECUTION_STATUS.RUNNING as const } : step idx === stepIndex ? { ...step, status: EXECUTION_STATUS.RUNNING } : step
)); ));
}, },
onStepComplete: (stepIndex: number, resultFiles: File[]) => { onStepComplete: (stepIndex: number, resultFiles: File[]) => {
setExecutionSteps(prev => prev.map((step, idx) => setExecutionSteps(prev => prev.map((step, idx) =>
idx === stepIndex ? { ...step, status: EXECUTION_STATUS.COMPLETED as const } : step idx === stepIndex ? { ...step, status: EXECUTION_STATUS.COMPLETED } : step
)); ));
}, },
onStepError: (stepIndex: number, error: string) => { onStepError: (stepIndex: number, error: string) => {
setExecutionSteps(prev => prev.map((step, idx) => setExecutionSteps(prev => prev.map((step, idx) =>
idx === stepIndex ? { ...step, status: EXECUTION_STATUS.ERROR as const, error } : step idx === stepIndex ? { ...step, status: EXECUTION_STATUS.ERROR, error } : step
)); ));
} }
}, },

View File

@ -64,7 +64,7 @@ export default function AutomationSelection({
<AutomationEntry <AutomationEntry
key={automation.id} key={automation.id}
badgeIcon={automation.icon} badgeIcon={automation.icon}
operations={automation.operations} operations={automation.operations.map(op => op.operation)}
onClick={() => onRun(automation)} onClick={() => onRun(automation)}
/> />
))} ))}

View File

@ -41,7 +41,7 @@ export function useAutomationForm({ mode, existingAutomation, toolRegistry }: Us
id: `${operation}-${Date.now()}-${index}`, id: `${operation}-${Date.now()}-${index}`,
operation: operation, operation: operation,
name: getToolName(operation), name: getToolName(operation),
configured: mode === AutomationMode.EDIT ? true : (typeof op === 'object' ? op.configured || false : false), configured: mode === AutomationMode.EDIT ? true : false,
parameters: typeof op === 'object' ? op.parameters || {} : {} parameters: typeof op === 'object' ? op.parameters || {} : {}
}; };
}); });

View File

@ -1,33 +1,53 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import StarIcon from '@mui/icons-material/Star'; import StarIcon from '@mui/icons-material/Star';
import { SuggestedAutomation } from '../../../types/automation';
export interface SuggestedAutomation {
id: string;
operations: string[];
icon: React.ComponentType<any>;
}
export function useSuggestedAutomations(): SuggestedAutomation[] { export function useSuggestedAutomations(): SuggestedAutomation[] {
const { t } = useTranslation(); const { t } = useTranslation();
const suggestedAutomations = useMemo<SuggestedAutomation[]>(() => [ const suggestedAutomations = useMemo<SuggestedAutomation[]>(() => {
{ const now = new Date().toISOString();
id: "compress-and-merge", return [
operations: ["compress", "merge"], {
icon: StarIcon, id: "compress-and-merge",
}, name: t("automation.suggested.compressAndMerge", "Compress & Merge"),
{ description: t("automation.suggested.compressAndMergeDesc", "Compress PDFs and merge them into one file"),
id: "ocr-and-convert", operations: [
operations: ["ocr", "convert"], { operation: "compress", parameters: {} },
icon: StarIcon, { operation: "merge", parameters: {} }
}, ],
{ createdAt: now,
id: "secure-workflow", updatedAt: now,
operations: ["sanitize", "addPassword", "changePermissions"], icon: StarIcon,
icon: StarIcon, },
}, {
], [t]); id: "ocr-and-convert",
name: t("automation.suggested.ocrAndConvert", "OCR & Convert"),
description: t("automation.suggested.ocrAndConvertDesc", "Extract text via OCR and convert to different format"),
operations: [
{ operation: "ocr", parameters: {} },
{ operation: "convert", parameters: {} }
],
createdAt: now,
updatedAt: now,
icon: StarIcon,
},
{
id: "secure-workflow",
name: t("automation.suggested.secureWorkflow", "Secure Workflow"),
description: t("automation.suggested.secureWorkflowDesc", "Sanitize, add password, and set permissions"),
operations: [
{ operation: "sanitize", parameters: {} },
{ operation: "addPassword", parameters: {} },
{ operation: "changePermissions", parameters: {} }
],
createdAt: now,
updatedAt: now,
icon: StarIcon,
},
];
}, [t]);
return suggestedAutomations; return suggestedAutomations;
} }

View File

@ -75,6 +75,10 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
); );
case 'creation': case 'creation':
if (!stepData.mode) {
console.error('Creation mode is undefined');
return null;
}
return ( return (
<AutomationCreation <AutomationCreation
mode={stepData.mode} mode={stepData.mode}
@ -89,6 +93,10 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
); );
case 'run': case 'run':
if (!stepData.automation) {
console.error('Automation config is undefined');
return null;
}
return ( return (
<AutomationRun <AutomationRun
automation={stepData.automation} automation={stepData.automation}

View File

@ -57,7 +57,10 @@ export enum AutomationMode {
export interface SuggestedAutomation { export interface SuggestedAutomation {
id: string; id: string;
name: string; name: string;
operations: string[]; description?: string;
operations: AutomationOperation[];
createdAt: string;
updatedAt: string;
icon: any; // MUI Icon component icon: any; // MUI Icon component
} }