mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 23:09:47 +00:00
Move content-type builder server custom field type conversion
This commit is contained in:
parent
e2dcefdb05
commit
cc95d65a3d
@ -4,7 +4,6 @@ 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
|
||||
@ -42,11 +41,9 @@ 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));
|
||||
}
|
||||
@ -70,14 +67,12 @@ 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,7 +8,6 @@ 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;
|
||||
@ -85,7 +84,6 @@ 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
|
||||
@ -101,7 +99,6 @@ const createContentType = async ({ contentType, components = [] }, options = {})
|
||||
};
|
||||
|
||||
components.forEach(component => {
|
||||
convertCustomFieldType(component.attributes);
|
||||
const options = replaceTmpUIDs(targetContentType(component));
|
||||
|
||||
if (!_.has(component, 'uid')) {
|
||||
@ -173,15 +170,12 @@ 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));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ const { nameToSlug, nameToCollectionName } = require('@strapi/utils');
|
||||
const { ApplicationError } = require('@strapi/utils').errors;
|
||||
const { isConfigurable } = require('../../utils/attributes');
|
||||
const createSchemaHandler = require('./schema-handler');
|
||||
const convertCustomFieldType = require('./utils/convert-custom-field-type');
|
||||
|
||||
module.exports = function createComponentBuilder() {
|
||||
return {
|
||||
@ -32,12 +33,15 @@ module.exports = function createComponentBuilder() {
|
||||
* create a component in the tmpComponent map
|
||||
*/
|
||||
createComponent(infos) {
|
||||
const { attributes } = infos;
|
||||
const uid = this.createComponentUID(infos);
|
||||
|
||||
if (this.components.has(uid)) {
|
||||
throw new ApplicationError('component.alreadyExists');
|
||||
}
|
||||
|
||||
convertCustomFieldType(attributes);
|
||||
|
||||
const handler = createSchemaHandler({
|
||||
dir: path.join(strapi.dirs.components, nameToSlug(infos.category)),
|
||||
filename: `${nameToSlug(infos.displayName)}.json`,
|
||||
@ -72,12 +76,13 @@ module.exports = function createComponentBuilder() {
|
||||
* create a component in the tmpComponent map
|
||||
*/
|
||||
editComponent(infos) {
|
||||
const { uid } = infos;
|
||||
const { uid, attributes } = infos;
|
||||
|
||||
if (!this.components.has(uid)) {
|
||||
throw new ApplicationError('component.notFound');
|
||||
}
|
||||
|
||||
convertCustomFieldType(attributes);
|
||||
const component = this.components.get(uid);
|
||||
|
||||
const [, nameUID] = uid.split('.');
|
||||
|
@ -8,6 +8,7 @@ const { ApplicationError } = require('@strapi/utils').errors;
|
||||
const { isRelation, isConfigurable } = require('../../utils/attributes');
|
||||
const { typeKinds } = require('../constants');
|
||||
const createSchemaHandler = require('./schema-handler');
|
||||
const convertCustomFieldType = require('./utils/convert-custom-field-type');
|
||||
|
||||
const reuseUnsetPreviousProperties = (newAttribute, oldAttribute) => {
|
||||
_.defaults(
|
||||
@ -71,12 +72,15 @@ module.exports = function createComponentBuilder() {
|
||||
* @returns {object} new content type
|
||||
*/
|
||||
createContentType(infos) {
|
||||
const { attributes } = infos;
|
||||
const uid = createContentTypeUID(infos);
|
||||
|
||||
if (this.contentTypes.has(uid)) {
|
||||
throw new ApplicationError('contentType.alreadyExists');
|
||||
}
|
||||
|
||||
convertCustomFieldType(attributes);
|
||||
|
||||
const contentType = createSchemaHandler({
|
||||
modelName: infos.singularName,
|
||||
dir: path.join(strapi.dirs.api, infos.singularName, 'content-types', infos.singularName),
|
||||
@ -124,12 +128,14 @@ module.exports = function createComponentBuilder() {
|
||||
},
|
||||
|
||||
editContentType(infos) {
|
||||
const { uid } = infos;
|
||||
const { uid, attributes } = infos;
|
||||
|
||||
if (!this.contentTypes.has(uid)) {
|
||||
throw new ApplicationError('contentType.notFound');
|
||||
}
|
||||
|
||||
convertCustomFieldType(attributes);
|
||||
|
||||
const contentType = this.contentTypes.get(uid);
|
||||
|
||||
const oldAttributes = contentType.schema.attributes;
|
||||
|
Loading…
x
Reference in New Issue
Block a user