Skip to content

feat: Add confirmation dialog before saving a Cloud Config parameter that has been modified since loading it #2770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dashboard/Data/Browser/Browser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,8 @@ body:global(.expanded) {

.noScroll {
overflow-x: hidden;
}

.confirmConfig {
padding: 10px 20px;
}
49 changes: 48 additions & 1 deletion src/dashboard/Data/Config/Config.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import TableView from 'dashboard/TableView.react';
import Toolbar from 'components/Toolbar/Toolbar.react';
import browserStyles from 'dashboard/Data/Browser/Browser.scss';
import { CurrentApp } from 'context/currentApp';
import Modal from 'components/Modal/Modal.react';

@subscribeTo('Config', 'config')
class Config extends TableView {
Expand All @@ -38,6 +39,7 @@ class Config extends TableView {
modalValue: '',
modalMasterKeyOnly: false,
loading: false,
confirmModalOpen: false,
};
}

Expand All @@ -58,6 +60,7 @@ class Config extends TableView {
loadData() {
this.setState({ loading: true });
this.props.config.dispatch(ActionTypes.FETCH).finally(() => {
this.cacheData = new Map(this.props.config.data);
this.setState({ loading: false });
});
}
Expand Down Expand Up @@ -101,6 +104,30 @@ class Config extends TableView {
/>
);
}

if (this.state.confirmModalOpen) {
extras = (
<Modal
type={Modal.Types.INFO}
icon="warn-outline"
title={'Are you sure?'}
confirmText="Continue"
cancelText="Cancel"
onCancel={() => this.setState({ confirmModalOpen: false })}
onConfirm={() => {
this.setState({ confirmModalOpen: false });
this.saveParam({
...this.confirmData,
override: true,
});
}}
>
<div className={[browserStyles.confirmConfig]}>
The parameter you are trying to save has been modified while you were editing it. This means your edit is not based on the current parameter value. Do you want to continue and overwrite the other changes?
</div>
</Modal>
);
}
return extras;
}

Expand Down Expand Up @@ -244,7 +271,27 @@ class Config extends TableView {
return data;
}

saveParam({ name, value, type, masterKeyOnly }) {
async saveParam({ name, value, type, masterKeyOnly, override }) {
const cachedParams = this.cacheData.get('params');
const cachedValue = cachedParams.get(name);

await this.props.config.dispatch(ActionTypes.FETCH);
const fetchedParams = this.props.config.data.get('params');

if (cachedValue !== fetchedParams.get(name) && !override) {
this.setState({
confirmModalOpen: true,
modalOpen: false,
});
this.confirmData = {
name,
value,
type,
masterKeyOnly,
};
return;
}

this.props.config
.dispatch(ActionTypes.SET, {
param: name,
Expand Down
Loading