import Joi from "@stirling-tools/joi";
import { Fragment } from "react";
interface GenericFieldProps {
fieldName: string,
joiDefinition: Joi.Description
}
interface Flags {
label: string,
description: string,
}
export function GenericField({ fieldName, joiDefinition }: GenericFieldProps) {
const flags = joiDefinition.flags as Flags;
switch (joiDefinition.type) {
case "number":
var validValues = joiDefinition.allow;
if(validValues) { // Restrained number input
return (
);
}
else { // Unrestrained number input
// TODO: Check if integer or not.
return (
);
}
break;
case "string":
if(joiDefinition.allow) { // Restrained text input
return (
);
}
else {
return (
)
}
break;
case "comma_array":
if(joiDefinition.items.length == 1) {
const item: Joi.Description = joiDefinition.items[0];
if(item.type == "number") {
const props: any = {};
item.rules.forEach((rule: { args: any, name: string}) => {
switch (rule.name) {
case "integer":
if(props.pattern) {
return (
props.pattern was already set, this is not implemented.
);
}
props.pattern = `(\\d+)(,\\s*\\d+)*`;
break;
case "min":
// TODO: Could validate this in frontend first.
break;
case "max":
// TODO: Could validate this in frontend first.
break;
default:
return (
comma_array, item rule {rule.name} is not implemented.
);
}
});
return (
);
}
else {
return (
comma_array, other types than numbers are not implemented yet.
comma_array, joi items are empty or bigger than one, this is not implemented
);
}
break;
case "alternatives": // TODO: Better support this. It is currently used by ScaleContent (working) and SplitByPreset (incompatible, but with that operator it isn't even considered a field so we need a different schema for that)
return (
);
case "boolean":
return (
);
case "date":
return (
);
default:
console.log(joiDefinition);
return (
GenericField.tsx: "{fieldName}": requested type "{joiDefinition.type}" not found. Check console for further info.