modifies RenderFields and customComponents to support more than one custom component per field
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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 (
|
||||
|
||||
11
src/index.js
11
src/index.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user