Remove immutable CTB

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2021-07-13 16:12:59 +02:00
parent 24083dee44
commit 21e22313a4
7 changed files with 123 additions and 158 deletions

View File

@ -351,7 +351,6 @@ const DataManagerProvider = ({
} }
}; };
// TODO
const getAllComponentsThatHaveAComponentInTheirAttributes = () => { const getAllComponentsThatHaveAComponentInTheirAttributes = () => {
// We need to create an object with all the non modified compos // We need to create an object with all the non modified compos
// plus the ones that are created on the fly // plus the ones that are created on the fly
@ -370,7 +369,6 @@ const DataManagerProvider = ({
return makeUnique(composWithCompos); return makeUnique(composWithCompos);
}; };
// TODO
const getAllNestedComponents = () => { const getAllNestedComponents = () => {
const appNestedCompo = retrieveNestedComponents(components); const appNestedCompo = retrieveNestedComponents(components);
const editingDataNestedCompos = retrieveNestedComponents(modifiedData.components || {}); const editingDataNestedCompos = retrieveNestedComponents(modifiedData.components || {});

View File

@ -185,7 +185,6 @@ const reducer = (state = initialState, action) =>
].components = updatedComponents; ].components = updatedComponents;
// Retrieve all the components that needs to be added to the modifiedData.components // Retrieve all the components that needs to be added to the modifiedData.components
// TODO check if it works
const nestedComponents = retrieveComponentsFromSchema( const nestedComponents = retrieveComponentsFromSchema(
current(draftState.modifiedData.contentType.schema.attributes), current(draftState.modifiedData.contentType.schema.attributes),
state.components state.components

View File

@ -1,4 +1,4 @@
import { get, has, isEqual, omit, sortBy, camelCase } from 'lodash'; import { get, isEqual, omit, sortBy, camelCase } from 'lodash';
import pluginId from '../../../pluginId'; import pluginId from '../../../pluginId';
import makeUnique from '../../../utils/makeUnique'; import makeUnique from '../../../utils/makeUnique';
@ -18,7 +18,7 @@ const getCreatedAndModifiedComponents = (allComponents, initialComponents) => {
const formatComponent = (component, mainDataUID, isCreatingData = false) => { const formatComponent = (component, mainDataUID, isCreatingData = false) => {
const formattedAttributes = formatAttributes( const formattedAttributes = formatAttributes(
get(component, 'schema.attributes', {}), get(component, 'schema.attributes', []),
mainDataUID, mainDataUID,
isCreatingData, isCreatingData,
true true
@ -48,7 +48,7 @@ const formatMainDataType = (data, isComponent = false) => {
const mainDataUID = get(data, 'uid', null); const mainDataUID = get(data, 'uid', null);
const formattedAttributes = formatAttributes( const formattedAttributes = formatAttributes(
get(data, 'schema.attributes', {}), get(data, 'schema.attributes', []),
mainDataUID, mainDataUID,
isCreatingData, isCreatingData,
false false
@ -75,10 +75,10 @@ const formatMainDataType = (data, isComponent = false) => {
* @param {Boolean} isComponent * @param {Boolean} isComponent
*/ */
const formatAttributes = (attributes, mainDataUID, isCreatingMainData, isComponent) => { const formatAttributes = (attributes, mainDataUID, isCreatingMainData, isComponent) => {
return Object.keys(attributes).reduce((acc, current) => { return attributes.reduce((acc, { name, ...rest }) => {
const currentAttribute = get(attributes, current, {}); const currentAttribute = rest;
const hasARelationWithMainDataUID = currentAttribute.target === mainDataUID; const hasARelationWithMainDataUID = currentAttribute.target === mainDataUID;
const isRelationType = has(currentAttribute, 'nature'); const isRelationType = currentAttribute.type === 'relation';
const currentTargetAttribute = get(currentAttribute, 'targetAttribute', null); const currentTargetAttribute = get(currentAttribute, 'targetAttribute', null);
if (!hasARelationWithMainDataUID) { if (!hasARelationWithMainDataUID) {
@ -87,12 +87,14 @@ const formatAttributes = (attributes, mainDataUID, isCreatingMainData, isCompone
targetAttribute: formatRelationTargetAttribute(currentTargetAttribute), targetAttribute: formatRelationTargetAttribute(currentTargetAttribute),
}); });
acc[current] = removeNullKeys(relationAttr); acc[name] = removeNullKeys(relationAttr);
} else { } else {
acc[current] = removeNullKeys(currentAttribute); acc[name] = removeNullKeys(currentAttribute);
} }
} }
// TODO check with @alexandrebodin if needed
// Not sure this is needed
if (hasARelationWithMainDataUID) { if (hasARelationWithMainDataUID) {
let target = currentAttribute.target; let target = currentAttribute.target;
@ -105,7 +107,7 @@ const formatAttributes = (attributes, mainDataUID, isCreatingMainData, isCompone
targetAttribute: formatRelationTargetAttribute(currentTargetAttribute), targetAttribute: formatRelationTargetAttribute(currentTargetAttribute),
}); });
acc[current] = removeNullKeys(formattedRelationAttribute); acc[name] = removeNullKeys(formattedRelationAttribute);
} }
return acc; return acc;

View File

@ -9,24 +9,22 @@ const expectedData = {
type: 'string', type: 'string',
}, },
address: { address: {
nature: 'oneWay', relation: 'oneToOne',
target: 'application::address.address', target: 'application::address.address',
unique: false, // targetAttribute: null,
required: false, type: 'relation',
}, },
testContentTypes: { testContentTypes: {
nature: 'oneToMany', relation: 'oneToMany',
targetAttribute: 'testContentType', targetAttribute: 'testContentType',
target: '__self__', target: '__self__',
unique: false, type: 'relation',
required: false,
}, },
testContentType: { testContentType: {
nature: 'manyToOne', relation: 'manyToOne',
target: '__self__', target: '__self__',
unique: false,
required: false,
targetAttribute: 'testContentTypes', targetAttribute: 'testContentTypes',
type: 'relation',
}, },
mainCompoField: { mainCompoField: {
type: 'component', type: 'component',
@ -55,24 +53,21 @@ const expectedData = {
type: 'string', type: 'string',
}, },
address: { address: {
nature: 'oneWay', relation: 'oneToOne',
target: 'application::address.address', target: 'application::address.address',
unique: false, type: 'relation',
required: false,
}, },
testContentTypes: { testContentTypes: {
nature: 'oneToMany', relation: 'oneToMany',
targetAttribute: 'testContentType', targetAttribute: 'testContentType',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false, type: 'relation',
required: false,
}, },
testContentType: { testContentType: {
nature: 'manyToOne', relation: 'manyToOne',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false,
required: false,
targetAttribute: 'testContentTypes', targetAttribute: 'testContentTypes',
type: 'relation',
}, },
mainCompoField: { mainCompoField: {
type: 'component', type: 'component',
@ -146,10 +141,9 @@ const expectedData = {
type: 'string', type: 'string',
}, },
testContentType: { testContentType: {
nature: 'oneWay', relation: 'oneToOne',
target: '__contentType__', target: '__contentType__',
unique: false, type: 'relation',
required: false,
}, },
subCompoField: { subCompoField: {
type: 'component', type: 'component',
@ -185,9 +179,7 @@ const expectedData = {
type: 'string', type: 'string',
required: true, required: true,
}, },
author: {
model: 'user',
},
link_to_biography: { link_to_biography: {
type: 'string', type: 'string',
required: true, required: true,
@ -206,10 +198,9 @@ const expectedData = {
type: 'string', type: 'string',
}, },
testContentType: { testContentType: {
nature: 'oneWay', relation: 'oneToOne',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false, type: 'relation',
required: false,
}, },
subCompoField: { subCompoField: {
type: 'component', type: 'component',
@ -245,9 +236,6 @@ const expectedData = {
type: 'string', type: 'string',
required: true, required: true,
}, },
author: {
model: 'user',
},
link_to_biography: { link_to_biography: {
type: 'string', type: 'string',
required: true, required: true,
@ -266,10 +254,9 @@ const expectedData = {
type: 'string', type: 'string',
}, },
testContentType: { testContentType: {
nature: 'oneWay', relation: 'oneToOne',
target: '__contentType__', target: '__contentType__',
unique: false, type: 'relation',
required: false,
}, },
subCompoField: { subCompoField: {
type: 'component', type: 'component',
@ -305,9 +292,6 @@ const expectedData = {
type: 'string', type: 'string',
required: true, required: true,
}, },
author: {
model: 'user',
},
link_to_biography: { link_to_biography: {
type: 'string', type: 'string',
required: true, required: true,
@ -326,10 +310,9 @@ const expectedData = {
type: 'string', type: 'string',
}, },
testContentType: { testContentType: {
nature: 'oneWay', relation: 'oneToOne',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false, type: 'relation',
required: false,
}, },
subCompoField: { subCompoField: {
type: 'component', type: 'component',
@ -365,9 +348,6 @@ const expectedData = {
type: 'string', type: 'string',
required: true, required: true,
}, },
author: {
model: 'user',
},
link_to_biography: { link_to_biography: {
type: 'string', type: 'string',
required: true, required: true,

View File

@ -9,18 +9,20 @@ const data = {
description: '', description: '',
connection: 'default', connection: 'default',
collectionName: 'components_metas', collectionName: 'components_metas',
attributes: { attributes: [
meta: { {
name: 'meta',
type: 'string', type: 'string',
required: true, required: true,
default: 'title', default: 'title',
}, },
value: { {
name: 'value',
type: 'text', type: 'text',
required: true, required: true,
default: 'A title', default: 'A title',
}, },
}, ],
}, },
}, },
'blog.quote': { 'blog.quote': {
@ -32,20 +34,19 @@ const data = {
icon: 'anchor', icon: 'anchor',
connection: 'default', connection: 'default',
collectionName: 'components_quotes', collectionName: 'components_quotes',
attributes: { attributes: [
quote: { {
name: 'quote',
type: 'text', type: 'text',
required: true, required: true,
}, },
author: {
model: 'user', {
plugin: 'users-permissions', name: 'link_to_biography',
},
link_to_biography: {
type: 'string', type: 'string',
required: true, required: true,
}, },
}, ],
}, },
}, },
}, },
@ -58,26 +59,25 @@ const data = {
schema: { schema: {
name: 'mainCompo', name: 'mainCompo',
icon: 'ad', icon: 'ad',
attributes: { attributes: [
name: { {
name: 'name',
type: 'string', type: 'string',
}, },
testContentType: { {
dominant: null, name: 'testContentType',
columnName: null, relation: 'oneToOne',
nature: 'oneWay', targetAttribute: null,
targetAttribute: '-',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false, type: 'relation',
targetColumnName: null,
required: false,
}, },
subCompoField: { {
name: 'subCompoField',
type: 'component', type: 'component',
repeatable: false, repeatable: false,
component: 'default.nested-compo', component: 'default.nested-compo',
}, },
}, ],
}, },
}, },
'default.nested-compo': { 'default.nested-compo': {
@ -87,15 +87,17 @@ const data = {
schema: { schema: {
name: 'nestedCompo', name: 'nestedCompo',
icon: 'address-book', icon: 'address-book',
attributes: { attributes: [
name: { {
name: 'name',
type: 'string', type: 'string',
}, },
email: { {
name: 'email',
type: 'email', type: 'email',
default: null, default: null,
}, },
}, ],
}, },
}, },
'default.metas': { 'default.metas': {
@ -107,18 +109,20 @@ const data = {
description: '', description: '',
connection: 'default', connection: 'default',
collectionName: 'components_metas', collectionName: 'components_metas',
attributes: { attributes: [
meta: { {
name: 'meta',
type: 'string', type: 'string',
required: true, required: true,
default: 'title', default: 'title',
}, },
value: { {
name: 'value',
type: 'text', type: 'text',
required: true, required: true,
default: 'A title', default: 'A title',
}, },
}, ],
}, },
}, },
'blog.quote': { 'blog.quote': {
@ -130,20 +134,18 @@ const data = {
icon: 'anchor', icon: 'anchor',
connection: 'default', connection: 'default',
collectionName: 'components_quotes', collectionName: 'components_quotes',
attributes: { attributes: [
quote: { {
name: 'quote',
type: 'string', type: 'string',
required: true, required: true,
}, },
author: { {
model: 'user', name: 'link_to_biography',
plugin: 'users-permissions',
},
link_to_biography: {
type: 'string', type: 'string',
required: true, required: true,
}, },
}, ],
}, },
}, },
}, },
@ -185,10 +187,7 @@ const data = {
}, },
}, },
}, },
// TODO add test for component
// componentToCreate: {
// },
contentTypeToCreate: { contentTypeToCreate: {
uid: 'application::test-content-type.test-content-type', uid: 'application::test-content-type.test-content-type',
isTemporary: true, isTemporary: true,
@ -197,56 +196,51 @@ const data = {
collectionName: 'test-content-types', collectionName: 'test-content-types',
connection: 'default', connection: 'default',
description: '', description: '',
attributes: { attributes: [
name: { {
name: 'name',
type: 'string', type: 'string',
}, },
address: { {
dominant: null, name: 'address',
columnName: null, relation: 'oneToOne',
nature: 'oneWay', targetAttribute: null,
targetAttribute: '-',
target: 'application::address.address', target: 'application::address.address',
unique: false, type: 'relation',
targetColumnName: null,
required: false,
}, },
testContentTypes: { {
dominant: null, name: 'testContentTypes',
columnName: null, relation: 'oneToMany',
nature: 'oneToMany',
targetAttribute: 'testContentType', targetAttribute: 'testContentType',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false, type: 'relation',
targetColumnName: null,
required: false,
}, },
testContentType: { {
nature: 'manyToOne', name: 'testContentType',
relation: 'manyToOne',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false,
required: false,
dominant: null,
targetAttribute: 'testContentTypes', targetAttribute: 'testContentTypes',
columnName: null, type: 'relation',
targetColumnName: null,
}, },
mainCompoField: { {
name: 'mainCompoField',
type: 'component', type: 'component',
repeatable: false, repeatable: false,
component: 'components.main-compo', component: 'components.main-compo',
}, },
existingCompo: { {
name: 'existingCompo',
type: 'component', type: 'component',
repeatable: true, repeatable: true,
component: 'default.metas', component: 'default.metas',
}, },
quote: { {
name: 'quote',
type: 'component', type: 'component',
repeatable: false, repeatable: false,
component: 'blog.quote', component: 'blog.quote',
}, },
}, ],
}, },
}, },
contentTypeToEdit: { contentTypeToEdit: {
@ -256,56 +250,51 @@ const data = {
collectionName: 'test-content-types', collectionName: 'test-content-types',
connection: 'default', connection: 'default',
description: '', description: '',
attributes: { attributes: [
name: { {
name: 'name',
type: 'string', type: 'string',
}, },
address: { {
dominant: null, name: 'address',
columnName: null, relation: 'oneToOne',
nature: 'oneWay', targetAttribute: null,
targetAttribute: '-',
target: 'application::address.address', target: 'application::address.address',
unique: false, type: 'relation',
targetColumnName: null,
required: false,
}, },
testContentTypes: { {
dominant: null, name: 'testContentTypes',
columnName: null, relation: 'oneToMany',
nature: 'oneToMany',
targetAttribute: 'testContentType', targetAttribute: 'testContentType',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false, type: 'relation',
targetColumnName: null,
required: false,
}, },
testContentType: { {
nature: 'manyToOne', name: 'testContentType',
relation: 'manyToOne',
target: 'application::test-content-type.test-content-type', target: 'application::test-content-type.test-content-type',
unique: false,
required: false,
dominant: null,
targetAttribute: 'testContentTypes', targetAttribute: 'testContentTypes',
columnName: null, type: 'relation',
targetColumnName: null,
}, },
mainCompoField: { {
name: 'mainCompoField',
type: 'component', type: 'component',
repeatable: false, repeatable: false,
component: 'components.main-compo', component: 'components.main-compo',
}, },
existingCompo: { {
name: 'existingCompo',
type: 'component', type: 'component',
repeatable: true, repeatable: true,
component: 'default.metas', component: 'default.metas',
}, },
quote: { {
name: 'quote',
type: 'component', type: 'component',
repeatable: false, repeatable: false,
component: 'blog.quote', component: 'blog.quote',
}, },
}, ],
}, },
}, },
}, },

View File

@ -20,7 +20,6 @@
"@strapi/helper-plugin": "3.6.5", "@strapi/helper-plugin": "3.6.5",
"@strapi/utils": "3.6.5", "@strapi/utils": "3.6.5",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"immutable": "^3.8.2",
"lodash": "4.17.21", "lodash": "4.17.21",
"pluralize": "^8.0.0", "pluralize": "^8.0.0",
"react": "^16.14.0", "react": "^16.14.0",
@ -31,7 +30,6 @@
"react-router-dom": "^5.0.0", "react-router-dom": "^5.0.0",
"reactstrap": "8.4.1", "reactstrap": "8.4.1",
"redux": "^4.0.1", "redux": "^4.0.1",
"redux-immutable": "^4.0.0",
"reselect": "^4.0.0", "reselect": "^4.0.0",
"yup": "^0.32.9" "yup": "^0.32.9"
}, },

View File

@ -19,9 +19,10 @@
"@buffetjs/styles": "3.3.5", "@buffetjs/styles": "3.3.5",
"@buffetjs/utils": "3.3.5", "@buffetjs/utils": "3.3.5",
"@purest/providers": "^1.0.2", "@purest/providers": "^1.0.2",
"@strapi/helper-plugin": "3.6.5",
"@strapi/utils": "3.6.5",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"grant-koa": "5.4.8", "grant-koa": "5.4.8",
"immutable": "^3.8.2",
"jsonwebtoken": "^8.1.0", "jsonwebtoken": "^8.1.0",
"koa2-ratelimit": "^0.9.0", "koa2-ratelimit": "^0.9.0",
"lodash": "4.17.21", "lodash": "4.17.21",
@ -35,8 +36,6 @@
"reactstrap": "8.4.1", "reactstrap": "8.4.1",
"redux-saga": "^0.16.0", "redux-saga": "^0.16.0",
"request": "^2.83.0", "request": "^2.83.0",
"@strapi/helper-plugin": "3.6.5",
"@strapi/utils": "3.6.5",
"uuid": "^3.1.0" "uuid": "^3.1.0"
}, },
"devDependencies": { "devDependencies": {