Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Adds sticky header row (site selection, date, filters) (#472)

Vignesh Joglekarb64f9de51aff
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea39502706..e5f846c928 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Simple notifications around traffic spikes plausible/analytics#453
- Dark theme option/system setting follow plausible/analytics#467
- "Load More" capability to pages modal plausible/analytics#480
+- Pinned filter and date selector rows while scrolling plausible/analytics#472
### Changed
- Use alpine as base image to decrease Docker image size plausible/analytics#353
diff --git a/assets/css/app.css b/assets/css/app.css
index c9eeda96e6..1879828815 100644
--- a/assets/css/app.css
+++ b/assets/css/app.css
@@ -29,7 +29,8 @@ html {
body {
-webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
+ -moz-osx-font-smoothing: grayscale;
+ overflow-x: hidden;
}
blockquote {
@@ -266,3 +267,15 @@ blockquote {
.dark .hoverinfo {
box-shadow: 1px 1px 5px rgb(26, 32, 44);
}
+
+.fullwidth-shadow::before {
+ @apply h-full absolute top-0 bg-gray-50 w-screen dark:bg-gray-850;
+ box-shadow: 0 4px 2px -2px rgba(0, 0, 0, 0.06);
+ content: "";
+ z-index: -1;
+ left: calc(-1 * calc(50vw - 50%));
+}
+
+.dark .fullwidth-shadow::before {
+ box-shadow: 0 4px 2px -2px rgba(200, 200, 200, 0.1);
+}
diff --git a/assets/js/dashboard/filters.js b/assets/js/dashboard/filters.js
index 032d7852a5..4adbe091dd 100644
--- a/assets/js/dashboard/filters.js
+++ b/assets/js/dashboard/filters.js
@@ -68,7 +68,7 @@ function renderFilter(history, [key, value], query) {
}
return (
- <span key={key} title={value} className="inline-flex bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-300 shadow text-sm rounded py-2 px-3 mr-4">
+ <span key={key} title={value} className="inline-flex bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-300 shadow text-sm rounded py-2 px-3 mr-4 mb-2">
{filterText(key, value, query)} <b className="ml-1 cursor-pointer" onClick={removeFilter}>✕</b>
</span>
)
diff --git a/assets/js/dashboard/historical.js b/assets/js/dashboard/historical.js
index e19a1e39a9..21f9c044da 100644
--- a/assets/js/dashboard/historical.js
+++ b/assets/js/dashboard/historical.js
@@ -10,8 +10,9 @@ import Pages from './stats/pages'
import Countries from './stats/countries'
import Devices from './stats/devices'
import Conversions from './stats/conversions'
+import { withPinnedHeader } from './pinned-header-hoc';
-export default class Historical extends React.Component {
+class Historical extends React.Component {
renderConversions() {
if (this.props.site.hasGoals) {
return (
@@ -25,14 +26,17 @@ export default class Historical extends React.Component {
render() {
return (
<div className="mb-12">
- <div className="w-full sm:flex justify-between items-center">
- <div className="w-full flex items-center">
- <SiteSwitcher site={this.props.site} loggedIn={this.props.loggedIn} />
- <CurrentVisitors timer={this.props.timer} site={this.props.site} />
+ <div id="stats-container-top"></div>
+ <div className={`sticky top-0 bg-gray-50 dark:bg-gray-850 py-3 z-9 ${this.props.stuck ? 'z-10 fullwidth-shadow' : ''}`}>
+ <div className="w-full sm:flex justify-between items-center">
+ <div className="w-full flex items-center">
+ <SiteSwitcher site={this.props.site} loggedIn={this.props.loggedIn} />
+ <CurrentVisitors timer={this.props.timer} site={this.props.site} />
+ </div>
+ <Datepicker site={this.props.site} query={this.props.query} />
</div>
- <Datepicker site={this.props.site} query={this.props.query} />
+ <Filters query={this.props.query} history={this.props.history} />
</div>
- <Filters query={this.props.query} history={this.props.history} />
<VisitorGraph site={this.props.site} query={this.props.query} />
<div className="w-full block md:flex items-start justify-between">
<Sources site={this.props.site} query={this.props.query} />
@@ -47,3 +51,5 @@ export default class Historical extends React.Component {
)
}
}
+
+export default withPinnedHeader(Historical, 'historical');
diff --git a/assets/js/dashboard/pinned-header-hoc.js b/assets/js/dashboard/pinned-header-hoc.js
new file mode 100644
index 0000000000..51547a252b
--- /dev/null
+++ b/assets/js/dashboard/pinned-header-hoc.js
@@ -0,0 +1,35 @@
+import React from 'react';
+
+export const withPinnedHeader = (WrappedComponent, flagName) => {
+ return class extends React.Component {
+ constructor(props) {
+ super(props)
+ this.state = {
+ stuck: false
+ }
+ }
+
+ componentDidMount() {
+ this.observer = new IntersectionObserver((entries) => {
+ if (entries[0].intersectionRatio === 0)
+ this.setState({ stuck: true });
+ else if (entries[0].intersectionRatio === 1)
+ this.setState({ stuck: false });
+ }, {
+ threshold: [0, 1]
+ });
+
+ this.observer.observe(document.querySelector("#stats-container-top"));
+ }
+
+ componentWillUnmount() {
+ this.observer.unobserve(document.querySelector("#stats-container-top"));
+ }
+
+ render() {
+ return (
+ <WrappedComponent stuck={this.state.stuck}{...this.props}/>
+ );
+ }
+ }
+}
diff --git a/assets/js/dashboard/realtime.js b/assets/js/dashboard/realtime.js
index c07b66878d..33a3303b53 100644
--- a/assets/js/dashboard/realtime.js
+++ b/assets/js/dashboard/realtime.js
@@ -10,8 +10,9 @@ import Pages from './stats/pages'
import Countries from './stats/countries'
import Devices from './stats/devices'
import Conversions from './stats/conversions'
+import { withPinnedHeader } from './pinned-header-hoc';
-export default class Stats extends React.Component {
+class Realtime extends React.Component {
renderConversions() {
if (this.props.site.hasGoals) {
return (
@@ -25,13 +26,16 @@ export default class Stats extends React.Component {
render() {
return (
<div className="mb-12">
- <div className="w-full sm:flex justify-between items-center">
- <div className="w-full flex items-center">
- <SiteSwitcher site={this.props.site} loggedIn={this.props.loggedIn} />
+ <div id="stats-container-top"></div>
+ <div className={`sticky top-0 bg-gray-50 dark:bg-gray-850 py-3 z-9 ${this.props.stuck ? 'z-10 fullwidth-shadow' : ''}`}>
+ <div className="w-full sm:flex justify-between items-center">
+ <div className="w-full flex items-center">
+ <SiteSwitcher site={this.props.site} loggedIn={this.props.loggedIn} />
+ </div>
+ <Datepicker site={this.props.site} query={this.props.query} />
</div>
- <Datepicker site={this.props.site} query={this.props.query} />
+ <Filters query={this.props.query} history={this.props.history} />
</div>
- <Filters query={this.props.query} history={this.props.history} />
<VisitorGraph site={this.props.site} query={this.props.query} timer={this.props.timer} />
<div className="w-full block md:flex items-start justify-between">
<Sources site={this.props.site} query={this.props.query} timer={this.props.timer} />
@@ -47,3 +51,5 @@ export default class Stats extends React.Component {
)
}
}
+
+export default withPinnedHeader(Realtime, 'realtime');
diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js
index 13c84b7d98..fe9b5e7900 100644
--- a/assets/tailwind.config.js
+++ b/assets/tailwind.config.js
@@ -25,6 +25,9 @@ module.exports = {
},
opacity: {
'15': '0.15',
+ },
+ zIndex: {
+ '9': 9,
}
},
},