Skip to content

Commit 36e4987

Browse files
committed
feat: confirmation on config param update
1 parent e3bf21d commit 36e4987

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/dashboard/Data/Browser/Browser.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,8 @@ body:global(.expanded) {
270270

271271
.noScroll {
272272
overflow-x: hidden;
273+
}
274+
275+
.confimConfig {
276+
padding: 10px 20px;
273277
}

src/dashboard/Data/Config/Config.react.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import TableView from 'dashboard/TableView.react';
2121
import Toolbar from 'components/Toolbar/Toolbar.react';
2222
import browserStyles from 'dashboard/Data/Browser/Browser.scss';
2323
import { CurrentApp } from 'context/currentApp';
24+
import Modal from 'components/Modal/Modal.react';
2425

2526
@subscribeTo('Config', 'config')
2627
class Config extends TableView {
@@ -38,6 +39,7 @@ class Config extends TableView {
3839
modalValue: '',
3940
modalMasterKeyOnly: false,
4041
loading: false,
42+
confirmModalOpen: false,
4143
};
4244
}
4345

@@ -58,6 +60,7 @@ class Config extends TableView {
5860
loadData() {
5961
this.setState({ loading: true });
6062
this.props.config.dispatch(ActionTypes.FETCH).finally(() => {
63+
this.cacheData = new Map(this.props.config.data);
6164
this.setState({ loading: false });
6265
});
6366
}
@@ -101,6 +104,30 @@ class Config extends TableView {
101104
/>
102105
);
103106
}
107+
108+
if (this.state.confirmModalOpen) {
109+
extras = (
110+
<Modal
111+
type={Modal.Types.INFO}
112+
icon="warn-outline"
113+
title={'Are you sure?'}
114+
confirmText="Continue"
115+
cancelText="Cancel"
116+
onCancel={() => this.setState({ confirmModalOpen: false })}
117+
onConfirm={() => {
118+
this.setState({ confirmModalOpen: false });
119+
this.saveParam({
120+
...this.confirmData,
121+
override: true,
122+
});
123+
}}
124+
>
125+
<div className={[browserStyles.confimConfig]}>
126+
The parameter you are trying to edit has been modified by another user. Do you want to continue?
127+
</div>
128+
</Modal>
129+
);
130+
}
104131
return extras;
105132
}
106133

@@ -244,7 +271,27 @@ class Config extends TableView {
244271
return data;
245272
}
246273

247-
saveParam({ name, value, type, masterKeyOnly }) {
274+
async saveParam({ name, value, type, masterKeyOnly, override }) {
275+
const cachedParams = this.cacheData.get('params');
276+
const cachedValue = cachedParams.get(name);
277+
278+
await this.props.config.dispatch(ActionTypes.FETCH);
279+
const fetchedParams = this.props.config.data.get('params');
280+
281+
if (cachedValue !== fetchedParams.get(name) && !override) {
282+
this.setState({
283+
confirmModalOpen: true,
284+
modalOpen: false,
285+
});
286+
this.confirmData = {
287+
name,
288+
value,
289+
type,
290+
masterKeyOnly,
291+
};
292+
return;
293+
}
294+
248295
this.props.config
249296
.dispatch(ActionTypes.SET, {
250297
param: name,

0 commit comments

Comments
 (0)