Skip to content

Commit 0f6dc7b

Browse files
mtrezzadavimacedo
andcommitted
added config param delete confirmation dialog (#1443)
* added config param delete confirmation dialog * fixed parameter not deleted Co-authored-by: Antonio Davi Macedo Coelho de Castro <[email protected]>
1 parent e6983f8 commit 0f6dc7b

File tree

2 files changed

+105
-28
lines changed

2 files changed

+105
-28
lines changed

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

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8-
import { ActionTypes } from 'lib/stores/ConfigStore';
9-
import Button from 'components/Button/Button.react';
10-
import ConfigDialog from 'dashboard/Data/Config/ConfigDialog.react';
11-
import EmptyState from 'components/EmptyState/EmptyState.react';
12-
import Icon from 'components/Icon/Icon.react';
13-
import { isDate } from 'lib/DateUtils';
14-
import Parse from 'parse';
15-
import React from 'react';
16-
import SidebarAction from 'components/Sidebar/SidebarAction';
17-
import subscribeTo from 'lib/subscribeTo';
18-
import TableHeader from 'components/Table/TableHeader.react';
19-
import TableView from 'dashboard/TableView.react';
20-
import Toolbar from 'components/Toolbar/Toolbar.react';
8+
import { ActionTypes } from 'lib/stores/ConfigStore';
9+
import Button from 'components/Button/Button.react';
10+
import ConfigDialog from 'dashboard/Data/Config/ConfigDialog.react';
11+
import DeleteParameterDialog from 'dashboard/Data/Config/DeleteParameterDialog.react';
12+
import EmptyState from 'components/EmptyState/EmptyState.react';
13+
import Icon from 'components/Icon/Icon.react';
14+
import { isDate } from 'lib/DateUtils';
15+
import Parse from 'parse';
16+
import React from 'react';
17+
import SidebarAction from 'components/Sidebar/SidebarAction';
18+
import subscribeTo from 'lib/subscribeTo';
19+
import TableHeader from 'components/Table/TableHeader.react';
20+
import TableView from 'dashboard/TableView.react';
21+
import Toolbar from 'components/Toolbar/Toolbar.react';
2122

2223
@subscribeTo('Config', 'config')
2324
class Config extends TableView {
@@ -28,6 +29,7 @@ class Config extends TableView {
2829
this.action = new SidebarAction('Create a parameter', this.createParameter.bind(this));
2930
this.state = {
3031
modalOpen: false,
32+
showDeleteParameterDialog: false,
3133
modalParam: '',
3234
modalType: 'String',
3335
modalValue: '',
@@ -56,20 +58,28 @@ class Config extends TableView {
5658
}
5759

5860
renderExtras() {
59-
if (!this.state.modalOpen) {
60-
return null;
61-
}
6261
const { currentApp = {} } = this.context;
63-
return (
64-
<ConfigDialog
65-
onConfirm={this.saveParam.bind(this)}
66-
onCancel={() => this.setState({ modalOpen: false })}
67-
param={this.state.modalParam}
68-
type={this.state.modalType}
69-
value={this.state.modalValue}
70-
masterKeyOnly={this.state.modalMasterKeyOnly}
71-
parseServerVersion={currentApp.serverInfo && currentApp.serverInfo.parseServerVersion} />
72-
);
62+
let extras = null;
63+
if (this.state.modalOpen) {
64+
extras = (
65+
<ConfigDialog
66+
onConfirm={this.saveParam.bind(this)}
67+
onCancel={() => this.setState({ modalOpen: false })}
68+
param={this.state.modalParam}
69+
type={this.state.modalType}
70+
value={this.state.modalValue}
71+
masterKeyOnly={this.state.modalMasterKeyOnly}
72+
parseServerVersion={currentApp.serverInfo && currentApp.serverInfo.parseServerVersion} />
73+
);
74+
} else if (this.state.showDeleteParameterDialog) {
75+
extras = (
76+
<DeleteParameterDialog
77+
param={this.state.modalParam}
78+
onCancel={() => this.setState({ showDeleteParameterDialog: false })}
79+
onConfirm={this.deleteParam.bind(this, this.state.modalParam)} />
80+
);
81+
}
82+
return extras;
7383
}
7484

7585
renderRow(data) {
@@ -119,6 +129,11 @@ class Config extends TableView {
119129
}
120130
openModal()
121131
}
132+
133+
let openDeleteParameterDialog = () => this.setState({
134+
showDeleteParameterDialog: true,
135+
modalParam: data.param
136+
});
122137

123138
return (
124139
<tr key={data.param}>
@@ -127,7 +142,7 @@ class Config extends TableView {
127142
<td style={columnStyleLarge} onClick={openModalValueColumn}>{value}</td>
128143
<td style={columnStyleSmall} onClick={openModal}>{data.masterKeyOnly.toString()}</td>
129144
<td style={{ textAlign: 'center' }}>
130-
<a onClick={this.deleteParam.bind(this, data.param)}>
145+
<a onClick={openDeleteParameterDialog}>
131146
<Icon width={16} height={16} name='trash-solid' fill='#ff395e' />
132147
</a>
133148
</td>
@@ -196,7 +211,9 @@ class Config extends TableView {
196211
this.props.config.dispatch(
197212
ActionTypes.DELETE,
198213
{ param: name }
199-
)
214+
).then(() => {
215+
this.setState({ showDeleteParameterDialog: false });
216+
});
200217
}
201218

202219
createParameter() {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2016-present, Parse, LLC
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the LICENSE file in
6+
* the root directory of this source tree.
7+
*/
8+
import Field from 'components/Field/Field.react';
9+
import Label from 'components/Label/Label.react';
10+
import Modal from 'components/Modal/Modal.react';
11+
import React from 'react';
12+
import TextInput from 'components/TextInput/TextInput.react';
13+
14+
export default class DeleteParameterDialog extends React.Component {
15+
constructor() {
16+
super();
17+
18+
this.state = {
19+
confirmation: ''
20+
};
21+
}
22+
23+
valid() {
24+
if (this.state.confirmation === this.props.param) {
25+
return true;
26+
}
27+
return false;
28+
}
29+
30+
render() {
31+
let content = (
32+
<Field
33+
label={
34+
<Label
35+
text='Confirm this action'
36+
description='Enter the parameter name to continue.' />
37+
}
38+
input={
39+
<TextInput
40+
placeholder='Parameter name'
41+
value={this.state.confirmation}
42+
onChange={(confirmation) => this.setState({ confirmation })} />
43+
} />
44+
);
45+
return (
46+
<Modal
47+
type={Modal.Types.DANGER}
48+
icon='warn-outline'
49+
title={`Delete parameter?`}
50+
subtitle={'This action cannot be undone!'}
51+
disabled={!this.valid()}
52+
confirmText={`Yes, delete`}
53+
cancelText={'Never mind, don\u2019t.'}
54+
onCancel={this.props.onCancel}
55+
onConfirm={this.props.onConfirm}>
56+
{content}
57+
</Modal>
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)