From e69e489af9db91afbef671422daac3820c8479b5 Mon Sep 17 00:00:00 2001 From: James Brunton Date: Tue, 19 Aug 2025 17:03:40 +0100 Subject: [PATCH] Enforce at least two files selected for merge --- .../src/components/tools/shared/FileStatusIndicator.tsx | 8 +++++--- frontend/src/components/tools/shared/FilesToolStep.tsx | 2 ++ frontend/src/components/tools/shared/createToolFlow.tsx | 2 ++ frontend/src/tools/Merge.tsx | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/tools/shared/FileStatusIndicator.tsx b/frontend/src/components/tools/shared/FileStatusIndicator.tsx index 22a25e627..3ea9b782d 100644 --- a/frontend/src/components/tools/shared/FileStatusIndicator.tsx +++ b/frontend/src/components/tools/shared/FileStatusIndicator.tsx @@ -5,17 +5,19 @@ import { useTranslation } from "react-i18next"; export interface FileStatusIndicatorProps { selectedFiles?: File[]; placeholder?: string; + minFiles?: number; } const FileStatusIndicator = ({ selectedFiles = [], placeholder, + minFiles = 1, }: FileStatusIndicatorProps) => { - const { t } = useTranslation(); +const { t } = useTranslation(); const defaultPlaceholder = placeholder || t("files.placeholder", "Select a PDF file in the main view to get started"); - + // Only show content when no files are selected - if (selectedFiles.length === 0) { + if (selectedFiles.length < minFiles) { return ( {defaultPlaceholder} diff --git a/frontend/src/components/tools/shared/FilesToolStep.tsx b/frontend/src/components/tools/shared/FilesToolStep.tsx index b062e9c02..8f7cebe0c 100644 --- a/frontend/src/components/tools/shared/FilesToolStep.tsx +++ b/frontend/src/components/tools/shared/FilesToolStep.tsx @@ -7,6 +7,7 @@ export interface FilesToolStepProps { isCollapsed?: boolean; onCollapsedClick?: () => void; placeholder?: string; + minFiles?: number; } export function createFilesToolStep( @@ -23,6 +24,7 @@ export function createFilesToolStep( )); } diff --git a/frontend/src/components/tools/shared/createToolFlow.tsx b/frontend/src/components/tools/shared/createToolFlow.tsx index ff6d2a6be..0c887be68 100644 --- a/frontend/src/components/tools/shared/createToolFlow.tsx +++ b/frontend/src/components/tools/shared/createToolFlow.tsx @@ -8,6 +8,7 @@ export interface FilesStepConfig { selectedFiles: File[]; isCollapsed?: boolean; placeholder?: string; + minFiles?: number; onCollapsedClick?: () => void; isVisible?: boolean; } @@ -68,6 +69,7 @@ export function createToolFlow(config: ToolFlowConfig) { selectedFiles: config.files.selectedFiles, isCollapsed: config.files.isCollapsed, placeholder: config.files.placeholder, + minFiles: config.files.minFiles, onCollapsedClick: config.files.onCollapsedClick })} diff --git a/frontend/src/tools/Merge.tsx b/frontend/src/tools/Merge.tsx index 45005627c..2c7927365 100644 --- a/frontend/src/tools/Merge.tsx +++ b/frontend/src/tools/Merge.tsx @@ -75,7 +75,8 @@ const Merge = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => { }) as any /* FIX ME: Parameter type is wrong on setSelectedFiles */); }, []); - const hasFiles = selectedFiles.length > 1; // Merge requires at least 2 files + const minFiles = 2; // Merging one file doesn't make sense + const hasFiles = selectedFiles.length >= minFiles; const hasResults = mergeOperation.files.length > 0 || mergeOperation.downloadUrl !== null; const settingsCollapsed = !hasFiles || hasResults; @@ -84,6 +85,7 @@ const Merge = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => { selectedFiles, isCollapsed: hasFiles && !hasResults, placeholder: "Select multiple PDF files to merge", + minFiles: minFiles, }, steps: [ {