Skip to content

Commit 63d356b

Browse files
ellemeditdrew-gross
authored andcommitted
Add/relation viewer (#452)
* Update improve Browser for relation * update: DataBrowser relation viewer has url * update: DataBrowser relation viewer can add row * update: DataBrowser relation viewer can go back * Add DataBrowser attach existing one to relation * update: DeleteRowsDialog messsage is more clear * update: AttachRowsDialog can add existing row by objectId * Lint unnecessary * Update attach rows to relation logic * update: after attaching, it will not refetch the relation and add state.data. * lint: remove direct mutating state, make const var to let * Update data fetching logic * update: merge data fetching logic of `componentWillMount` and `componentWillReceiveProps`. * shows back button if filter applied * lint many things. (you can blame it) * Update AttachRowsDialog changed FormModal from Modal * fixed: typos * added: create and attach buttons for relation viewer
1 parent 32efab9 commit 63d356b

File tree

10 files changed

+485
-150
lines changed

10 files changed

+485
-150
lines changed

src/components/DataBrowserHeaderBar/DataBrowserHeaderBar.react.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ export default class DataBrowserHeaderBar extends React.Component {
6161
finalStyle.background = 'rgba(224,224,234,0.10)';
6262
}
6363
elements.push(
64-
<div key='add' className={styles.addColumn} style={finalStyle}>
65-
{readonly ?
66-
null :
64+
readonly ? null : (
65+
<div key='add' className={styles.addColumn} style={finalStyle}>
6766
<a
6867
href='javascript:;'
6968
role='button'
7069
className={styles.addColumnButton}
7170
onClick={onAddColumn}>
7271
Add a new column
73-
</a>}
74-
</div>
72+
</a>
73+
</div>
74+
)
7575
);
7676

7777
return <div className={styles.bar}>{elements}</div>;

src/components/EmptyState/EmptyState.react.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ let ctaButton = (cta, action) => {
3535
}
3636
}
3737

38-
let EmptyState = ({ icon='', title='', description='', cta='', action=()=>{}}) => (
38+
let EmptyState = ({
39+
icon='',
40+
title='',
41+
description='',
42+
cta='',
43+
action=() => {},
44+
secondaryCta='',
45+
secondaryAction=() => {},
46+
}) => (
3947
<div className={center}>
4048
<div className={styles.icon}>
4149
<Icon
@@ -47,6 +55,8 @@ let EmptyState = ({ icon='', title='', description='', cta='', action=()=>{}}) =
4755
<div className={styles.title}>{title}</div>
4856
<div className={styles.description}>{description}</div>
4957
{ctaButton(cta, action)}
58+
{secondaryCta && ' '}
59+
{ctaButton(secondaryCta, secondaryAction)}
5060
</div>
5161
);
5262

@@ -68,6 +78,12 @@ EmptyState.propTypes = {
6878
action: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).describe(
6979
'An href link or a click handler that is forwarded to the CTA button.'
7080
),
81+
secondaryCta: PropTypes.string.describe(
82+
'The text that appears in the secondary CTA button.'
83+
),
84+
secondaryAction: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).describe(
85+
'An href link or a click handler that is forwarded to the secondary CTA button.'
86+
),
7187
};
7288

7389
export default EmptyState;

src/components/Toolbar/Toolbar.react.js

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,59 @@
77
*/
88
import PropTypes from 'lib/PropTypes';
99
import React from 'react';
10+
import Icon from 'components/Icon/Icon.react';
1011
import styles from 'components/Toolbar/Toolbar.scss';
12+
import history from 'dashboard/history';
1113

12-
let Toolbar = (props) => (
13-
<div className={styles.toolbar}>
14-
<div className={styles.title}>
15-
<div className={styles.section}>{props.section}</div>
16-
<div>
17-
<span className={styles.subsection}>
18-
{props.subsection}
19-
</span>
20-
<span className={styles.details}>
21-
{props.details}
22-
</span>
14+
const goBack = () => history.goBack();
15+
16+
let Toolbar = (props) => {
17+
let backButton;
18+
if (props.relation || (props.filters && props.filters.size)) {
19+
backButton = (
20+
<a
21+
className={styles.iconButton}
22+
onClick={goBack}
23+
>
24+
<Icon
25+
width={32}
26+
height={32}
27+
fill="#ffffff"
28+
name="left-outline"
29+
/>
30+
</a>
31+
);
32+
}
33+
return (
34+
<div className={styles.toolbar}>
35+
<div className={styles.title}>
36+
<div className={styles.nav}>
37+
{backButton}
38+
</div>
39+
<div className={styles.titleText}>
40+
<div className={styles.section}>{props.section}</div>
41+
<div>
42+
<span className={styles.subsection}>
43+
{props.subsection}
44+
</span>
45+
<span className={styles.details}>
46+
{props.details}
47+
</span>
48+
</div>
49+
</div>
50+
</div>
51+
<div className={styles.actions}>
52+
{props.children}
2353
</div>
2454
</div>
25-
<div className={styles.actions}>
26-
{props.children}
27-
</div>
28-
</div>
29-
);
55+
);
56+
};
3057

3158
Toolbar.propTypes = {
3259
section: PropTypes.string,
3360
subsection: PropTypes.string,
34-
details: PropTypes.string
61+
details: PropTypes.string,
62+
relation: PropTypes.object,
3563
};
3664

3765
export default Toolbar;

src/components/Toolbar/Toolbar.scss

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,27 @@
2424
}
2525
}
2626

27-
2827
.title {
2928
position: absolute;
3029
left: 14px;
3130
bottom: 10px;
3231
}
3332

33+
.nav {
34+
display: inline-block;
35+
}
36+
37+
.iconButton {
38+
display: block;
39+
padding-top: 10px;
40+
padding-right: 10px;
41+
cursor: pointer;
42+
}
43+
44+
.titleText {
45+
display: inline-block;
46+
}
47+
3448
.section {
3549
@include DosisFont;
3650
color: #757985;

src/dashboard/Dashboard.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class Dashboard extends React.Component {
212212

213213
<Route path='browser' component={false ? SchemaOverview : Browser} /> //In progress features. Change false to true to work on this feature.
214214
<Route path='browser/:className' component={Browser} />
215+
<Route path='browser/:className/:entityId/:relationName' component={Browser} />
215216

216217
<Route path='cloud_code' component={CloudCode} />
217218
<Route path='cloud_code/*' component={CloudCode} />
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 Parse from 'parse';
7+
8+
export default class AttachRowsDialog extends React.Component {
9+
constructor(props) {
10+
super(props);
11+
12+
this.state = {
13+
objectIds: '',
14+
};
15+
16+
this.handleObjectIdsChange = this.handleObjectIdsChange.bind(this);
17+
this.handleConfirm = this.handleConfirm.bind(this);
18+
}
19+
20+
handleObjectIdsChange(objectIds) {
21+
this.setState({ objectIds });
22+
}
23+
24+
handleConfirm() {
25+
const objectIds = this.state.objectIds.split(',').reduce((resourceIds, targetResourceId) => {
26+
const objectId = targetResourceId && targetResourceId.trim();
27+
if (!objectId) return;
28+
return [...resourceIds, objectId];
29+
}, []);
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;
40+
}
41+
42+
render() {
43+
const {
44+
relation,
45+
onCancel,
46+
onConfirm,
47+
} = this.props;
48+
return (
49+
<FormModal
50+
icon="plus"
51+
iconSize={40}
52+
title="Attach Rows"
53+
subtitle={`Attach existing rows from ${relation.targetClassName}`}
54+
onClose={this.props.onCancel}
55+
onSubmit={this.handleConfirm}
56+
open
57+
submitText="Attach"
58+
inProgressText="Attaching ..."
59+
>
60+
<Field
61+
label={
62+
<Label
63+
text="objectIds"
64+
description={`IDs of ${relation.targetClassName} rows to attach`}
65+
/>
66+
}
67+
input={
68+
<TextInput
69+
placeholder="ox0QZFl7eg, qs81Q72lTL, etc..."
70+
value={this.state.objectIds}
71+
onChange={this.handleObjectIdsChange}
72+
/>
73+
}
74+
/>
75+
</FormModal>
76+
);
77+
}
78+
}

0 commit comments

Comments
 (0)