merge headache

This commit is contained in:
Connor Yoh 2025-08-21 19:12:12 +01:00
parent 14f6cf76e2
commit b2822c1d43
8 changed files with 96 additions and 88 deletions

View File

@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
import { Button, Text, Stack, Group, Card, Progress } from "@mantine/core";
import PlayArrowIcon from "@mui/icons-material/PlayArrow";
import CheckIcon from "@mui/icons-material/Check";
import { useFileSelection } from "../../../contexts/FileSelectionContext";
import { useFileSelection } from "../../../contexts/FileContext";
import { useFlatToolRegistry } from "../../../data/useTranslatedToolRegistry";
interface AutomationRunProps {

View File

@ -1,15 +1,22 @@
import React from 'react';
import React, { useCallback } from 'react';
import { Stack, Text, Divider, Card, Group } from '@mantine/core';
import { useTranslation } from 'react-i18next';
import { useSuggestedTools } from '../../../hooks/useSuggestedTools';
import { useToolNavigation } from '../../../contexts/ToolNavigationContext';
import { useNavigationActions, useNavigationState, type ModeType } from '../../../contexts/NavigationContext';
export interface SuggestedToolsSectionProps {}
export function SuggestedToolsSection(): React.ReactElement {
const { t } = useTranslation();
const { handleToolSelect, selectedToolKey } = useToolNavigation();
const suggestedTools = useSuggestedTools(selectedToolKey, handleToolSelect);
const { actions } = useNavigationActions();
const { currentMode } = useNavigationState();
// Create handleToolSelect function that navigates to the tool
const handleToolSelect = useCallback((toolId: string) => {
actions.setMode(toolId as ModeType);
}, [actions]);
const suggestedTools = useSuggestedTools(currentMode, handleToolSelect);
return (
<Stack gap="md">

View File

@ -1,85 +1,85 @@
/**
* ToolNavigationContext - Handles tool selection and navigation without tool registry
* This breaks the circular dependency by not importing the tool registry
*/
// /**
// * ToolNavigationContext - Handles tool selection and navigation without tool registry
// * This breaks the circular dependency by not importing the tool registry
// */
import React, { createContext, useContext, useState, useCallback } from 'react';
import { useFileContext } from './FileContext';
// import React, { createContext, useContext, useState, useCallback } from 'react';
// import { useFileContext } from './FileContext';
// Navigation state interface
interface ToolNavigationState {
selectedToolKey: string | null;
}
// // Navigation state interface
// interface ToolNavigationState {
// selectedToolKey: string | null;
// }
// Context value interface
interface ToolNavigationContextValue extends ToolNavigationState {
// Navigation Actions
selectTool: (toolKey: string) => void;
clearToolSelection: () => void;
handleToolSelect: (toolId: string) => void;
}
// // Context value interface
// interface ToolNavigationContextValue extends ToolNavigationState {
// // Navigation Actions
// selectTool: (toolKey: string) => void;
// clearToolSelection: () => void;
// handleToolSelect: (toolId: string) => void;
// }
const ToolNavigationContext = createContext<ToolNavigationContextValue | undefined>(undefined);
// const ToolNavigationContext = createContext<ToolNavigationContextValue | undefined>(undefined);
// Provider component
interface ToolNavigationProviderProps {
children: React.ReactNode;
}
// // Provider component
// interface ToolNavigationProviderProps {
// children: React.ReactNode;
// }
export function ToolNavigationProvider({ children }: ToolNavigationProviderProps) {
const [selectedToolKey, setSelectedToolKey] = useState<string | null>(null);
const { setCurrentView } = useFileContext();
// export function ToolNavigationProvider({ children }: ToolNavigationProviderProps) {
// const [selectedToolKey, setSelectedToolKey] = useState<string | null>(null);
// const { setCurrentView } = useFileContext();
const selectTool = useCallback((toolKey: string) => {
setSelectedToolKey(toolKey);
}, []);
// const selectTool = useCallback((toolKey: string) => {
// setSelectedToolKey(toolKey);
// }, []);
const clearToolSelection = useCallback(() => {
setSelectedToolKey(null);
}, []);
// const clearToolSelection = useCallback(() => {
// setSelectedToolKey(null);
// }, []);
const handleToolSelect = useCallback((toolId: string) => {
// Handle special cases
if (toolId === 'allTools') {
clearToolSelection();
return;
}
// const handleToolSelect = useCallback((toolId: string) => {
// // Handle special cases
// if (toolId === 'allTools') {
// clearToolSelection();
// return;
// }
selectTool(toolId);
setCurrentView('fileEditor');
}, [selectTool, setCurrentView, clearToolSelection]);
// selectTool(toolId);
// setCurrentView('fileEditor');
// }, [selectTool, setCurrentView, clearToolSelection]);
const contextValue: ToolNavigationContextValue = {
selectedToolKey,
selectTool,
clearToolSelection,
handleToolSelect
};
// const contextValue: ToolNavigationContextValue = {
// selectedToolKey,
// selectTool,
// clearToolSelection,
// handleToolSelect
// };
return (
<ToolNavigationContext.Provider value={contextValue}>
{children}
</ToolNavigationContext.Provider>
);
}
// return (
// <ToolNavigationContext.Provider value={contextValue}>
// {children}
// </ToolNavigationContext.Provider>
// );
// }
// Custom hook to use the context
export function useToolNavigation(): ToolNavigationContextValue {
const context = useContext(ToolNavigationContext);
if (!context) {
// During development hot reload, temporarily return a safe fallback
if (process.env.NODE_ENV === 'development') {
console.warn('ToolNavigationContext temporarily unavailable during hot reload, using fallback');
// // Custom hook to use the context
// export function useToolNavigation(): ToolNavigationContextValue {
// const context = useContext(ToolNavigationContext);
// if (!context) {
// // During development hot reload, temporarily return a safe fallback
// if (process.env.NODE_ENV === 'development') {
// console.warn('ToolNavigationContext temporarily unavailable during hot reload, using fallback');
return {
selectedToolKey: null,
selectTool: () => {},
clearToolSelection: () => {},
handleToolSelect: () => {}
} as ToolNavigationContextValue;
}
// return {
// selectedToolKey: null,
// selectTool: () => {},
// clearToolSelection: () => {},
// handleToolSelect: () => {}
// } as ToolNavigationContextValue;
// }
throw new Error('useToolNavigation must be used within a ToolNavigationProvider');
}
return context;
}
// throw new Error('useToolNavigation must be used within a ToolNavigationProvider');
// }
// return context;
// }

View File

@ -26,7 +26,7 @@ import { ToolOperationConfig, ToolOperationHook, useToolOperation } from '../sha
describe('useAddPasswordOperation', () => {
const mockUseToolOperation = vi.mocked(useToolOperation);
const getToolConfig = (): ToolOperationConfig<AddPasswordFullParameters> => mockUseToolOperation.mock.calls[0][0];
const getToolConfig = (): ToolOperationConfig<AddPasswordFullParameters> => mockUseToolOperation.mock.calls[0][0] as ToolOperationConfig<AddPasswordFullParameters>;
const mockToolOperationReturn: ToolOperationHook<unknown> = {
files: [],

View File

@ -25,7 +25,7 @@ import { ToolOperationConfig, ToolOperationHook, useToolOperation } from '../sha
describe('useChangePermissionsOperation', () => {
const mockUseToolOperation = vi.mocked(useToolOperation);
const getToolConfig = (): ToolOperationConfig<ChangePermissionsParameters> => mockUseToolOperation.mock.calls[0][0];
const getToolConfig = (): ToolOperationConfig<ChangePermissionsParameters> => mockUseToolOperation.mock.calls[0][0] as ToolOperationConfig<ChangePermissionsParameters>;
const mockToolOperationReturn: ToolOperationHook<unknown> = {
files: [],

View File

@ -53,7 +53,7 @@ export const buildOCRFormData = (parameters: OCRParameters, file: File): FormDat
};
// Static response handler for OCR - can be used by automation executor
export const ocrResponseHandler = async (blob: Blob, originalFiles: File[], extractZipFiles: (blob: Blob) => Promise<{ success: boolean; extractedFiles: File[]; errors: string[] }>): Promise<File[]> => {
export const ocrResponseHandler = async (blob: Blob, originalFiles: File[], extractZipFiles: (blob: Blob) => Promise<File[]>): Promise<File[]> => {
const headBuf = await blob.slice(0, 8).arrayBuffer();
const head = new TextDecoder().decode(new Uint8Array(headBuf));
@ -61,8 +61,8 @@ export const ocrResponseHandler = async (blob: Blob, originalFiles: File[], extr
if (head.startsWith('PK')) {
const base = stripExt(originalFiles[0].name);
try {
const result = await extractZipFiles(blob);
if (result.success && result.extractedFiles.length > 0) return result.extractedFiles;
const extractedFiles = await extractZipFiles(blob);
if (extractedFiles.length > 0) return extractedFiles;
} catch { /* ignore and try local extractor */ }
try {
const local = await extractZipFile(blob); // local fallback
@ -108,7 +108,9 @@ export const useOCROperation = () => {
// OCR-specific parsing: ZIP (sidecar) vs PDF vs HTML error
const responseHandler = useCallback(async (blob: Blob, originalFiles: File[]): Promise<File[]> => {
return ocrResponseHandler(blob, originalFiles, extractZipFiles);
// extractZipFiles from useToolResources already returns File[] directly
const simpleExtractZipFiles = extractZipFiles;
return ocrResponseHandler(blob, originalFiles, simpleExtractZipFiles);
}, [extractZipFiles]);
const ocrConfig: ToolOperationConfig<OCRParameters> = {

View File

@ -25,7 +25,7 @@ import { ToolOperationConfig, ToolOperationHook, useToolOperation } from '../sha
describe('useRemovePasswordOperation', () => {
const mockUseToolOperation = vi.mocked(useToolOperation);
const getToolConfig = (): ToolOperationConfig<RemovePasswordParameters> => mockUseToolOperation.mock.calls[0][0];
const getToolConfig = (): ToolOperationConfig<RemovePasswordParameters> => mockUseToolOperation.mock.calls[0][0] as ToolOperationConfig<RemovePasswordParameters>;
const mockToolOperationReturn: ToolOperationHook<unknown> = {
files: [],

View File

@ -1,7 +1,7 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { useFileContext } from "../contexts/FileContext";
import { useToolFileSelection } from "../contexts/FileSelectionContext";
import { useFileSelection } from "../contexts/FileContext";
import { createToolFlow } from "../components/tools/shared/createToolFlow";
import { createFilesToolStep } from "../components/tools/shared/FilesToolStep";
@ -16,8 +16,7 @@ import { useSavedAutomations } from "../hooks/tools/automate/useSavedAutomations
const Automate = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
const { t } = useTranslation();
const { setCurrentMode } = useFileContext();
const { selectedFiles } = useToolFileSelection();
const { selectedFiles } = useFileSelection();
const [currentStep, setCurrentStep] = useState<'selection' | 'creation' | 'run'>('selection');
const [stepData, setStepData] = useState<any>({});