mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 00:03:40 +00:00
Fixes #1262
This commit is contained in:
parent
85e638c901
commit
09ad42d1d2
@ -52,51 +52,80 @@ class PopUpRelations extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick = e => {
|
setPlaceholders = (firstCTName, secondCTName, relationType, values = this.props.values) => {
|
||||||
const value = e.target.id.split('.');
|
if (relationType === 'oneToMany') {
|
||||||
const target = {
|
firstCTName = pluralize(firstCTName);
|
||||||
type: 'string',
|
}
|
||||||
value: value[0],
|
|
||||||
name: 'params.target',
|
|
||||||
};
|
|
||||||
|
|
||||||
this.props.onChange({ target });
|
if (relationType === 'manyToOne') {
|
||||||
|
secondCTName = pluralize(secondCTName);
|
||||||
|
}
|
||||||
|
|
||||||
this.props.onChange({
|
if (relationType === 'manyToMany') {
|
||||||
target: {
|
firstCTName = pluralize(firstCTName);
|
||||||
type: 'string',
|
secondCTName = pluralize(secondCTName);
|
||||||
value: value[1] !== 'undefined' ? value[1] : '',
|
}
|
||||||
name: 'params.pluginValue',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const relationType = get(this.props.values, ['params', 'nature']);
|
|
||||||
|
|
||||||
if (get(this.props.contentType, 'name') !== value[0]) {
|
|
||||||
let firstCTName = value[0];
|
|
||||||
let secondCTName = get(this.props.contentType, 'name');
|
|
||||||
|
|
||||||
if (relationType === 'oneToMany') {
|
|
||||||
firstCTName = pluralize(firstCTName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (relationType === 'manyToOne') {
|
|
||||||
secondCTName = pluralize(secondCTName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (relationType === 'manyToMany') {
|
|
||||||
firstCTName = pluralize(firstCTName);
|
|
||||||
secondCTName = pluralize(secondCTName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (get(this.props.contentType, 'name') !== get(values, 'params.target')) {
|
||||||
this.props.onChange({ target: { name: 'name', value: firstCTName } });
|
this.props.onChange({ target: { name: 'name', value: firstCTName } });
|
||||||
this.props.onChange({ target: { name: 'params.key', value: secondCTName } });
|
this.props.onChange({ target: { name: 'params.key', value: secondCTName } });
|
||||||
|
this.props.resetFormErrors();
|
||||||
} else {
|
} else {
|
||||||
this.props.onChange({ target: { name: 'name', value: '' } });
|
this.props.onChange({ target: { name: 'name', value: '' } });
|
||||||
this.props.onChange({ target: { name: 'params.key', value: '' } });
|
this.props.onChange({ target: { name: 'params.key', value: '' } });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChange = e => {
|
||||||
|
this.props.onChange(e);
|
||||||
|
const shouldResetKeyParams = e.target.value === 'oneWay';
|
||||||
|
|
||||||
|
if (!this.props.isEditting && !shouldResetKeyParams) {
|
||||||
|
this.setPlaceholders(
|
||||||
|
get(this.props.values, ['params', 'target']),
|
||||||
|
get(this.props.contentType, 'name'),
|
||||||
|
e.target.value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldResetKeyParams) {
|
||||||
|
this.props.onChange({ target: { name: 'params.key', value: '-' } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClick = e => {
|
||||||
|
const value = e.target.id.split('.');
|
||||||
|
[
|
||||||
|
{
|
||||||
|
target: {
|
||||||
|
type: 'string',
|
||||||
|
value: value[0],
|
||||||
|
name: 'params.target',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
target: {
|
||||||
|
type: 'string',
|
||||||
|
value: value[1] !== 'undefined' ? value[1] : '',
|
||||||
|
name: 'params.pluginValue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
].map(target => this.props.onChange(target));
|
||||||
|
|
||||||
|
if (!this.props.isEditting) {
|
||||||
|
if (get(this.props.contentType, 'name') !== value[0]) {
|
||||||
|
this.setPlaceholders(
|
||||||
|
value[0],
|
||||||
|
get(this.props.contentType, 'name'),
|
||||||
|
get(this.props.values, ['params', 'nature']),
|
||||||
|
value[0],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.props.onChange({ target: { name: 'name', value: '' } });
|
||||||
|
this.props.onChange({ target: { name: 'params.key', value: '' } });
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
init = props => {
|
init = props => {
|
||||||
@ -120,8 +149,8 @@ class PopUpRelations extends React.Component {
|
|||||||
|
|
||||||
if (get(props.contentType, 'name') !== get(props.dropDownItems, ['0', 'name'])) {
|
if (get(props.contentType, 'name') !== get(props.dropDownItems, ['0', 'name'])) {
|
||||||
[
|
[
|
||||||
{ target: { name: 'name', value: get(this.props.dropDownItems, ['0', 'name']) } },
|
{ target: { name: 'name', value: get(props.dropDownItems, ['0', 'name']) } },
|
||||||
{ target: { name: 'params.key', value: get(this.props.contentType, 'name') } },
|
{ target: { name: 'params.key', value: get(props.contentType, 'name') } },
|
||||||
].map(target => this.props.onChange(target));
|
].map(target => this.props.onChange(target));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -226,7 +255,7 @@ class PopUpRelations extends React.Component {
|
|||||||
/>
|
/>
|
||||||
<RelationNaturePicker
|
<RelationNaturePicker
|
||||||
selectedIco={get(this.props.values, ['params', 'nature'])}
|
selectedIco={get(this.props.values, ['params', 'nature'])}
|
||||||
onChange={this.props.onChange}
|
onChange={this.handleChange}
|
||||||
contentTypeName={get(this.props.contentType, 'name')}
|
contentTypeName={get(this.props.contentType, 'name')}
|
||||||
contentTypeTarget={get(this.props.values, ['params', 'target'])}
|
contentTypeTarget={get(this.props.values, ['params', 'target'])}
|
||||||
/>
|
/>
|
||||||
@ -318,6 +347,7 @@ PopUpRelations.propTypes = {
|
|||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
onSubmit: PropTypes.func.isRequired,
|
onSubmit: PropTypes.func.isRequired,
|
||||||
popUpTitle: PropTypes.string.isRequired,
|
popUpTitle: PropTypes.string.isRequired,
|
||||||
|
resetFormErrors: PropTypes.func.isRequired,
|
||||||
routePath: PropTypes.string.isRequired,
|
routePath: PropTypes.string.isRequired,
|
||||||
showLoader: PropTypes.bool,
|
showLoader: PropTypes.bool,
|
||||||
showRelation: PropTypes.bool.isRequired,
|
showRelation: PropTypes.bool.isRequired,
|
||||||
|
|||||||
@ -397,8 +397,6 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
|
|||||||
|
|
||||||
if (target.name === 'params.nature' && target.value === "oneWay") {
|
if (target.name === 'params.nature' && target.value === "oneWay") {
|
||||||
this.props.changeInputAttribute('params.key', '-');
|
this.props.changeInputAttribute('params.key', '-');
|
||||||
}else if (target.name === 'params.nature'){
|
|
||||||
this.props.changeInputAttribute('params.key', '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -575,6 +573,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
|
|||||||
formErrors={this.props.formErrors}
|
formErrors={this.props.formErrors}
|
||||||
didCheckErrors={this.props.didCheckErrors}
|
didCheckErrors={this.props.didCheckErrors}
|
||||||
isEditting={edit}
|
isEditting={edit}
|
||||||
|
resetFormErrors={this.props.resetFormErrors}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,9 @@ function formReducer(state = initialState, action) {
|
|||||||
.update('formErrors', (list) => list.splice(findIndex(state.get('formErrors').toJS(), ['target', 'name']), 1))
|
.update('formErrors', (list) => list.splice(findIndex(state.get('formErrors').toJS(), ['target', 'name']), 1))
|
||||||
.set('didCheckErrors', !state.get('didCheckErrors'));
|
.set('didCheckErrors', !state.get('didCheckErrors'));
|
||||||
case RESET_FORM_ERRORS:
|
case RESET_FORM_ERRORS:
|
||||||
return state.set('formErrors', List());
|
return state
|
||||||
|
.update('didCheckErrors', v => v = !v)
|
||||||
|
.set('formErrors', List());
|
||||||
case RESET_IS_FORM_SET:
|
case RESET_IS_FORM_SET:
|
||||||
return state
|
return state
|
||||||
.set('isFormSet', false)
|
.set('isFormSet', false)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user