From dd20fc8a17edfcba74209f5450f6b27cf897b94c Mon Sep 17 00:00:00 2001 From: Ru Singh Date: Fri, 13 Aug 2021 13:30:42 +0530 Subject: [PATCH] Feature/details modal mobile (#1211) * chore(docker): improve repeat contributions workflow * This change adds two new commands to gracefully stop and remove the Postgres and Clickhouse docker containers. To do so, it also gives them a recognizable name. * Additionally, the Postgres container is updated to use a named volume for its data. This lower friction for repeat contributions where one would otherwise sign up and activate their accounts again and again each time. * Format countries modal * Remove unused imports * Run ESLint and make related fixes * ESlint formatting for entry pages modal * WIP: proof of concept for scrollable modals on mobile * Fix modals being too wide on desktop * Make modals truly responsive This fixes the desktop behaviour completely now. * Update changelog with modals responsiveness * Update desktop modal width to 860px It was an oversight to set it at 800px in the first place. Co-authored-by: Uku Taht --- CHANGELOG.md | 1 + assets/css/modal.css | 2 +- assets/js/dashboard/stats/modals/countries.js | 40 +++++++---- .../js/dashboard/stats/modals/entry-pages.js | 66 ++++++++++++++----- .../js/dashboard/stats/modals/exit-pages.js | 4 +- .../dashboard/stats/modals/google-keywords.js | 6 +- assets/js/dashboard/stats/modals/modal.js | 42 +++++++++++- assets/js/dashboard/stats/modals/pages.js | 4 +- .../stats/modals/referrer-drilldown.js | 4 +- assets/js/dashboard/stats/modals/sources.js | 4 +- 10 files changed, 132 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5efb58019..81bef6294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file. - UI fix for the main graph on mobile overlapping its tick items on both axis - UI fixes for text not showing properly in bars across multiple lines. This hides the totals on <768px and only shows the uniques and % to accommodate the goals text too. Larger screens still truncate as usual. - Turn off autocomplete for name and password inputs in the _New shared link_ form. +- Details modals are now responsive and take up less horizontal space on smaller screens to make it easier to scroll. ### Removed - Removes AppSignal monitoring package diff --git a/assets/css/modal.css b/assets/css/modal.css index 2a36314ef..a87b55f76 100644 --- a/assets/css/modal.css +++ b/assets/css/modal.css @@ -31,7 +31,7 @@ bottom: 0; background: rgba(0,0,0,0.6); z-index: 99; - overflow-x: hidden; + overflow-x: auto; overflow-y: auto; } diff --git a/assets/js/dashboard/stats/modals/countries.js b/assets/js/dashboard/stats/modals/countries.js index 0e833389a..0442aaa70 100644 --- a/assets/js/dashboard/stats/modals/countries.js +++ b/assets/js/dashboard/stats/modals/countries.js @@ -5,7 +5,6 @@ import Datamap from 'datamaps' import Modal from './modal' import * as api from '../../api' import numberFormatter from '../../number-formatter' -import Bar from '../bar' import {parseQuery} from '../../query' class CountriesModal extends React.Component { @@ -22,6 +21,10 @@ class CountriesModal extends React.Component { .then((res) => this.setState({loading: false, countries: res})) } + label() { + return this.state.query.period === 'realtime' ? 'Current visitors' : 'Visitors' + } + renderCountry(country) { const query = new URLSearchParams(window.location.search) query.set('country', country.name) @@ -33,7 +36,11 @@ class CountriesModal extends React.Component { return ( - + {countryFullName} @@ -44,27 +51,36 @@ class CountriesModal extends React.Component { ) } - label() { - return this.state.query.period === 'realtime' ? 'Current visitors' : 'Visitors' - } - renderBody() { if (this.state.loading) { return (
) - } else if (this.state.countries) { + } + + if (this.state.countries) { return ( - + <>

Top countries

- +
- - + + @@ -72,7 +88,7 @@ class CountriesModal extends React.Component {
Country{this.label()} + Country + + {this.label()} +
-
+ ) } } diff --git a/assets/js/dashboard/stats/modals/entry-pages.js b/assets/js/dashboard/stats/modals/entry-pages.js index fae48642f..386a90911 100644 --- a/assets/js/dashboard/stats/modals/entry-pages.js +++ b/assets/js/dashboard/stats/modals/entry-pages.js @@ -1,6 +1,6 @@ import React from "react"; -import { Link } from 'react-router-dom' -import { withRouter } from 'react-router-dom' +import { Link , withRouter } from 'react-router-dom' + import Modal from './modal' import * as api from '../../api' @@ -26,12 +26,23 @@ class EntryPagesModal extends React.Component { loadPages() { const {query, page, pages} = this.state; - api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/entry-pages`, query, {limit: 100, page}) - .then((res) => this.setState((state) => ({loading: false, pages: state.pages.concat(res), moreResultsAvailable: res.length === 100}))) + api.get( + `/api/stats/${encodeURIComponent(this.props.site.domain)}/entry-pages`, + query, + {limit: 100, page} + ) + .then( + (res) => this.setState((state) => ({ + loading: false, + pages: state.pages.concat(res), + moreResultsAvailable: res.length === 100 + })) + ) } loadMore() { - this.setState({loading: true, page: this.state.page + 1}, this.loadPages.bind(this)) + const { page } = this.state; + this.setState({loading: true, page: page + 1}, this.loadPages.bind(this)) } showVisitDuration() { @@ -40,10 +51,9 @@ class EntryPagesModal extends React.Component { formatBounceRate(page) { if (typeof(page.bounce_rate) === 'number') { - return page.bounce_rate + '%' - } else { - return '-' + return `${page.bounce_rate}%`; } + return '-'; } renderPage(page) { @@ -53,7 +63,15 @@ class EntryPagesModal extends React.Component { return ( - {page.name} + + {page.name} + {numberFormatter(page.count)} {numberFormatter(page.entries)} @@ -79,18 +97,34 @@ class EntryPagesModal extends React.Component { renderBody() { if (this.state.pages) { return ( - + <>

Entry Pages

- +
- - - - {} + + + + @@ -98,7 +132,7 @@ class EntryPagesModal extends React.Component {
Page urlUnique EntrancesTotal EntrancesVisit DurationPage url + Unique Entrances + Total Entrances + Visit Duration +
-
+ ) } } diff --git a/assets/js/dashboard/stats/modals/exit-pages.js b/assets/js/dashboard/stats/modals/exit-pages.js index a4e295a2b..384ee420d 100644 --- a/assets/js/dashboard/stats/modals/exit-pages.js +++ b/assets/js/dashboard/stats/modals/exit-pages.js @@ -80,10 +80,10 @@ class ExitPagesModal extends React.Component {
- +
- + diff --git a/assets/js/dashboard/stats/modals/google-keywords.js b/assets/js/dashboard/stats/modals/google-keywords.js index 35d8d0fe2..268550f88 100644 --- a/assets/js/dashboard/stats/modals/google-keywords.js +++ b/assets/js/dashboard/stats/modals/google-keywords.js @@ -81,11 +81,11 @@ class GoogleKeywordsModal extends React.Component { } } else if (this.state.searchTerms.length > 0) { return ( -
Page urlPage url Unique Exits Total Exits Exit Rate
+
- - + + diff --git a/assets/js/dashboard/stats/modals/modal.js b/assets/js/dashboard/stats/modals/modal.js index cd6603baa..bfc6fe832 100644 --- a/assets/js/dashboard/stats/modals/modal.js +++ b/assets/js/dashboard/stats/modals/modal.js @@ -2,12 +2,22 @@ import React from "react"; import { createPortal } from "react-dom"; import { withRouter } from 'react-router-dom'; +// This corresponds to the 'md' breakpoint on TailwindCSS. +const MD_WIDTH = 768; +// We assume that the dashboard is by default opened on a desktop. This is also a fall-back for when, for any reason, the width is not ascertained. +const DEFAULT_WIDTH = 1080; + + class Modal extends React.Component { constructor(props) { super(props) + this.state = { + viewport: DEFAULT_WIDTH, + } this.node = React.createRef() this.handleClickOutside = this.handleClickOutside.bind(this) this.handleKeyup = this.handleKeyup.bind(this) + this.handleResize = this.handleResize.bind(this) } componentDidMount() { @@ -15,6 +25,8 @@ class Modal extends React.Component { document.body.style.height = '100vh'; document.addEventListener("mousedown", this.handleClickOutside); document.addEventListener("keyup", this.handleKeyup); + window.addEventListener('resize', this.handleResize, false); + this.handleResize(); } componentWillUnmount() { @@ -22,6 +34,7 @@ class Modal extends React.Component { document.body.style.height = null; document.removeEventListener("mousedown", this.handleClickOutside); document.removeEventListener("keyup", this.handleKeyup); + window.removeEventListener('resize', this.handleResize, false); } handleClickOutside(e) { @@ -38,16 +51,43 @@ class Modal extends React.Component { } } + handleResize() { + this.setState({ viewport: window.innerWidth }); + } + close() { this.props.history.push(`/${encodeURIComponent(this.props.site.domain)}${this.props.location.search}`) } + /** + * @description + * Decide whether to set max-width, and if so, to what. + * If no max-width is available, set width instead to min-content such that we can rely on widths set on th. + * On >md, we use the same behaviour as before: set width to 800 pixels. + * Note that When a max-width comes from the parent component, we rely on that *always*. + */ + getStyle() { + const { maxWidth } = this.props; + const { viewport } = this.state; + const styleObject = {}; + if (maxWidth) { + styleObject.maxWidth = maxWidth; + } else { + styleObject.width = viewport <= MD_WIDTH ? "min-content" : "860px"; + } + return styleObject; + } + render() { return createPortal(
-
+
{this.props.children}
diff --git a/assets/js/dashboard/stats/modals/pages.js b/assets/js/dashboard/stats/modals/pages.js index cd0c8d4b6..b0323bcbb 100644 --- a/assets/js/dashboard/stats/modals/pages.js +++ b/assets/js/dashboard/stats/modals/pages.js @@ -96,10 +96,10 @@ class PagesModal extends React.Component {
-
Search TermVisitorsSearch TermVisitors
+
- + {this.showPageviews() && } {this.showExtra() && } diff --git a/assets/js/dashboard/stats/modals/referrer-drilldown.js b/assets/js/dashboard/stats/modals/referrer-drilldown.js index 499674adf..20e62f660 100644 --- a/assets/js/dashboard/stats/modals/referrer-drilldown.js +++ b/assets/js/dashboard/stats/modals/referrer-drilldown.js @@ -149,10 +149,10 @@ class ReferrerDrilldownModal extends React.Component {

{this.state.totalVisitors} visitors from {decodeURIComponent(this.props.match.params.referrer)}
{toHuman(this.state.query)}

{this.renderGoalText()} -
Page urlPage url { this.label() }PageviewsBounce rate
+
- + {this.showExtra() && } {this.showExtra() && } diff --git a/assets/js/dashboard/stats/modals/sources.js b/assets/js/dashboard/stats/modals/sources.js index 18c7ed8c5..2d591ffb0 100644 --- a/assets/js/dashboard/stats/modals/sources.js +++ b/assets/js/dashboard/stats/modals/sources.js @@ -125,10 +125,10 @@ class SourcesModal extends React.Component {
-
ReferrerReferrer VisitorsBounce rateVisit duration
+
- + {this.showExtra() && } {this.showExtra() && }
SourceSource {this.label()}Bounce rateVisit duration