diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/index.js b/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/index.js
new file mode 100644
index 0000000000..16db4aca4d
--- /dev/null
+++ b/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/index.js
@@ -0,0 +1,22 @@
+/**
+*
+* RelationModal
+*
+*/
+
+import React from 'react';
+import PropTypes from 'prop-types';
+import styles from './styles.scss';
+
+function RelationModal() {
+ return (
+
+
+ );
+}
+
+RelationModal.propTypes = {
+
+};
+
+export default RelationModal;
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/styles.scss b/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/styles.scss
new file mode 100644
index 0000000000..485ba3afd0
--- /dev/null
+++ b/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/styles.scss
@@ -0,0 +1,3 @@
+.relationModal {
+
+}
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/tests/index.test.js b/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/tests/index.test.js
new file mode 100644
index 0000000000..4d9e1193ea
--- /dev/null
+++ b/packages/strapi-plugin-content-type-builder/admin/src/components/RelationModal/tests/index.test.js
@@ -0,0 +1,26 @@
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import RelationModal from '../index';
+
+// import mountWithIntl from 'testUtils/mountWithIntl';
+// import formatMessagesWithPluginId from 'testUtils/formatMessages';
+
+
+// This part is needed if you need to test the lifecycle of a container that contains FormattedMessages
+
+// import pluginId from '../../../pluginId';
+// import pluginTradsEn from '../../../translations/en.json';
+
+// import { RelationModal } from '../index';
+
+// const messages = formatMessagesWithPluginId(pluginId, pluginTradsEn);
+// const renderComponent = (props = {}) => mountWithIntl(, messages);
+
+describe('', () => {
+ it('should not crash', () => {
+ shallow();
+
+ // renderComponent({});
+ });
+});
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js
index 6239fa6b27..5ecaff9f9f 100644
--- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js
+++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/actions.js
@@ -15,6 +15,8 @@ import {
GET_DATA_SUCCEEDED,
ON_CHANGE_NEW_CONTENT_TYPE,
ON_CREATE_ATTRIBUTE,
+ SUBMIT_TEMP_CONTENT_TYPE,
+ SUBMIT_TEMP_CONTENT_TYPE_SUCCEEDED,
} from './constants';
export function addAttributeToTempContentType(attributeType) {
@@ -95,6 +97,18 @@ export function onCreateAttribute({ target }) {
};
}
+export function submitTempContentType() {
+ return {
+ type: SUBMIT_TEMP_CONTENT_TYPE,
+ };
+}
+
+export function submitTempContentTypeSucceeded() {
+ return {
+ type: SUBMIT_TEMP_CONTENT_TYPE_SUCCEEDED,
+ };
+}
+
// utils
export const buildModelAttributes = (attributes) => {
const formattedAttributes = attributes.reduce((acc, current) => {
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/constants.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/constants.js
index 15c6dee8d3..edaaebad2c 100644
--- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/constants.js
+++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/constants.js
@@ -14,3 +14,5 @@ export const GET_DATA = 'ContentTypeBuilder/App/GET_DATA';
export const GET_DATA_SUCCEEDED = 'ContentTypeBuilder/App/GET_DATA_SUCCEEDED';
export const ON_CHANGE_NEW_CONTENT_TYPE = 'ContentTypeBuilder/App/ON_CHANGE_NEW_CONTENT_TYPE';
export const ON_CREATE_ATTRIBUTE = 'ContentTypeBuilder/App/ON_CREATE_ATTRIBUTE';
+export const SUBMIT_TEMP_CONTENT_TYPE = 'ContentTypeBuilder/App/SUBMIT_TEMP_CONTENT_TYPE';
+export const SUBMIT_TEMP_CONTENT_TYPE_SUCCEEDED = 'ContentTypeBuilder/App/SUBMIT_TEMP_CONTENT_TYPE_SUCCEEDED';
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js
index f2c21fbd45..b09747bb9c 100644
--- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js
+++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/index.js
@@ -76,7 +76,7 @@ export class App extends React.Component { // eslint-disable-line react/prefer-s
render() {
const { isLoading } = this.props;
-
+ console.log(this.props.newContentType)
if (isLoading) {
return ;
}
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/reducer.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/reducer.js
index 088f4c40fc..98540e3be4 100644
--- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/reducer.js
+++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/reducer.js
@@ -14,6 +14,7 @@ import {
GET_DATA_SUCCEEDED,
ON_CHANGE_NEW_CONTENT_TYPE,
ON_CREATE_ATTRIBUTE,
+ SUBMIT_TEMP_CONTENT_TYPE_SUCCEEDED,
} from './constants';
export const initialState = fromJS({
@@ -36,6 +37,7 @@ export const initialState = fromJS({
function appReducer(state = initialState, action) {
switch (action.type) {
case ADD_ATTRIBUTE_TO_TEMP_CONTENT_TYPE: {
+ console.log({ reducer: state.get('newContentType').toJS()})
return state
.updateIn([
'newContentType',
@@ -54,6 +56,7 @@ function appReducer(state = initialState, action) {
.update('temporaryAttribute', () => Map({}));
}
case CANCEL_NEW_CONTENT_TYPE:
+ console.log('llll');
return state
.update('newContentType', () => Map(initialState.get('newContentType')));
case CLEAR_TEMPORARY_ATTRIBUTE:
@@ -81,11 +84,24 @@ function appReducer(state = initialState, action) {
.updateIn(['newContentType', 'connection'], () => action.connections[0])
.update('models', () => List(action.models));
case ON_CHANGE_NEW_CONTENT_TYPE:
+ console.log('change', action.keys, action.value);
return state
.updateIn(['newContentType', ...action.keys], () => action.value);
case ON_CREATE_ATTRIBUTE:
return state
.updateIn(['temporaryAttribute', ...action.keys], () => action.value);
+ case SUBMIT_TEMP_CONTENT_TYPE_SUCCEEDED:
+ console.log(state.get('newContentType'));
+ console.log(state.get('newContentType').toJS());
+ console.log(state.getIn(['newContentType', 'name']));
+ return state
+ .updateIn([
+ 'modifiedData',
+ state.getIn(['newContentType', 'name']),
+ ], () => state.get('newContentType'))
+ .updateIn(['models', state.get('models').size - 1, 'isTemporary'], () => false)
+ .update('models', list => list.sortBy(el => el.name))
+ .update('newContentType', () => Map(initialState.get('newContentType')));
default:
return state;
}
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/saga.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/saga.js
index e8b42f30a9..32d905418e 100644
--- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/saga.js
+++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/saga.js
@@ -1,9 +1,18 @@
import { all, fork, takeLatest, call, put } from 'redux-saga/effects';
+import { get } from 'lodash';
import request from 'utils/request';
import pluginId from '../../pluginId';
-import { getDataSucceeded, deleteModelSucceeded } from './actions';
-import { GET_DATA, DELETE_MODEL } from './constants';
+import {
+ getDataSucceeded,
+ deleteModelSucceeded,
+ submitTempContentTypeSucceeded,
+} from './actions';
+import {
+ GET_DATA,
+ DELETE_MODEL,
+ SUBMIT_TEMP_CONTENT_TYPE,
+} from './constants';
export function* getData() {
try {
@@ -33,10 +42,20 @@ export function* deleteModel({ modelName }) {
}
}
+export function* submitTempCT() {
+ try {
+ yield put(submitTempContentTypeSucceeded());
+ } catch(err) {
+ const errorMessage = get(error, ['response', 'payload', 'message', '0', 'messages', '0', 'id'], 'notification.error');
+ strapi.notification.error(errorMessage)
+ }
+}
+
// Individual exports for testing
export default function* defaultSaga() {
yield all([
fork(takeLatest, GET_DATA, getData),
fork(takeLatest, DELETE_MODEL, deleteModel),
+ fork(takeLatest, SUBMIT_TEMP_CONTENT_TYPE, submitTempCT),
]);
}
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/saga.test.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/saga.test.js
index 1be59deae5..8de843d2ef 100644
--- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/saga.test.js
+++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/tests/saga.test.js
@@ -4,10 +4,10 @@
/* eslint-disable redux-saga/yield-effects */
import { all, fork, takeLatest, put } from 'redux-saga/effects';
-import defaultSaga, { deleteModel, getData } from '../saga';
+import defaultSaga, { deleteModel, getData, submitTempCT } from '../saga';
import { deleteModelSucceeded, getDataSucceeded } from '../actions';
-import { DELETE_MODEL, GET_DATA } from '../constants';
+import { DELETE_MODEL, GET_DATA, SUBMIT_TEMP_CONTENT_TYPE } from '../constants';
const response = [
{
@@ -104,6 +104,7 @@ describe('defaultSaga Saga', () => {
all([
fork(takeLatest, GET_DATA, getData),
fork(takeLatest, DELETE_MODEL, deleteModel),
+ fork(takeLatest, SUBMIT_TEMP_CONTENT_TYPE, submitTempCT),
]));
});
});
diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js
index e93295701e..e0d40a90e7 100644
--- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js
+++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js
@@ -41,6 +41,7 @@ import {
addAttributeToTempContentType,
clearTemporaryAttribute,
onCreateAttribute,
+ submitTempContentType,
} from '../App/actions';
import CustomLink from './CustomLink';
@@ -113,6 +114,8 @@ export class ModelPage extends React.Component { // eslint-disable-line react/pr
getModelRelationShipsLength = () => Object.keys(this.getModelRelationShips()).length;
getPluginHeaderActions = () => {
+ const { submitTempContentType } = this.props;
+
if (this.isUpdatingTemporaryContentType() && this.getModelAttributesLength() > 0) {
return [
{
@@ -123,7 +126,7 @@ export class ModelPage extends React.Component { // eslint-disable-line react/pr
},
{
label: `${pluginId}.form.button.save`,
- onClick: () => {},
+ onClick: submitTempContentType,
kind: 'primary',
type: 'submit',
id: 'saveData',
@@ -359,6 +362,7 @@ ModelPage.propTypes = {
initialData: PropTypes.object.isRequired,
models: PropTypes.array.isRequired,
onCreateAttribute: PropTypes.func.isRequired,
+ submitTempContentType: PropTypes.func.isRequired,
};
const mapStateToProps = createStructuredSelector({
@@ -371,6 +375,7 @@ export function mapDispatchToProps(dispatch) {
addAttributeToTempContentType,
clearTemporaryAttribute,
onCreateAttribute,
+ submitTempContentType,
},
dispatch,
);