analytics/lib/plausible_web
RobertJoonas e5b56dbe62
Refactor VisitorGraph (#3936)
* Give a more semantic name to a function

* Make the LineGraph component thinner

* Move LineGraph into a separate file

* Move interval logic into interval-picker.js

This commit also fixes a bug where the interval name displayed inside
the picker component flickers the default interval when the graph is
loading.

The problem was that we were counting on graphData for returning us the
current interval: `let currentInterval = graphData?.interval`

We should always know the default interval before making the main-graph
request. Sending graphData to IntervalPicker component does not make
sense anyway.

* extract data fetching functions out of VisitorGraph component

* Return graph_metric key from Top Stats API

This commit introduces no behavioral changes - only starts returning an
additional field, allowing us to avoid the following logic in React:

1. Finding the metric names, given a stat display name. E.g.
   `Unique visitors (last 30 min) -> visitors`

2. Checking if a metric is graphable or not

* Move metric state into localStorage

This commit gets rid of the internal `metric` state in the VisitorGraph
component and starts using localStorage for that instead.

This commit also chains the main-graph request into the top-stats request
callback - meaning that we'll always fetch new graph data after top stats
are updated. And we do it all in a single function.

Doing so simplifies the loading state significantly, and also helps to
make it clear, that at all times, existing top stats are required before
we can fetch the graph. That's because the metric is determined by which
Top stats are returned (for example, we can't be sure whether revenue
metrics will be returned or not).

* Make sure graph tooltip says "Converted Visitors"

* Extract a StatsExport function component

Again, instead of relying on `graphData?.interval` we can read it from
localStorage, or default to the largest interval available. The export
should not be dependant on the graph.

* Extract SamplingNotice function component

* Extract WithImportedSwitch function component

* Stop "lazy-loading" the graph and top stats

Since the container is always on top on the page, it will be visible on
the first render in any case - no matter the screen size.

* Turn VisitorGraph into a function component

* Display empty container until everything has loaded

* Do not display loading spinner on realtime ticks

* Turn Top Stats into a fn component

* fetch top stats and graph async

* Make sure revenue metrics can remain on the graph

* Add an extra check to canMetricBeGraphed

* fix typo

* remove redundant double negation
2024-04-04 13:39:55 +01:00
..
components Use sessionStorage for "dashboard first launch" banner tracking (#3892) 2024-03-26 09:49:15 +01:00
controllers Refactor VisitorGraph (#3936) 2024-04-04 13:39:55 +01:00
live Implement adjusting imported date range to actual and existing stats (#3943) 2024-03-28 09:32:41 +01:00
mjml Small bugfix + refactor email reports (#3642) 2023-12-21 12:56:06 +00:00
plugins/api Plugins API: mark data_domain as nullable in capabilities schema (#3840) 2024-02-28 10:26:01 +01:00
plugs Add GET /capabilities to Plugins API (#3808) 2024-02-21 12:41:56 +01:00
templates Refactor VisitorGraph (#3936) 2024-04-04 13:39:55 +01:00
two_factor Implement UI for 2FA setup and verification (#3541) 2023-12-06 12:01:19 +01:00
views Reapply 3918 (#3940) 2024-03-25 10:36:22 +01:00
captcha.ex Include tests for Captcha success/failure scenarios (#2344) 2022-10-17 08:16:59 -03:00
email.ex Add multiple imports per site (#3724) 2024-02-14 09:32:36 +01:00
endpoint.ex make robots.txt restrictive by default (#3905) 2024-03-19 12:07:30 +01:00
refinspector.ex Store referrers from android apps (#3715) 2024-03-21 17:45:34 +02:00
remote_ip.ex IP Block List (#3761) 2024-02-12 14:55:20 +01:00
router.ex CSV imports (UI) (#3845) 2024-03-26 12:55:14 +01:00