Skip to content

Commit 924b5b7

Browse files
authored
Fix date filters (#1682)
* Date pickups not working on filters * catching onClick event,stop propagating to parent
1 parent efd24f8 commit 924b5b7

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

src/components/BrowserFilter/BrowserFilter.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default class BrowserFilter extends React.Component {
110110
filters={this.state.filters}
111111
onChange={filters => this.setState({ filters: filters })}
112112
renderRow={props => (
113-
<FilterRow {...props} active={this.props.filters.size > 0} />
113+
<FilterRow {...props} active={this.props.filters.size > 0} parentContentId={POPOVER_CONTENT_ID} />
114114
)}
115115
/>
116116
<div className={styles.footer}>

src/components/BrowserFilter/FilterRow.react.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let setFocus = (input) => {
2727
}
2828
}
2929

30-
function compareValue(info, value, onChangeCompareTo, active) {
30+
function compareValue(info, value, onChangeCompareTo, active, parentContentId) {
3131
switch (info.type) {
3232
case null:
3333
return null;
@@ -70,7 +70,8 @@ function compareValue(info, value, onChangeCompareTo, active) {
7070
className={styles.date}
7171
value={Parse._decode('date', value)}
7272
onChange={(value) => onChangeCompareTo(Parse._encode(value))}
73-
ref={setFocus} />
73+
ref={setFocus}
74+
parentContentId={parentContentId} />
7475
);
7576
}
7677
}
@@ -87,6 +88,7 @@ let FilterRow = ({
8788
onChangeCompareTo,
8889
onDeleteRow,
8990
active,
91+
parentContentId,
9092
}) => (
9193
<div className={styles.row}>
9294
<ChromeDropdown
@@ -100,7 +102,7 @@ let FilterRow = ({
100102
value={Constraints[currentConstraint].name}
101103
options={constraints.map((c) => Constraints[c].name)}
102104
onChange={(c) => onChangeConstraint(constraintLookup[c])} />
103-
{compareValue(compareInfo, compareTo, onChangeCompareTo, active)}
105+
{compareValue(compareInfo, compareTo, onChangeCompareTo, active, parentContentId)}
104106
<a role='button' href='javascript:;' className={styles.remove} onClick={onDeleteRow}><Icon name='minus-solid' width={14} height={14} fill='rgba(0,0,0,0.4)' /></a>
105107
</div>
106108
);

src/components/DateTimeEntry/DateTimeEntry.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class DateTimeEntry extends React.Component {
8787
let popover = null;
8888
if (this.state.open) {
8989
popover = (
90-
<Popover fixed={true} position={this.state.position} onExternalClick={this.close.bind(this)}>
90+
<Popover fixed={true} position={this.state.position} onExternalClick={this.close.bind(this)} parentContentId={this.props.parentContentId}>
9191
<DateTimePicker
9292
value={this.props.value}
9393
width={Math.max(this.node.clientWidth, 240)}

src/components/DateTimePicker/DateTimePicker.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default class DateTimePicker extends React.Component {
9090

9191
render() {
9292
return (
93-
<div style={{ width: this.props.width }} className={styles.picker}>
93+
<div style={{ width: this.props.width }} className={styles.picker} onClick={(e) => e.stopPropagation()} >
9494
<Calendar local={this.props.local} value={this.props.value} onChange={(newValue) => {
9595
let timeRef = this.props.value || hoursFrom(new Date(), 1);
9696
let newDate = this.props.local ? new Date(

src/components/Popover/Popover.react.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export default class Popover extends React.Component {
5757
this._popoverLayer.className = styles.transition;
5858
}
5959

60+
if (this.props.parentContentId) {
61+
this._popoverLayer.dataset.parentContentId = this.props.parentContentId;
62+
}
63+
6064
document.body.addEventListener('click', this._checkExternalClick);
6165
}
6266

@@ -78,7 +82,7 @@ export default class Popover extends React.Component {
7882
: this._popoverLayer;
7983
const isChromeDropdown = e.target.parentNode.classList.contains('chromeDropdown');
8084
if (
81-
!hasAncestor(e.target, popoverWrapper) &&
85+
!hasAncestor(e.target, popoverWrapper, contentId) &&
8286
this.props.onExternalClick &&
8387
!isChromeDropdown
8488
) {

src/lib/hasAncestor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8-
export default function hasAncestor(node, ancestor) {
8+
export default function hasAncestor(node, ancestor, contentId) {
99
let cur = node.parentNode;
1010
while (cur && cur.nodeType === 1) {
1111
if (cur === ancestor) {
1212
return true;
13+
} else if (contentId && cur.dataset.parentContentId === contentId) {
14+
return true;
1315
}
1416
cur = cur.parentNode;
1517
}

0 commit comments

Comments
 (0)