Skip to content

Commit 5b301f3

Browse files
ellemeditdrew-gross
authored andcommitted
Add AttachSelectedRowsDialog (#465)
* Add AttachSelectedRowsDialog * fixed: <Icon /> href reference bug by relative path * added: `Attach this/these rows to relation` button to `Edit` BrowserToolbar * Update typo * Update prevent filtering touchable columns * fixed: base URL with update dependencies * updated: `FormModal` uses ES6 Promise instead of Parse.Promise
1 parent 512bc71 commit 5b301f3

File tree

8 files changed

+272
-43
lines changed

8 files changed

+272
-43
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"babel-runtime": "~5.8.25",
4747
"css-loader": "~0.18.0",
4848
"file-loader": "^0.8.5",
49-
"history": "~1.9.1",
49+
"history": "^2.1.2",
5050
"http-server": "~0.8.5",
5151
"immutable": "~3.7.5",
5252
"immutable-devtools": "~0.0.4",
@@ -61,7 +61,7 @@
6161
"react-dnd": "~2.1.4",
6262
"react-dnd-html5-backend": "~2.0.0",
6363
"react-dom": "^15.0.1",
64-
"react-router": "2.3.0",
64+
"react-router": "^2.6.0",
6565
"sass-loader": "~3.1.2",
6666
"style-loader": "~0.12.3",
6767
"svg-prep": "~1.0.0",

src/components/FormModal/FormModal.react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class FormModal extends React.Component {
5454
clearFields();
5555
onSuccess(result);
5656
this.setState({inProgress: false});
57-
}).fail(({ message, error, notice, errors = [] }) => {
57+
}).catch(({ message, error, notice, errors = [] }) => {
5858
this.setState({
5959
errorMessage: errors.join(' ') || message || error || notice || 'An error occurred',
6060
inProgress: false,

src/components/Icon/Icon.react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let Icon = ({ name, fill, width, height }) => {
1818
}
1919
return (
2020
<svg {...props} >
21-
<use xlinkHref={`bundles/sprites.svg#${name}`} />
21+
<use xlinkHref={`/bundles/sprites.svg#${name}`} />
2222
</svg>
2323
);
2424
};

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,23 @@ export default class AttachRowsDialog extends React.Component {
2727
if (!objectId) return;
2828
return [...resourceIds, objectId];
2929
}, []);
30-
const promise = new Parse.Promise();
31-
console.log(promise);
32-
this.props.onConfirm(objectIds)
33-
.then(promise.resolve)
34-
.catch((error) => {
35-
promise.reject({
36-
error,
37-
});
38-
});
39-
return promise;
30+
return this.props.onConfirm(objectIds);
4031
}
4132

4233
render() {
4334
const {
4435
relation,
4536
onCancel,
46-
onConfirm,
4737
} = this.props;
4838
return (
4939
<FormModal
40+
open
5041
icon="plus"
5142
iconSize={40}
52-
title="Attach Rows"
43+
title="Attach Rows To Relation"
5344
subtitle={`Attach existing rows from ${relation.targetClassName}`}
5445
onClose={this.props.onCancel}
5546
onSubmit={this.handleConfirm}
56-
open
5747
submitText="Attach"
5848
inProgressText="Attaching ..."
5949
>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
import React from 'react';
2+
import FormModal from 'components/FormModal/FormModal.react';
3+
import Field from 'components/Field/Field.react';
4+
import Label from 'components/Label/Label.react';
5+
import TextInput from 'components/TextInput/TextInput.react';
6+
import Dropdown from 'components/Dropdown/Dropdown.react';
7+
import Option from 'components/Dropdown/Option.react';
8+
import Parse from 'parse';
9+
import { SpecialClasses } from 'lib/Constants';
10+
11+
export default class AttachSelectedRowsDialog extends React.Component {
12+
constructor(props) {
13+
super(props);
14+
15+
this.state = {
16+
currentClass: null,
17+
currentColumn: null,
18+
touchableColumns: [],
19+
targetObjectId: '',
20+
objectIds: [],
21+
};
22+
23+
this.handleConfirm = this.handleConfirm.bind(this);
24+
this.handleClassChange = this.handleClassChange.bind(this);
25+
this.handleColumnChange = this.handleColumnChange.bind(this);
26+
this.handleTargetObjectIdChange = this.handleTargetObjectIdChange.bind(this);
27+
}
28+
29+
componentWillMount() {
30+
const { selection, classes, onSelectClass } = this.props;
31+
if (selection) {
32+
const currentClass = classes[0];
33+
const objectIds = [];
34+
for (const objectId in selection) {
35+
objectIds.push(objectId);
36+
}
37+
const touchableColumns = onSelectClass(currentClass);
38+
const currentColumn = touchableColumns[0];
39+
this.setState({
40+
currentClass: currentClass,
41+
touchableColumns,
42+
currentColumn,
43+
objectIds,
44+
});
45+
}
46+
}
47+
48+
handleTargetObjectIdChange(targetObjectId) {
49+
this.setState({ targetObjectId });
50+
}
51+
52+
handleConfirm() {
53+
const {
54+
currentClass,
55+
currentColumn,
56+
targetObjectId,
57+
objectIds,
58+
} = this.state;
59+
return this.props.onConfirm(currentClass, targetObjectId, currentColumn, objectIds);
60+
}
61+
62+
handleClassChange(className) {
63+
const touchableColumns = this.props.onSelectClass(className);
64+
this.setState({
65+
currentClass: className,
66+
touchableColumns,
67+
currentColumn: touchableColumns[0],
68+
});
69+
}
70+
71+
handleColumnChange(column) {
72+
this.setState({
73+
currentColumn: column,
74+
});
75+
}
76+
77+
render() {
78+
const {
79+
relation,
80+
onCancel,
81+
classes,
82+
} = this.props;
83+
let targetRelationSelector;
84+
let targetEntityIdInsert;
85+
if (this.state.touchableColumns.length) {
86+
targetRelationSelector = (
87+
<Field
88+
label={
89+
<Label
90+
text="Target Relation"
91+
description="Target class's relation column"
92+
/>
93+
}
94+
input={
95+
<Dropdown
96+
value={this.state.currentColumn}
97+
onChange={this.handleColumnChange}
98+
>
99+
{this.state.touchableColumns.map(column => (
100+
<Option key={column} value={column}>
101+
{column}
102+
</Option>
103+
))}
104+
</Dropdown>
105+
}
106+
/>
107+
);
108+
}
109+
if (this.state.currentColumn) {
110+
targetEntityIdInsert = (
111+
<Field
112+
label={
113+
<Label
114+
text="Target objectId"
115+
description={`${this.state.currentClass} objectId`}
116+
/>
117+
}
118+
input={
119+
<TextInput
120+
placeholder="ox0QZFl7eg, qs81Q72lTL, etc..."
121+
value={this.state.targetObjectId}
122+
onChange={this.handleTargetObjectIdChange}
123+
/>
124+
}
125+
/>
126+
);
127+
}
128+
return (
129+
<FormModal
130+
open
131+
icon="plus"
132+
iconSize={40}
133+
title="Attach Selected Rows to Relation"
134+
submitText="Attach"
135+
inProgressText="Attaching ..."
136+
onClose={this.props.onCancel}
137+
onSubmit={this.handleConfirm}
138+
>
139+
<Field
140+
label={
141+
<Label
142+
text="Target Class"
143+
description="Target relation's parent class"
144+
/>
145+
}
146+
input={
147+
<Dropdown
148+
value={this.state.currentClass}
149+
onChange={this.handleClassChange}
150+
>
151+
{classes.map(className => (
152+
<Option key={className} value={className}>
153+
{SpecialClasses[className] || className}
154+
</Option>
155+
))}
156+
</Dropdown>
157+
}
158+
/>
159+
{targetRelationSelector}
160+
{targetEntityIdInsert}
161+
</FormModal>
162+
);
163+
}
164+
}

0 commit comments

Comments
 (0)