Skip to content

Commit

Permalink
Fix date filters (parse-community#1682)
Browse files Browse the repository at this point in the history
* Date pickups not working on filters

* catching onClick event,stop propagating to parent
  • Loading branch information
sadakchap authored and Arul- committed Apr 20, 2021
1 parent 9114c2d commit 4f382f9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/BrowserFilter/BrowserFilter.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class BrowserFilter extends React.Component {
filters={this.state.filters}
onChange={filters => this.setState({ filters: filters })}
renderRow={props => (
<FilterRow {...props} active={this.props.filters.size > 0} />
<FilterRow {...props} active={this.props.filters.size > 0} parentContentId={POPOVER_CONTENT_ID} />
)}
/>
<div className={styles.footer}>
Expand Down
8 changes: 5 additions & 3 deletions src/components/BrowserFilter/FilterRow.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let setFocus = (input) => {
}
}

function compareValue(info, value, onChangeCompareTo, active) {
function compareValue(info, value, onChangeCompareTo, active, parentContentId) {
switch (info.type) {
case null:
return null;
Expand Down Expand Up @@ -70,7 +70,8 @@ function compareValue(info, value, onChangeCompareTo, active) {
className={styles.date}
value={Parse._decode('date', value)}
onChange={(value) => onChangeCompareTo(Parse._encode(value))}
ref={setFocus} />
ref={setFocus}
parentContentId={parentContentId} />
);
}
}
Expand All @@ -87,6 +88,7 @@ let FilterRow = ({
onChangeCompareTo,
onDeleteRow,
active,
parentContentId,
}) => (
<div className={styles.row}>
<ChromeDropdown
Expand All @@ -100,7 +102,7 @@ let FilterRow = ({
value={Constraints[currentConstraint].name}
options={constraints.map((c) => Constraints[c].name)}
onChange={(c) => onChangeConstraint(constraintLookup[c])} />
{compareValue(compareInfo, compareTo, onChangeCompareTo, active)}
{compareValue(compareInfo, compareTo, onChangeCompareTo, active, parentContentId)}
<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>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/DateTimeEntry/DateTimeEntry.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class DateTimeEntry extends React.Component {
let popover = null;
if (this.state.open) {
popover = (
<Popover fixed={true} position={this.state.position} onExternalClick={this.close.bind(this)}>
<Popover fixed={true} position={this.state.position} onExternalClick={this.close.bind(this)} parentContentId={this.props.parentContentId}>
<DateTimePicker
value={this.props.value}
width={Math.max(this.node.clientWidth, 240)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DateTimePicker/DateTimePicker.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class DateTimePicker extends React.Component {

render() {
return (
<div style={{ width: this.props.width }} className={styles.picker}>
<div style={{ width: this.props.width }} className={styles.picker} onClick={(e) => e.stopPropagation()} >
<Calendar local={this.props.local} value={this.props.value} onChange={(newValue) => {
let timeRef = this.props.value || hoursFrom(new Date(), 1);
let newDate = this.props.local ? new Date(
Expand Down
6 changes: 5 additions & 1 deletion src/components/Popover/Popover.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export default class Popover extends React.Component {
this._popoverLayer.className = styles.transition;
}

if (this.props.parentContentId) {
this._popoverLayer.dataset.parentContentId = this.props.parentContentId;
}

document.body.addEventListener('click', this._checkExternalClick);
}

Expand All @@ -78,7 +82,7 @@ export default class Popover extends React.Component {
: this._popoverLayer;
const isChromeDropdown = e.target.parentNode.classList.contains('chromeDropdown');
if (
!hasAncestor(e.target, popoverWrapper) &&
!hasAncestor(e.target, popoverWrapper, contentId) &&
this.props.onExternalClick &&
!isChromeDropdown
) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/hasAncestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
export default function hasAncestor(node, ancestor) {
export default function hasAncestor(node, ancestor, contentId) {
let cur = node.parentNode;
while (cur && cur.nodeType === 1) {
if (cur === ancestor) {
return true;
} else if (contentId && cur.dataset.parentContentId === contentId) {
return true;
}
cur = cur.parentNode;
}
Expand Down

0 comments on commit 4f382f9

Please sign in to comment.