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

Allow for Esc to clear all filters #625

Merged
merged 4 commits into from
Jan 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
- "Load More" capability to pages modal plausible/analytics#480
- Unique Visitors (last 30 min) as a top stat in realtime view plausible/analytics#500
- Pinned filter and date selector rows while scrolling plausible/analytics#472
- Escape keyboard shortcut to clear all filters plausible/analytics#625

### Changed
- Use alpine as base image to decrease Docker image size plausible/analytics#353
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DatePicker extends React.Component {
handleKeyup(e) {
const { query, history } = this.props;

if (e.ctrlKey || e.ctrlKey || e.altKey) return;
if (e.ctrlKey || e.metaKey || e.altKey) return

const newSearch = {
period: false,
Expand Down
13 changes: 13 additions & 0 deletions assets/js/dashboard/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class Filters extends React.Component {
this.handleResize = this.handleResize.bind(this);
this.rewrapFilters = this.rewrapFilters.bind(this);
this.renderFilterList = this.renderFilterList.bind(this);
this.handleKeyup = this.handleKeyup.bind(this)
}

componentDidMount() {
document.addEventListener('mousedown', this.handleClick, false);
window.addEventListener('resize', this.handleResize, false);
document.addEventListener('keyup', this.handleKeyup);

this.rewrapFilters();
this.handleResize();
Expand All @@ -52,10 +54,21 @@ class Filters extends React.Component {
}

componentWillUnmount() {
document.removeEventListener("keyup", this.handleKeyup);
document.removeEventListener('mousedown', this.handleClick, false);
window.removeEventListener('resize', this.handleResize, false);
}

handleKeyup(e) {
const {query, history} = this.props

if (e.ctrlKey || e.metaKey || e.altKey) return

if (e.key === 'Escape') {
this.clearAllFilters(history, query)
}
}

handleResize() {
this.setState({ viewport: window.innerWidth || 639});
}
Expand Down