mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 06:09:23 +00:00
Fix edit bug
This commit is contained in:
parent
b63a283610
commit
4e3bf1251d
@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { AutomationTool, AutomationConfig, AutomationMode } from '../../../types/automation';
|
import { AutomationTool, AutomationConfig, AutomationMode } from '../../../types/automation';
|
||||||
import { AUTOMATION_CONSTANTS } from '../../../constants/automation';
|
import { AUTOMATION_CONSTANTS } from '../../../constants/automation';
|
||||||
@ -16,18 +16,18 @@ export function useAutomationForm({ mode, existingAutomation, toolRegistry }: Us
|
|||||||
const [automationName, setAutomationName] = useState('');
|
const [automationName, setAutomationName] = useState('');
|
||||||
const [selectedTools, setSelectedTools] = useState<AutomationTool[]>([]);
|
const [selectedTools, setSelectedTools] = useState<AutomationTool[]>([]);
|
||||||
|
|
||||||
const getToolName = (operation: string) => {
|
const getToolName = useCallback((operation: string) => {
|
||||||
const tool = toolRegistry?.[operation] as any;
|
const tool = toolRegistry?.[operation] as any;
|
||||||
return tool?.name || t(`tools.${operation}.name`, operation);
|
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;
|
const config = toolRegistry[operation]?.operationConfig;
|
||||||
if (config?.defaultParameters) {
|
if (config?.defaultParameters) {
|
||||||
return { ...config.defaultParameters };
|
return { ...config.defaultParameters };
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
};
|
}, [toolRegistry]);
|
||||||
|
|
||||||
// Initialize based on mode and existing automation
|
// Initialize based on mode and existing automation
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -58,7 +58,7 @@ export function useAutomationForm({ mode, existingAutomation, toolRegistry }: Us
|
|||||||
}));
|
}));
|
||||||
setSelectedTools(defaultTools);
|
setSelectedTools(defaultTools);
|
||||||
}
|
}
|
||||||
}, [mode, existingAutomation, selectedTools.length, t, getToolName]);
|
}, [mode, existingAutomation, t, getToolName]);
|
||||||
|
|
||||||
const addTool = (operation: string) => {
|
const addTool = (operation: string) => {
|
||||||
const newTool: AutomationTool = {
|
const newTool: AutomationTool = {
|
||||||
|
@ -13,14 +13,14 @@ import { useAutomateOperation } from "../hooks/tools/automate/useAutomateOperati
|
|||||||
import { BaseToolProps } from "../types/tool";
|
import { BaseToolProps } from "../types/tool";
|
||||||
import { useFlatToolRegistry } from "../data/useTranslatedToolRegistry";
|
import { useFlatToolRegistry } from "../data/useTranslatedToolRegistry";
|
||||||
import { useSavedAutomations } from "../hooks/tools/automate/useSavedAutomations";
|
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";
|
import { AUTOMATION_STEPS } from "../constants/automation";
|
||||||
|
|
||||||
const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { selectedFiles } = useFileSelection();
|
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 [stepData, setStepData] = useState<AutomationStepData>({ step: AUTOMATION_STEPS.SELECTION });
|
||||||
|
|
||||||
const automateOperation = useAutomateOperation();
|
const automateOperation = useAutomateOperation();
|
||||||
@ -56,7 +56,7 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|||||||
|
|
||||||
const renderCurrentStep = () => {
|
const renderCurrentStep = () => {
|
||||||
switch (currentStep) {
|
switch (currentStep) {
|
||||||
case 'selection':
|
case AUTOMATION_STEPS.SELECTION:
|
||||||
return (
|
return (
|
||||||
<AutomationSelection
|
<AutomationSelection
|
||||||
savedAutomations={savedAutomations}
|
savedAutomations={savedAutomations}
|
||||||
@ -74,7 +74,7 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
case 'creation':
|
case AUTOMATION_STEPS.CREATION:
|
||||||
if (!stepData.mode) {
|
if (!stepData.mode) {
|
||||||
console.error('Creation mode is undefined');
|
console.error('Creation mode is undefined');
|
||||||
return null;
|
return null;
|
||||||
@ -92,7 +92,7 @@ const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
case 'run':
|
case AUTOMATION_STEPS.RUN:
|
||||||
if (!stepData.automation) {
|
if (!stepData.automation) {
|
||||||
console.error('Automation config is undefined');
|
console.error('Automation config is undefined');
|
||||||
return null;
|
return null;
|
||||||
|
@ -24,8 +24,10 @@ export interface AutomationTool {
|
|||||||
parameters?: Record<string, any>;
|
parameters?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type AutomationStep = typeof import('../constants/automation').AUTOMATION_STEPS[keyof typeof import('../constants/automation').AUTOMATION_STEPS];
|
||||||
|
|
||||||
export interface AutomationStepData {
|
export interface AutomationStepData {
|
||||||
step: 'selection' | 'creation' | 'run';
|
step: AutomationStep;
|
||||||
mode?: AutomationMode;
|
mode?: AutomationMode;
|
||||||
automation?: AutomationConfig;
|
automation?: AutomationConfig;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user