modifies RenderFields and customComponents to support more than one custom component per field

This commit is contained in:
James
2020-04-01 16:00:47 -04:00
parent 5857a8eb5a
commit 17b40c329f
3 changed files with 8 additions and 17 deletions

View File

@@ -14,19 +14,21 @@ function stringify(obj) {
}
module.exports = function (config) {
const allCollectionComponents = config.collections.reduce((obj, collection) => {
obj[collection.slug] = {
const allCollectionComponents = config.collections.reduce((components, collection) => {
const newComponents = { ...components };
newComponents[collection.slug] = {
fields: {},
...(collection.components || {}),
};
collection.fields.forEach((field) => {
if (field.component) {
obj[collection.slug].fields[field.name] = field.component;
if (field.components) {
newComponents[collection.slug].fields[field.name] = field.components;
}
});
return obj;
return newComponents;
}, {});
const string = stringify({

View File

@@ -10,7 +10,7 @@ const RenderFields = ({ fields, initialData, customComponents }) => {
<>
{fields.map((field, i) => {
const { defaultValue } = field;
const FieldComponent = customComponents?.[field.name] || fieldTypes[field.type];
const FieldComponent = customComponents?.[field.name]?.field || fieldTypes[field.type];
if (FieldComponent) {
return (

View File

@@ -21,9 +21,6 @@ class Payload {
this.registerCollections = registerCollections.bind(this);
this.registerGlobals = registerGlobals.bind(this);
this.getCollections.bind(this);
this.getGlobals.bind(this);
// Setup & initialization
connectMongoose(this.config.mongoURL);
@@ -50,14 +47,6 @@ class Payload {
// Bind static
this.express.use(this.config.staticURL, express.static(this.config.staticDir));
}
getCollections() {
return this.collections;
}
getGlobals() {
return this.globals;
}
}
module.exports = Payload;