Fix set defaultDbConnection bug

This commit is contained in:
cyril lopez 2017-08-09 09:17:53 +02:00
parent c83e68141a
commit 1cbe94941d
6 changed files with 37 additions and 5 deletions

View File

@ -67,12 +67,12 @@ class List extends React.Component { // eslint-disable-line react/prefer-statele
}
toggle = () => {
if (this.props.actionBeforeOpenPopUp && !this.state.modal) this.props.actionBeforeOpenPopUp();
this.setState({ modal: !this.state.modal });
}
handleSubmit = (e) => {
e.preventDefault();
// this.setState({ modal: !this.state.modal });
if (this.state.isPopUpFormValid) {
this.setState({ modal: !this.state.modal });
@ -153,6 +153,7 @@ class List extends React.Component { // eslint-disable-line react/prefer-statele
}
List.propTypes = {
actionBeforeOpenPopUp: React.PropTypes.func,
handlei18n: React.PropTypes.bool,
handleListPopUpSubmit: React.PropTypes.func,
listButtonLabel: React.PropTypes.string,

View File

@ -29,6 +29,7 @@ import {
DATABASE_EDIT,
LANGUAGE_ACTION_ERROR,
DATABASE_ACTION_ERROR,
EMPTY_DB_MODIFIED_DATA,
} from './constants';
export function defaultAction() {
@ -281,3 +282,9 @@ export function databaseEdit(data, apiUrl) {
apiUrl,
};
}
export function emptyDbModifiedData() {
return {
type: EMPTY_DB_MODIFIED_DATA,
};
}

View File

@ -28,3 +28,4 @@ export const SPECIFIC_DATABASE_FETCH = 'SettingsManager/Home/SPECIFIC_DATABASE_F
export const SPECIFIC_DATABASE_FETCH_SUCCEEDED = 'SettingsManager/Home/SPECIFIC_DATABASE_FETCH_SUCCEEDED';
export const DATABASE_EDIT = 'SettingsManager/Home/DATABASE_EDIT';
export const DATABASE_ACTION_ERROR = 'SettingsManager/Home/DATABASE_ACTION_ERROR';
export const EMPTY_DB_MODIFIED_DATA = 'SettingsManager/Home/EMPTY_DB_MODIFIED_DATA';

View File

@ -53,6 +53,7 @@ import {
databasesFetch,
databaseDelete,
editSettings,
emptyDbModifiedData,
languageDelete,
languagesFetch,
newLanguagePost,
@ -322,6 +323,10 @@ export class Home extends React.Component { // eslint-disable-line react/prefer-
/>
)
emptyDbModifiedData = () => {
this.setState({ toggleDefaultConnection: false });
this.props.emptyDbModifiedData();
}
renderComponent = () => {
// check if settingName (params.slug) has a custom view display
const specificComponent = findKey(this.customComponents, (value) => includes(value, this.props.params.slug)) || 'defaultComponent';
@ -339,6 +344,7 @@ export class Home extends React.Component { // eslint-disable-line react/prefer-
let sections;
let renderPopUpForm = false;
let renderRow = false;
let actionBeforeOpenPopUp;
switch (this.props.params.slug) {
case 'languages':
@ -354,6 +360,7 @@ export class Home extends React.Component { // eslint-disable-line react/prefer-
renderPopUpForm = this.renderPopUpFormDatabase;
handleListPopUpSubmit = this.addConnection;
renderRow = this.renderRowDatabase;
actionBeforeOpenPopUp = this.emptyDbModifiedData;
break;
default:
sections = this.props.home.configsDisplay.sections;
@ -382,16 +389,16 @@ export class Home extends React.Component { // eslint-disable-line react/prefer-
renderPopUpForm={renderPopUpForm}
renderListComponent={renderListComponent}
cancelAction={this.props.home.cancelAction}
actionBeforeOpenPopUp={actionBeforeOpenPopUp}
/>
);
}
setDefaultConnectionDb = (e) => {
setDefaultConnectionDb = () => {
const value = this.state.toggleDefaultConnection ?
this.props.home.addDatabaseSection.sections[1].items[0].value
: this.props.home.modifiedData[this.props.home.dbNameTarget];
// const target = { name: e.target.id, value: this.props.home.modifiedData[this.props.home.dbNameTarget] }
const target = { name: e.target.id, value };
const target = { name: 'database.defaultConnection', value };
this.handleChange({target});
this.setState({ toggleDefaultConnection: !this.state.toggleDefaultConnection });
}
@ -452,6 +459,7 @@ function mapDispatchToProps(dispatch) {
databaseEdit,
databasesFetch,
editSettings,
emptyDbModifiedData,
languageDelete,
languagesFetch,
newDatabasePost,
@ -471,6 +479,7 @@ Home.propTypes = {
databaseEdit: React.PropTypes.func,
databasesFetch: React.PropTypes.func,
editSettings: React.PropTypes.func,
emptyDbModifiedData: React.PropTypes.func,
environments: React.PropTypes.array,
home: React.PropTypes.object,
languageDelete: React.PropTypes.func,

View File

@ -22,6 +22,7 @@ import {
DATABASE_DELETE,
DATABASE_ACTION_ERROR,
NEW_LANGUAGE_POST,
EMPTY_DB_MODIFIED_DATA,
} from './constants';
/* eslint-disable new-cap */
@ -39,6 +40,7 @@ const initialState = fromJS({
dbNameTarget: '',
selectOptions: Map(),
});
/* eslint-disable no-case-declarations */
function homeReducer(state = initialState, action) {
switch (action.type) {
@ -92,6 +94,11 @@ function homeReducer(state = initialState, action) {
case LANGUAGE_ACTION_ERROR:
return state.set('didCreatedNewLanguage', true);
case DATABASE_ACTION_SUCCEEDED:
const newDefaultDbConnection = state.getIn(['modifiedData', 'database.defaultConnection']);
return state
.set('modifiedData', Map())
.setIn(['modifiedData', 'database.defaultConnection'], newDefaultDbConnection)
.set('didCreatedNewDb', true);
case DATABASE_ACTION_ERROR:
return state.set('didCreatedNewDb', true);
case SPECIFIC_DATABASE_FETCH_SUCCEEDED:
@ -100,7 +107,13 @@ function homeReducer(state = initialState, action) {
.set('dbNameTarget', action.dbNameTarget)
.set('initialData', Map(action.data))
.set('modifiedData', Map(action.data));
case NEW_LANGUAGE_POST: // eslint-disable-line no-case-declarations
case EMPTY_DB_MODIFIED_DATA:
const defaultDbConnection = state.getIn(['modifiedData', 'database.defaultConnection']);
return state
.set('modifiedData', Map())
.set('dbNameTarget', 'database.connections.${name}.name') // eslint-disable-line no-template-curly-in-string
.setIn(['modifiedData', 'database.defaultConnection'], defaultDbConnection);
case NEW_LANGUAGE_POST:
const sections = state.getIn(['configsDisplay', 'sections']);
sections.push({ active: false, name: state.getIn(['modifiedData', 'language.defaultLocale']) });
const newSections = sortBy(sections, (o) => o.name);

View File

@ -221,6 +221,7 @@ export function* postDatabase(action) {
});
yield put(databaseActionSucceeded());
window.Strapi.notification.success('New Database added');
} catch(error) {
window.Strapi.notification.error('An error occured');