From da7ccc45e4ca28b1663669e06b07c13c160b9ab8 Mon Sep 17 00:00:00 2001 From: Vignesh Joglekar Date: Thu, 21 Jan 2021 07:11:48 -0600 Subject: [PATCH] Allow for `Esc` to clear all filters (#625) * Allow for `Esc` to clear all filters * Changelog * Change duplicated ctrlKey (in DatePicker too) --- CHANGELOG.md | 1 + assets/js/dashboard/datepicker.js | 2 +- assets/js/dashboard/filters.js | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ce8df27b..ada8679cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/assets/js/dashboard/datepicker.js b/assets/js/dashboard/datepicker.js index b8007c361..42882e5b7 100644 --- a/assets/js/dashboard/datepicker.js +++ b/assets/js/dashboard/datepicker.js @@ -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, diff --git a/assets/js/dashboard/filters.js b/assets/js/dashboard/filters.js index 52715c322..13c1d36da 100644 --- a/assets/js/dashboard/filters.js +++ b/assets/js/dashboard/filters.js @@ -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(); @@ -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}); }