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