#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Make Auto Rotate's settings editable in the pipeline composer (#7222)
ConnorYoh6094040e0afc
diff --git a/frontend/editor/src/core/hooks/tools/autoRotate/useAutoRotateOperation.ts b/frontend/editor/src/core/hooks/tools/autoRotate/useAutoRotateOperation.tsindex 6460a66cfa..488a15a8e2 100644--- a/frontend/editor/src/core/hooks/tools/autoRotate/useAutoRotateOperation.ts+++ b/frontend/editor/src/core/hooks/tools/autoRotate/useAutoRotateOperation.ts@@ -16,12 +16,43 @@ import {ToolOperationHook,} from "@app/hooks/tools/shared/useToolOperation";import { createStandardErrorHandler } from "@app/utils/toolErrorHandler";+import type {+ ToolApiParams,+ ToolEndpoint,+} from "@app/hooks/tools/shared/toolApiMapping";import {AutoRotateParameters,+ AutoRotateDetectionMode,defaultParameters,} from "@app/hooks/tools/autoRotate/useAutoRotateParameters";-export const AUTO_ROTATE_ENDPOINT = "/api/v1/misc/auto-rotate-pdf";+export const AUTO_ROTATE_ENDPOINT =+ "/api/v1/misc/auto-rotate-pdf" satisfies ToolEndpoint;++type AutoRotateApiParams = ToolApiParams[typeof AUTO_ROTATE_ENDPOINT];++/**+ * Frontend params -> the endpoint's request model. Declaring these is what lets a+ * backend pipeline step carry this tool's settings: serializeToolStep sends `{}`+ * for a tool without mappers, and the pipeline composer can only offer a settings+ * panel for a tool that can map its parameters both ways.+ */+export const autoRotateToApiParams = (+ parameters: AutoRotateParameters,+): AutoRotateApiParams => ({+ detectionMode: parameters.detectionMode,+ confidenceThreshold: parameters.confidenceThreshold,+ inferUndetected: parameters.inferUndetected,+});++/** Rehydrate this tool's settings from a stored step's request body. */+export const autoRotateFromApiParams = (+ apiParams: AutoRotateApiParams,+): Partial<AutoRotateParameters> => ({+ detectionMode: apiParams.detectionMode as AutoRotateDetectionMode,+ confidenceThreshold: apiParams.confidenceThreshold,+ inferUndetected: apiParams.inferUndetected,+});export type AutoRotateMethod = "text" | "osd" | "inferred" | "none";@@ -135,6 +166,8 @@ export const autoRotateOperationConfig = defineCustomTool<AutoRotateParameters>(operationType: "autoRotate",endpoint: AUTO_ROTATE_ENDPOINT,customProcessor: createAutoRotateProcessor(),+ toApiParams: autoRotateToApiParams,+ fromApiParams: autoRotateFromApiParams,defaultParameters,},);diff --git a/frontend/editor/src/core/hooks/tools/shared/toolAutomation.test.ts b/frontend/editor/src/core/hooks/tools/shared/toolAutomation.test.tsindex 03b85798d8..f4cb974692 100644--- a/frontend/editor/src/core/hooks/tools/shared/toolAutomation.test.ts+++ b/frontend/editor/src/core/hooks/tools/shared/toolAutomation.test.ts@@ -22,6 +22,8 @@ import { defaultParameters as compressDefaults } from "@app/hooks/tools/compressimport { splitOperationConfig } from "@app/hooks/tools/split/useSplitOperation";import { SPLIT_METHODS } from "@app/constants/splitConstants";import { redactOperationConfig } from "@app/hooks/tools/redact/useRedactOperation";+import { autoRotateOperationConfig } from "@app/hooks/tools/autoRotate/useAutoRotateOperation";+import { defaultParameters as autoRotateDefaults } from "@app/hooks/tools/autoRotate/useAutoRotateParameters";function entry(over: Partial<ToolRegistryEntry>): ToolRegistryEntry {return {@@ -92,6 +94,11 @@ const dynamicRegistry: Partial<ToolRegistry> = {automationSettings: NoopSettings,operationConfig: asRegistryConfig(redactOperationConfig),}),+ autoRotate: entry({+ name: "Auto Rotate",+ automationSettings: NoopSettings,+ operationConfig: asRegistryConfig(autoRotateOperationConfig),+ }),};describe("getExecutableTools", () => {@@ -157,6 +164,40 @@ describe("serialize/deserialize round-trip", () => {});});+ test("auto rotate carries its detection settings into the backend step", () => {+ // A custom-processor tool: the browser applies the rotations, but a backend+ // pipeline still has to receive the detection settings, which only happens+ // because the config declares mappers.+ const step: WorkingToolStep = {+ toolId: "autoRotate" as ToolId,+ operation: "/api/v1/misc/auto-rotate-pdf",+ params: {+ ...autoRotateDefaults,+ detectionMode: "osd",+ confidenceThreshold: 20,+ inferUndetected: false,+ },+ support: "editable",+ };++ const api = serializeToolStep(step, dynamicRegistry);+ expect(api.operation).toBe("/api/v1/misc/auto-rotate-pdf");+ expect(api.parameters).toEqual({+ detectionMode: "osd",+ confidenceThreshold: 20,+ inferUndetected: false,+ });++ const back = deserializeToolStep(api, dynamicRegistry);+ expect(back.toolId).toBe("autoRotate");+ expect(back.support).toBe("editable");+ expect(back.params).toMatchObject({+ detectionMode: "osd",+ confidenceThreshold: 20,+ inferUndetected: false,+ });+ });+test("a dynamic-endpoint tool (split by chapters) round-trips as an editable step", () => {const step: WorkingToolStep = {toolId: "split" as ToolId,