Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid filter tab disappears on apply filter #1229

Merged
merged 6 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions src/components/BrowserFilter/BrowserFilter.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,30 @@ export default class BrowserFilter extends React.Component {
open: false,
filters: new List(),
};
this.toggle = this.toggle.bind(this)
}

componentDidMount() {
this.node = ReactDOM.findDOMNode(this);
}

componentWillReceiveProps(props) {
if (props.schema !== this.props.schema) {
if (props.className !== this.props.className) {
this.setState({ open: false });
}
}

open() {
toggle() {
let filters = this.props.filters;
if (this.props.filters.size === 0) {
let available = Filters.availableFilters(this.props.schema, null, BLACKLISTED_FILTERS);
let field = Object.keys(available)[0];
filters = new List([new Map({ field: field, constraint: available[field][0] })]);
}
this.setState({
open: true,
this.setState(prevState => ({
open: !prevState.open,
filters: filters,
});
}));
this.props.setCurrent(null);
}

Expand All @@ -62,9 +63,7 @@ export default class BrowserFilter extends React.Component {
}

clear() {
this.setState({ open: false }, () => {
this.props.onChange(new Map());
});
this.props.onChange(new Map());
}

apply() {
Expand All @@ -76,27 +75,26 @@ export default class BrowserFilter extends React.Component {
}*/
return filter;
})
this.setState({ open: false }, () => {
this.props.onChange(formatted);
});
this.props.onChange(formatted);
}

render() {
let popover = null;
let buttonStyle = [styles.entry];

if (this.state.open) {
let position = Position.inDocument(this.node);
let popoverStyle = [styles.popover];
buttonStyle.push(styles.title);

if (this.props.filters.size) {
popoverStyle.push(styles.active);
}
let available = Filters.availableFilters(this.props.schema, this.state.filters);
popover = (
<Popover fixed={true} position={position}>
<Popover fixed={true} position={position} onExternalClick={this.toggle}>
<div className={popoverStyle.join(' ')} onClick={() => this.props.setCurrent(null)}>
<div className={styles.title} onClick={() => this.setState({ open: false })}>
<Icon name='filter-solid' width={14} height={14} />
<span>{this.props.filters.size ? 'Filtered' : 'Filter'}</span>
</div>
<div onClick={this.toggle} style={{ cursor: 'pointer', width: this.node.clientWidth, height: this.node.clientHeight }}></div>
<div className={styles.body}>
<Filter
blacklist={BLACKLISTED_FILTERS}
Expand Down Expand Up @@ -129,13 +127,12 @@ export default class BrowserFilter extends React.Component {
</Popover>
);
}
let buttonStyle = [styles.entry];
if (this.props.filters.size) {
buttonStyle.push(styles.active);
}
return (
<div className={styles.wrap}>
<div className={buttonStyle.join(' ')} onClick={this.open.bind(this)}>
<div className={buttonStyle.join(' ')} onClick={this.toggle}>
<Icon name='filter-solid' width={14} height={14} />
<span>{this.props.filters.size ? 'Filtered' : 'Filter'}</span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Popover/Popover.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
import PropTypes from 'lib/PropTypes';
import PropTypes from 'lib/PropTypes';
import hasAncestor from 'lib/hasAncestor';
import React from 'react';
import ReactDOM from 'react-dom';
Expand Down Expand Up @@ -83,7 +83,7 @@ export default class Popover extends React.Component {
}

_checkExternalClick(e) {
if (!hasAncestor(e.target, this._popoverLayer) &&
if (!hasAncestor(e.target, this._popoverWrapper) &&
this.props.onExternalClick) {
this.props.onExternalClick(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/dashboard/Data/Browser/BrowserToolbar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ let BrowserToolbar = ({
setCurrent={setCurrent}
schema={schema}
filters={filters}
onChange={onFilterChange} />
onChange={onFilterChange}
className={className} />
<div className={styles.toolbarSeparator} />
{enableSecurityDialog ? <SecurityDialog
setCurrent={setCurrent}
Expand Down