Fixed ESLint warnings, change property naming
Fixed ESLint Warnings Add Documentation for Components under "Custom types" Change property populate to componentspull/93/head
parent
378cd7bb58
commit
c269b4847e
15
README.md
15
README.md
|
@ -354,6 +354,21 @@ This property can accept an array of field names from the type. It is meant to s
|
|||
|
||||
> `required:` NO | `type:` array
|
||||
|
||||
#### Components
|
||||
|
||||
This property can accept an array of component names from the type. Strapi Components can be included in the export/import process. With "." nested components can also be included in the process.
|
||||
```
|
||||
customTypes: [{
|
||||
configName: 'webhook',
|
||||
queryString: 'webhook',
|
||||
uid: 'name',
|
||||
components: ['ParentComponentA', 'ParentComponentA.ChildComponent', 'ParentComponentB']
|
||||
}],
|
||||
|
||||
###### Key: `components`
|
||||
|
||||
> `required:` NO | `type:` array
|
||||
|
||||
|
||||
## 🔍 Naming convention
|
||||
All the config files written in the sync directory have the same naming convention. It goes as follows:
|
||||
|
|
|
@ -3,7 +3,7 @@ const { logMessage, sanitizeConfig, dynamicSort, noLimit, getCombinedUid, getCom
|
|||
const { difference, same } = require('../utils/getArrayDiff');
|
||||
|
||||
const ConfigType = class ConfigType {
|
||||
constructor({ queryString, configName, uid, jsonFields, relations, populate }) {
|
||||
constructor({ queryString, configName, uid, jsonFields, relations, components }) {
|
||||
if (!configName) {
|
||||
strapi.log.error(logMessage('A config type was registered without a config name.'));
|
||||
process.exit(0);
|
||||
|
@ -25,7 +25,7 @@ const ConfigType = class ConfigType {
|
|||
this.configPrefix = configName;
|
||||
this.jsonFields = jsonFields || [];
|
||||
this.relations = relations || [];
|
||||
this.populate = populate || null;
|
||||
this.components = components || null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,7 +202,7 @@ const ConfigType = class ConfigType {
|
|||
*/
|
||||
getAllFromDatabase = async () => {
|
||||
const AllConfig = await noLimit(strapi.query(this.queryString), {
|
||||
populate: this.populate,
|
||||
populate: this.components,
|
||||
});
|
||||
const configs = {};
|
||||
|
||||
|
@ -232,12 +232,12 @@ const ConfigType = class ConfigType {
|
|||
formattedConfig[relationName] = relations;
|
||||
}));
|
||||
|
||||
if (Array.isArray(this.populate)) {
|
||||
this.populate
|
||||
.filter((populatedFields) => !populatedFields.includes("."))
|
||||
.map((populatedFields) => {
|
||||
formattedConfig[populatedFields] = formattedConfig[
|
||||
populatedFields
|
||||
if (Array.isArray(this.components)) {
|
||||
this.components
|
||||
.filter((componentFields) => !componentFields.includes("."))
|
||||
.map((componentFields) => {
|
||||
formattedConfig[componentFields] = formattedConfig[
|
||||
componentFields
|
||||
].map((fields) => {
|
||||
sanitizeConfig(fields);
|
||||
return fields;
|
||||
|
|
|
@ -69,19 +69,19 @@ const sanitizeConfig = (config, relation, relationSortFields) => {
|
|||
config[relation] = formattedRelations;
|
||||
}
|
||||
|
||||
const sanitizeRecursive = (config) => {
|
||||
delete config._id;
|
||||
delete config.id;
|
||||
delete config.updatedAt;
|
||||
delete config.createdAt;
|
||||
const recursiveSanitizeConfig = (recursivedSanitizedConfig) => {
|
||||
delete recursivedSanitizedConfig._id;
|
||||
delete recursivedSanitizedConfig.id;
|
||||
delete recursivedSanitizedConfig.updatedAt;
|
||||
delete recursivedSanitizedConfig.createdAt;
|
||||
|
||||
Object.keys(config).map((key, index) => {
|
||||
if (config[key] && typeof config[key] === "object") {
|
||||
sanitizeRecursive(config[key]);
|
||||
Object.keys(recursivedSanitizedConfig).map((key, index) => {
|
||||
if (recursivedSanitizedConfig[key] && typeof recursivedSanitizedConfig[key] === "object") {
|
||||
recursiveSanitizeConfig(recursivedSanitizedConfig[key]);
|
||||
}
|
||||
});
|
||||
};
|
||||
sanitizeRecursive(config);
|
||||
recursiveSanitizeConfig(config);
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue