mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +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 = {
|
const expected = {
|
||||||
...INITIAL_STATE_DATA,
|
...INITIAL_STATE_DATA,
|
||||||
actionType: 'create',
|
actionType: 'create',
|
||||||
modalType: 'attribute',
|
modalType: 'customField',
|
||||||
attributeType: 'text',
|
attributeType: 'text',
|
||||||
customFieldUid: 'plugin::mycustomfields.color',
|
customFieldUid: 'plugin::mycustomfields.color',
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
||||||
const createBuilder = require('./schema-builder');
|
const createBuilder = require('./schema-builder');
|
||||||
|
const convertCustomFieldType = require('./utils/convert-custom-field-type');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a component attributes
|
* Formats a component attributes
|
||||||
@ -41,9 +42,11 @@ const createComponent = async ({ component, components = [] }) => {
|
|||||||
const uidMap = builder.createNewComponentUIDMap(components);
|
const uidMap = builder.createNewComponentUIDMap(components);
|
||||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||||
|
|
||||||
|
convertCustomFieldType(component.attributes);
|
||||||
const newComponent = builder.createComponent(replaceTmpUIDs(component));
|
const newComponent = builder.createComponent(replaceTmpUIDs(component));
|
||||||
|
|
||||||
components.forEach(component => {
|
components.forEach(component => {
|
||||||
|
convertCustomFieldType(component.attributes);
|
||||||
if (!_.has(component, 'uid')) {
|
if (!_.has(component, 'uid')) {
|
||||||
return builder.createComponent(replaceTmpUIDs(component));
|
return builder.createComponent(replaceTmpUIDs(component));
|
||||||
}
|
}
|
||||||
@ -67,12 +70,14 @@ const editComponent = async (uid, { component, components = [] }) => {
|
|||||||
const uidMap = builder.createNewComponentUIDMap(components);
|
const uidMap = builder.createNewComponentUIDMap(components);
|
||||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||||
|
|
||||||
|
convertCustomFieldType(component.attributes);
|
||||||
const updatedComponent = builder.editComponent({
|
const updatedComponent = builder.editComponent({
|
||||||
uid,
|
uid,
|
||||||
...replaceTmpUIDs(component),
|
...replaceTmpUIDs(component),
|
||||||
});
|
});
|
||||||
|
|
||||||
components.forEach(component => {
|
components.forEach(component => {
|
||||||
|
convertCustomFieldType(component.attributes);
|
||||||
if (!_.has(component, 'uid')) {
|
if (!_.has(component, 'uid')) {
|
||||||
return builder.createComponent(replaceTmpUIDs(component));
|
return builder.createComponent(replaceTmpUIDs(component));
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ const { ApplicationError } = require('@strapi/utils').errors;
|
|||||||
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
||||||
const createBuilder = require('./schema-builder');
|
const createBuilder = require('./schema-builder');
|
||||||
const { coreUids, pluginsUids } = require('./constants');
|
const { coreUids, pluginsUids } = require('./constants');
|
||||||
|
const convertCustomFieldType = require('./utils/convert-custom-field-type');
|
||||||
|
|
||||||
const isContentTypeVisible = model =>
|
const isContentTypeVisible = model =>
|
||||||
getOr(true, 'pluginOptions.content-type-builder.visible', model) === true;
|
getOr(true, 'pluginOptions.content-type-builder.visible', model) === true;
|
||||||
@ -84,6 +85,7 @@ const createContentType = async ({ contentType, components = [] }, options = {})
|
|||||||
|
|
||||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||||
|
|
||||||
|
convertCustomFieldType(contentType.attributes);
|
||||||
const newContentType = builder.createContentType(replaceTmpUIDs(contentType));
|
const newContentType = builder.createContentType(replaceTmpUIDs(contentType));
|
||||||
|
|
||||||
// allow components to target the new contentType
|
// allow components to target the new contentType
|
||||||
@ -99,6 +101,7 @@ const createContentType = async ({ contentType, components = [] }, options = {})
|
|||||||
};
|
};
|
||||||
|
|
||||||
components.forEach(component => {
|
components.forEach(component => {
|
||||||
|
convertCustomFieldType(component.attributes);
|
||||||
const options = replaceTmpUIDs(targetContentType(component));
|
const options = replaceTmpUIDs(targetContentType(component));
|
||||||
|
|
||||||
if (!_.has(component, 'uid')) {
|
if (!_.has(component, 'uid')) {
|
||||||
@ -170,12 +173,15 @@ const editContentType = async (uid, { contentType, components = [] }) => {
|
|||||||
const uidMap = builder.createNewComponentUIDMap(components);
|
const uidMap = builder.createNewComponentUIDMap(components);
|
||||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||||
|
|
||||||
|
convertCustomFieldType(contentType.attributes);
|
||||||
const updatedContentType = builder.editContentType({
|
const updatedContentType = builder.editContentType({
|
||||||
uid,
|
uid,
|
||||||
...replaceTmpUIDs(contentType),
|
...replaceTmpUIDs(contentType),
|
||||||
});
|
});
|
||||||
|
|
||||||
components.forEach(component => {
|
components.forEach(component => {
|
||||||
|
convertCustomFieldType(component.attributes);
|
||||||
|
|
||||||
if (!_.has(component, 'uid')) {
|
if (!_.has(component, 'uid')) {
|
||||||
return builder.createComponent(replaceTmpUIDs(component));
|
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