Skip to content

Commit 6cfcb46

Browse files
fn-faisalfaisal154
andauthored
Add option to create a field after creating a class #1726 (#1728)
* combined create class flow * config revert * reformating -- 1 * reset forms after submitting * Improve feed back for add column dialog * improve add column dialog -- 2 * reverting isDisabled * mergeconflicts resolve 2 * required column changes * required col in addAndContinue * removed index.html Co-authored-by: Faisal Nadeem <mfaisalnadeem@hotmail.com>
1 parent 526fedd commit 6cfcb46

File tree

5 files changed

+71
-18
lines changed

5 files changed

+71
-18
lines changed

Parse-Dashboard/parse-dashboard-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
}
1212
],
1313
"iconsFolder": "icons"
14-
}
14+
}

src/components/Modal/Modal.react.js

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ let Modal = (({
3939
customFooter,
4040
textModal = false,
4141
width,
42+
continueText,
43+
onContinue,
44+
showContinue,
4245
buttonsInCenter = React.Children.count(children) === 0,
4346
}) => {
4447
if (children) {
@@ -63,6 +66,15 @@ let Modal = (({
6366
disabled={!!disabled}
6467
onClick={onConfirm}
6568
progress={progress} />
69+
{
70+
showContinue === true ?
71+
<Button
72+
primary={true}
73+
value={continueText}
74+
color={buttonColors[type]}
75+
disabled={!!disabled}
76+
onClick={onContinue}
77+
progress={progress} />: null}
6678
</div>
6779
);
6880

src/dashboard/Data/Browser/AddColumnDialog.react.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ export default class AddColumnDialog extends React.Component {
206206
confirmText='Add column'
207207
cancelText={'Never mind, don\u2019t.'}
208208
onCancel={this.props.onCancel}
209+
continueText={'Add column & continue'}
210+
showContinue={true}
211+
onContinue={() => {
212+
this.props.onContinue(this.state);
213+
}}
209214
onConfirm={() => {
210215
this.props.onConfirm(this.state);
211216
}}>
@@ -246,4 +251,4 @@ export default class AddColumnDialog extends React.Component {
246251
</Modal>
247252
);
248253
}
249-
}
254+
}

src/dashboard/Data/Browser/Browser.react.js

+42-16
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Browser extends DashboardView {
7979

8080
isUnique: false,
8181
uniqueField: null,
82+
keepAddingCols: false,
8283
markRequiredField: false,
8384
requiredColumnFields: []
8485
};
@@ -117,6 +118,7 @@ class Browser extends DashboardView {
117118
this.showCreateClass = this.showCreateClass.bind(this);
118119
this.createClass = this.createClass.bind(this);
119120
this.addColumn = this.addColumn.bind(this);
121+
this.addColumnAndContinue = this.addColumnAndContinue.bind(this);
120122
this.removeColumn = this.removeColumn.bind(this);
121123
this.showNote = this.showNote.bind(this);
122124
this.showEditRowDialog = this.showEditRowDialog.bind(this);
@@ -274,6 +276,21 @@ class Browser extends DashboardView {
274276
});
275277
}
276278

279+
newColumn(payload, required) {
280+
return this.props.schema.dispatch(ActionTypes.ADD_COLUMN, payload)
281+
.then(() => {
282+
if (required) {
283+
let requiredCols = [...this.state.requiredColumnFields, name];
284+
this.setState({
285+
requiredColumnFields: requiredCols
286+
});
287+
}
288+
})
289+
.catch((err) => {
290+
this.showNote(err.message, true);
291+
});
292+
}
293+
277294
addColumn({ type, name, target, required, defaultValue }) {
278295
let payload = {
279296
className: this.props.params.className,
@@ -283,18 +300,23 @@ class Browser extends DashboardView {
283300
required,
284301
defaultValue
285302
};
286-
this.props.schema.dispatch(ActionTypes.ADD_COLUMN, payload).then(() => {
287-
// if new required field column is added, then add field in requiredColumn
288-
if (required) {
289-
let requiredCols = [...this.state.requiredColumnFields, name];
290-
this.setState({
291-
requiredColumnFields: requiredCols
292-
});
293-
}
294-
}).catch((err) => {
295-
this.showNote(err.message, true);
296-
}).finally(() => {
297-
this.setState({ showAddColumnDialog: false });
303+
this.newColumn(payload, required).finally(() => {
304+
this.setState({ showAddColumnDialog: false, keepAddingCols: false });
305+
});
306+
}
307+
308+
addColumnAndContinue({ type, name, target, required, defaultValue }) {
309+
let payload = {
310+
className: this.props.params.className,
311+
columnType: type,
312+
name: name,
313+
targetClass: target,
314+
required,
315+
defaultValue
316+
};
317+
this.newColumn(payload, required).finally(() => {
318+
this.setState({ showAddColumnDialog: false, keepAddingCols: false });
319+
this.setState({ showAddColumnDialog: true, keepAddingCols: true });
298320
});
299321
}
300322

@@ -412,7 +434,7 @@ class Browser extends DashboardView {
412434
}
413435
this.state.counts[obj.className] += 1;
414436
}
415-
437+
416438
this.setState(state);
417439
},
418440
error => {
@@ -599,7 +621,7 @@ class Browser extends DashboardView {
599621
// Construct complex pagination query
600622
let equalityQuery = queryFromFilters(source, this.state.filters);
601623
let comp = this.state.data[this.state.data.length - 1].get(field);
602-
624+
603625
if (sortDir === '-') {
604626
query.lessThan(field, comp);
605627
equalityQuery.lessThan('objectId', this.state.data[this.state.data.length - 1].id);
@@ -719,7 +741,7 @@ class Browser extends DashboardView {
719741
} else {
720742
obj.set(attr, value);
721743
}
722-
744+
723745
if (isNewObject) {
724746
// for dynamically changing required placeholder text for _User class new row object
725747
if (obj.className === '_User' && attr === 'authData' && value !== undefined) {
@@ -739,7 +761,7 @@ class Browser extends DashboardView {
739761
if (obj.className === '_User' && obj.get('username') === undefined && obj.get('password') === undefined && obj.get('authData') === undefined) {
740762
this.setRequiredColumnFields();
741763
}
742-
764+
743765
this.setState({
744766
isNewObject: obj
745767
});
@@ -1209,6 +1231,8 @@ class Browser extends DashboardView {
12091231
if (this.state.showCreateClassDialog) {
12101232
extras = (
12111233
<CreateClassDialog
1234+
currentAppSlug={this.context.currentApp.slug}
1235+
onAddColumn={this.showAddColumn}
12121236
currentClasses={this.props.schema.data.get('classes').keySeq().toArray()}
12131237
onCancel={() => this.setState({ showCreateClassDialog: false })}
12141238
onConfirm={this.createClass} />
@@ -1221,10 +1245,12 @@ class Browser extends DashboardView {
12211245
});
12221246
extras = (
12231247
<AddColumnDialog
1248+
onAddColumn={this.showAddColumn}
12241249
currentColumns={currentColumns}
12251250
classes={this.props.schema.data.get('classes').keySeq().toArray()}
12261251
onCancel={() => this.setState({ showAddColumnDialog: false })}
12271252
onConfirm={this.addColumn}
1253+
onContinue={this.addColumnAndContinue}
12281254
showNote={this.showNote}
12291255
parseServerVersion={currentApp.serverInfo && currentApp.serverInfo.parseServerVersion} />
12301256
);

src/dashboard/Data/Browser/CreateClassDialog.react.js

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Option from 'components/Dropdown/Option.react';
1313
import React from 'react';
1414
import { SpecialClasses } from 'lib/Constants';
1515
import TextInput from 'components/TextInput/TextInput.react';
16+
import history from 'dashboard/history';
1617

1718
function validClassName(name) {
1819
return !!name.match(/^[a-zA-Z][_a-zA-Z0-9]*$/);
@@ -68,7 +69,16 @@ export default class CreateClassDialog extends React.Component {
6869
disabled={!this.valid()}
6970
confirmText='Create class'
7071
cancelText={'Cancel'}
72+
continueText={'Create class & add columns'}
7173
onCancel={this.props.onCancel}
74+
showContinue={true}
75+
onContinue={async () => {
76+
let type = this.state.type;
77+
let className = type === 'Custom' ? this.state.name : '_' + type;
78+
await this.props.onConfirm(className);
79+
history.push(`/apps/${this.props.currentAppSlug}/browser/${className}`);
80+
this.props.onAddColumn();
81+
}}
7282
onConfirm={() => {
7383
let type = this.state.type;
7484
let className = type === 'Custom' ? this.state.name : '_' + type;

0 commit comments

Comments
 (0)