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 ( {joiDefinition.allow.map((e: string) => { return (
); } else { // Unrestrained number input // TODO: Check if integer or not. return (
); } break; case "string": if(joiDefinition.allow) { // Restrained text input return ( {joiDefinition.allow.map((e: string) => { return (
); } else { // TODO: Implement unrestrained text input return (
string, unrestrained text input is not implemented
) } break; case "comma_array": if(joiDefinition.items.length == 1) { const item: Joi.Description = joiDefinition.items[0]; if(item.type == "number") { if(item.rules.length == 1) { return (
); } else { return (
comma_array, item rules are empty or bigger than one, this is not implemented.
); } } else { return (
comma_array, other types than numbers are not implemented yet.
); } } else { // TODO: Implement multiple items if necessary return (
comma_array, joi items are empty or bigger than one, this is not implemented
); } break; default: console.log(joiDefinition); return (
GenericField.tsx:
"{fieldName}": requested type "{joiDefinition.type}" not found. Check console for further info.
) } }