Data-drive remaining simple tools

This commit is contained in:
James Brunton 2025-09-04 13:57:19 +01:00
parent 5be766121a
commit 6376189a63
9 changed files with 125 additions and 189 deletions

View File

@ -1,21 +0,0 @@
import { useTranslation } from 'react-i18next';
import { TooltipContent } from '../../types/tips';
export const useChangePermissionsTips = (): TooltipContent => {
const { t } = useTranslation();
return {
header: {
title: t("changePermissions.tooltip.header.title", "Change Permissions")
},
tips: [
{
description: t("changePermissions.tooltip.description.text", "Changes document permissions, allowing/disallowing access to different features in PDF readers.")
},
{
title: t("warning.tooltipTitle", "Warning"),
description: t("changePermissions.tooltip.warning.text", "To make these permissions unchangeable, use the Add Password tool to set an owner password.")
}
]
};
};

View File

@ -1,61 +1,12 @@
import { useTranslation } from "react-i18next"; import GenericTool from '../components/tools/shared/GenericTool';
import { createToolFlow } from "../components/tools/shared/createToolFlow"; import { changePermissionsDefinition } from './definitions/changePermissionsDefinition';
import ChangePermissionsSettings from "../components/tools/changePermissions/ChangePermissionsSettings"; import { BaseToolProps, ToolComponent } from '../types/tool';
import { useChangePermissionsParameters } from "../hooks/tools/changePermissions/useChangePermissionsParameters";
import { useChangePermissionsOperation } from "../hooks/tools/changePermissions/useChangePermissionsOperation";
import { useChangePermissionsTips } from "../components/tooltips/useChangePermissionsTips";
import { useBaseTool } from "../hooks/tools/shared/useBaseTool";
import { BaseToolProps, ToolComponent } from "../types/tool";
const ChangePermissions = (props: BaseToolProps) => { const ChangePermissions = (props: BaseToolProps) => {
const { t } = useTranslation(); return <GenericTool definition={changePermissionsDefinition} {...props} />;
const changePermissionsTips = useChangePermissionsTips();
const base = useBaseTool(
'changePermissions',
useChangePermissionsParameters,
useChangePermissionsOperation,
props
);
return createToolFlow({
files: {
selectedFiles: base.selectedFiles,
isCollapsed: base.hasResults,
},
steps: [
{
title: t("changePermissions.title", "Document Permissions"),
isCollapsed: base.settingsCollapsed,
onCollapsedClick: base.settingsCollapsed ? base.handleSettingsReset : undefined,
tooltip: changePermissionsTips,
content: (
<ChangePermissionsSettings
parameters={base.params.parameters}
onParameterChange={base.params.updateParameter}
disabled={base.endpointLoading}
/>
),
},
],
executeButton: {
text: t("changePermissions.submit", "Change Permissions"),
isVisible: !base.hasResults,
loadingText: t("loading"),
onClick: base.handleExecute,
disabled: !base.params.validateParameters() || !base.hasFiles || !base.endpointEnabled,
},
review: {
isVisible: base.hasResults,
operation: base.operation,
title: t("changePermissions.results.title", "Modified PDFs"),
onFileClick: base.handleThumbnailClick,
onUndo: base.handleUndo,
},
});
}; };
// Static method to get the operation hook for automation // Static method to get the operation hook for automation
ChangePermissions.tool = () => useChangePermissionsOperation; ChangePermissions.tool = () => changePermissionsDefinition.useOperation;
export default ChangePermissions as ToolComponent; export default ChangePermissions as ToolComponent;

View File

@ -1,45 +1,12 @@
import { useTranslation } from "react-i18next"; import GenericTool from '../components/tools/shared/GenericTool';
import { createToolFlow } from "../components/tools/shared/createToolFlow"; import { removeCertificateSignDefinition } from './definitions/removeCertificateSignDefinition';
import { useRemoveCertificateSignParameters } from "../hooks/tools/removeCertificateSign/useRemoveCertificateSignParameters"; import { BaseToolProps, ToolComponent } from '../types/tool';
import { useRemoveCertificateSignOperation } from "../hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation";
import { useBaseTool } from "../hooks/tools/shared/useBaseTool";
import { BaseToolProps, ToolComponent } from "../types/tool";
const RemoveCertificateSign = (props: BaseToolProps) => { const RemoveCertificateSign = (props: BaseToolProps) => {
const { t } = useTranslation(); return <GenericTool definition={removeCertificateSignDefinition} {...props} />;
const base = useBaseTool(
'removeCertificateSign',
useRemoveCertificateSignParameters,
useRemoveCertificateSignOperation,
props
);
return createToolFlow({
files: {
selectedFiles: base.selectedFiles,
isCollapsed: base.hasResults,
placeholder: t("removeCertSign.files.placeholder", "Select a PDF file in the main view to get started"),
},
steps: [],
executeButton: {
text: t("removeCertSign.submit", "Remove Signature"),
isVisible: !base.hasResults,
loadingText: t("loading"),
onClick: base.handleExecute,
disabled: !base.params.validateParameters() || !base.hasFiles || !base.endpointEnabled,
},
review: {
isVisible: base.hasResults,
operation: base.operation,
title: t("removeCertSign.results.title", "Certificate Removal Results"),
onFileClick: base.handleThumbnailClick,
onUndo: base.handleUndo,
},
});
}; };
// Static method to get the operation hook for automation // Static method to get the operation hook for automation
RemoveCertificateSign.tool = () => useRemoveCertificateSignOperation; RemoveCertificateSign.tool = () => removeCertificateSignDefinition.useOperation;
export default RemoveCertificateSign as ToolComponent; export default RemoveCertificateSign as ToolComponent;

View File

@ -1,45 +1,12 @@
import { useTranslation } from "react-i18next"; import GenericTool from '../components/tools/shared/GenericTool';
import { createToolFlow } from "../components/tools/shared/createToolFlow"; import { singleLargePageDefinition } from './definitions/singleLargePageDefinition';
import { useSingleLargePageParameters } from "../hooks/tools/singleLargePage/useSingleLargePageParameters"; import { BaseToolProps, ToolComponent } from '../types/tool';
import { useSingleLargePageOperation } from "../hooks/tools/singleLargePage/useSingleLargePageOperation";
import { useBaseTool } from "../hooks/tools/shared/useBaseTool";
import { BaseToolProps, ToolComponent } from "../types/tool";
const SingleLargePage = (props: BaseToolProps) => { const SingleLargePage = (props: BaseToolProps) => {
const { t } = useTranslation(); return <GenericTool definition={singleLargePageDefinition} {...props} />;
const base = useBaseTool(
'singleLargePage',
useSingleLargePageParameters,
useSingleLargePageOperation,
props
);
return createToolFlow({
files: {
selectedFiles: base.selectedFiles,
isCollapsed: base.hasResults,
placeholder: t("pdfToSinglePage.files.placeholder", "Select a PDF file in the main view to get started"),
},
steps: [],
executeButton: {
text: t("pdfToSinglePage.submit", "Convert To Single Page"),
isVisible: !base.hasResults,
loadingText: t("loading"),
onClick: base.handleExecute,
disabled: !base.params.validateParameters() || !base.hasFiles || !base.endpointEnabled,
},
review: {
isVisible: base.hasResults,
operation: base.operation,
title: t("pdfToSinglePage.results.title", "Single Page Results"),
onFileClick: base.handleThumbnailClick,
onUndo: base.handleUndo,
},
});
}; };
// Static method to get the operation hook for automation // Static method to get the operation hook for automation
SingleLargePage.tool = () => useSingleLargePageOperation; SingleLargePage.tool = () => singleLargePageDefinition.useOperation;
export default SingleLargePage as ToolComponent; export default SingleLargePage as ToolComponent;

View File

@ -1,45 +1,12 @@
import { useTranslation } from "react-i18next"; import GenericTool from '../components/tools/shared/GenericTool';
import { createToolFlow } from "../components/tools/shared/createToolFlow"; import { unlockPdfFormsDefinition } from './definitions/unlockPdfFormsDefinition';
import { useUnlockPdfFormsParameters } from "../hooks/tools/unlockPdfForms/useUnlockPdfFormsParameters"; import { BaseToolProps, ToolComponent } from '../types/tool';
import { useUnlockPdfFormsOperation } from "../hooks/tools/unlockPdfForms/useUnlockPdfFormsOperation";
import { useBaseTool } from "../hooks/tools/shared/useBaseTool";
import { BaseToolProps, ToolComponent } from "../types/tool";
const UnlockPdfForms = (props: BaseToolProps) => { const UnlockPdfForms = (props: BaseToolProps) => {
const { t } = useTranslation(); return <GenericTool definition={unlockPdfFormsDefinition} {...props} />;
const base = useBaseTool(
'unlockPdfForms',
useUnlockPdfFormsParameters,
useUnlockPdfFormsOperation,
props
);
return createToolFlow({
files: {
selectedFiles: base.selectedFiles,
isCollapsed: base.hasFiles || base.hasResults,
placeholder: t("unlockPDFForms.files.placeholder", "Select a PDF file in the main view to get started"),
},
steps: [],
executeButton: {
text: t("unlockPDFForms.submit", "Unlock Forms"),
isVisible: !base.hasResults,
loadingText: t("loading"),
onClick: base.handleExecute,
disabled: !base.params.validateParameters() || !base.hasFiles || !base.endpointEnabled,
},
review: {
isVisible: base.hasResults,
operation: base.operation,
title: t("unlockPDFForms.results.title", "Unlocked Forms Results"),
onFileClick: base.handleThumbnailClick,
onUndo: base.handleUndo,
},
});
}; };
// Static method to get the operation hook for automation // Static method to get the operation hook for automation
UnlockPdfForms.tool = () => useUnlockPdfFormsOperation; UnlockPdfForms.tool = () => unlockPdfFormsDefinition.useOperation;
export default UnlockPdfForms as ToolComponent; export default UnlockPdfForms as ToolComponent;

View File

@ -0,0 +1,42 @@
import { ToolDefinition } from '../../components/tools/shared/toolDefinition';
import { ChangePermissionsParameters, useChangePermissionsParameters } from '../../hooks/tools/changePermissions/useChangePermissionsParameters';
import { useChangePermissionsOperation } from '../../hooks/tools/changePermissions/useChangePermissionsOperation';
import ChangePermissionsSettings from '../../components/tools/changePermissions/ChangePermissionsSettings';
export const changePermissionsDefinition: ToolDefinition<ChangePermissionsParameters> = {
id: 'changePermissions',
useParameters: useChangePermissionsParameters,
useOperation: useChangePermissionsOperation,
steps: [
{
key: 'settings',
title: (t) => t("changePermissions.title", "Document Permissions"),
component: ChangePermissionsSettings,
tooltip: (t) => ({
header: {
title: t("changePermissions.tooltip.header.title", "Change Permissions")
},
tips: [
{
description: t("changePermissions.tooltip.description.text", "Changes document permissions, allowing/disallowing access to different features in PDF readers.")
},
{
title: t("warning.tooltipTitle", "Warning"),
description: t("changePermissions.tooltip.warning.text", "To make these permissions unchangeable, use the Add Password tool to set an owner password.")
}
]
}),
},
],
executeButton: {
text: (t) => t("changePermissions.submit", "Change Permissions"),
loadingText: (t) => t("loading"),
},
review: {
title: (t) => t("changePermissions.results.title", "Modified PDFs"),
},
};

View File

@ -0,0 +1,21 @@
import { ToolDefinition } from '../../components/tools/shared/toolDefinition';
import { RemoveCertificateSignParameters, useRemoveCertificateSignParameters } from '../../hooks/tools/removeCertificateSign/useRemoveCertificateSignParameters';
import { useRemoveCertificateSignOperation } from '../../hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation';
export const removeCertificateSignDefinition: ToolDefinition<RemoveCertificateSignParameters> = {
id: 'removeCertificateSign',
useParameters: useRemoveCertificateSignParameters,
useOperation: useRemoveCertificateSignOperation,
steps: [],
executeButton: {
text: (t) => t("removeCertSign.submit", "Remove Signature"),
loadingText: (t) => t("loading"),
},
review: {
title: (t) => t("removeCertSign.results.title", "Certificate Removal Results"),
},
};

View File

@ -0,0 +1,21 @@
import { ToolDefinition } from '../../components/tools/shared/toolDefinition';
import { SingleLargePageParameters, useSingleLargePageParameters } from '../../hooks/tools/singleLargePage/useSingleLargePageParameters';
import { useSingleLargePageOperation } from '../../hooks/tools/singleLargePage/useSingleLargePageOperation';
export const singleLargePageDefinition: ToolDefinition<SingleLargePageParameters> = {
id: 'singleLargePage',
useParameters: useSingleLargePageParameters,
useOperation: useSingleLargePageOperation,
steps: [],
executeButton: {
text: (t) => t("pdfToSinglePage.submit", "Convert To Single Page"),
loadingText: (t) => t("loading"),
},
review: {
title: (t) => t("pdfToSinglePage.results.title", "Single Page Results"),
},
};

View File

@ -0,0 +1,21 @@
import { ToolDefinition } from '../../components/tools/shared/toolDefinition';
import { UnlockPdfFormsParameters, useUnlockPdfFormsParameters } from '../../hooks/tools/unlockPdfForms/useUnlockPdfFormsParameters';
import { useUnlockPdfFormsOperation } from '../../hooks/tools/unlockPdfForms/useUnlockPdfFormsOperation';
export const unlockPdfFormsDefinition: ToolDefinition<UnlockPdfFormsParameters> = {
id: 'unlockPdfForms',
useParameters: useUnlockPdfFormsParameters,
useOperation: useUnlockPdfFormsOperation,
steps: [],
executeButton: {
text: (t) => t("unlockPDFForms.submit", "Unlock Forms"),
loadingText: (t) => t("loading"),
},
review: {
title: (t) => t("unlockPDFForms.results.title", "Unlocked Forms Results"),
},
};