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

Cloning Rows #1697

Merged
merged 25 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
70999b1
disabled clone rows option for standard classes
sadakchap May 5, 2021
326b0e8
providing a way to edit clone rows on error 137
sadakchap May 5, 2021
d97e896
allowing user to clone rows for standard classes
sadakchap May 6, 2021
1783154
Merge branch 'master' of parse-community/parse-dashboard into edit-cl…
sadakchap May 11, 2021
92c7132
Merge branch 'master' of parse-community/parse-dashboard into edit-cl…
sadakchap May 17, 2021
59aeb63
checking dirty clone objects on failed clone
sadakchap May 17, 2021
9b3be18
giving option to clone or cancel per row for failed clone rows
sadakchap May 17, 2021
9705713
fixed wrapTop for data rows when edit clone row
sadakchap May 17, 2021
b7b7b93
showing modal Clone menu
sadakchap May 21, 2021
acc1c22
disabling other menu item on modal state
sadakchap May 21, 2021
2a4479a
clone rows for requried field
sadakchap May 27, 2021
53cd6e6
showing cloned rows for missing required field error
sadakchap Jun 2, 2021
4cb326d
removing username & authData for User class object
sadakchap Jun 25, 2021
be85c8e
removed null initialization var
sadakchap Jul 13, 2021
079f43f
removing username while cloning User obj
sadakchap Jul 20, 2021
5d1b9ff
added clone icon attribution note
sadakchap Jul 27, 2021
88a64e1
Merge branch 'master' of parse-community/parse-dashboard into edit-cl…
sadakchap Jul 27, 2021
5209ee6
added required placehlder text for edit clone rows
sadakchap Jul 27, 2021
b874314
clearing required field row after abort add
sadakchap Jul 27, 2021
6f04895
udpating config file
sadakchap Jul 27, 2021
846bca5
dynamic update required fields from BrowserRow new
sadakchap Jul 30, 2021
8a49c8b
remove requiredColumnFields state var from Browser
sadakchap Jul 30, 2021
b296eae
Update package-lock.json
mtrezza Aug 4, 2021
41425d3
Merge branch 'master' of github.com:parse-community/parse-dashboard i…
sadakchap Aug 4, 2021
5c5df3e
disabling all menu options on edit clone row modal state
sadakchap Aug 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Browser extends DashboardView {
data: null,
lastMax: -1,
newObject: null,
editCloneRows: null,

lastError: null,
lastNote: null,
Expand Down Expand Up @@ -121,6 +122,7 @@ class Browser extends DashboardView {
this.closeEditRowDialog = this.closeEditRowDialog.bind(this);
this.handleShowAcl = this.handleShowAcl.bind(this);
this.onDialogToggle = this.onDialogToggle.bind(this);
this.addEditCloneRows = this.addEditCloneRows.bind(this);
this.abortAddRow = this.abortAddRow.bind(this);
}

Expand Down Expand Up @@ -309,6 +311,12 @@ class Browser extends DashboardView {
this.showEditRowDialog();
}

addEditCloneRows(cloneRows) {
this.setState({
editCloneRows: cloneRows
});
}

removeColumn(name) {
let payload = {
className: this.props.params.className,
Expand Down Expand Up @@ -339,6 +347,7 @@ class Browser extends DashboardView {
newObject: null,
lastMax: -1,
selection: {},
editCloneRows: null,
};
if (relation) {
await this.setState(initialState);
Expand Down Expand Up @@ -550,8 +559,12 @@ class Browser extends DashboardView {
}

updateRow(row, attr, value) {
const isNewObject = row < 0;
const obj = isNewObject ? this.state.newObject : this.state.data[row];
let isNewObject = row === -1;
let isEditCloneObj = row < -1;
let obj = isNewObject ? this.state.newObject : this.state.data[row];
if(isEditCloneObj){
obj = this.state.editCloneRows[row + (this.state.editCloneRows.length + 1)];
}
if (!obj) {
return;
}
Expand All @@ -565,11 +578,11 @@ class Browser extends DashboardView {
obj.set(attr, value);
}
obj.save(null, { useMasterKey: true }).then((objectSaved) => {
const createdOrUpdated = isNewObject ? 'created' : 'updated';
const createdOrUpdated = isNewObject || isEditCloneObj ? 'created' : 'updated';
let msg = objectSaved.className + ' with id \'' + objectSaved.id + '\' ' + createdOrUpdated;
this.showNote(msg, false);

const state = { data: this.state.data };
const state = { data: this.state.data, editCloneRows: this.state.editCloneRows };

if (isNewObject) {
const relation = this.state.relation;
Expand Down Expand Up @@ -608,13 +621,23 @@ class Browser extends DashboardView {
this.state.counts[obj.className] += 1;
}
}
if (isEditCloneObj) {
state.editCloneRows = state.editCloneRows.filter(
cloneObj => cloneObj._localId !== obj._localId
);
if (state.editCloneRows.length === 0) state.editCloneRows = null;
if (this.props.params.className === obj.className) {
this.state.data.unshift(obj);
}
this.state.counts[obj.className] += 1;
}
this.setState(state);
}, (error) => {
let msg = typeof error === 'string' ? error : error.message;
if (msg) {
msg = msg[0].toUpperCase() + msg.substr(1);
}
if (!isNewObject) {
if (!isNewObject && !isEditCloneObj) {
obj.set(attr, prev);
this.setState({ data: this.state.data });
}
Expand Down Expand Up @@ -855,6 +878,9 @@ class Browser extends DashboardView {
}
});
} catch (error) {
if(error.code === 137){
this.addEditCloneRows(toClone);
}
this.setState({
selection: {},
showCloneSelectedRowsDialog: false
Expand Down Expand Up @@ -1050,6 +1076,7 @@ class Browser extends DashboardView {
data={this.state.data}
ordering={this.state.ordering}
newObject={this.state.newObject}
editCloneRows={this.state.editCloneRows}
relation={this.state.relation}
disableKeyControls={this.hasExtras()}
updateRow={this.updateRow}
Expand Down
50 changes: 50 additions & 0 deletions src/dashboard/Data/Browser/BrowserTable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,46 @@ export default class BrowserTable extends React.Component {
(rowWidth, { visible, width }) => visible ? rowWidth + width : rowWidth,
this.props.onAddRow ? 210 : 0
);
let editCloneRows = null;
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
if(this.props.editCloneRows){
editCloneRows = (
<div style={{ marginBottom: 30, borderBottom: '1px solid #169CEE' }}>
{this.props.editCloneRows.map((cloneRow, idx) => {
let index = (this.props.editCloneRows.length + 1) * -1 + idx;
const currentCol = this.props.current && this.props.current.row === index ? this.props.current.col : undefined;
const isEditingRow = this.props.current && this.props.current.row === index && !!this.props.editing;
return (
<BrowserRow
key={index}
isEditing={isEditingRow}
className={this.props.className}
columns={this.props.columns}
schema={this.props.schema}
simplifiedSchema={this.props.simplifiedSchema}
filters={this.props.filters}
currentCol={currentCol}
isUnique={this.props.isUnique}
obj={cloneRow}
onPointerClick={this.props.onPointerClick}
onFilterChange={this.props.onFilterChange}
order={this.props.order}
readOnlyFields={READ_ONLY}
row={index}
rowWidth={rowWidth}
selection={this.props.selection}
selectRow={this.props.selectRow}
setCurrent={this.props.setCurrent}
setEditing={this.props.setEditing}
setRelation={this.props.setRelation}
setCopyableValue={this.props.setCopyableValue}
setContextMenu={this.props.setContextMenu}
onEditSelectedRow={this.props.onEditSelectedRow}
/>
);
})}
</div>
)
}
let newRow = null;
if (this.props.newObject && this.state.offset <= 0) {
const currentCol = this.props.current && this.props.current.row === -1 ? this.props.current.col : undefined;
Expand Down Expand Up @@ -205,6 +245,9 @@ export default class BrowserTable extends React.Component {
}
let obj = this.props.current.row < 0 ? this.props.newObject : this.props.data[this.props.current.row];
let value = obj;
if(!obj && this.props.current.row < -1){
obj = this.props.editCloneRows[this.props.current.row + this.props.editCloneRows.length + 1];
}
if (!this.props.isUnique) {
if (type === 'Array' || type === 'Object') {
// This is needed to avoid unwanted conversions of objects to Parse.Objects.
Expand All @@ -226,9 +269,15 @@ export default class BrowserTable extends React.Component {
value = '';
}
let wrapTop = Math.max(0, this.props.current.row * ROW_HEIGHT);
if(this.props.current.row < -1 && this.props.editCloneRows){
wrapTop = ROW_HEIGHT * (this.props.current.row + (this.props.editCloneRows.length + 1));
}
if (this.props.current.row > -1 && this.props.newObject) {
wrapTop += 60;
}
if (this.props.current.row >= -1 && this.props.editCloneRows) {
wrapTop += ROW_HEIGHT * (this.props.editCloneRows.length + 1);
}
let wrapLeft = 30;
for (let i = 0; i < this.props.current.col; i++) {
const column = this.props.order[i];
Expand Down Expand Up @@ -297,6 +346,7 @@ export default class BrowserTable extends React.Component {
table = (
<div className={styles.table} ref='table'>
<div style={{ height: Math.max(0, this.state.offset * ROW_HEIGHT) }} />
{editCloneRows}
{newRow}
{rows}
<div style={{ height: Math.max(0, (this.props.data.length - this.state.offset - MAX_ROWS) * ROW_HEIGHT) }} />
Expand Down