# Description of Changes Note on tooltips: I'll do more PRs on tooltips, however this has priority, hence I submitted this for now. #### Before: <img width="758" height="721" alt="image" src="https://github.com/user-attachments/assets/ce3166d2-c681-447e-82df-68fe6d18669d" /> <img width="782" height="485" alt="image" src="https://github.com/user-attachments/assets/48970a4c-9911-4ade-9346-c33c5a6a319f" /> <img width="782" height="602" alt="image" src="https://github.com/user-attachments/assets/9f77648d-4d1a-4e4b-93af-eaab6db849ff" /> <img width="782" height="602" alt="image" src="https://github.com/user-attachments/assets/ae653534-bf04-47a0-8aab-0bb5b9c3ecef" /> #### After: <img width="758" height="721" alt="image" src="https://github.com/user-attachments/assets/8d45e876-a0df-4fe3-89a8-5184492db204" /> <img width="782" height="602" alt="image" src="https://github.com/user-attachments/assets/550ee105-1286-4072-9f55-46255b3fbe80" /> <img width="782" height="602" alt="image" src="https://github.com/user-attachments/assets/fba7ea93-73fe-4529-84fe-c37816375a9e" /> <img width="782" height="602" alt="image" src="https://github.com/user-attachments/assets/ca452e77-b58b-4a5b-8e97-e6ccef4cf500" /> <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [X] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [X] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [X] I have performed a self-review of my own code - [X] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [X] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import { useEffect } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useFileSelection } from "@app/contexts/FileContext";
|
|
import { createToolFlow } from "@app/components/tools/shared/createToolFlow";
|
|
import { BaseToolProps, ToolComponent } from "@app/types/tool";
|
|
import { useEndpointEnabled } from "@app/hooks/useEndpointConfig";
|
|
import { useAddAttachmentsParameters } from "@app/hooks/tools/addAttachments/useAddAttachmentsParameters";
|
|
import { useAddAttachmentsOperation } from "@app/hooks/tools/addAttachments/useAddAttachmentsOperation";
|
|
import { useAccordionSteps } from "@app/hooks/tools/shared/useAccordionSteps";
|
|
import AddAttachmentsSettings from "@app/components/tools/addAttachments/AddAttachmentsSettings";
|
|
import { useAddAttachmentsTips } from "@app/components/tooltips/useAddAttachmentsTips";
|
|
|
|
const AddAttachments = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|
const { t } = useTranslation();
|
|
const { selectedFiles } = useFileSelection();
|
|
const addAttachmentsTips = useAddAttachmentsTips();
|
|
|
|
const params = useAddAttachmentsParameters();
|
|
const operation = useAddAttachmentsOperation();
|
|
|
|
const { enabled: endpointEnabled, loading: endpointLoading } = useEndpointEnabled("add-attachments");
|
|
|
|
useEffect(() => {
|
|
operation.resetResults();
|
|
onPreviewFile?.(null);
|
|
}, [params.parameters]);
|
|
|
|
const handleExecute = async () => {
|
|
try {
|
|
await operation.executeOperation(params.parameters, selectedFiles);
|
|
if (operation.files && onComplete) {
|
|
onComplete(operation.files);
|
|
}
|
|
} catch (error: any) {
|
|
onError?.(error?.message || t("AddAttachmentsRequest.error.failed", "Add attachments operation failed"));
|
|
}
|
|
};
|
|
|
|
const hasFiles = selectedFiles.length > 0;
|
|
const hasResults = operation.files.length > 0 || operation.downloadUrl !== null;
|
|
|
|
enum AddAttachmentsStep {
|
|
NONE = 'none',
|
|
ATTACHMENTS = 'attachments'
|
|
}
|
|
|
|
const accordion = useAccordionSteps<AddAttachmentsStep>({
|
|
noneValue: AddAttachmentsStep.NONE,
|
|
initialStep: AddAttachmentsStep.ATTACHMENTS,
|
|
stateConditions: {
|
|
hasFiles,
|
|
hasResults: false // Don't collapse when there are results for add attachments
|
|
},
|
|
afterResults: () => {
|
|
operation.resetResults();
|
|
onPreviewFile?.(null);
|
|
}
|
|
});
|
|
|
|
const getSteps = () => {
|
|
const steps: any[] = [];
|
|
|
|
// Step 1: Attachments Selection
|
|
steps.push({
|
|
title: t("AddAttachmentsRequest.attachments", "Select Attachments"),
|
|
isCollapsed: accordion.getCollapsedState(AddAttachmentsStep.ATTACHMENTS),
|
|
onCollapsedClick: () => accordion.handleStepToggle(AddAttachmentsStep.ATTACHMENTS),
|
|
isVisible: true,
|
|
tooltip: addAttachmentsTips,
|
|
content: (
|
|
<AddAttachmentsSettings
|
|
parameters={params.parameters}
|
|
onParameterChange={params.updateParameter}
|
|
disabled={endpointLoading}
|
|
/>
|
|
),
|
|
});
|
|
|
|
return steps;
|
|
};
|
|
|
|
return createToolFlow({
|
|
files: {
|
|
selectedFiles,
|
|
isCollapsed: hasResults,
|
|
},
|
|
steps: getSteps(),
|
|
executeButton: {
|
|
text: t('AddAttachmentsRequest.submit', 'Add Attachments'),
|
|
isVisible: !hasResults,
|
|
loadingText: t('loading'),
|
|
onClick: handleExecute,
|
|
disabled: !params.validateParameters() || !hasFiles || !endpointEnabled,
|
|
},
|
|
review: {
|
|
isVisible: hasResults,
|
|
operation: operation,
|
|
title: t('AddAttachmentsRequest.results.title', 'Attachment Results'),
|
|
onFileClick: (file) => onPreviewFile?.(file),
|
|
onUndo: async () => {
|
|
await operation.undoOperation();
|
|
onPreviewFile?.(null);
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
AddAttachments.tool = () => useAddAttachmentsOperation;
|
|
|
|
export default AddAttachments as ToolComponent;
|