2024-01-28 19:14:53 +01:00
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
2024-02-23 23:48:03 +01:00
|
|
|
import { BaseSyntheticEvent, createContext, useState } from "react";
|
2024-02-04 17:01:50 +01:00
|
|
|
import { Operator } from "@stirling-pdf/shared-operations/src/functions";
|
|
|
|
import i18next from "i18next";
|
2024-02-23 23:48:03 +01:00
|
|
|
import Joi from "@stirling-tools/joi";
|
|
|
|
import { BuildFields } from "../components/fields/BuildFields";
|
2024-01-28 19:14:53 +01:00
|
|
|
|
|
|
|
function Dynamic() {
|
2024-02-23 23:48:03 +01:00
|
|
|
const [schemaDescription, setSchemaDescription] = useState<Joi.Description>();
|
|
|
|
|
|
|
|
|
2024-01-28 21:22:59 +01:00
|
|
|
const operators = ["impose"]; // TODO: Make this dynamic
|
2024-02-05 13:28:46 -05:00
|
|
|
|
2024-01-28 19:14:53 +01:00
|
|
|
function selectionChanged(s: BaseSyntheticEvent) {
|
|
|
|
const selectedValue = s.target.value;
|
2024-02-23 23:48:03 +01:00
|
|
|
if(selectedValue == "none") {
|
|
|
|
setSchemaDescription(undefined);
|
|
|
|
return;
|
|
|
|
}
|
2024-02-04 17:01:50 +01:00
|
|
|
|
2024-02-05 13:28:46 -05:00
|
|
|
i18next.loadNamespaces("impose", (err, t) => {
|
2024-02-04 17:01:50 +01:00
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
const LoadingModule = import(`@stirling-pdf/shared-operations/src/functions/${selectedValue}`) as Promise<{ [key: string]: typeof Operator }>;
|
|
|
|
LoadingModule.then((Module) => {
|
|
|
|
const Operator = Module[capitalizeFirstLetter(selectedValue)];
|
2024-02-05 12:15:01 -05:00
|
|
|
const description = Operator.schema.describe();
|
|
|
|
|
2024-02-23 23:48:03 +01:00
|
|
|
setSchemaDescription(description); // This will update children
|
2024-02-05 13:28:46 -05:00
|
|
|
console.log(description);
|
|
|
|
});
|
2024-02-04 17:01:50 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function capitalizeFirstLetter(string: String) {
|
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
2024-01-28 19:14:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2>Dynamic test page for operators</h2>
|
|
|
|
|
|
|
|
<input type="file" id="pdfFile" accept=".pdf" multiple />
|
|
|
|
<br />
|
|
|
|
<select id="pdfOptions" onChange={selectionChanged}>
|
|
|
|
<option value="none">none</option>
|
2024-02-05 13:28:46 -05:00
|
|
|
{ operators.map((operator, i) => {
|
|
|
|
return (<option value={operator}>{operator}</option>)
|
2024-01-28 21:22:59 +01:00
|
|
|
}) }
|
2024-01-28 19:14:53 +01:00
|
|
|
</select>
|
2024-02-23 23:48:03 +01:00
|
|
|
|
|
|
|
<div id="values">
|
|
|
|
<BuildFields schemaDescription={schemaDescription}></BuildFields>
|
|
|
|
</div>
|
2024-02-05 13:28:46 -05:00
|
|
|
|
2024-01-28 19:14:53 +01:00
|
|
|
<br />
|
2024-02-23 23:48:03 +01:00
|
|
|
<button id="processButton">Process process file with current settings</button>
|
2024-01-28 19:14:53 +01:00
|
|
|
|
|
|
|
<p>
|
|
|
|
<Link to="/">Go back home...</Link>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-05 13:28:46 -05:00
|
|
|
export default Dynamic;
|