Skip to content

Commit 0023b32

Browse files
authored
Merge pull request #80 from back4app/analytics-report-event
Analytics report event
2 parents 49b8b6a + 2dc66fd commit 0023b32

File tree

8 files changed

+213
-152
lines changed

8 files changed

+213
-152
lines changed

src/components/ExplorerActiveChartButton/ExplorerActiveChartButton.react.js

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ export default class ExplorerActiveChartButton extends React.Component {
3232
this.node = ReactDOM.findDOMNode(this);
3333
}
3434

35+
componentWillMount() {
36+
// Used to close query picker
37+
document.addEventListener('mousedown', this.handleClick.bind(this), false)
38+
}
39+
40+
componentWillUnmount() {
41+
// Used to close query picker
42+
document.removeEventListener('mousedown', this.handleClick.bind(this), false)
43+
}
44+
45+
// Intercept all click events
46+
handleClick(e) {
47+
// Verify if the click is outside the picker
48+
if (this.state.open && this.parentNode && !this.parentNode.contains(e.target)) {
49+
// Click target is not inside the configuration dropdown
50+
if (e.target.parentNode && !e.target.parentNode.className.match('menu'))
51+
this.handleClosePopover() // Close picker
52+
}
53+
}
54+
55+
// Set parent node
56+
setParentNode(node) {
57+
this.parentNode = node
58+
}
59+
3560
handleCheckbox() {
3661
let nextActiveState = !this.state.active;
3762
this.props.onToggle(nextActiveState);
@@ -40,16 +65,36 @@ export default class ExplorerActiveChartButton extends React.Component {
4065
});
4166
}
4267

43-
handleSave(query) {
68+
handleSave(query, saveOnDatabase) {
4469
this.setState({ open: false });
45-
this.props.onSave(query);
70+
this.props.onSave(query, saveOnDatabase);
4671
}
4772

4873
handleDismiss() {
4974
this.setState({ open: false });
5075
this.props.onDismiss();
5176
}
5277

78+
handleOpenPopover() {
79+
let position = Position.inDocument(this.node);
80+
let align = Directions.LEFT;
81+
if (position.x > 700) {
82+
position.x += this.node.clientWidth;
83+
align = Directions.RIGHT;
84+
}
85+
// Add the button height to the picker appear on the bottom
86+
position.y += this.node.clientHeight
87+
this.setState({
88+
open: !this.state.open,
89+
position,
90+
align
91+
});
92+
}
93+
94+
handleClosePopover() {
95+
this.setState({ open: false });
96+
}
97+
5398
renderButton() {
5499
let checkMark = null;
55100
let color = '#343445';
@@ -63,19 +108,7 @@ export default class ExplorerActiveChartButton extends React.Component {
63108
dropdown = (
64109
<div
65110
className={[styles.rightArrow, verticalCenter].join(' ')}
66-
onClick={() => {
67-
let position = Position.inDocument(this.node);
68-
let align = Directions.LEFT;
69-
if (position.x > 700) {
70-
position.x += this.node.clientWidth;
71-
align = Directions.RIGHT;
72-
}
73-
this.setState({
74-
open: !this.state.open,
75-
position,
76-
align
77-
});
78-
}} />
111+
onClick={this.handleOpenPopover.bind(this)} />
79112
);
80113
}
81114

@@ -90,7 +123,11 @@ export default class ExplorerActiveChartButton extends React.Component {
90123
}}>
91124
{checkMark}
92125
</div>
93-
<div className={styles.label}>{this.props.query.name}</div>
126+
<div
127+
className={styles.label}
128+
onClick={this.handleOpenPopover.bind(this)}>
129+
{this.props.query.name}
130+
</div>
94131
{dropdown}
95132
</div>
96133
);
@@ -110,12 +147,17 @@ export default class ExplorerActiveChartButton extends React.Component {
110147

111148
popover = (
112149
<Popover
113-
fixed={false}
150+
fixed={true}
114151
position={this.state.position}>
115-
<div className={classes.join(' ')}>
116-
{content}
117-
<div className={styles.callout} style={calloutStyle}></div>
152+
<div
153+
ref={this.setParentNode.bind(this)}
154+
className={classes.join(' ')}>
155+
<div
156+
className={styles.callout}
157+
style={calloutStyle}>
158+
</div>
118159
<ExplorerQueryComposer
160+
index={this.props.index || 0}
119161
isNew={false}
120162
query={this.props.query}
121163
isTimeSeries={this.props.isTimeSeries}

src/components/ExplorerActiveChartButton/ExplorerActiveChartButton.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
position: absolute;
4646
max-width: 200px;
4747
left: 30px;
48-
top: 8px;
48+
top: 4px;
4949
}
5050

5151
.composerContainer {

src/components/ExplorerMenuButton/ExplorerMenuButton.react.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,38 @@ export default class ExplorerMenuButton extends React.Component {
2424
position: null,
2525
align: Directions.LEFT
2626
};
27+
this.parentNode = {}
2728
}
2829

2930
componentDidMount() {
3031
this.node = ReactDOM.findDOMNode(this);
3132
}
3233

34+
componentWillMount() {
35+
// Used to close query picker
36+
document.addEventListener('mousedown', this.handleClick.bind(this), false)
37+
}
38+
39+
componentWillUnmount() {
40+
// Used to close query picker
41+
document.removeEventListener('mousedown', this.handleClick.bind(this), false)
42+
}
43+
44+
// Intercept all click events
45+
handleClick(e) {
46+
// Verify if the click is outside the picker
47+
if (this.state.currentView && this.parentNode && !this.parentNode.contains(e.target)) {
48+
// Click target is not inside the configuration dropdown
49+
if (e.target.parentNode && !e.target.parentNode.className.match('menu'))
50+
this.toggle() // Close picker
51+
}
52+
}
53+
54+
// Set parent node
55+
setParentNode(node) {
56+
this.parentNode = node
57+
}
58+
3359
toggle() {
3460
this.setState(() => {
3561
if (this.state.currentView) {
@@ -41,6 +67,8 @@ export default class ExplorerMenuButton extends React.Component {
4167
position.x += this.node.clientWidth;
4268
align = Directions.RIGHT;
4369
}
70+
// Add the button height to the picker appear on the bottom
71+
position.y += this.node.clientHeight
4472
return {
4573
currentView: 'picker',
4674
position,
@@ -102,17 +130,18 @@ export default class ExplorerMenuButton extends React.Component {
102130
<ExplorerQueryComposer
103131
isNew={true}
104132
isTimeSeries={this.props.isTimeSeries}
105-
onSave={this.handleSave.bind(this)} />
133+
onSave={this.handleSave.bind(this)}
134+
index={this.props.index || 0}/>
106135
);
107136
break;
108137
}
109138

110139
popover = (
111140
<Popover
112-
fixed={false}
141+
fixed={true}
113142
position={this.state.position}>
114-
<div className={classes.join(' ')}>
115-
{content}
143+
<div ref={this.setParentNode.bind(this)}
144+
className={classes.join(' ')}>
116145
<div className={styles.callout} style={calloutStyle}></div>
117146
{queryMenu}
118147
</div>

0 commit comments

Comments
 (0)