Created RelationModal

This commit is contained in:
soupette 2019-03-14 12:09:53 +01:00
parent a6d079cd89
commit 481d948cfb
10 changed files with 114 additions and 6 deletions

View File

@ -0,0 +1,22 @@
/**
*
* RelationModal
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import styles from './styles.scss';
function RelationModal() {
return (
<div className={styles.relationModal}>
</div>
);
}
RelationModal.propTypes = {
};
export default RelationModal;

View File

@ -0,0 +1,3 @@
.relationModal {
}

View File

@ -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(<RelationModal {...props} />, messages);
describe('<RelationModal />', () => {
it('should not crash', () => {
shallow(<RelationModal />);
// renderComponent({});
});
});

View File

@ -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) => {

View File

@ -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';

View File

@ -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 <Loader />;
}

View File

@ -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;
}

View File

@ -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),
]);
}

View File

@ -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),
]));
});
});

View File

@ -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,
);