Skip to content

Commit 17fd7c8

Browse files
committed
feat(config): modal add array entry
1 parent ea80fd2 commit 17fd7c8

File tree

2 files changed

+78
-15
lines changed

2 files changed

+78
-15
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 AddArrayEntryDialog extends React.Component {
15+
constructor() {
16+
super();
17+
this.state = { value: '' };
18+
}
19+
20+
valid() {
21+
return this.state.value !== '';
22+
}
23+
24+
getValue() {
25+
try {
26+
return JSON.parse(this.state.value);
27+
} catch {
28+
return this.state.value;
29+
}
30+
}
31+
32+
render() {
33+
return (
34+
<Modal
35+
type={Modal.Types.INFO}
36+
icon="plus-solid"
37+
title="Add entry"
38+
confirmText="Add"
39+
cancelText="Cancel"
40+
onCancel={this.props.onCancel}
41+
onConfirm={() => this.props.onConfirm(this.getValue())}
42+
disabled={!this.valid()}
43+
>
44+
<Field
45+
label={<Label text="Value" />}
46+
input={<TextInput autofocus={true} value={this.state.value} onChange={value => this.setState({ value })} />}
47+
/>
48+
</Modal>
49+
);
50+
}
51+
}

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ActionTypes } from 'lib/stores/ConfigStore';
99
import Button from 'components/Button/Button.react';
1010
import ConfigDialog from 'dashboard/Data/Config/ConfigDialog.react';
1111
import DeleteParameterDialog from 'dashboard/Data/Config/DeleteParameterDialog.react';
12+
import AddArrayEntryDialog from 'dashboard/Data/Config/AddArrayEntryDialog.react';
1213
import EmptyState from 'components/EmptyState/EmptyState.react';
1314
import Icon from 'components/Icon/Icon.react';
1415
import { isDate } from 'lib/DateUtils';
@@ -44,6 +45,8 @@ class Config extends TableView {
4445
confirmModalOpen: false,
4546
lastError: null,
4647
lastNote: null,
48+
showAddEntryDialog: false,
49+
addEntryParam: '',
4750
};
4851
this.noteTimeout = null;
4952
}
@@ -111,6 +114,15 @@ class Config extends TableView {
111114
onConfirm={this.deleteParam.bind(this, this.state.modalParam)}
112115
/>
113116
);
117+
} else if (this.state.showAddEntryDialog) {
118+
extras = (
119+
<AddArrayEntryDialog
120+
onCancel={this.closeAddEntryDialog.bind(this)}
121+
onConfirm={value =>
122+
this.addArrayEntry(this.state.addEntryParam, value)
123+
}
124+
/>
125+
);
114126
}
115127

116128
if (this.state.confirmModalOpen) {
@@ -235,7 +247,8 @@ class Config extends TableView {
235247
// Define column styles
236248
const columnStyleLarge = { width: '30%', cursor: 'pointer' };
237249
const columnStyleSmall = { width: '15%', cursor: 'pointer' };
238-
const columnStyleAction = { width: '10%', textAlign: 'center' };
250+
const columnStyleValue = { width: '25%', cursor: 'pointer' };
251+
const columnStyleAction = { width: '10%' };
239252

240253
const openModalValueColumn = () => {
241254
if (data.value instanceof Parse.File) {
@@ -258,20 +271,20 @@ class Config extends TableView {
258271
<td style={columnStyleSmall} onClick={openModal}>
259272
{type}
260273
</td>
261-
<td style={columnStyleLarge} onClick={openModalValueColumn}>
274+
<td style={columnStyleValue} onClick={openModalValueColumn}>
262275
{value}
263276
</td>
264277
<td style={columnStyleAction}>
265278
{type === 'Array' && (
266-
<a onClick={() => this.addArrayEntry(data.param)}>
279+
<a onClick={() => this.openAddEntryDialog(data.param)}>
267280
<Icon width={16} height={16} name="plus-solid" />
268281
</a>
269282
)}
270283
</td>
271284
<td style={columnStyleSmall} onClick={openModal}>
272285
{data.masterKeyOnly.toString()}
273286
</td>
274-
<td style={{ textAlign: 'center' }}>
287+
<td style={{ textAlign: 'center', width: '5%' }}>
275288
<a onClick={openDeleteParameterDialog}>
276289
<Icon width={16} height={16} name="trash-solid" fill="#ff395e" />
277290
</a>
@@ -473,17 +486,15 @@ class Config extends TableView {
473486
}, 3500);
474487
}
475488

476-
async addArrayEntry(param) {
477-
const input = window.prompt('New array entry (JSON supported)');
478-
if (input === null) {
479-
return;
480-
}
481-
let value;
482-
try {
483-
value = JSON.parse(input);
484-
} catch (e) {
485-
value = input;
486-
}
489+
openAddEntryDialog(param) {
490+
this.setState({ showAddEntryDialog: true, addEntryParam: param });
491+
}
492+
493+
closeAddEntryDialog() {
494+
this.setState({ showAddEntryDialog: false, addEntryParam: '' });
495+
}
496+
497+
async addArrayEntry(param, value) {
487498
try {
488499
this.setState({ loading: true });
489500
await Parse._request(
@@ -503,6 +514,7 @@ class Config extends TableView {
503514
} finally {
504515
this.setState({ loading: false });
505516
}
517+
this.closeAddEntryDialog();
506518
}
507519
}
508520

0 commit comments

Comments
 (0)