mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Convert custom field type for contentTypes and components
This commit is contained in:
parent
959992cc95
commit
f1a271cf72
@ -37,7 +37,7 @@ describe('FromModalNavigationProvider', () => {
|
||||
const expected = {
|
||||
...INITIAL_STATE_DATA,
|
||||
actionType: 'create',
|
||||
modalType: 'attribute',
|
||||
modalType: 'customField',
|
||||
attributeType: 'text',
|
||||
customFieldUid: 'plugin::mycustomfields.color',
|
||||
};
|
||||
|
@ -4,6 +4,7 @@ const _ = require('lodash');
|
||||
|
||||
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
||||
const createBuilder = require('./schema-builder');
|
||||
const convertCustomFieldType = require('./utils/convert-custom-field-type');
|
||||
|
||||
/**
|
||||
* Formats a component attributes
|
||||
@ -41,9 +42,11 @@ const createComponent = async ({ component, components = [] }) => {
|
||||
const uidMap = builder.createNewComponentUIDMap(components);
|
||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||
|
||||
convertCustomFieldType(component.attributes);
|
||||
const newComponent = builder.createComponent(replaceTmpUIDs(component));
|
||||
|
||||
components.forEach(component => {
|
||||
convertCustomFieldType(component.attributes);
|
||||
if (!_.has(component, 'uid')) {
|
||||
return builder.createComponent(replaceTmpUIDs(component));
|
||||
}
|
||||
@ -67,12 +70,14 @@ const editComponent = async (uid, { component, components = [] }) => {
|
||||
const uidMap = builder.createNewComponentUIDMap(components);
|
||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||
|
||||
convertCustomFieldType(component.attributes);
|
||||
const updatedComponent = builder.editComponent({
|
||||
uid,
|
||||
...replaceTmpUIDs(component),
|
||||
});
|
||||
|
||||
components.forEach(component => {
|
||||
convertCustomFieldType(component.attributes);
|
||||
if (!_.has(component, 'uid')) {
|
||||
return builder.createComponent(replaceTmpUIDs(component));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ const { ApplicationError } = require('@strapi/utils').errors;
|
||||
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
||||
const createBuilder = require('./schema-builder');
|
||||
const { coreUids, pluginsUids } = require('./constants');
|
||||
const convertCustomFieldType = require('./utils/convert-custom-field-type');
|
||||
|
||||
const isContentTypeVisible = model =>
|
||||
getOr(true, 'pluginOptions.content-type-builder.visible', model) === true;
|
||||
@ -84,6 +85,7 @@ const createContentType = async ({ contentType, components = [] }, options = {})
|
||||
|
||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||
|
||||
convertCustomFieldType(contentType.attributes);
|
||||
const newContentType = builder.createContentType(replaceTmpUIDs(contentType));
|
||||
|
||||
// allow components to target the new contentType
|
||||
@ -99,6 +101,7 @@ const createContentType = async ({ contentType, components = [] }, options = {})
|
||||
};
|
||||
|
||||
components.forEach(component => {
|
||||
convertCustomFieldType(component.attributes);
|
||||
const options = replaceTmpUIDs(targetContentType(component));
|
||||
|
||||
if (!_.has(component, 'uid')) {
|
||||
@ -170,12 +173,15 @@ const editContentType = async (uid, { contentType, components = [] }) => {
|
||||
const uidMap = builder.createNewComponentUIDMap(components);
|
||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||
|
||||
convertCustomFieldType(contentType.attributes);
|
||||
const updatedContentType = builder.editContentType({
|
||||
uid,
|
||||
...replaceTmpUIDs(contentType),
|
||||
});
|
||||
|
||||
components.forEach(component => {
|
||||
convertCustomFieldType(component.attributes);
|
||||
|
||||
if (!_.has(component, 'uid')) {
|
||||
return builder.createComponent(replaceTmpUIDs(component));
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @description
|
||||
* Sets attribute.type to customField
|
||||
* @param {object} attributes Attributes found on content-type or component
|
||||
*/
|
||||
const convertCustomFieldType = attributes => {
|
||||
Object.values(attributes).forEach(attribute => {
|
||||
if (attribute.customField) {
|
||||
attribute.type = 'customField';
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = convertCustomFieldType;
|
Loading…
x
Reference in New Issue
Block a user