Fixed ESLint warnings, change property naming

Fixed ESLint Warnings
Add Documentation for Components under "Custom types"
Change property populate to components
pull/93/head
ppaoli 2023-09-04 13:04:08 +02:00 committed by Boaz Poolman
parent 378cd7bb58
commit c269b4847e
3 changed files with 33 additions and 18 deletions

View File

@ -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 > `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 ## 🔍 Naming convention
All the config files written in the sync directory have the same naming convention. It goes as follows: All the config files written in the sync directory have the same naming convention. It goes as follows:

View File

@ -3,7 +3,7 @@ const { logMessage, sanitizeConfig, dynamicSort, noLimit, getCombinedUid, getCom
const { difference, same } = require('../utils/getArrayDiff'); const { difference, same } = require('../utils/getArrayDiff');
const ConfigType = class ConfigType { const ConfigType = class ConfigType {
constructor({ queryString, configName, uid, jsonFields, relations, populate }) { constructor({ queryString, configName, uid, jsonFields, relations, components }) {
if (!configName) { if (!configName) {
strapi.log.error(logMessage('A config type was registered without a config name.')); strapi.log.error(logMessage('A config type was registered without a config name.'));
process.exit(0); process.exit(0);
@ -25,7 +25,7 @@ const ConfigType = class ConfigType {
this.configPrefix = configName; this.configPrefix = configName;
this.jsonFields = jsonFields || []; this.jsonFields = jsonFields || [];
this.relations = relations || []; this.relations = relations || [];
this.populate = populate || null; this.components = components || null;
} }
/** /**
@ -202,7 +202,7 @@ const ConfigType = class ConfigType {
*/ */
getAllFromDatabase = async () => { getAllFromDatabase = async () => {
const AllConfig = await noLimit(strapi.query(this.queryString), { const AllConfig = await noLimit(strapi.query(this.queryString), {
populate: this.populate, populate: this.components,
}); });
const configs = {}; const configs = {};
@ -232,12 +232,12 @@ const ConfigType = class ConfigType {
formattedConfig[relationName] = relations; formattedConfig[relationName] = relations;
})); }));
if (Array.isArray(this.populate)) { if (Array.isArray(this.components)) {
this.populate this.components
.filter((populatedFields) => !populatedFields.includes(".")) .filter((componentFields) => !componentFields.includes("."))
.map((populatedFields) => { .map((componentFields) => {
formattedConfig[populatedFields] = formattedConfig[ formattedConfig[componentFields] = formattedConfig[
populatedFields componentFields
].map((fields) => { ].map((fields) => {
sanitizeConfig(fields); sanitizeConfig(fields);
return fields; return fields;

View File

@ -69,19 +69,19 @@ const sanitizeConfig = (config, relation, relationSortFields) => {
config[relation] = formattedRelations; config[relation] = formattedRelations;
} }
const sanitizeRecursive = (config) => { const recursiveSanitizeConfig = (recursivedSanitizedConfig) => {
delete config._id; delete recursivedSanitizedConfig._id;
delete config.id; delete recursivedSanitizedConfig.id;
delete config.updatedAt; delete recursivedSanitizedConfig.updatedAt;
delete config.createdAt; delete recursivedSanitizedConfig.createdAt;
Object.keys(config).map((key, index) => { Object.keys(recursivedSanitizedConfig).map((key, index) => {
if (config[key] && typeof config[key] === "object") { if (recursivedSanitizedConfig[key] && typeof recursivedSanitizedConfig[key] === "object") {
sanitizeRecursive(config[key]); recursiveSanitizeConfig(recursivedSanitizedConfig[key]);
} }
}); });
}; };
sanitizeRecursive(config); recursiveSanitizeConfig(config);
return config; return config;
}; };