James Brunton 8eeb4c148c
Add Sanitize UI (#4123)
# Description of Changes

Implementation of Sanitize UI for V2.

Also removes parameter validation from standard tool hooks because the
logic would have to be duplicated between parameter handling and
operation hooks, and the nicer workflow is for the tools to reject using
the Go button if the validation fails, rather than the operation hook
checking it, since that can't appear in the UI.

Co-authored-by: James <james@crosscourtanalytics.com>
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
Co-authored-by: ConnorYoh <40631091+ConnorYoh@users.noreply.github.com>
2025-08-12 16:05:59 +01:00

52 lines
1.7 KiB
TypeScript

import { Stack, Text, Checkbox } from "@mantine/core";
import { useTranslation } from "react-i18next";
import { SanitizeParameters, defaultParameters } from "../../../hooks/tools/sanitize/useSanitizeParameters";
interface SanitizeSettingsProps {
parameters: SanitizeParameters;
onParameterChange: (key: keyof SanitizeParameters, value: boolean) => void;
disabled?: boolean;
}
const SanitizeSettings = ({ parameters, onParameterChange, disabled = false }: SanitizeSettingsProps) => {
const { t } = useTranslation();
const options = (Object.keys(defaultParameters) as Array<keyof SanitizeParameters>).map((key) => ({
key: key,
label: t(`sanitize.options.${key}`, key),
description: t(`sanitize.options.${key}.desc`, `${key} from the PDF`),
default: defaultParameters[key],
}));
return (
<Stack gap="md">
<Text size="sm" fw={500}>
{t('sanitize.options.title', 'Sanitization Options')}
</Text>
<Stack gap="sm">
{options.map((option) => (
<Checkbox
key={option.key}
checked={parameters[option.key]}
onChange={(event) => onParameterChange(option.key, event.currentTarget.checked)}
disabled={disabled}
label={
<div>
<Text size="sm">{option.label}</Text>
<Text size="xs" c="dimmed">{option.description}</Text>
</div>
}
/>
))}
</Stack>
<Text size="xs" c="dimmed">
{t('sanitize.options.note', 'Select the elements you want to remove from the PDF. At least one option must be selected.')}
</Text>
</Stack>
);
};
export default SanitizeSettings;