Skip to content
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

Add option to create a field after creating a class #1726 #1728

Merged
merged 12 commits into from
Jul 26, 2021
2 changes: 1 addition & 1 deletion Parse-Dashboard/parse-dashboard-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
}
],
"iconsFolder": "icons"
}
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
}
40 changes: 40 additions & 0 deletions Parse-Dashboard/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<base href="/"/>
<script>
PARSE_DASHBOARD_PATH = "/";
</script>
</head>
<html>
<title>Parse Dashboard</title>
<body>
<div id="browser_mount"></div>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://a.back4app.com/a.js','ga');
ga('create', 'UA-66038885-1', 'auto');
ga('send', 'pageview');
setTimeout("ga('send','event','Profitable Engagement','time on page more than 30 seconds')",30000);
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
</script>
<!--Start of Zopim Live Chat Script-->
<script>
window.zEmbed||(function(){
var queue = [];

window.zEmbed = function() {
queue.push(arguments);
}
window.zE = window.zE || window.zEmbed;
document.zendeskHost = "back4app.zendesk.com";
document.zEQueue = queue;
}());
</script>
<script src="https://assets.zendesk.com/embeddable_framework/main.js" data-ze-csp="true" async defer></script>
<!--End of Zopim Live Chat Script-->
<script src="https://survey.solucx.com.br/widget.js"></script>
<script type="text/javascript" src="http://localhost:9000/back4app-navigation.bundle.js"></script><script type="text/javascript" src="bundles/dashboard.f18722a9d8069488bac7.js"></script><script type="text/javascript" src="bundles/login.2cc31a054b35c671c417.js"></script></body>
</html>
12 changes: 12 additions & 0 deletions src/components/Modal/Modal.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ let Modal = (({
customFooter,
textModal = false,
width,
continueText,
onContinue,
showContinue,
buttonsInCenter = React.Children.count(children) === 0,
}) => {
if (children) {
Expand All @@ -63,6 +66,15 @@ let Modal = (({
disabled={!!disabled}
onClick={onConfirm}
progress={progress} />
{
showContinue === true ?
<Button
primary={true}
value={continueText}
color={buttonColors[type]}
disabled={!!disabled}
onClick={onContinue}
progress={progress} />: null}
</div>
);

Expand Down
7 changes: 6 additions & 1 deletion src/dashboard/Data/Browser/AddColumnDialog.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export default class AddColumnDialog extends React.Component {
confirmText='Add column'
cancelText={'Never mind, don\u2019t.'}
onCancel={this.props.onCancel}
continueText={'Add column & continue'}
showContinue={true}
onContinue={() => {
this.props.onContinue(this.state);
}}
onConfirm={() => {
this.props.onConfirm(this.state);
}}>
Expand Down Expand Up @@ -246,4 +251,4 @@ export default class AddColumnDialog extends React.Component {
</Modal>
);
}
}
}
49 changes: 33 additions & 16 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Browser extends DashboardView {

isUnique: false,
uniqueField: null,
keepAddingCols: false,
markRequiredField: false,
requiredColumnFields: []
};
Expand Down Expand Up @@ -117,6 +118,7 @@ class Browser extends DashboardView {
this.showCreateClass = this.showCreateClass.bind(this);
this.createClass = this.createClass.bind(this);
this.addColumn = this.addColumn.bind(this);
this.addColumnAndContinue = this.addColumnAndContinue.bind(this);
this.removeColumn = this.removeColumn.bind(this);
this.showNote = this.showNote.bind(this);
this.showEditRowDialog = this.showEditRowDialog.bind(this);
Expand Down Expand Up @@ -274,6 +276,12 @@ class Browser extends DashboardView {
});
}

newColumn(payload) {
return this.props.schema.dispatch(ActionTypes.ADD_COLUMN, payload).catch((err) => {
this.showNote(err.message, true);
});
}

addColumn({ type, name, target, required, defaultValue }) {
let payload = {
className: this.props.params.className,
Expand All @@ -283,18 +291,23 @@ class Browser extends DashboardView {
required,
defaultValue
};
this.props.schema.dispatch(ActionTypes.ADD_COLUMN, payload).then(() => {
// if new required field column is added, then add field in requiredColumn
if (required) {
let requiredCols = [...this.state.requiredColumnFields, name];
this.setState({
requiredColumnFields: requiredCols
});
}
}).catch((err) => {
this.showNote(err.message, true);
}).finally(() => {
this.setState({ showAddColumnDialog: false });
this.newColumn(payload).finally(() => {
this.setState({ showAddColumnDialog: false, keepAddingCols: false });
});
}

addColumnAndContinue({ type, name, target, required, defaultValue }) {
let payload = {
className: this.props.params.className,
columnType: type,
name: name,
targetClass: target,
required,
defaultValue
};
this.newColumn(payload).finally(() => {
this.setState({ showAddColumnDialog: false, keepAddingCols: false });
this.setState({ showAddColumnDialog: true, keepAddingCols: true });
});
}

Expand Down Expand Up @@ -412,7 +425,7 @@ class Browser extends DashboardView {
}
this.state.counts[obj.className] += 1;
}

this.setState(state);
},
error => {
Expand Down Expand Up @@ -599,7 +612,7 @@ class Browser extends DashboardView {
// Construct complex pagination query
let equalityQuery = queryFromFilters(source, this.state.filters);
let comp = this.state.data[this.state.data.length - 1].get(field);

if (sortDir === '-') {
query.lessThan(field, comp);
equalityQuery.lessThan('objectId', this.state.data[this.state.data.length - 1].id);
Expand Down Expand Up @@ -719,7 +732,7 @@ class Browser extends DashboardView {
} else {
obj.set(attr, value);
}

if (isNewObject) {
// for dynamically changing required placeholder text for _User class new row object
if (obj.className === '_User' && attr === 'authData' && value !== undefined) {
Expand All @@ -739,7 +752,7 @@ class Browser extends DashboardView {
if (obj.className === '_User' && obj.get('username') === undefined && obj.get('password') === undefined && obj.get('authData') === undefined) {
this.setRequiredColumnFields();
}

this.setState({
isNewObject: obj
});
Expand Down Expand Up @@ -1209,6 +1222,8 @@ class Browser extends DashboardView {
if (this.state.showCreateClassDialog) {
extras = (
<CreateClassDialog
currentAppSlug={this.context.currentApp.slug}
onAddColumn={this.showAddColumn}
currentClasses={this.props.schema.data.get('classes').keySeq().toArray()}
onCancel={() => this.setState({ showCreateClassDialog: false })}
onConfirm={this.createClass} />
Expand All @@ -1221,10 +1236,12 @@ class Browser extends DashboardView {
});
extras = (
<AddColumnDialog
onAddColumn={this.showAddColumn}
currentColumns={currentColumns}
classes={this.props.schema.data.get('classes').keySeq().toArray()}
onCancel={() => this.setState({ showAddColumnDialog: false })}
onConfirm={this.addColumn}
onContinue={this.addColumnAndContinue}
showNote={this.showNote}
parseServerVersion={currentApp.serverInfo && currentApp.serverInfo.parseServerVersion} />
);
Expand Down
10 changes: 10 additions & 0 deletions src/dashboard/Data/Browser/CreateClassDialog.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Option from 'components/Dropdown/Option.react';
import React from 'react';
import { SpecialClasses } from 'lib/Constants';
import TextInput from 'components/TextInput/TextInput.react';
import history from 'dashboard/history';

function validClassName(name) {
return !!name.match(/^[a-zA-Z][_a-zA-Z0-9]*$/);
Expand Down Expand Up @@ -68,7 +69,16 @@ export default class CreateClassDialog extends React.Component {
disabled={!this.valid()}
confirmText='Create class'
cancelText={'Cancel'}
continueText={'Create class & add columns'}
onCancel={this.props.onCancel}
showContinue={true}
onContinue={async () => {
let type = this.state.type;
let className = type === 'Custom' ? this.state.name : '_' + type;
await this.props.onConfirm(className);
history.push(`/apps/${this.props.currentAppSlug}/browser/${className}`);
this.props.onAddColumn();
}}
onConfirm={() => {
let type = this.state.type;
let className = type === 'Custom' ? this.state.name : '_' + type;
Expand Down