Fix edit bug

This commit is contained in:
Connor Yoh 2025-08-25 13:08:28 +01:00
parent b63a283610
commit 4e3bf1251d
3 changed files with 14 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { AutomationTool, AutomationConfig, AutomationMode } from '../../../types/automation';
import { AUTOMATION_CONSTANTS } from '../../../constants/automation';
@ -16,18 +16,18 @@ export function useAutomationForm({ mode, existingAutomation, toolRegistry }: Us
const [automationName, setAutomationName] = useState('');
const [selectedTools, setSelectedTools] = useState<AutomationTool[]>([]);
const getToolName = (operation: string) => {
const getToolName = useCallback((operation: string) => {
const tool = toolRegistry?.[operation] as any;
return tool?.name || t(`tools.${operation}.name`, operation);
};
}, [toolRegistry, t]);
const getToolDefaultParameters = (operation: string): Record<string, any> => {
const getToolDefaultParameters = useCallback((operation: string): Record<string, any> => {
const config = toolRegistry[operation]?.operationConfig;
if (config?.defaultParameters) {
return { ...config.defaultParameters };
}
return {};
};
}, [toolRegistry]);
// Initialize based on mode and existing automation
useEffect(() => {
@ -58,7 +58,7 @@ export function useAutomationForm({ mode, existingAutomation, toolRegistry }: Us
}));
setSelectedTools(defaultTools);
}
}, [mode, existingAutomation, selectedTools.length, t, getToolName]);
}, [mode, existingAutomation, t, getToolName]);
const addTool = (operation: string) => {
const newTool: AutomationTool = {

View File

@ -13,14 +13,14 @@ import { useAutomateOperation } from "../hooks/tools/automate/useAutomateOperati
import { BaseToolProps } from "../types/tool";
import { useFlatToolRegistry } from "../data/useTranslatedToolRegistry";
import { useSavedAutomations } from "../hooks/tools/automate/useSavedAutomations";
import { AutomationConfig, AutomationStepData, AutomationMode } from "../types/automation";
import { AutomationConfig, AutomationStepData, AutomationMode, AutomationStep } from "../types/automation";
import { AUTOMATION_STEPS } from "../constants/automation";
const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
const { t } = useTranslation();
const { selectedFiles } = useFileSelection();
const [currentStep, setCurrentStep] = useState<'selection' | 'creation' | 'run'>(AUTOMATION_STEPS.SELECTION);
const [currentStep, setCurrentStep] = useState<AutomationStep>(AUTOMATION_STEPS.SELECTION);
const [stepData, setStepData] = useState<AutomationStepData>({ step: AUTOMATION_STEPS.SELECTION });
const automateOperation = useAutomateOperation();
@ -56,7 +56,7 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
const renderCurrentStep = () => {
switch (currentStep) {
case 'selection':
case AUTOMATION_STEPS.SELECTION:
return (
<AutomationSelection
savedAutomations={savedAutomations}
@ -74,7 +74,7 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
/>
);
case 'creation':
case AUTOMATION_STEPS.CREATION:
if (!stepData.mode) {
console.error('Creation mode is undefined');
return null;
@ -92,7 +92,7 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
/>
);
case 'run':
case AUTOMATION_STEPS.RUN:
if (!stepData.automation) {
console.error('Automation config is undefined');
return null;

View File

@ -24,8 +24,10 @@ export interface AutomationTool {
parameters?: Record<string, any>;
}
export type AutomationStep = typeof import('../constants/automation').AUTOMATION_STEPS[keyof typeof import('../constants/automation').AUTOMATION_STEPS];
export interface AutomationStepData {
step: 'selection' | 'creation' | 'run';
step: AutomationStep;
mode?: AutomationMode;
automation?: AutomationConfig;
}