Commit dc73bc50 authored by Jesús Espino's avatar Jesús Espino Committed by George Goldberg
Browse files

MM-10770: Add confirm modal on exit team scheme and system scheme edition (#1285)

parent 96ef8873
......@@ -8,6 +8,8 @@ import {loadRolesIfNeeded, editRole} from 'mattermost-redux/actions/roles';
import {getRoles} from 'mattermost-redux/selectors/entities/roles';
import {setNavigationBlocked} from 'actions/admin_actions.jsx';
import PermissionSystemSchemeSettings from './permission_system_scheme_settings.jsx';
function mapStateToProps(state) {
......@@ -22,6 +24,7 @@ function mapDispatchToProps(dispatch) {
actions: bindActionCreators({
loadRolesIfNeeded,
editRole,
setNavigationBlocked,
}, dispatch),
};
}
......
......@@ -4,7 +4,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import {Link} from 'react-router-dom';
import {Modal} from 'react-bootstrap';
import {PermissionsScope, DefaultRolePermissions} from 'utils/constants.jsx';
......@@ -14,6 +13,7 @@ import SaveButton from 'components/save_button.jsx';
import LoadingScreen from 'components/loading_screen.jsx';
import AccordionToggleIcon from 'components/svg/accordion_toggle_icon.jsx';
import FormError from 'components/form_error.jsx';
import BlockableLink from 'components/admin_console/blockable_link';
import PermissionsTree from '../permissions_tree.jsx';
......@@ -24,6 +24,7 @@ export default class PermissionSystemSchemeSettings extends React.Component {
actions: PropTypes.shape({
loadRolesIfNeeded: PropTypes.func.isRequired,
editRole: PropTypes.func.isRequired,
setNavigationBlocked: PropTypes.func.isRequired,
}).isRequired,
};
......@@ -145,6 +146,7 @@ export default class PermissionSystemSchemeSettings extends React.Component {
}
}
this.setState({serverError, saving: false, saveNeeded});
this.props.actions.setNavigationBlocked(saveNeeded);
}
);
}
......@@ -170,6 +172,7 @@ export default class PermissionSystemSchemeSettings extends React.Component {
roles[roleId] = role;
this.setState({roles, saveNeeded: true});
this.props.actions.setNavigationBlocked(true);
}
resetDefaults = () => {
......@@ -180,6 +183,7 @@ export default class PermissionSystemSchemeSettings extends React.Component {
});
this.setState({roles: newRolesState, saveNeeded: true});
this.props.actions.setNavigationBlocked(true);
}
render = () => {
......@@ -191,7 +195,7 @@ export default class PermissionSystemSchemeSettings extends React.Component {
<div className='wrapper--fixed'>
<h3 className={'admin-console-header ' + (hasCustomSchemes ? 'with-back' : '')}>
{hasCustomSchemes &&
<Link
<BlockableLink
to='/admin_console/permissions/schemes'
className='fa fa-chevron-left back'
/>}
......@@ -350,7 +354,7 @@ export default class PermissionSystemSchemeSettings extends React.Component {
onClick={this.handleSubmit}
savingMessage={localizeMessage('admin.saving', 'Saving Config...')}
/>
<Link
<BlockableLink
className='cancel-button'
to='/admin_console/permissions/schemes'
>
......@@ -358,7 +362,7 @@ export default class PermissionSystemSchemeSettings extends React.Component {
id='admin.permissions.permissionSchemes.cancel'
defaultMessage='Cancel'
/>
</Link>
</BlockableLink>
<a
onClick={() => this.setState({showResetDefaultModal: true})}
className='cancel-button reset-defaults-btn'
......
......@@ -10,8 +10,11 @@ import {getRoles} from 'mattermost-redux/selectors/entities/roles';
import {getScheme, makeGetSchemeTeams} from 'mattermost-redux/selectors/entities/schemes';
import {getScheme as loadScheme, patchScheme, createScheme, getSchemeTeams as loadSchemeTeams} from 'mattermost-redux/actions/schemes';
import {updateTeamScheme} from 'mattermost-redux/actions/teams';
import {setNavigationBlocked} from 'actions/admin_actions.jsx';
import PermissionTeamSchemeSettings from './permission_team_scheme_settings.jsx';
function makeMapStateToProps() {
......@@ -39,6 +42,7 @@ function mapDispatchToProps(dispatch) {
patchScheme,
updateTeamScheme,
createScheme,
setNavigationBlocked,
}, dispatch),
};
}
......
......@@ -4,7 +4,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import {Link} from 'react-router-dom';
import {PermissionsScope} from 'utils/constants.jsx';
import {localizeMessage} from 'utils/utils.jsx';
......@@ -14,6 +13,7 @@ import LoadingScreen from 'components/loading_screen.jsx';
import AccordionToggleIcon from 'components/svg/accordion_toggle_icon.jsx';
import FormError from 'components/form_error.jsx';
import TeamSelectorModal from 'components/team_selector_modal';
import BlockableLink from 'components/admin_console/blockable_link';
import PermissionsTree from '../permissions_tree.jsx';
......@@ -33,6 +33,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
patchScheme: PropTypes.func.isRequired,
createScheme: PropTypes.func.isRequired,
updateTeamScheme: PropTypes.func.isRequired,
setNavigationBlocked: PropTypes.func.isRequired,
}).isRequired,
};
......@@ -174,10 +175,12 @@ export default class PermissionTeamSchemeSettings extends React.Component {
handleNameChange = (e) => {
this.setState({schemeName: e.target.value, saveNeeded: true});
this.props.actions.setNavigationBlocked(true);
}
handleDescriptionChange = (e) => {
this.setState({schemeDescription: e.target.value, saveNeeded: true});
this.props.actions.setNavigationBlocked(true);
}
handleSubmit = async () => {
......@@ -220,6 +223,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
});
if (result.error) {
this.setState({serverError: result.error.message, saving: false, saveNeeded: true});
this.props.actions.setNavigationBlocked(true);
return;
}
const newScheme = result.data;
......@@ -273,6 +277,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
}
this.setState({serverError, saving: false, saveNeeded});
this.props.actions.setNavigationBlocked(saveNeeded);
this.props.history.push('/admin_console/permissions/schemes');
}
......@@ -310,6 +315,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
}
this.setState({roles, saveNeeded: true});
this.props.actions.setNavigationBlocked(true);
}
openAddTeam = () => {
......@@ -319,6 +325,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
removeTeam = (teamId) => {
const teams = (this.state.teams || this.props.teams).filter((team) => team.id !== teamId);
this.setState({teams, saveNeeded: true});
this.props.actions.setNavigationBlocked(true);
}
addTeams = (teams) => {
......@@ -327,6 +334,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
teams: [...currentTeams, ...teams],
saveNeeded: true,
});
this.props.actions.setNavigationBlocked(true);
}
closeAddTeam = () => {
......@@ -352,7 +360,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
/>
}
<h3 className='admin-console-header with-back'>
<Link
<BlockableLink
to='/admin_console/permissions/schemes'
className='fa fa-chevron-left back'
/>
......@@ -584,7 +592,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
onClick={this.handleSubmit}
savingMessage={localizeMessage('admin.saving', 'Saving Config...')}
/>
<Link
<BlockableLink
className='cancel-button'
to='/admin_console/permissions/schemes'
>
......@@ -592,7 +600,7 @@ export default class PermissionTeamSchemeSettings extends React.Component {
id='admin.permissions.permissionSchemes.cancel'
defaultMessage='Cancel'
/>
</Link>
</BlockableLink>
<div className='error-message'>
<FormError error={this.state.serverError}/>
</div>
......
......@@ -7,9 +7,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
<h3
className="admin-console-header with-back"
>
<Link
<Connect(BlockableLink)
className="fa fa-chevron-left back"
replace={false}
to="/admin_console/permissions/schemes"
/>
<FormattedMessage
......@@ -242,9 +241,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
saving={false}
savingMessage="Saving Config..."
/>
<Link
<Connect(BlockableLink)
className="cancel-button"
replace={false}
to="/admin_console/permissions/schemes"
>
<FormattedMessage
......@@ -252,7 +250,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
id="admin.permissions.permissionSchemes.cancel"
values={Object {}}
/>
</Link>
</Connect(BlockableLink)>
<a
className="cancel-button reset-defaults-btn"
onClick={[Function]}
......@@ -650,9 +648,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
saving={false}
savingMessage="Saving Config..."
/>
<Link
<Connect(BlockableLink)
className="cancel-button"
replace={false}
to="/admin_console/permissions/schemes"
>
<FormattedMessage
......@@ -660,7 +657,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
id="admin.permissions.permissionSchemes.cancel"
values={Object {}}
/>
</Link>
</Connect(BlockableLink)>
<a
className="cancel-button reset-defaults-btn"
onClick={[Function]}
......@@ -770,9 +767,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
<h3
className="admin-console-header with-back"
>
<Link
<Connect(BlockableLink)
className="fa fa-chevron-left back"
replace={false}
to="/admin_console/permissions/schemes"
/>
<FormattedMessage
......@@ -987,9 +983,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
saving={false}
savingMessage="Saving Config..."
/>
<Link
<Connect(BlockableLink)
className="cancel-button"
replace={false}
to="/admin_console/permissions/schemes"
>
<FormattedMessage
......@@ -997,7 +992,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_system_
id="admin.permissions.permissionSchemes.cancel"
values={Object {}}
/>
</Link>
</Connect(BlockableLink)>
<a
className="cancel-button reset-defaults-btn"
onClick={[Function]}
......
......@@ -7,9 +7,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
<h3
className="admin-console-header with-back"
>
<Link
<Connect(BlockableLink)
className="fa fa-chevron-left back"
replace={false}
to="/admin_console/permissions/schemes"
/>
<FormattedMessage
......@@ -319,9 +318,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
saving={false}
savingMessage="Saving Config..."
/>
<Link
<Connect(BlockableLink)
className="cancel-button"
replace={false}
to="/admin_console/permissions/schemes"
>
<FormattedMessage
......@@ -329,7 +327,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
id="admin.permissions.permissionSchemes.cancel"
values={Object {}}
/>
</Link>
</Connect(BlockableLink)>
<div
className="error-message"
>
......@@ -372,9 +370,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
<h3
className="admin-console-header with-back"
>
<Link
<Connect(BlockableLink)
className="fa fa-chevron-left back"
replace={false}
to="/admin_console/permissions/schemes"
/>
<FormattedMessage
......@@ -671,9 +668,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
saving={false}
savingMessage="Saving Config..."
/>
<Link
<Connect(BlockableLink)
className="cancel-button"
replace={false}
to="/admin_console/permissions/schemes"
>
<FormattedMessage
......@@ -681,7 +677,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
id="admin.permissions.permissionSchemes.cancel"
values={Object {}}
/>
</Link>
</Connect(BlockableLink)>
<div
className="error-message"
>
......@@ -717,9 +713,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
<h3
className="admin-console-header with-back"
>
<Link
<Connect(BlockableLink)
className="fa fa-chevron-left back"
replace={false}
to="/admin_console/permissions/schemes"
/>
<FormattedMessage
......@@ -1029,9 +1024,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
saving={false}
savingMessage="Saving Config..."
/>
<Link
<Connect(BlockableLink)
className="cancel-button"
replace={false}
to="/admin_console/permissions/schemes"
>
<FormattedMessage
......@@ -1039,7 +1033,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
id="admin.permissions.permissionSchemes.cancel"
values={Object {}}
/>
</Link>
</Connect(BlockableLink)>
<div
className="error-message"
>
......@@ -1092,9 +1086,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
<h3
className="admin-console-header with-back"
>
<Link
<Connect(BlockableLink)
className="fa fa-chevron-left back"
replace={false}
to="/admin_console/permissions/schemes"
/>
<FormattedMessage
......@@ -1391,9 +1384,8 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
saving={false}
savingMessage="Saving Config..."
/>
<Link
<Connect(BlockableLink)
className="cancel-button"
replace={false}
to="/admin_console/permissions/schemes"
>
<FormattedMessage
......@@ -1401,7 +1393,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_team_sc
id="admin.permissions.permissionSchemes.cancel"
values={Object {}}
/>
</Link>
</Connect(BlockableLink)>
<div
className="error-message"
>
......
......@@ -38,6 +38,7 @@ describe('components/admin_console/permission_schemes_settings/permission_system
actions: {
loadRolesIfNeeded: jest.fn().mockReturnValue(Promise.resolve()),
editRole: jest.fn(),
setNavigationBlocked: jest.fn(),
},
};
......
......@@ -61,6 +61,7 @@ describe('components/admin_console/permission_schemes_settings/permission_team_s
patchScheme: jest.fn(),
createScheme: jest.fn(),
updateTeamScheme: jest.fn(),
setNavigationBlocked: jest.fn(),
},
history: {
push: jest.fn(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment