Skip to content

Commit 92c7132

Browse files
committed
Merge branch 'master' of parse-community/parse-dashboard into edit-clone-rows
2 parents 1783154 + 46be742 commit 92c7132

File tree

4 files changed

+134
-39
lines changed

4 files changed

+134
-39
lines changed

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"LICENSE"
3636
],
3737
"dependencies": {
38-
"@babel/runtime": "7.13.10",
38+
"@babel/runtime": "7.13.17",
3939
"bcryptjs": "2.3.0",
4040
"body-parser": "1.19.0",
4141
"codemirror-graphql": "github:timsuchanek/codemirror-graphql#details-fix",

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

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class Browser extends DashboardView {
124124
this.onDialogToggle = this.onDialogToggle.bind(this);
125125
this.addEditCloneRows = this.addEditCloneRows.bind(this);
126126
this.abortAddRow = this.abortAddRow.bind(this);
127+
this.saveNewRow = this.saveNewRow.bind(this);
127128
}
128129

129130
componentWillMount() {
@@ -305,6 +306,66 @@ class Browser extends DashboardView {
305306
}
306307
}
307308

309+
saveNewRow(){
310+
const obj = this.state.newObject;
311+
if (!obj) {
312+
return;
313+
}
314+
315+
obj.save(null, { useMasterKey: true }).then(
316+
objectSaved => {
317+
let msg = objectSaved.className + ' with id \'' + objectSaved.id + '\' created';
318+
this.showNote(msg, false);
319+
320+
const state = { data: this.state.data };
321+
const relation = this.state.relation;
322+
if (relation) {
323+
const parent = relation.parent;
324+
const parentRelation = parent.relation(relation.key);
325+
parentRelation.add(obj);
326+
const targetClassName = relation.targetClassName;
327+
parent.save(null, { useMasterKey: true }).then(
328+
() => {
329+
this.setState({
330+
newObject: null,
331+
data: [obj, ...this.state.data],
332+
relationCount: this.state.relationCount + 1,
333+
counts: {
334+
...this.state.counts,
335+
[targetClassName]: this.state.counts[targetClassName] + 1
336+
}
337+
});
338+
},
339+
error => {
340+
let msg = typeof error === "string" ? error : error.message;
341+
if (msg) {
342+
msg = msg[0].toUpperCase() + msg.substr(1);
343+
}
344+
obj.set(attr, prev);
345+
this.setState({ data: this.state.data });
346+
this.showNote(msg, true);
347+
}
348+
);
349+
} else {
350+
state.newObject = null;
351+
if (this.props.params.className === obj.className) {
352+
this.state.data.unshift(obj);
353+
}
354+
this.state.counts[obj.className] += 1;
355+
}
356+
357+
this.setState(state);
358+
},
359+
error => {
360+
let msg = typeof error === "string" ? error : error.message;
361+
if (msg) {
362+
msg = msg[0].toUpperCase() + msg.substr(1);
363+
}
364+
this.showNote(msg, true);
365+
}
366+
);
367+
}
368+
308369
addRowWithModal() {
309370
this.addRow();
310371
this.selectRow(undefined, true);
@@ -372,6 +433,14 @@ class Browser extends DashboardView {
372433
query.ascending(field)
373434
}
374435

436+
if (field !== 'objectId') {
437+
if (sortDir === '-') {
438+
query.addDescending('objectId');
439+
} else {
440+
query.addAscending('objectId');
441+
}
442+
}
443+
375444
query.limit(MAX_ROWS_FETCHED);
376445
this.excludeFields(query, source);
377446

@@ -447,37 +516,38 @@ class Browser extends DashboardView {
447516
let className = this.props.params.className;
448517
let source = this.state.relation || className;
449518
let query = queryFromFilters(source, this.state.filters);
450-
if (this.state.ordering !== '-createdAt') {
519+
let field = this.state.ordering;
520+
let sortDir = field[0] === '-' ? '-' : '+';
521+
field = field[0] === '-' ? field.slice(1) : field;
522+
if (this.state.ordering !== '-objectId' && this.state.ordering !== 'objectId') {
451523
// Construct complex pagination query
452524
let equalityQuery = queryFromFilters(source, this.state.filters);
453-
let field = this.state.ordering;
454-
let ascending = true;
455525
let comp = this.state.data[this.state.data.length - 1].get(field);
456-
if (field === 'objectId' || field === '-objectId') {
457-
comp = this.state.data[this.state.data.length - 1].id;
458-
}
459-
if (field[0] === '-') {
460-
field = field.substr(1);
526+
527+
if (sortDir === '-') {
461528
query.lessThan(field, comp);
462-
ascending = false;
529+
equalityQuery.lessThan('objectId', this.state.data[this.state.data.length - 1].id);
463530
} else {
464531
query.greaterThan(field, comp);
532+
equalityQuery.greaterThan('objectId', this.state.data[this.state.data.length - 1].id);
465533
}
466-
if (field === 'createdAt') {
467-
equalityQuery.greaterThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
468-
} else {
469-
equalityQuery.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
470-
equalityQuery.equalTo(field, comp);
471-
}
534+
equalityQuery.equalTo(field, comp);
472535
query = Parse.Query.or(query, equalityQuery);
473-
if (ascending) {
474-
query.ascending(this.state.ordering);
536+
if (sortDir === '-') {
537+
query.descending(field);
538+
query.addDescending('objectId');
475539
} else {
476-
query.descending(this.state.ordering.substr(1));
540+
query.ascending(field);
541+
query.addAscending('objectId');
477542
}
478543
} else {
479-
query.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
480-
query.addDescending('createdAt');
544+
if (sortDir === '-') {
545+
query.lessThan('objectId', this.state.data[this.state.data.length - 1].id);
546+
query.addDescending('objectId');
547+
} else {
548+
query.greaterThan('objectId', this.state.data[this.state.data.length - 1].id);
549+
query.addAscending('objectId');
550+
}
481551
}
482552
query.limit(MAX_ROWS_FETCHED);
483553
this.excludeFields(query, source);
@@ -577,6 +647,12 @@ class Browser extends DashboardView {
577647
} else {
578648
obj.set(attr, value);
579649
}
650+
if(isNewObject){
651+
this.setState({
652+
isNewObject: obj
653+
});
654+
return;
655+
}
580656
obj.save(null, { useMasterKey: true }).then((objectSaved) => {
581657
const createdOrUpdated = isNewObject || isEditCloneObj ? 'created' : 'updated';
582658
let msg = objectSaved.className + ' with id \'' + objectSaved.id + '\' ' + createdOrUpdated;
@@ -1065,6 +1141,7 @@ class Browser extends DashboardView {
10651141
onCloneSelectedRows={this.showCloneSelectedRowsDialog}
10661142
onEditSelectedRow={this.showEditRowDialog}
10671143
onEditPermissions={this.onDialogToggle}
1144+
onSaveNewRow={this.saveNewRow}
10681145
onAbortAddRow={this.abortAddRow}
10691146

10701147
columns={columns}
@@ -1085,6 +1162,7 @@ class Browser extends DashboardView {
10851162
setRelation={this.setRelation}
10861163
onAddColumn={this.showAddColumn}
10871164
onAddRow={this.addRow}
1165+
onAbortAddRow={this.abortAddRow}
10881166
onAddRowWithModal={this.addRowWithModal}
10891167
onAddClass={this.showCreateClass}
10901168
showNote={this.showNote} />

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default class BrowserTable extends React.Component {
159159
if (this.props.newObject && this.state.offset <= 0) {
160160
const currentCol = this.props.current && this.props.current.row === -1 ? this.props.current.col : undefined;
161161
newRow = (
162-
<div style={{ marginBottom: 30, borderBottom: '1px solid #169CEE' }}>
162+
<div style={{ borderBottom: '1px solid #169CEE' }}>
163163
<BrowserRow
164164
key={-1}
165165
className={this.props.className}
@@ -180,7 +180,24 @@ export default class BrowserTable extends React.Component {
180180
setRelation={this.props.setRelation}
181181
setCopyableValue={this.props.setCopyableValue}
182182
setContextMenu={this.props.setContextMenu}
183-
onEditSelectedRow={this.props.onEditSelectedRow} />
183+
onEditSelectedRow={this.props.onEditSelectedRow}
184+
/>
185+
<Button
186+
value="Add"
187+
width="55px"
188+
primary={true}
189+
onClick={() => {
190+
this.props.onSaveNewRow();
191+
this.props.setEditing(false);
192+
}}
193+
additionalStyles={{ fontSize: '12px', height: '20px', lineHeight: '20px', margin: '5px', padding: '0'}}
194+
/>
195+
<Button
196+
value="Cancel"
197+
width="55px"
198+
onClick={this.props.onAbortAddRow}
199+
additionalStyles={{ fontSize: '12px', height: '20px', lineHeight: '20px', margin: '5px', padding: '0'}}
200+
/>
184201
</div>
185202
);
186203
}

0 commit comments

Comments
 (0)