fastapi-rtk
Version:
A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.
25 lines (24 loc) • 1.01 kB
JavaScript
import { isSchemaTypeInclude } from "fastapi-rtk/.bundled-jsonforms";
import { getItemId } from "fastapi-rtk/utils";
function convertToFormInputs(item, schema) {
const result = {};
Object.entries(schema.properties || {}).forEach(([key, value]) => {
var _a;
const schemaOptions = value.items ? value.items : value;
const options = schemaOptions.oneOf ? schemaOptions.oneOf.map((option) => option.const) : schemaOptions.enum;
if (options) {
if (isSchemaTypeInclude(value.type, "array") && Array.isArray(item[key])) {
const existingValues = ((_a = item[key]) == null ? void 0 : _a.map((item2) => String(getItemId(item2) ?? item2))) || [];
result[key] = options.filter((val) => existingValues.includes(val));
} else {
result[key] = options.find((val) => val === String(getItemId(item[key]) ?? item[key]));
}
} else {
result[key] = getItemId(item[key]) ?? item[key] ?? void 0;
}
});
return result;
}
export {
convertToFormInputs
};