2024-01-28 19:14:53 +01:00
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
|
|
|
import { BaseSyntheticEvent } from "react";
|
2024-02-04 17:01:50 +01:00
|
|
|
import { Operator } from "@stirling-pdf/shared-operations/src/functions";
|
|
|
|
import i18next from "i18next";
|
2024-01-28 19:14:53 +01:00
|
|
|
|
|
|
|
function Dynamic() {
|
2024-01-28 21:22:59 +01:00
|
|
|
const operators = ["impose"]; // TODO: Make this dynamic
|
2024-01-28 19:14:53 +01:00
|
|
|
|
|
|
|
function selectionChanged(s: BaseSyntheticEvent) {
|
|
|
|
const selectedValue = s.target.value;
|
|
|
|
if(selectedValue == "none") return;
|
2024-02-04 17:01:50 +01:00
|
|
|
|
|
|
|
i18next.loadNamespaces("impose", (err, t) => {
|
|
|
|
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)];
|
|
|
|
const description = Operator.schema.describe(); // TODO: The browser build of joi does not include describe.
|
|
|
|
|
|
|
|
console.log(description);
|
|
|
|
// TODO: use description to generate fields
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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 />
|
|
|
|
|
|
|
|
<br />
|
|
|
|
<textarea name="workflow" id="workflow"></textarea>
|
|
|
|
<br />
|
|
|
|
<select id="pdfOptions" onChange={selectionChanged}>
|
|
|
|
<option value="none">none</option>
|
2024-01-28 21:22:59 +01:00
|
|
|
{ operators.map((operator, i) => {
|
2024-01-28 19:14:53 +01:00
|
|
|
return (<option value={operator}>{operator}</option>)
|
2024-01-28 21:22:59 +01:00
|
|
|
}) }
|
2024-01-28 19:14:53 +01:00
|
|
|
</select>
|
|
|
|
<button id="loadButton">Load</button>
|
|
|
|
<br />
|
|
|
|
|
|
|
|
<br />
|
|
|
|
<button id="doneButton">Done</button>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<Link to="/">Go back home...</Link>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default Dynamic;
|