Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .pre-commit-config.yaml +19 -0
- .tool-versions +3 -0
- Agent.md +126 -0
- CHANGELOG.md +699 -0
- CODE_OF_CONDUCT.md +65 -0
- CONTRIBUTING.md +63 -0
- Dockerfile +88 -0
- LICENSE.md +661 -0
- Makefile +115 -0
- README.md +19 -0
- SECURITY.md +15 -0
- assets/.prettierignore +7 -0
- assets/.prettierrc.json +5 -0
- assets/.stylelintrc.json +13 -0
- assets/css/app.css +340 -0
- assets/css/flatpickr-colors.css +252 -0
- assets/css/loader.css +50 -0
- assets/css/modal.css +53 -0
- assets/css/tooltip.css +44 -0
- assets/data/countries_meta.json +1006 -0
- assets/eslint.config.mjs +99 -0
- assets/jest.config.json +20 -0
- assets/js/app.js +127 -0
- assets/js/dashboard/annotations/annotation-list-items.tsx +60 -0
- assets/js/dashboard/annotations/annotations-modals.tsx +380 -0
- assets/js/dashboard/annotations/annotations.test.ts +297 -0
- assets/js/dashboard/annotations/annotations.ts +224 -0
- assets/js/dashboard/annotations/hover-annotations-list.tsx +36 -0
- assets/js/dashboard/annotations/interactive-annotations-list.tsx +75 -0
- assets/js/dashboard/annotations/routeless-annotations-modals.tsx +190 -0
- assets/js/dashboard/api.ts +274 -0
- assets/js/dashboard/components/button.tsx +65 -0
- assets/js/dashboard/components/combobox.js +379 -0
- assets/js/dashboard/components/drilldown-link.tsx +86 -0
- assets/js/dashboard/components/error-panel.tsx +49 -0
- assets/js/dashboard/components/feature-preview-mocks.tsx +101 -0
- assets/js/dashboard/components/feature-setup-notice.tsx +131 -0
- assets/js/dashboard/components/filter-operator-selector.js +95 -0
- assets/js/dashboard/components/form-elements.tsx +261 -0
- assets/js/dashboard/components/graph-tooltip.tsx +100 -0
- assets/js/dashboard/components/graph.test.ts +106 -0
- assets/js/dashboard/components/graph.tsx +992 -0
- assets/js/dashboard/components/icons.tsx +191 -0
- assets/js/dashboard/components/lazy-loader.js +23 -0
- assets/js/dashboard/components/modal-layout.tsx +59 -0
- assets/js/dashboard/components/notice.tsx +26 -0
- assets/js/dashboard/components/pill.tsx +58 -0
- assets/js/dashboard/components/placeholder.tsx +20 -0
- assets/js/dashboard/components/popover.tsx +119 -0
- assets/js/dashboard/components/search-input.tsx +96 -0
.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# See https://pre-commit.com for more information
|
| 2 |
+
# See https://pre-commit.com/hooks.html for more hooks
|
| 3 |
+
repos:
|
| 4 |
+
- repo: https://gitlab.com/jvenom/elixir-pre-commit-hooks
|
| 5 |
+
rev: v1.0.0
|
| 6 |
+
hooks:
|
| 7 |
+
- id: mix-format
|
| 8 |
+
|
| 9 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
| 10 |
+
rev: v4.0.1
|
| 11 |
+
hooks:
|
| 12 |
+
- id: check-case-conflict
|
| 13 |
+
- id: check-symlinks
|
| 14 |
+
- id: check-yaml
|
| 15 |
+
- id: destroyed-symlinks
|
| 16 |
+
- id: end-of-file-fixer
|
| 17 |
+
exclude: priv/tracker/js
|
| 18 |
+
- id: mixed-line-ending
|
| 19 |
+
- id: trailing-whitespace
|
.tool-versions
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
erlang 28.5.0.3
|
| 2 |
+
elixir 1.20.2-otp-28
|
| 3 |
+
nodejs 23.2.0
|
Agent.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Agent Deployment Notes & Tricks
|
| 2 |
+
|
| 3 |
+
## 1. Deployment Configuration
|
| 4 |
+
|
| 5 |
+
### Target Space
|
| 6 |
+
- **Profile:** `Leon4gr45`
|
| 7 |
+
- **Space:** `analytics`
|
| 8 |
+
- **Full Identifier:** `Leon4gr45/analytics`
|
| 9 |
+
- **Frontend Port:** `7860` (mandatory for all Hugging Face Spaces)
|
| 10 |
+
|
| 11 |
+
### Deployment Method
|
| 12 |
+
Choose the correct SDK based on the app type based on the codebase language:
|
| 13 |
+
|
| 14 |
+
- **Gradio SDK** — for Gradio applications
|
| 15 |
+
- **Streamlit SDK** — for Streamlit applications
|
| 16 |
+
- **Docker SDK** — for all other applications (recommended default for flexibility)
|
| 17 |
+
|
| 18 |
+
### HF Token
|
| 19 |
+
- The environment variable `HF_TOKEN` will always be provided at execution time.
|
| 20 |
+
- Never hardcode the token. Always read it from the environment.
|
| 21 |
+
- All monitoring and log‑streaming commands rely on `HF_TOKEN`.
|
| 22 |
+
|
| 23 |
+
### Required Files
|
| 24 |
+
- `Dockerfile` (or `app.py` for Gradio/Streamlit SDKs)
|
| 25 |
+
- `README.md` with Hugging Face YAML frontmatter:
|
| 26 |
+
```yaml
|
| 27 |
+
---
|
| 28 |
+
title: Plausible Analytics
|
| 29 |
+
emoji: 📈
|
| 30 |
+
colorFrom: blue
|
| 31 |
+
colorTo: indigo
|
| 32 |
+
sdk: docker
|
| 33 |
+
app_port: 7860
|
| 34 |
+
pinned: false
|
| 35 |
+
---
|
| 36 |
+
```
|
| 37 |
+
- `.hfignore` to exclude unnecessary files
|
| 38 |
+
- This `Agent.md` file (must be committed before deployment)
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## 2. API Exposure and Documentation
|
| 43 |
+
|
| 44 |
+
### Mandatory Endpoints
|
| 45 |
+
Every deployment **must** expose:
|
| 46 |
+
|
| 47 |
+
- **`/health`**
|
| 48 |
+
- Returns HTTP 200 when the app is ready.
|
| 49 |
+
- Required for Hugging Face to transition the Space from *starting* → *running*.
|
| 50 |
+
|
| 51 |
+
- **`/api-docs`**
|
| 52 |
+
- Documents **all** available API endpoints.
|
| 53 |
+
- Must be reachable at:
|
| 54 |
+
`https://Leon4gr45-analytics.hf.space/api-docs`
|
| 55 |
+
|
| 56 |
+
### Functional Endpoints
|
| 57 |
+
Document each endpoint here. For every endpoint, include:
|
| 58 |
+
|
| 59 |
+
- **Method:** GET/POST/PUT/DELETE
|
| 60 |
+
- **Path:** `/predict`, `/generate`, `/upload`, etc.
|
| 61 |
+
- **Purpose:** What the endpoint does
|
| 62 |
+
- **Request Example:** JSON or query parameters
|
| 63 |
+
- **Response Example:** JSON schema or example payload
|
| 64 |
+
|
| 65 |
+
### /health
|
| 66 |
+
- Method: GET
|
| 67 |
+
- Purpose: Health check/Readiness test for transitioning space to running.
|
| 68 |
+
- Request: N/A
|
| 69 |
+
- Response:
|
| 70 |
+
```json
|
| 71 |
+
{"ok": true}
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
### /api-docs
|
| 75 |
+
- Method: GET
|
| 76 |
+
- Purpose: Document all available API endpoints.
|
| 77 |
+
- Request: N/A
|
| 78 |
+
- Response:
|
| 79 |
+
```json
|
| 80 |
+
{
|
| 81 |
+
"endpoints": [...]
|
| 82 |
+
}
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### /api/event
|
| 86 |
+
- Method: POST
|
| 87 |
+
- Purpose: Send analytic events directly via API.
|
| 88 |
+
- Request:
|
| 89 |
+
```json
|
| 90 |
+
{
|
| 91 |
+
"name": "pageview",
|
| 92 |
+
"url": "https://example.com"
|
| 93 |
+
}
|
| 94 |
+
```
|
| 95 |
+
- Response:
|
| 96 |
+
```json
|
| 97 |
+
{"ok": true}
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
All endpoints listed here appear in `/api-docs`.
|
| 101 |
+
|
| 102 |
+
---
|
| 103 |
+
|
| 104 |
+
## 3. Deployment Workflow
|
| 105 |
+
|
| 106 |
+
Precondition: Use the huggingface hub cli hf to check that the space is empty of files and delete any which are still in there and not belonging to the project to be uploaded.
|
| 107 |
+
|
| 108 |
+
### Standard Deployment Command
|
| 109 |
+
After any code change, run:
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
hf upload Leon4gr45/analytics --repo-type=space
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
### Scan build and run logs
|
| 116 |
+
Get build logs (SSE):
|
| 117 |
+
```bash
|
| 118 |
+
curl -N -H "Authorization: Bearer $HF_TOKEN" "https://huggingface.co/api/spaces/Leon4gr45/analytics/logs/build"
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
Get run logs (SSE) once the build logs succeed:
|
| 122 |
+
```bash
|
| 123 |
+
curl -N -H "Authorization: Bearer $HF_TOKEN" "https://huggingface.co/api/spaces/Leon4gr45/analytics/logs/run"
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
After 300 seconds, see if the deployment has been successful, and if not, fix the errors of deployment, and redeploy and monitor in a cycle until the space is running and reacts to the api endpoints you created.
|
CHANGELOG.md
ADDED
|
@@ -0,0 +1,699 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Changelog
|
| 2 |
+
|
| 3 |
+
All notable changes to this project will be documented in this file.
|
| 4 |
+
|
| 5 |
+
## Unreleased
|
| 6 |
+
|
| 7 |
+
### Added
|
| 8 |
+
|
| 9 |
+
- Annotations feature
|
| 10 |
+
- Pages report can now be broken down by URL (hostname + path) in addition to path only
|
| 11 |
+
- New "AI Assistants" acquisition channel + improved recognized sources database
|
| 12 |
+
- Allow querying revenue metrics (`total_revenue`, `average_revenue`) with visit dimensions in Stats API v2
|
| 13 |
+
- Allow querying `views_per_visit` with a time dimension in Stats API
|
| 14 |
+
- Add `bounce_rate` to page-filtered Top Stats even when imports are included, but render a metric warning about imported data not included in `bounce_rate` tooltip.
|
| 15 |
+
- Add `time_on_page` to page-filtered Top Stats even when imports are included, unless legacy time on page is in view.
|
| 16 |
+
- Adds team_id to query debug metadata (saved in system.query_log log_comment column)
|
| 17 |
+
- Add "Unknown" option to Countries shield, for when the country code is unrecognized
|
| 18 |
+
- Add "Last 24 Hours" to dashboard time range picker and Stats API v2
|
| 19 |
+
- Always compare against the same time range in comparisons with "Today"
|
| 20 |
+
- Added vertical indicator line to graph to make it easier to see what's hovered / selected
|
| 21 |
+
|
| 22 |
+
### Removed
|
| 23 |
+
|
| 24 |
+
- Removed the standalone team switcher page; team switching is now done from the topbar dropdown only
|
| 25 |
+
- Removed `Bamboo.SMTPAdapter` from supported e-mail adapters; the library is no longer in active developments and does not compile under Elixir 1.20+
|
| 26 |
+
|
| 27 |
+
### Changed
|
| 28 |
+
|
| 29 |
+
- Keybind hints are hidden on smaller screens
|
| 30 |
+
- Site index is sortable alphanumerically and by traffic
|
| 31 |
+
- "Top referrers" and "Search terms" breakdowns are rendered side by side with other "Sources" tabs instead of replacing them
|
| 32 |
+
- Improved top bar and top stats UI/styling
|
| 33 |
+
- Moved graph interval picker, export button, imported data toggle and notices out of the graph and into a new options menu in the top bar
|
| 34 |
+
- Standardised and improved segment and filter modals styling
|
| 35 |
+
- Changed graph tooltip positioning logic: it now aligns to the top of the chart, to the right of the hovered data point
|
| 36 |
+
- Use ResizeObserver instead of polling in tracker for scroll depth. Removes forced reflows caused by the tracker script.
|
| 37 |
+
- Update custom range datepicker styles
|
| 38 |
+
- Improved site transfer UI
|
| 39 |
+
- Redesigned authentication pages (register, sign in, 2FA, password reset, account activation)
|
| 40 |
+
|
| 41 |
+
### Fixed
|
| 42 |
+
|
| 43 |
+
- Improve team member removal/team role change
|
| 44 |
+
- Validate empty filter clauses list in Stats API v2
|
| 45 |
+
- Fixed Stats API timeseries returning time buckets falling outside the queried range
|
| 46 |
+
- Fixed issue with all non-interactive events being counted as interactive
|
| 47 |
+
- Fixed countries map countries staying highlighted on Chrome
|
| 48 |
+
- Fixed comparison tooltip in the top pages report missing date labels
|
| 49 |
+
- Fixed top bar not scrolling horizontally on mobile
|
| 50 |
+
- Fixed incline/decline percentages not showing in top stats in comparison mode
|
| 51 |
+
- Fixed issue with timestamps being rendered incorrectly in segment menus and modals for some timezones
|
| 52 |
+
- Fixed main graph being clipped when the browser's root font size is smaller than the default 16px
|
| 53 |
+
- Fixed issue with users with billing role not being able to create personal segments
|
| 54 |
+
- Fixed period arrow keys hijacking custom-range calendar
|
| 55 |
+
|
| 56 |
+
## v3.2.0 - 2026-01-16
|
| 57 |
+
|
| 58 |
+
### Added
|
| 59 |
+
|
| 60 |
+
- A visitor percentage breakdown is now shown on all reports, both on the dashboard and in the detailed breakdown
|
| 61 |
+
- Shared links can now be limited to a particular segment of the data
|
| 62 |
+
|
| 63 |
+
### Removed
|
| 64 |
+
|
| 65 |
+
### Changed
|
| 66 |
+
|
| 67 |
+
- Segment filters are visible to anyone who can view the dashboard with that segment applied, including personal segments on public dashboards
|
| 68 |
+
- When accessing a link to a shared password-protected dashboard subpage (e.g. `.../pages`), the viewer will be redirected to that subpage after providing the password
|
| 69 |
+
|
| 70 |
+
### Fixed
|
| 71 |
+
|
| 72 |
+
- To make internal stats API requests for password-protected shared links, shared link auth cookie must be set in the requests
|
| 73 |
+
- Fixed issue with site guests in Editor role and team members in Editor role not being able to change the domain of site
|
| 74 |
+
- Fixed direct dashboard links that use legacy dashboard filters containing URL encoded special characters (e.g. character `ê` in the legacy filter `?page=%C3%AA`)
|
| 75 |
+
- Fix bug with tracker script config cache that made requests for certain cached scripts give error 500
|
| 76 |
+
|
| 77 |
+
## v3.1.0 - 2025-11-13
|
| 78 |
+
|
| 79 |
+
### Added
|
| 80 |
+
|
| 81 |
+
- Custom events can now be marked as non-interactive in events API and tracker script: events marked as non-interactive are not counted towards bounce rate
|
| 82 |
+
- Ability to leave team via Team Settings > Leave Team
|
| 83 |
+
- Stats APIv2 now supports `include.trim_relative_date_range` - this option allows trimming empty values after current time for `day`, `month` and `year` date_range values
|
| 84 |
+
- Properties are now included in full site exports done via Site Settings > Imports & Exports
|
| 85 |
+
- Google Search Console integration settings: properties can be dynamically sought
|
| 86 |
+
- Weekly/monthly e-mail reports now contain top goal conversions
|
| 87 |
+
- Newly created sites are offered a new dynamic tracking script and snippet that's specific to the site
|
| 88 |
+
- Old sites that go to "Review installation" flow are offered the new script and snippet, along with a migration guide from legacy snippets, legacy snippets continue to function as before
|
| 89 |
+
- The new tracker script allows configuring `transformRequest` function to change event payloads before they're sent
|
| 90 |
+
- The new tracker script allows configuring `customProperties` function hook to derive custom props for events on the fly
|
| 91 |
+
- The new tracker script supports tracking form submissions if enabled
|
| 92 |
+
- The new tracker script automatically updates to respect site domain if it's changed in "Change domain" flow
|
| 93 |
+
- The new tracker script automatically updates to respect the following configuration options available in "New site" flows and "Review installation" flows: whether to track outbound links, file downloads, form submissions
|
| 94 |
+
- The new tracker script allows overriding almost all options by changing the snippet on the website, with the function `plausible.init({ ...your overrides... })` - this can be unique page-by-page
|
| 95 |
+
- A new `@plausible-analytics/tracker` ESM module is available on NPM - it has near-identical configuration API and identical tracking logic as the script and it receives bugfixes and updates concurrently with the new tracker script
|
| 96 |
+
- Ability to enforce enabling 2FA by all team members
|
| 97 |
+
|
| 98 |
+
### Removed
|
| 99 |
+
|
| 100 |
+
### Changed
|
| 101 |
+
|
| 102 |
+
- A session is now marked as a bounce if it has less than 2 pageviews and no interactive custom events
|
| 103 |
+
- All dropmenus on dashboard are navigable with Tab (used to be a mix between tab and arrow keys), and no two dropmenus can be open at once on the dashboard
|
| 104 |
+
- Special path-based events like "404" don't need `event.props.path` to be explicitly defined when tracking: it is set to be the same as `event.pathname` in event ingestion; if it is explicitly defined, it is not overridden for backwards compatibility
|
| 105 |
+
- Main graph no longer shows empty values after current time for `day`, `month` and `year` periods
|
| 106 |
+
- Include `bounce_rate` metric in Entry Pages breakdown
|
| 107 |
+
- Dark mode theme has been refined with darker color scheme and better visual hierarchy
|
| 108 |
+
- Creating shared links now happens in a modal
|
| 109 |
+
|
| 110 |
+
### Fixed
|
| 111 |
+
|
| 112 |
+
- Make clicking Compare / Disable Comparison in period picker menu close the menu
|
| 113 |
+
- Do not log page views for hidden pages (prerendered pages and new tabs), until pages are viewed
|
| 114 |
+
- Password-authenticated shared links now carry over dashboard params properly
|
| 115 |
+
- Realtime and hourly graphs of visit duration, views per visit no longer overcount due to long-lasting sessions, instead showing each visit when they occurred
|
| 116 |
+
- Fixed realtime and hourly graphs of visits overcounting
|
| 117 |
+
- When reporting only `visitors` and `visits` per hour, count visits in each hour they were active in
|
| 118 |
+
- Fixed unhandled tracker-related exceptions on link clicks within svgs
|
| 119 |
+
- Remove Subscription and Invoices menu from CE
|
| 120 |
+
- Fix email sending error "Mua.SMTPError" 503 Bad sequence of commands
|
| 121 |
+
- Make button to include / exclude imported data visible on Safari
|
| 122 |
+
|
| 123 |
+
## v3.0.0 - 2025-04-11
|
| 124 |
+
|
| 125 |
+
### Added
|
| 126 |
+
|
| 127 |
+
- Ability to sort by and compare the `exit_rate` metric in the dashboard Exit Pages > Details report
|
| 128 |
+
- Add top 3 pages into the traffic spike email
|
| 129 |
+
- Two new shorthand time periods `28d` and `91d` available on both dashboard and in public API
|
| 130 |
+
- Average scroll depth metric
|
| 131 |
+
- Scroll Depth goals
|
| 132 |
+
- Dashboard shows comparisons for all reports
|
| 133 |
+
- UTM Medium report and API shows (gclid) and (msclkid) for paid searches when no explicit utm medium present.
|
| 134 |
+
- Support for `case_sensitive: false` modifiers in Stats API V2 filters for case-insensitive searches.
|
| 135 |
+
- Add text version to emails plausible/analytics#4674
|
| 136 |
+
- Add acquisition channels report
|
| 137 |
+
- Add filter `is not` for goals in dashboard plausible/analytics#4983
|
| 138 |
+
- Add Segments feature
|
| 139 |
+
- Support `["is", "segment", [<segment ID>]]` filter in Stats API
|
| 140 |
+
- Time on page metric is now sortable in reports
|
| 141 |
+
- Plausible tracker script now reports maximum scroll depth reached and time engaged with the site in an `engagement` event. These are reported as `sd` and `e` integer parameters to /api/event endpoint respectively. If you're using a custom proxy for plausible script, please ensure that these parameters are being passed forward.
|
| 142 |
+
- Plausible tracker script now reports the version of the script in the `v` parameter sent with each request.
|
| 143 |
+
- Add support for creating and managing teams owning multiple sites
|
| 144 |
+
- Introduce "billing" team role for users
|
| 145 |
+
- Introduce "editor" role with permissions greater than "viewer" but lesser than "admin"
|
| 146 |
+
- Support behavioral filters `has_done` and `has_not_done` on the Stats API to allow filtering sessions by other events that have been completed.
|
| 147 |
+
- `time_on_page` metric is now graphable, sortable on the dashboard, and available in the Stats API and CSV and GA4 exports/imports
|
| 148 |
+
|
| 149 |
+
### Removed
|
| 150 |
+
|
| 151 |
+
- Internal stats API routes no longer support legacy dashboard filter format.
|
| 152 |
+
- Dashboard no longer shows "Unique visitors" in top stats when filtering by a goal which used to count all users including ones who didn't complete the goal. "Unique conversions" shows the number of unique visitors who completed the goal.
|
| 153 |
+
|
| 154 |
+
### Changed
|
| 155 |
+
|
| 156 |
+
- Default period for brand new sites is now `today` rather than `last 28 days`. On the next day, the default changes to `last 28 days`.
|
| 157 |
+
- Increase decimal precision of the "Exit rate" metric from 0 to 1 (e.g. 67 -> 66.7)
|
| 158 |
+
- Increase decimal precision of the "Conversion rate" metric from 1 to 2 (e.g. 16.7 -> 16.67)
|
| 159 |
+
- The "Last 30 days" period is now "Last 28 days" on the dashboard and also the new default. Keyboard shortcut `T` still works for last 30 days.
|
| 160 |
+
- Last `7d` and `30d` periods do not include today anymore
|
| 161 |
+
- Filters appear in the search bar as ?f=is,page,/docs,/blog&f=... instead of ?filters=((is,page,(/docs,/blog)),...) for Plausible links sent on various platforms to work reliably.
|
| 162 |
+
- Details modal search inputs are now case-insensitive.
|
| 163 |
+
- Improved report performance in cases where site has a lot of unique pathnames
|
| 164 |
+
- Plausible script now uses `fetch` with keepalive flag as default over `XMLHttpRequest`. This will ensure more reliable tracking. Reminder to use `compat` script variant if tracking Internet Explorer is required.
|
| 165 |
+
- The old `/api/health` healtcheck is soft-deprecated in favour of separate `/api/system/health/live` and `/api/system/health/ready` checks
|
| 166 |
+
- Changed top bar filter menu and how applied filters wrap
|
| 167 |
+
- Main graph now shows revenue with relevant currency symbol when hovering a data point
|
| 168 |
+
- Main graph now shows `-` instead of `0` for visit duration, scroll depth when hovering a data point with no visit data
|
| 169 |
+
- Make Stats and Sites API keys scoped to teams they are created in
|
| 170 |
+
- Remove permissions to manage sites guests and run destructive actions from team editor and guest editor roles in favour of team admin role
|
| 171 |
+
- Time-on-page metric has been reworked. It now uses `engagement` events sent by plausible tracker script. We still use the old calculation methods for periods before the self-hosted instance was upgraded. Warnings are shown in the dashboard and API when legacy calculation methods are used.
|
| 172 |
+
- Always set site and team member limits to unlimited for Community Edition
|
| 173 |
+
- Stats API now supports more `date_range` shorthand options like `30d`, `3mo`.
|
| 174 |
+
- Stop showing Plausible footer when viewing stats, except when viewing a public dashboard or unembedded shared link dashboard.
|
| 175 |
+
- Changed Plugins API Token creation flow to only display token once it's created.
|
| 176 |
+
|
| 177 |
+
### Fixed
|
| 178 |
+
|
| 179 |
+
- Fix fetching favicons from DuckDuckGo when the domain includes a pathname
|
| 180 |
+
- Fix `visitors.csv` (in dashboard CSV export) vs dashboard main graph reporting different results for `visitors` and `visits` with a `time:minute` interval.
|
| 181 |
+
- The tracker script now sends pageviews when a page gets loaded from bfcache
|
| 182 |
+
- Fix returning filter suggestions for multiple custom property values in the dashboard Filter modal
|
| 183 |
+
- Fix typo on login screen
|
| 184 |
+
- Fix Direct / None details modal not opening
|
| 185 |
+
- Fix year over year comparisons being offset by a day for leap years
|
| 186 |
+
- Breakdown modals now display correct comparison values instead of 0 after pagination
|
| 187 |
+
- Fix database mismatch between event and session user_ids after rotating salts
|
| 188 |
+
- `/api/v2/query` no longer returns a 500 when querying percentage metric without `visitors`
|
| 189 |
+
- Fix current visitors loading when viewing a dashboard with a shared link
|
| 190 |
+
- Fix Conversion Rate graph being unselectable when "Goal is ..." filter is within a segment
|
| 191 |
+
- Fix Channels filter input appearing when clicking Sources in filter menu or clicking an applied "Channel is..." filter
|
| 192 |
+
- Fix Conversion Rate metrics column disappearing from reports when "Goal is ..." filter is within a segment
|
| 193 |
+
- Graph tooltip now shows year when graph has data from multiple years
|
| 194 |
+
|
| 195 |
+
## v2.1.5 - 2025-02-03
|
| 196 |
+
|
| 197 |
+
### Added
|
| 198 |
+
|
| 199 |
+
- Add text version to emails https://github.com/plausible/analytics/pull/4674
|
| 200 |
+
- Add error logging when email delivery fails https://github.com/plausible/analytics/pull/4885
|
| 201 |
+
|
| 202 |
+
### Removed
|
| 203 |
+
|
| 204 |
+
- Remove Plausible Cloud contacts https://github.com/plausible/analytics/pull/4766
|
| 205 |
+
- Remove trial mentions https://github.com/plausible/analytics/pull/4668
|
| 206 |
+
- Remove billings and upgrade tabs from settings https://github.com/plausible/analytics/pull/4897
|
| 207 |
+
|
| 208 |
+
## v2.1.4 - 2024-10-08
|
| 209 |
+
|
| 210 |
+
### Added
|
| 211 |
+
|
| 212 |
+
- Add ability to review and revoke particular logged in user sessions
|
| 213 |
+
- Add ability to change password from user settings screen
|
| 214 |
+
- Add error logs for background jobs plausible/analytics#4657
|
| 215 |
+
|
| 216 |
+
### Changed
|
| 217 |
+
|
| 218 |
+
- Revised User Settings UI
|
| 219 |
+
- Default to `invite_only` for registration plausible/analytics#4616
|
| 220 |
+
|
| 221 |
+
### Fixed
|
| 222 |
+
|
| 223 |
+
- Fix cross-device file move in CSV exports/imports plausible/analytics#4640
|
| 224 |
+
|
| 225 |
+
## v2.1.3 - 2024-09-26
|
| 226 |
+
|
| 227 |
+
### Fixed
|
| 228 |
+
|
| 229 |
+
- Change cookie key to resolve login issue plausible/analytics#4621
|
| 230 |
+
- Set secure attribute on cookies when BASE_URL has HTTPS scheme plausible/analytics#4623
|
| 231 |
+
- Don't track custom events in CE plausible/analytics#4627
|
| 232 |
+
|
| 233 |
+
## v2.1.2 - 2024-09-24
|
| 234 |
+
|
| 235 |
+
### Added
|
| 236 |
+
|
| 237 |
+
- UI to edit goals along with display names
|
| 238 |
+
- Support contains filter for goals
|
| 239 |
+
- UI to edit funnels
|
| 240 |
+
- Add Details views for browsers, browser versions, os-s, os versions, and screen sizes reports
|
| 241 |
+
- Add a search functionality in all Details views
|
| 242 |
+
- Icons for browsers plausible/analytics#4239
|
| 243 |
+
- Automatic custom property selection in the dashboard Properties report
|
| 244 |
+
- Add `contains_not` filter support to dashboard
|
| 245 |
+
- Traffic drop notifications plausible/analytics#4300
|
| 246 |
+
- Add search and pagination functionality into Google Keywords > Details modal
|
| 247 |
+
- ClickHouse system.query_log table log_comment column now contains information about source of queries. Useful for debugging
|
| 248 |
+
- New /debug/clickhouse route for super admins which shows information on clickhouse queries executed by user
|
| 249 |
+
- Typescript support for `/assets`
|
| 250 |
+
- Testing framework for `/assets`
|
| 251 |
+
- Automatic HTTPS plausible/analytics#4491
|
| 252 |
+
- Make details views on dashboard sortable
|
| 253 |
+
|
| 254 |
+
### Removed
|
| 255 |
+
|
| 256 |
+
- Deprecate `ECTO_IPV6` and `ECTO_CH_IPV6` env vars in CE plausible/analytics#4245
|
| 257 |
+
- Remove support for importing data from no longer available Universal Analytics
|
| 258 |
+
- Soft-deprecate `DATABASE_SOCKET_DIR` plausible/analytics#4202
|
| 259 |
+
|
| 260 |
+
### Changed
|
| 261 |
+
|
| 262 |
+
- Support Unix sockets in `DATABASE_URL` plausible/analytics#4202
|
| 263 |
+
- Realtime and hourly graphs now show visits lasting their whole duration instead when specific events occur
|
| 264 |
+
- Increase hourly request limit for API keys in CE from 600 to 1000000 (practically removing the limit) plausible/analytics#4200
|
| 265 |
+
- Make TCP connections try IPv6 first with IPv4 fallback in CE plausible/analytics#4245
|
| 266 |
+
- `is` and `is not` filters in dashboard no longer support wildcards. Use contains/does not contain filter instead.
|
| 267 |
+
- `bounce_rate` metric now returns 0 instead of null for event:page breakdown when page has never been entry page.
|
| 268 |
+
- Make `TOTP_VAULT_KEY` optional plausible/analytics#4317
|
| 269 |
+
- Sources like 'google' and 'facebook' are now stored in capitalized forms ('Google', 'Facebook') plausible/analytics#4417
|
| 270 |
+
- `DATABASE_CACERTFILE` now forces TLS for PostgreSQL connections, so you don't need to add `?ssl=true` in `DATABASE_URL`
|
| 271 |
+
- Change auth session cookies to token-based ones with server-side expiration management.
|
| 272 |
+
- Improve Google error messages in CE plausible/analytics#4485
|
| 273 |
+
- Better compress static assets in CE plausible/analytics#4476
|
| 274 |
+
- Return domain-less cookies in CE plausible/analytics#4482
|
| 275 |
+
- Internal stats API routes now return a JSON error over HTML in case of invalid access.
|
| 276 |
+
|
| 277 |
+
### Fixed
|
| 278 |
+
|
| 279 |
+
- Fix access to Stats API feature in CE plausible/analytics#4244
|
| 280 |
+
- Fix filter suggestions when same filter previously applied
|
| 281 |
+
- Fix MX lookup when using relays with Bamboo.Mua plausible/analytics#4350
|
| 282 |
+
- Don't include imports when showing time series hourly interval. Previously imported data was shown each midnight
|
| 283 |
+
- Fix property filter suggestions 500 error when property hasn't been selected
|
| 284 |
+
- Bamboo.Mua: add Date and Message-ID headers if missing plausible/analytics#4474
|
| 285 |
+
- Fix migration order across `plausible_db` and `plausible_events_db` databases plausible/analytics#4466
|
| 286 |
+
- Fix tooltips for countries/cities/regions links in dashboard
|
| 287 |
+
|
| 288 |
+
## v2.1.1 - 2024-06-06
|
| 289 |
+
|
| 290 |
+
### Added
|
| 291 |
+
|
| 292 |
+
- Snippet integration verification
|
| 293 |
+
- Limited filtering support for imported data in the dashboard and via Stats API
|
| 294 |
+
- Automatic sites.imported_data -> site_imports data migration in CE plausible/analytics#4155
|
| 295 |
+
|
| 296 |
+
### Fixed
|
| 297 |
+
|
| 298 |
+
- Fix CSV import by adding a newline to the INSERT statement plausible/analytics#4172
|
| 299 |
+
- Fix url parameters escaping of = sign plausible/analytics#4185
|
| 300 |
+
- Fix redirect after registration in CE plausible/analytics#4165
|
| 301 |
+
- Fix VersionedSessions migration in ClickHouse v24 plausible/analytics#4162
|
| 302 |
+
|
| 303 |
+
## v2.1.0 - 2024-05-23
|
| 304 |
+
|
| 305 |
+
### Added
|
| 306 |
+
|
| 307 |
+
- Hostname Allow List in Site Settings
|
| 308 |
+
- Pages Block List in Site Settings
|
| 309 |
+
- Add `conversion_rate` to Stats API Timeseries and on the main graph
|
| 310 |
+
- Add `total_conversions` and `conversion_rate` to `visitors.csv` in a goal-filtered CSV export
|
| 311 |
+
- Ability to display total conversions (with a goal filter) on the main graph
|
| 312 |
+
- Add `conversion_rate` to Stats API Timeseries and on the main graph
|
| 313 |
+
- Add `time_on_page` metric into the Stats API
|
| 314 |
+
- County Block List in Site Settings
|
| 315 |
+
- Query the `views_per_visit` metric based on imported data as well if possible
|
| 316 |
+
- Group `operating_system_versions` by `operating_system` in Stats API breakdown
|
| 317 |
+
- Add `operating_system_versions.csv` into the CSV export
|
| 318 |
+
- Display `Total visitors`, `Conversions`, and `CR` in the "Details" views of Countries, Regions and Cities (when filtering by a goal)
|
| 319 |
+
- Add `conversion_rate` to Regions and Cities reports (when filtering by a goal)
|
| 320 |
+
- Add the `conversion_rate` metric to Stats API Breakdown and Aggregate endpoints
|
| 321 |
+
- IP Block List in Site Settings
|
| 322 |
+
- Allow filtering with `contains`/`matches` operator for Sources, Browsers and Operating Systems.
|
| 323 |
+
- Allow filtering by multiple custom properties
|
| 324 |
+
- Wildcard and member filtering on the Stats API `event:goal` property
|
| 325 |
+
- Allow filtering with `contains`/`matches` operator for custom properties
|
| 326 |
+
- Add `referrers.csv` to CSV export
|
| 327 |
+
- Add a new Properties section in the dashboard to break down by custom properties
|
| 328 |
+
- Add `custom_props.csv` to CSV export (almost the same as the old `prop_breakdown.csv`, but has different column headers, and includes props for pageviews too, not only custom events)
|
| 329 |
+
- Add `referrers.csv` to CSV export
|
| 330 |
+
- Improve password validation in registration and password reset forms
|
| 331 |
+
- Adds Gravatar profile image to navbar
|
| 332 |
+
- Enforce email reverification on update
|
| 333 |
+
- Add Plugins API Tokens provisioning UI
|
| 334 |
+
- Add searching sites by domain in /sites view
|
| 335 |
+
- Add last 24h plots to /sites view
|
| 336 |
+
- Add site pinning to /sites view
|
| 337 |
+
- Add support for JSON logger, via LOG_FORMAT=json environment variable
|
| 338 |
+
- Add support for 2FA authentication
|
| 339 |
+
- Add 'browser_versions.csv' to CSV export
|
| 340 |
+
- Add `CLICKHOUSE_MAX_BUFFER_SIZE_BYTES` env var which defaults to `100000` (100KB)
|
| 341 |
+
- Add alternative SMTP adapter plausible/analytics#3654
|
| 342 |
+
- Add `EXTRA_CONFIG_PATH` env var to specify extra Elixir config plausible/analytics#3906
|
| 343 |
+
- Add restrictive `robots.txt` for self-hosted plausible/analytics#3905
|
| 344 |
+
- Add Yesterday as an time range option in the dashboard
|
| 345 |
+
- Add dmg extension to the list of default tracked file downloads
|
| 346 |
+
- Add support for importing Google Analytics 4 data
|
| 347 |
+
- Import custom events from Google Analytics 4
|
| 348 |
+
- Ability to filter Search Console keywords by page, country and device plausible/analytics#4077
|
| 349 |
+
- Add `DATA_DIR` env var for exports/imports plausible/analytics#4100
|
| 350 |
+
- Add custom events support to CSV export and import
|
| 351 |
+
|
| 352 |
+
### Removed
|
| 353 |
+
|
| 354 |
+
- Removed the nested custom event property breakdown UI when filtering by a goal in Goal Conversions
|
| 355 |
+
- Removed the `prop_names` returned in the Stats API `event:goal` breakdown response
|
| 356 |
+
- Removed the `prop-breakdown.csv` file from CSV export
|
| 357 |
+
- Deprecated `CLICKHOUSE_MAX_BUFFER_SIZE`
|
| 358 |
+
- Removed `/app/init-admin.sh` that was deprecated in v2.0.0 plausible/analytics#3903
|
| 359 |
+
- Remove `DISABLE_AUTH` deprecation warning plausible/analytics#3904
|
| 360 |
+
|
| 361 |
+
### Changed
|
| 362 |
+
|
| 363 |
+
- A visits `entry_page` and `exit_page` is only set and updated for pageviews, not custom events
|
| 364 |
+
- Limit the number of Goal Conversions shown on the dashboard and render a "Details" link when there are more entries to show
|
| 365 |
+
- Show Outbound Links / File Downloads / 404 Pages / Cloaked Links instead of Goal Conversions when filtering by the corresponding goal
|
| 366 |
+
- Require custom properties to be explicitly added from Site Settings > Custom Properties in order for them to show up on the dashboard
|
| 367 |
+
- GA/SC sections moved to new settings: Integrations
|
| 368 |
+
- Replace `CLICKHOUSE_MAX_BUFFER_SIZE` with `CLICKHOUSE_MAX_BUFFER_SIZE_BYTES`
|
| 369 |
+
- Validate metric isn't queried multiple times
|
| 370 |
+
- Filters in dashboard are represented by jsonurl
|
| 371 |
+
- `MAILER_EMAIL` now defaults to an address built off of `BASE_URL` plausible/analytics#4538
|
| 372 |
+
- default `MAILER_ADAPTER` has been changed to `Bamboo.Mua` plausible/analytics#4538
|
| 373 |
+
|
| 374 |
+
### Fixed
|
| 375 |
+
|
| 376 |
+
- Creating many sites no longer leads to cookie overflow
|
| 377 |
+
- Ignore sessions without pageviews for `entry_page` and `exit_page` breakdowns
|
| 378 |
+
- Using `VersionedCollapsingMergeTree` to store visit data to avoid rare race conditions that led to wrong visit data being shown
|
| 379 |
+
- Fix `conversion_rate` metric in a `browser_versions` breakdown
|
| 380 |
+
- Calculate `conversion_rate` percentage change in the same way like `bounce_rate` (subtraction instead of division)
|
| 381 |
+
- Calculate `bounce_rate` percentage change in the Stats API in the same way as it's done in the dashboard
|
| 382 |
+
- Stop returning custom events in goal breakdown with a pageview goal filter and vice versa
|
| 383 |
+
- Only return `(none)` values in custom property breakdown for the first page (pagination) of results
|
| 384 |
+
- Fixed weekly/monthly e-mail report [rendering issues](https://github.com/plausible/analytics/issues/284)
|
| 385 |
+
- Fix [broken interval selection](https://github.com/plausible/analytics/issues/2982) in the all time view plausible/analytics#3110
|
| 386 |
+
- Fixed [IPv6 problems](https://github.com/plausible/analytics/issues/3173) in data migration plausible/analytics#3179
|
| 387 |
+
- Fixed [long URLs display](https://github.com/plausible/analytics/issues/3158) in Outbound Link breakdown view
|
| 388 |
+
- Fixed [Sentry reports](https://github.com/plausible/analytics/discussions/3166) for ingestion requests plausible/analytics#3182
|
| 389 |
+
- Fix breakdown pagination bug in the dashboard details view when filtering by goals
|
| 390 |
+
- Update bot detection (matomo 6.1.4, ua_inspector 3.4.0)
|
| 391 |
+
- Improved the Goal Settings page (search, autcompletion etc.)
|
| 392 |
+
- Log mailer errors plausible/analytics#3336
|
| 393 |
+
- Allow custom event timeseries in stats API plausible/analytics#3505
|
| 394 |
+
- Fixes for sites with UTF characters in domain plausible/analytics#3560
|
| 395 |
+
- Fix crash when using special characters in filter plausible/analytics#3634
|
| 396 |
+
- Fix automatic scrolling to the bottom on the dashboard if previously selected properties tab plausible/analytics#3872
|
| 397 |
+
- Allow running the container with arbitrary UID plausible/analytics#2986
|
| 398 |
+
- Fix `width=manual` in embedded dashboards plausible/analytics#3910
|
| 399 |
+
- Fix URL escaping when pipes are used in UTM tags plausible/analytics#3930
|
| 400 |
+
|
| 401 |
+
## v2.0.0 - 2023-07-12
|
| 402 |
+
|
| 403 |
+
### Added
|
| 404 |
+
|
| 405 |
+
- Call to action for tracking Goal Conversions and an option to hide the section from the dashboard
|
| 406 |
+
- Add support for `with_imported=true` in Stats API aggregate endpoint
|
| 407 |
+
- Ability to use '--' instead of '=' sign in the `tagged-events` classnames
|
| 408 |
+
- 'Last updated X seconds ago' info to 'current visitors' tooltips
|
| 409 |
+
- Add support for more Bamboo adapters, i.e. `Bamboo.MailgunAdapter`, `Bamboo.MandrillAdapter`, `Bamboo.SendGridAdapter` plausible/analytics#2649
|
| 410 |
+
- Ability to change domain for existing site (requires numeric IDs data migration, instructions will be provided separately) UI + API (`PUT /api/v1/sites`)
|
| 411 |
+
- Add `LOG_FAILED_LOGIN_ATTEMPTS` environment variable to enable failed login attempts logs plausible/analytics#2936
|
| 412 |
+
- Add `MAILER_NAME` environment variable support plausible/analytics#2937
|
| 413 |
+
- Add `MAILGUN_BASE_URI` support for `Bamboo.MailgunAdapter` plausible/analytics#2935
|
| 414 |
+
- Add a landing page for self-hosters plausible/analytics#2989
|
| 415 |
+
- Allow optional IPv6 for clickhouse repo plausible/analytics#2970
|
| 416 |
+
|
| 417 |
+
### Fixed
|
| 418 |
+
|
| 419 |
+
- Fix tracker bug - call callback function even when event is ignored
|
| 420 |
+
- Make goal-filtered CSV export return only unique_conversions timeseries in the 'visitors.csv' file
|
| 421 |
+
- Stop treating page filter as an entry page filter
|
| 422 |
+
- City report showing N/A instead of city names with imported data plausible/analytics#2675
|
| 423 |
+
- Empty values for Screen Size, OS and Browser are uniformly replaced with "(not set)"
|
| 424 |
+
- Fix [more pageviews with session prop filter than with no filters](https://github.com/plausible/analytics/issues/1666)
|
| 425 |
+
- Cascade delete sent_renewal_notifications table when user is deleted plausible/analytics#2549
|
| 426 |
+
- Show appropriate top-stat metric labels on the realtime dashboard when filtering by a goal
|
| 427 |
+
- Fix breakdown API pagination when using event metrics plausible/analytics#2562
|
| 428 |
+
- Automatically update all visible dashboard reports in the realtime view
|
| 429 |
+
- Connect via TLS when using HTTPS scheme in ClickHouse URL plausible/analytics#2570
|
| 430 |
+
- Add error message in case a transfer to an invited (but not joined) user is requested plausible/analytics#2651
|
| 431 |
+
- Fix bug with [showing property breakdown with a prop filter](https://github.com/plausible/analytics/issues/1789)
|
| 432 |
+
- Fix bug when combining goal and prop filters plausible/analytics#2654
|
| 433 |
+
- Fix broken favicons when domain includes a slash
|
| 434 |
+
- Fix bug when using multiple [wildcard goal filters](https://github.com/plausible/analytics/pull/3015)
|
| 435 |
+
- Fix a bug where realtime would fail with imported data
|
| 436 |
+
- Fix a bug where the country name was not shown when [filtering through the map](https://github.com/plausible/analytics/issues/3086)
|
| 437 |
+
|
| 438 |
+
### Changed
|
| 439 |
+
|
| 440 |
+
- Treat page filter as entry page filter for `bounce_rate`
|
| 441 |
+
- Reject events with long URIs and data URIs plausible/analytics#2536
|
| 442 |
+
- Always show direct traffic in sources reports plausible/analytics#2531
|
| 443 |
+
- Stop recording XX and T1 country codes plausible/analytics#2556
|
| 444 |
+
- Device type is now determined from the User-Agent instead of window.innerWidth plausible/analytics#2711
|
| 445 |
+
- Add padding by default to embedded dashboards so that shadows are not cut off plausible/analytics#2744
|
| 446 |
+
- Update the User Agents database (https://github.com/matomo-org/device-detector/releases/tag/6.1.1)
|
| 447 |
+
- Disable registration in self-hosted setups by default plausible/analytics#3014
|
| 448 |
+
|
| 449 |
+
### Removed
|
| 450 |
+
|
| 451 |
+
- Remove Firewall plug and `IP_BLOCKLIST` environment variable
|
| 452 |
+
- Remove the ability to collapse the main graph plausible/analytics#2627
|
| 453 |
+
- Remove `custom_dimension_filter` feature flag plausible/analytics#2996
|
| 454 |
+
|
| 455 |
+
## v1.5.1 - 2022-12-06
|
| 456 |
+
|
| 457 |
+
### Fixed
|
| 458 |
+
|
| 459 |
+
- Return empty list when breaking down by event:page without events plausible/analytics#2530
|
| 460 |
+
- Fallback to empty build metadata when failing to parse $BUILD_METADATA plausible/analytics#2503
|
| 461 |
+
|
| 462 |
+
## v1.5.0 - 2022-12-02
|
| 463 |
+
|
| 464 |
+
### Added
|
| 465 |
+
|
| 466 |
+
- Set a different interval on the top graph plausible/analytics#1574 (thanks to @Vigasaurus for this feature)
|
| 467 |
+
- A `tagged-events` script extension for out-of-the-box custom event tracking
|
| 468 |
+
- The ability to escape `|` characters with `\` in Stats API filter values
|
| 469 |
+
- An upper bound of 1000 to the `limit` parameter in Stats API
|
| 470 |
+
- The `exclusions` script extension now also takes a `data-include` attribute tag
|
| 471 |
+
- A `file-downloads` script extension for automatically tracking file downloads as custom events
|
| 472 |
+
- Integration with [Matomo's referrer spam list](https://github.com/matomo-org/referrer-spam-list/blob/master/spammers.txt) to block known spammers
|
| 473 |
+
- API route `PUT /api/v1/sites/goals` with form params `site_id`, `event_name` and/or `page_path`, and `goal_type` with supported types `event` and `page`
|
| 474 |
+
- API route `DELETE /api/v1/sites/goals/:goal_id` with form params `site_id`
|
| 475 |
+
- The public breakdown endpoint can be queried with the "events" metric
|
| 476 |
+
- Data exported via the download button will contain CSV data for all visible graps in a zip file.
|
| 477 |
+
- Region and city-level geolocation plausible/analytics#1449
|
| 478 |
+
- The `u` option can now be used in the `manual` extension to specify a URL when triggering events.
|
| 479 |
+
- Delete a site and all related data through the Sites API
|
| 480 |
+
- Subscribed users can see their Paddle invoices from the last 12 months under the user settings
|
| 481 |
+
- Allow custom styles to be passed to embedded iframe plausible/analytics#1522
|
| 482 |
+
- New UTM Tags `utm_content` and `utm_term` plausible/analytics#515
|
| 483 |
+
- If a session was started without a screen_size it is updated if an event with screen_size occurs
|
| 484 |
+
- Added `LISTEN_IP` configuration parameter plausible/analytics#1189
|
| 485 |
+
- The breakdown endpoint with the property query `property=event:goal` returns custom goal properties (within `props`)
|
| 486 |
+
- Added IPv6 Ecto support (via the environment-variable `ECTO_IPV6`)
|
| 487 |
+
- New filter type: `contains`, available for `page`, `entry_page`, `exit_page`
|
| 488 |
+
- Add filter for custom property
|
| 489 |
+
- Add ability to import historical data from GA: plausible/analytics#1753
|
| 490 |
+
- API route `GET /api/v1/sites/:site_id`
|
| 491 |
+
- Hovering on top of list items will now show a [tooltip with the exact number instead of a shortened version](https://github.com/plausible/analytics/discussions/1968)
|
| 492 |
+
- Filter goals in realtime filter by clicking goal name
|
| 493 |
+
- The time format (12 hour or 24 hour) for graph timelines is now presented based on the browser's defined language
|
| 494 |
+
- Choice of metric for main-graph both in UI and API (visitors, pageviews, bounce_rate, visit_duration) plausible/analytics#1364
|
| 495 |
+
- New width=manual mode for embedded dashboards plausible/analytics#2148
|
| 496 |
+
- Add more timezone options
|
| 497 |
+
- Add new strategy to recommend timezone when creating a new site
|
| 498 |
+
- Alert outgrown enterprise users of their usage plausible/analytics#2197
|
| 499 |
+
- Manually lock and unlock enterprise users plausible/analytics#2197
|
| 500 |
+
- ARM64 support for docker images plausible/analytics#2103
|
| 501 |
+
- Add support for international domain names (IDNs) plausible/analytics#2034
|
| 502 |
+
- Allow self-hosters to register an account on first launch
|
| 503 |
+
- Fix ownership transfer invitation link in self-hosted deployments
|
| 504 |
+
|
| 505 |
+
### Fixed
|
| 506 |
+
|
| 507 |
+
- Plausible script does not prevent default if it's been prevented by an external script [plausible/analytics#1941](https://github.com/plausible/analytics/issues/1941)
|
| 508 |
+
- Hash part of the URL can now be used when excluding pages with `script.exclusions.hash.js`.
|
| 509 |
+
- UI fix where multi-line text in pills would not be underlined properly on small screens.
|
| 510 |
+
- UI fix to align footer columns
|
| 511 |
+
- Guests can now use the favicon to toggle additional info about the site bing viewed (such as in public embeds).
|
| 512 |
+
- Fix SecurityError in tracking script when user has blocked all local storage
|
| 513 |
+
- Prevent dashboard graph from being selected when long pressing on the graph in a mobile browser
|
| 514 |
+
- The exported `pages.csv` file now includes pageviews again [plausible/analytics#1878](https://github.com/plausible/analytics/issues/1878)
|
| 515 |
+
- Fix a bug where city, region and country filters were filtering stats but not the location list
|
| 516 |
+
- Fix a bug where regions were not being saved
|
| 517 |
+
- Timezone offset labels now update with time changes
|
| 518 |
+
- Render 404 if shared link auth cannot be verified [plausible/analytics#2225](https://github.com/plausible/analytics/pull/2225)
|
| 519 |
+
- Restore compatibility with older format of shared links [plausible/analytics#2225](https://github.com/plausible/analytics/pull/2225)
|
| 520 |
+
- Fix 'All time' period for sites with no recorded stats [plausible/analytics#2277](https://github.com/plausible/analytics/pull/2277)
|
| 521 |
+
- Ensure settings page can be rendered after a form error [plausible/analytics#2278](https://github.com/plausible/analytics/pull/2278)
|
| 522 |
+
- Ensure newlines from settings files are trimmed [plausible/analytics#2480](https://github.com/plausible/analytics/pull/2480)
|
| 523 |
+
|
| 524 |
+
### Changed
|
| 525 |
+
|
| 526 |
+
- `script.file-downloads.outbound-links.js` only sends an outbound link event when an outbound download link is clicked
|
| 527 |
+
- Plausible script now uses callback navigation (instead of waiting for 150ms every time) when sending custom events
|
| 528 |
+
- Cache the tracking script for 24 hours
|
| 529 |
+
- Move `entry_page` and `exit_page` to be part of the `Page` filter group
|
| 530 |
+
- Paginate /api/sites results and add a `View all` link to the site-switcher dropdown in the dashboard.
|
| 531 |
+
- Remove the `+ Add Site` link to the site-switcher dropdown in the dashboard.
|
| 532 |
+
- `DISABLE_REGISTRATIONS` configuration parameter can now accept `invite_only` to allow invited users to register an account while keeping regular registrations disabled plausible/analytics#1841
|
| 533 |
+
- New and improved Session tracking module for higher throughput and lower latency. [PR#1934](https://github.com/plausible/analytics#1934)
|
| 534 |
+
- Do not display ZZ country code in countries report [PR#1934](https://github.com/plausible/analytics#2223)
|
| 535 |
+
- Add fallback icon for when DDG favicon cannot be fetched [PR#2279](https://github.com/plausible/analytics#2279)
|
| 536 |
+
|
| 537 |
+
### Security
|
| 538 |
+
|
| 539 |
+
- Add Content-Security-Policy header to favicon path
|
| 540 |
+
|
| 541 |
+
## v1.4.1 - 2021-11-29
|
| 542 |
+
|
| 543 |
+
### Fixed
|
| 544 |
+
|
| 545 |
+
- Fixes database error when pathname contains a question mark
|
| 546 |
+
|
| 547 |
+
## v1.4.0 - 2021-10-27
|
| 548 |
+
|
| 549 |
+
### Added
|
| 550 |
+
|
| 551 |
+
- New parameter `metrics` for the `/api/v1/stats/timeseries` endpoint plausible/analytics#952
|
| 552 |
+
- CSV export now includes pageviews, bounce rate and visit duration in addition to visitors plausible/analytics#952
|
| 553 |
+
- Send stats to multiple dashboards by configuring a comma-separated list of domains plausible/analytics#968
|
| 554 |
+
- To authenticate against a local postgresql via socket authentication, the environment-variables
|
| 555 |
+
`DATABASE_SOCKET_DIR` & `DATABASE_NAME` were added.
|
| 556 |
+
- Time on Page metric available in detailed Top Pages report plausible/analytics#1007
|
| 557 |
+
- Wildcard based page, entry page and exit page filters plausible/analytics#1067
|
| 558 |
+
- Exclusion filters for page, entry page and exit page filters plausible/analytics#1067
|
| 559 |
+
- Menu (with auto-complete) to add new and edit existing filters directly plausible/analytics#1089
|
| 560 |
+
- Added `CLICKHOUSE_FLUSH_INTERVAL_MS` and `CLICKHOUSE_MAX_BUFFER_SIZE` configuration parameters plausible/analytics#1073
|
| 561 |
+
- Ability to invite users to sites with different roles plausible/analytics#1122
|
| 562 |
+
- Option to configure a custom name for the script file
|
| 563 |
+
- Add Conversion Rate to Top Sources, Top Pages Devices, Countries when filtered by a goal plausible/analytics#1299
|
| 564 |
+
- Add list view for countries report in dashboard plausible/analytics#1381
|
| 565 |
+
- Add ability to view more than 100 custom goal properties plausible/analytics#1382
|
| 566 |
+
|
| 567 |
+
### Fixed
|
| 568 |
+
|
| 569 |
+
- Fix weekly report time range plausible/analytics#951
|
| 570 |
+
- Make sure embedded dashboards can run when user has blocked third-party cookies plausible/analytics#971
|
| 571 |
+
- Sites listing page will paginate if the user has a lot of sites plausible/analytics#994
|
| 572 |
+
- Crash when changing theme on a loaded dashboard plausible/analytics#1123
|
| 573 |
+
- UI fix for details button overlapping content on mobile plausible/analytics#1114
|
| 574 |
+
- UI fix for the main graph on mobile overlapping its tick items on both axis
|
| 575 |
+
- 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.
|
| 576 |
+
- Turn off autocomplete for name and password inputs in the _New shared link_ form.
|
| 577 |
+
- Details modals are now responsive and take up less horizontal space on smaller screens to make it easier to scroll.
|
| 578 |
+
- Fix reading config from file
|
| 579 |
+
- Fix some links not opening correctly in new tab
|
| 580 |
+
- UI fix for more than one row of custom event properties plausible/analytics#1383
|
| 581 |
+
- UI fix for user menu and time picker overlapping plausible/analytics#1352
|
| 582 |
+
- Respect the `path` component of BASE_URL to allow subfolder installatons
|
| 583 |
+
|
| 584 |
+
### Removed
|
| 585 |
+
|
| 586 |
+
- Removes AppSignal monitoring package
|
| 587 |
+
|
| 588 |
+
### Changes
|
| 589 |
+
|
| 590 |
+
- Disable email verification by default. Added a configuration option `ENABLE_EMAIL_VERIFICATION=true` if you want to keep the old behaviour
|
| 591 |
+
|
| 592 |
+
## [1.3] - 2021-04-14
|
| 593 |
+
|
| 594 |
+
### Added
|
| 595 |
+
|
| 596 |
+
- Stats API [currently in beta] plausible/analytics#679
|
| 597 |
+
- Ability to view and filter by entry and exit pages, in addition to regular page hits plausible/analytics#712
|
| 598 |
+
- 30 day and 6 month keybindings (`T` and `S`, respectively) plausible/analytics#709
|
| 599 |
+
- Site switching keybinds (1-9 for respective sites) plausible/analytics#735
|
| 600 |
+
- Glob (wildcard) based pageview goals plausible/analytics#750
|
| 601 |
+
- Support for embedding shared links in an iframe plausible/analytics#812
|
| 602 |
+
- Include a basic IP-To-Country database by default plausible/analytics#906
|
| 603 |
+
- Add name/label to shared links plausible/analytics#910
|
| 604 |
+
|
| 605 |
+
### Fixed
|
| 606 |
+
|
| 607 |
+
- Capitalized date/time selection keybinds not working plausible/analytics#709
|
| 608 |
+
- Invisible text on Google Search Console settings page in dark mode plausible/analytics#759
|
| 609 |
+
- Disable analytics tracking when running Cypress tests
|
| 610 |
+
- CSV reports can be downloaded via shared links plausible/analytics#884
|
| 611 |
+
- Fixes weekly/monthly email report delivery over SMTP plausible/analytics#889
|
| 612 |
+
- Disable self-tracking with self hosting plausible/analytics#907
|
| 613 |
+
- Fix current visitors request when using shared links
|
| 614 |
+
|
| 615 |
+
## [1.2] - 2021-01-26
|
| 616 |
+
|
| 617 |
+
### Added
|
| 618 |
+
|
| 619 |
+
- Ability to add event metadata plausible/analytics#381
|
| 620 |
+
- Add tracker module to automatically track outbound links plausible/analytics#389
|
| 621 |
+
- Display weekday on the visitor graph plausible/analytics#175
|
| 622 |
+
- Collect and display browser & OS versions plausible/analytics#397
|
| 623 |
+
- Simple notifications around traffic spikes plausible/analytics#453
|
| 624 |
+
- Dark theme option/system setting follow plausible/analytics#467
|
| 625 |
+
- "Load More" capability to pages modal plausible/analytics#480
|
| 626 |
+
- Unique Visitors (last 30 min) as a top stat in realtime view plausible/analytics#500
|
| 627 |
+
- Pinned filter and date selector rows while scrolling plausible/analytics#472
|
| 628 |
+
- Escape keyboard shortcut to clear all filters plausible/analytics#625
|
| 629 |
+
- Tracking exclusions, see our documentation [here](https://docs.plausible.io/excluding) and [here](https://docs.plausible.io/excluding-pages) for details plausible/analytics#489
|
| 630 |
+
- Keybindings for selecting dates/ranges plausible/analytics#630
|
| 631 |
+
|
| 632 |
+
### Changed
|
| 633 |
+
|
| 634 |
+
- Use alpine as base image to decrease Docker image size plausible/analytics#353
|
| 635 |
+
- Ignore automated browsers (Phantom, Selenium, Headless Chrome, etc)
|
| 636 |
+
- Display domain's favicon on the home page
|
| 637 |
+
- Ignore consecutive pageviews on same pathname plausible/analytics#417
|
| 638 |
+
- Validate domain format on site creation plausible/analytics#427
|
| 639 |
+
- Improve settings UX and design plausible/analytics#412
|
| 640 |
+
- Improve site listing UX and design plausible/analytics#438
|
| 641 |
+
- Improve onboarding UX and design plausible/analytics#441
|
| 642 |
+
- Allows outbound link tracking script to use new tab redirection plausible/analytics#494
|
| 643 |
+
- "This Month" view is now Month-to-date for the current month plausible/analytics#491
|
| 644 |
+
- My sites now show settings cog at all times on smaller screens plausible/analytics#497
|
| 645 |
+
- Background jobs are enabled by default for self-hosted installations plausible/analytics#603
|
| 646 |
+
- All new users on self-hosted installations have a never-ending trial plausible/analytics#603
|
| 647 |
+
- Changed caret/chevron color in datepicker and filters dropdown
|
| 648 |
+
|
| 649 |
+
### Fixed
|
| 650 |
+
|
| 651 |
+
- Do not error when activating an already activated account plausible/analytics#370
|
| 652 |
+
- Ignore arrow keys when modifier keys are pressed plausible/analytics#363
|
| 653 |
+
- Show correct stats when goal filter is combined with source plausible/analytics#374
|
| 654 |
+
- Going back in history now correctly resets the period filter plausible/analytics#408
|
| 655 |
+
- Fix URL decoding in query parameters plausible/analytics#416
|
| 656 |
+
- Fix overly-sticky date in query parameters plausible/analytics/#439
|
| 657 |
+
- Prevent picking dates before site insertion plausible/analtics#446
|
| 658 |
+
- Fix overly-sticky from and to in query parameters plausible/analytics#495
|
| 659 |
+
- Adds support for single-day date selection plausible/analytics#495
|
| 660 |
+
- Goal conversion rate in realtime view is now accurate plausible/analytics#500
|
| 661 |
+
- Various UI/UX issues plausible/analytics#503
|
| 662 |
+
|
| 663 |
+
### Security
|
| 664 |
+
|
| 665 |
+
- Do not run the plausible Docker container as root plausible/analytics#362
|
| 666 |
+
|
| 667 |
+
## [1.1.1] - 2020-10-14
|
| 668 |
+
|
| 669 |
+
### Fixed
|
| 670 |
+
|
| 671 |
+
- Revert Dockerfile change that introduced a regression
|
| 672 |
+
|
| 673 |
+
## [1.1.0] - 2020-10-14
|
| 674 |
+
|
| 675 |
+
### Added
|
| 676 |
+
|
| 677 |
+
- Linkify top pages [plausible/analytics#91](https://github.com/plausible/analytics/issues/91)
|
| 678 |
+
- Filter by country, screen size, browser and operating system [plausible/analytics#303](https://github.com/plausible/analytics/issues/303)
|
| 679 |
+
|
| 680 |
+
### Fixed
|
| 681 |
+
|
| 682 |
+
- Fix issue with creating a PostgreSQL database when `?ssl=true` [plausible/analytics#347](https://github.com/plausible/analytics/issues/347)
|
| 683 |
+
- Do no disclose current URL to DuckDuckGo's favicon service [plausible/analytics#343](https://github.com/plausible/analytics/issues/343)
|
| 684 |
+
- Updated UAInspector database to detect newer devices [plausible/analytics#309](https://github.com/plausible/analytics/issues/309)
|
| 685 |
+
|
| 686 |
+
## [1.0.0] - 2020-10-06
|
| 687 |
+
|
| 688 |
+
### Added
|
| 689 |
+
|
| 690 |
+
- Collect and present link tags (`utm_medium`, `utm_source`, `utm_campaign`) in the dashboard
|
| 691 |
+
|
| 692 |
+
### Changed
|
| 693 |
+
|
| 694 |
+
- Replace configuration parameters `CLICKHOUSE_DATABASE_{HOST,NAME,USER,PASSWORD}` with a single `CLICKHOUSE_DATABASE_URL` [plausible/analytics#317](https://github.com/plausible/analytics/pull/317)
|
| 695 |
+
- Disable subscriptions by default
|
| 696 |
+
- Remove `CLICKHOUSE_DATABASE_POOLSIZE`, `DATABASE_POOLSIZE` and `DATABASE_TLS_ENABLED` parameters. Use query parameters in `CLICKHOUSE_DATABASE_URL` and `DATABASE_URL` instead.
|
| 697 |
+
- Remove `HOST` and `SCHEME` parameters in favor of a single `BASE_URL` parameter.
|
| 698 |
+
- Make `Bamboo.SMTPAdapter` the default as opposed to `Bamboo.PostmarkAdapter`
|
| 699 |
+
- Disable subscription flow by default
|
CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Code of Conduct
|
| 2 |
+
|
| 3 |
+
Plausible, both the open-source project and the company that develops it, pledges to be a community with a healthy and friendly environment. What follows is a set of guidelines on how we get there.
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
## Our Standards
|
| 7 |
+
|
| 8 |
+
Examples of behavior that contributes to a positive environment for our
|
| 9 |
+
community include:
|
| 10 |
+
|
| 11 |
+
* Demonstrating empathy and kindness toward other people
|
| 12 |
+
* Being respectful of differing opinions, viewpoints, and experiences
|
| 13 |
+
* Gracefully accepting constructive criticism and direct feedback, as well as offering it in that spirit.
|
| 14 |
+
* Assuming good intentions. Approaching work relationships with a default of trust and positivity.
|
| 15 |
+
|
| 16 |
+
Examples of unacceptable behavior include:
|
| 17 |
+
|
| 18 |
+
* The use of sexualized language or imagery, and sexual attention or
|
| 19 |
+
advances of any kind
|
| 20 |
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
| 21 |
+
* Any form of discrimination and harassment. Particularly on the basis of race, color, religion, sex, sexual orientation, gender identity or expression, age, disability, marital status, citizenship, national origin, genetic information, or any other characteristic protected by law.
|
| 22 |
+
* Publishing others' private information, such as a physical or email
|
| 23 |
+
address, without their explicit permission
|
| 24 |
+
* Other conduct which could reasonably be considered inappropriate in a
|
| 25 |
+
professional setting
|
| 26 |
+
|
| 27 |
+
## Enforcement Responsibilities
|
| 28 |
+
|
| 29 |
+
Community leaders are responsible for clarifying and enforcing our standards of
|
| 30 |
+
acceptable behavior and will take appropriate and fair corrective action in
|
| 31 |
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
| 32 |
+
or harmful.
|
| 33 |
+
|
| 34 |
+
Community leaders have the right and responsibility to remove, edit, or reject
|
| 35 |
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
| 36 |
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
| 37 |
+
decisions when appropriate.
|
| 38 |
+
|
| 39 |
+
The community leaders at this time are:
|
| 40 |
+
* Marko Saric (marko@plausible.io)
|
| 41 |
+
* Uku Taht (uku@plausible.io)
|
| 42 |
+
|
| 43 |
+
## Scope
|
| 44 |
+
|
| 45 |
+
This Code of Conduct applies within all community spaces, and also applies when
|
| 46 |
+
an individual is officially representing the community in public spaces.
|
| 47 |
+
Examples of representing our community include using an official e-mail address,
|
| 48 |
+
posting via an official social media account, or acting as an appointed
|
| 49 |
+
representative at an online or offline event.
|
| 50 |
+
|
| 51 |
+
## Enforcement
|
| 52 |
+
|
| 53 |
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
| 54 |
+
reported to the community leaders responsible for enforcement.
|
| 55 |
+
|
| 56 |
+
All complaints will be reviewed and investigated promptly and fairly. Depending on the severity of the offense and the findings of the investigation, the response may include private warning, a ban from the community, or even termination for contractors and employees. The reactive measures taken will be shared with the reporting member of the community when possible.
|
| 57 |
+
|
| 58 |
+
All community leaders are obligated to respect the privacy and security of the
|
| 59 |
+
reporter of any incident.
|
| 60 |
+
|
| 61 |
+
## Attribution
|
| 62 |
+
|
| 63 |
+
This Code of Conduct is adapted from the [Contributor Covenant code of conduct](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
|
| 64 |
+
|
| 65 |
+
Some inspiration was also taken from [Basecamp's code of conduct](https://basecamp.com/handbook/appendix-07-code-of-conduct)
|
CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributing
|
| 2 |
+
|
| 3 |
+
We welcome everyone to contribute to Plausible. This document is to help you on setting up your environment, finding a task, and opening pull requests.
|
| 4 |
+
|
| 5 |
+
## Development setup
|
| 6 |
+
|
| 7 |
+
The easiest way to get up and running is to [install](https://docs.docker.com/get-docker/) and use Docker for running both Postgres and Clickhouse.
|
| 8 |
+
|
| 9 |
+
Make sure Docker, Elixir, Erlang and Node.js are all installed on your development machine. The [`.tool-versions`](https://github.com/plausible/analytics/blob/master/.tool-versions) file is available to use with [asdf](https://github.com/asdf-vm/asdf) or similar tools.
|
| 10 |
+
|
| 11 |
+
### Start the environment
|
| 12 |
+
|
| 13 |
+
1. Run both `make postgres` and `make clickhouse`.
|
| 14 |
+
2. You can set up everything with `make install`, alternatively run each command separately:
|
| 15 |
+
1. Run `mix deps.get`. This will download the required Elixir dependencies.
|
| 16 |
+
2. Run `mix ecto.create`. This will create the required databases in both Postgres and Clickhouse.
|
| 17 |
+
3. Run `mix ecto.migrate` to build the database schema.
|
| 18 |
+
4. Run `mix run priv/repo/seeds.exs` to seed the database. Check the [Seeds](#Seeds) section for more.
|
| 19 |
+
5. Run `npm ci --prefix assets` to install the required client-side dependencies.
|
| 20 |
+
6. Run `npm ci --prefix tracker` to install the required tracker dependencies.
|
| 21 |
+
7. Run `mix assets.setup` to install Tailwind and Esbuild
|
| 22 |
+
8. Run `npm run deploy --prefix tracker` to generate tracker files in `priv/tracker/js`
|
| 23 |
+
9. Run `mix download_country_database` to fetch geolocation database
|
| 24 |
+
3. Run `make server` or `mix phx.server` to start the Phoenix server.
|
| 25 |
+
4. The system is now available on `localhost:8000`.
|
| 26 |
+
|
| 27 |
+
### Seeds
|
| 28 |
+
|
| 29 |
+
You can optionally seed your database to automatically create an account and a site with stats:
|
| 30 |
+
|
| 31 |
+
1. Run `mix run priv/repo/seeds.exs` to seed the database.
|
| 32 |
+
2. Start the server with `make server` and navigate to `http://localhost:8000/login`.
|
| 33 |
+
3. Log in with the following e-mail and password combination: `user@plausible.test` and `plausible`.
|
| 34 |
+
4. You should now have a `dummy.site` site with generated stats.
|
| 35 |
+
|
| 36 |
+
Alternatively, you can manually create a new account:
|
| 37 |
+
|
| 38 |
+
1. Navigate to `http://localhost:8000/register` and fill in the form.
|
| 39 |
+
2. Fill in the rest of the forms and for the domain use `dummy.site`
|
| 40 |
+
3. Skip the JS snippet and click start collecting data.
|
| 41 |
+
4. Run `mix send_pageview` from the terminal to generate a fake pageview event for the dummy site.
|
| 42 |
+
5. You should now be all set!
|
| 43 |
+
|
| 44 |
+
### Stopping Docker containers
|
| 45 |
+
|
| 46 |
+
1. Stop and remove the Postgres container with `make postgres-stop`.
|
| 47 |
+
2. Stop and remove the Clickhouse container with `make clickhouse-stop`.
|
| 48 |
+
|
| 49 |
+
Volumes are preserved. You'll find that the Postgres and Clickhouse state are retained when you bring them up again the next time: no need to re-register and so on.
|
| 50 |
+
|
| 51 |
+
Note: Since we are deleting the containers, be careful when deleting volumes with `docker volume prune`. You might accidentally delete the database and would have to go through re-registration process.
|
| 52 |
+
|
| 53 |
+
### Pre-commit hooks
|
| 54 |
+
|
| 55 |
+
`pre-commit` requires Python to be available locally and covers Elixir, JavaScript, and CSS. Set up with `pip install --user pre-commit` followed by `pre-commit install`. Conversely, if the prompts are far too bothersome, remove with `pre-commit uninstall`.
|
| 56 |
+
|
| 57 |
+
## Finding a task
|
| 58 |
+
|
| 59 |
+
Bugs can be found in our [issue tracker](https://github.com/plausible/analytics/issues). Issues are usually up for grabs.
|
| 60 |
+
|
| 61 |
+
New features need to be discussed with the core team and the community first. If you're tackling a feature, please make sure it has been already discussed in the [Discussions tab](https://github.com/plausible/analytics/discussions). We kindly ask contributors to use the discussion comment section to propose a solution before opening a pull request.
|
| 62 |
+
|
| 63 |
+
Pull requests without an associated issue or discussion may still be merged, but we will focus on changes that have already been talked through.
|
Dockerfile
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# we can not use the pre-built tar because the distribution is
|
| 2 |
+
# platform specific, it makes sense to build it in the docker
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
#### Builder
|
| 6 |
+
FROM hexpm/elixir:1.20.2-erlang-28.5.0.3-alpine-3.22.5@sha256:8875407828c1b789485f9fcc6006e1ace39bb073b0467a95df3a3905d8d86d30 AS buildcontainer
|
| 7 |
+
|
| 8 |
+
ARG MIX_ENV=ce
|
| 9 |
+
|
| 10 |
+
# preparation
|
| 11 |
+
ENV MIX_ENV=$MIX_ENV
|
| 12 |
+
ENV NODE_ENV=production
|
| 13 |
+
ENV NODE_OPTIONS=--openssl-legacy-provider
|
| 14 |
+
|
| 15 |
+
# custom ERL_FLAGS are passed for (public) multi-platform builds
|
| 16 |
+
# to fix qemu segfault, more info: https://github.com/erlang/otp/pull/6340
|
| 17 |
+
ARG ERL_FLAGS
|
| 18 |
+
ENV ERL_FLAGS=$ERL_FLAGS
|
| 19 |
+
|
| 20 |
+
RUN mkdir /app
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# install build dependencies
|
| 24 |
+
RUN apk add --no-cache git "nodejs-current=23.11.1-r0" yarn npm python3 ca-certificates wget gnupg make gcc libc-dev brotli
|
| 25 |
+
|
| 26 |
+
COPY mix.exs ./
|
| 27 |
+
COPY mix.lock ./
|
| 28 |
+
COPY config ./config
|
| 29 |
+
RUN mix local.hex --force && \
|
| 30 |
+
mix local.rebar --force && \
|
| 31 |
+
mix deps.get --only ${MIX_ENV} && \
|
| 32 |
+
mix deps.compile
|
| 33 |
+
|
| 34 |
+
COPY assets/package.json assets/package-lock.json ./assets/
|
| 35 |
+
COPY tracker/package.json tracker/package-lock.json ./tracker/
|
| 36 |
+
|
| 37 |
+
RUN npm install --prefix ./assets && \
|
| 38 |
+
npm install --prefix ./tracker
|
| 39 |
+
|
| 40 |
+
COPY assets ./assets
|
| 41 |
+
COPY tracker ./tracker
|
| 42 |
+
COPY priv ./priv
|
| 43 |
+
COPY lib ./lib
|
| 44 |
+
COPY extra ./extra
|
| 45 |
+
|
| 46 |
+
RUN npm run deploy --prefix ./tracker && \
|
| 47 |
+
mix assets.deploy && \
|
| 48 |
+
mix phx.digest priv/static && \
|
| 49 |
+
mix download_country_database && \
|
| 50 |
+
mix sentry.package_source_code
|
| 51 |
+
|
| 52 |
+
WORKDIR /app
|
| 53 |
+
COPY rel rel
|
| 54 |
+
RUN mix release plausible
|
| 55 |
+
|
| 56 |
+
# Main Docker Image
|
| 57 |
+
FROM alpine:3.22.5@sha256:14358309a308569c32bdc37e2e0e9694be33a9d99e68afb0f5ff33cc1f695dce
|
| 58 |
+
LABEL maintainer="plausible.io <hello@plausible.io>"
|
| 59 |
+
|
| 60 |
+
ARG BUILD_METADATA={}
|
| 61 |
+
ENV BUILD_METADATA=$BUILD_METADATA
|
| 62 |
+
ENV LANG=C.UTF-8
|
| 63 |
+
ARG MIX_ENV=ce
|
| 64 |
+
ENV MIX_ENV=$MIX_ENV
|
| 65 |
+
|
| 66 |
+
RUN adduser -S -H -u 999 -G nogroup plausible
|
| 67 |
+
|
| 68 |
+
RUN apk upgrade --no-cache
|
| 69 |
+
RUN apk add --no-cache openssl ncurses libstdc++ libgcc ca-certificates \
|
| 70 |
+
&& if [ "$MIX_ENV" = "ce" ]; then apk add --no-cache certbot; fi
|
| 71 |
+
|
| 72 |
+
COPY --from=buildcontainer --chmod=555 /app/_build/${MIX_ENV}/rel/plausible /app
|
| 73 |
+
COPY --chmod=755 ./rel/docker-entrypoint.sh /entrypoint.sh
|
| 74 |
+
|
| 75 |
+
# we need to allow "others" access to app folder, because
|
| 76 |
+
# docker container can be started with arbitrary uid
|
| 77 |
+
RUN mkdir -p /var/lib/plausible && chmod ugo+rw -R /var/lib/plausible
|
| 78 |
+
|
| 79 |
+
USER 999
|
| 80 |
+
WORKDIR /app
|
| 81 |
+
ENV LISTEN_IP=0.0.0.0
|
| 82 |
+
ENV PORT=7860
|
| 83 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
| 84 |
+
EXPOSE 7860
|
| 85 |
+
ENV DEFAULT_DATA_DIR=/var/lib/plausible
|
| 86 |
+
VOLUME /var/lib/plausible
|
| 87 |
+
CMD ["run"]
|
| 88 |
+
|
LICENSE.md
ADDED
|
@@ -0,0 +1,661 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 19 November 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU Affero General Public License is a free, copyleft license for
|
| 11 |
+
software and other kinds of works, specifically designed to ensure
|
| 12 |
+
cooperation with the community in the case of network server software.
|
| 13 |
+
|
| 14 |
+
The licenses for most software and other practical works are designed
|
| 15 |
+
to take away your freedom to share and change the works. By contrast,
|
| 16 |
+
our General Public Licenses are intended to guarantee your freedom to
|
| 17 |
+
share and change all versions of a program--to make sure it remains free
|
| 18 |
+
software for all its users.
|
| 19 |
+
|
| 20 |
+
When we speak of free software, we are referring to freedom, not
|
| 21 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 22 |
+
have the freedom to distribute copies of free software (and charge for
|
| 23 |
+
them if you wish), that you receive source code or can get it if you
|
| 24 |
+
want it, that you can change the software or use pieces of it in new
|
| 25 |
+
free programs, and that you know you can do these things.
|
| 26 |
+
|
| 27 |
+
Developers that use our General Public Licenses protect your rights
|
| 28 |
+
with two steps: (1) assert copyright on the software, and (2) offer
|
| 29 |
+
you this License which gives you legal permission to copy, distribute
|
| 30 |
+
and/or modify the software.
|
| 31 |
+
|
| 32 |
+
A secondary benefit of defending all users' freedom is that
|
| 33 |
+
improvements made in alternate versions of the program, if they
|
| 34 |
+
receive widespread use, become available for other developers to
|
| 35 |
+
incorporate. Many developers of free software are heartened and
|
| 36 |
+
encouraged by the resulting cooperation. However, in the case of
|
| 37 |
+
software used on network servers, this result may fail to come about.
|
| 38 |
+
The GNU General Public License permits making a modified version and
|
| 39 |
+
letting the public access it on a server without ever releasing its
|
| 40 |
+
source code to the public.
|
| 41 |
+
|
| 42 |
+
The GNU Affero General Public License is designed specifically to
|
| 43 |
+
ensure that, in such cases, the modified source code becomes available
|
| 44 |
+
to the community. It requires the operator of a network server to
|
| 45 |
+
provide the source code of the modified version running there to the
|
| 46 |
+
users of that server. Therefore, public use of a modified version, on
|
| 47 |
+
a publicly accessible server, gives the public access to the source
|
| 48 |
+
code of the modified version.
|
| 49 |
+
|
| 50 |
+
An older license, called the Affero General Public License and
|
| 51 |
+
published by Affero, was designed to accomplish similar goals. This is
|
| 52 |
+
a different license, not a version of the Affero GPL, but Affero has
|
| 53 |
+
released a new version of the Affero GPL which permits relicensing under
|
| 54 |
+
this license.
|
| 55 |
+
|
| 56 |
+
The precise terms and conditions for copying, distribution and
|
| 57 |
+
modification follow.
|
| 58 |
+
|
| 59 |
+
TERMS AND CONDITIONS
|
| 60 |
+
|
| 61 |
+
0. Definitions.
|
| 62 |
+
|
| 63 |
+
"This License" refers to version 3 of the GNU Affero General Public License.
|
| 64 |
+
|
| 65 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 66 |
+
works, such as semiconductor masks.
|
| 67 |
+
|
| 68 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 69 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 70 |
+
"recipients" may be individuals or organizations.
|
| 71 |
+
|
| 72 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 73 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 74 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 75 |
+
earlier work or a work "based on" the earlier work.
|
| 76 |
+
|
| 77 |
+
A "covered work" means either the unmodified Program or a work based
|
| 78 |
+
on the Program.
|
| 79 |
+
|
| 80 |
+
To "propagate" a work means to do anything with it that, without
|
| 81 |
+
permission, would make you directly or secondarily liable for
|
| 82 |
+
infringement under applicable copyright law, except executing it on a
|
| 83 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 84 |
+
distribution (with or without modification), making available to the
|
| 85 |
+
public, and in some countries other activities as well.
|
| 86 |
+
|
| 87 |
+
To "convey" a work means any kind of propagation that enables other
|
| 88 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 89 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 90 |
+
|
| 91 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 92 |
+
to the extent that it includes a convenient and prominently visible
|
| 93 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 94 |
+
tells the user that there is no warranty for the work (except to the
|
| 95 |
+
extent that warranties are provided), that licensees may convey the
|
| 96 |
+
work under this License, and how to view a copy of this License. If
|
| 97 |
+
the interface presents a list of user commands or options, such as a
|
| 98 |
+
menu, a prominent item in the list meets this criterion.
|
| 99 |
+
|
| 100 |
+
1. Source Code.
|
| 101 |
+
|
| 102 |
+
The "source code" for a work means the preferred form of the work
|
| 103 |
+
for making modifications to it. "Object code" means any non-source
|
| 104 |
+
form of a work.
|
| 105 |
+
|
| 106 |
+
A "Standard Interface" means an interface that either is an official
|
| 107 |
+
standard defined by a recognized standards body, or, in the case of
|
| 108 |
+
interfaces specified for a particular programming language, one that
|
| 109 |
+
is widely used among developers working in that language.
|
| 110 |
+
|
| 111 |
+
The "System Libraries" of an executable work include anything, other
|
| 112 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 113 |
+
packaging a Major Component, but which is not part of that Major
|
| 114 |
+
Component, and (b) serves only to enable use of the work with that
|
| 115 |
+
Major Component, or to implement a Standard Interface for which an
|
| 116 |
+
implementation is available to the public in source code form. A
|
| 117 |
+
"Major Component", in this context, means a major essential component
|
| 118 |
+
(kernel, window system, and so on) of the specific operating system
|
| 119 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 120 |
+
produce the work, or an object code interpreter used to run it.
|
| 121 |
+
|
| 122 |
+
The "Corresponding Source" for a work in object code form means all
|
| 123 |
+
the source code needed to generate, install, and (for an executable
|
| 124 |
+
work) run the object code and to modify the work, including scripts to
|
| 125 |
+
control those activities. However, it does not include the work's
|
| 126 |
+
System Libraries, or general-purpose tools or generally available free
|
| 127 |
+
programs which are used unmodified in performing those activities but
|
| 128 |
+
which are not part of the work. For example, Corresponding Source
|
| 129 |
+
includes interface definition files associated with source files for
|
| 130 |
+
the work, and the source code for shared libraries and dynamically
|
| 131 |
+
linked subprograms that the work is specifically designed to require,
|
| 132 |
+
such as by intimate data communication or control flow between those
|
| 133 |
+
subprograms and other parts of the work.
|
| 134 |
+
|
| 135 |
+
The Corresponding Source need not include anything that users
|
| 136 |
+
can regenerate automatically from other parts of the Corresponding
|
| 137 |
+
Source.
|
| 138 |
+
|
| 139 |
+
The Corresponding Source for a work in source code form is that
|
| 140 |
+
same work.
|
| 141 |
+
|
| 142 |
+
2. Basic Permissions.
|
| 143 |
+
|
| 144 |
+
All rights granted under this License are granted for the term of
|
| 145 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 146 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 147 |
+
permission to run the unmodified Program. The output from running a
|
| 148 |
+
covered work is covered by this License only if the output, given its
|
| 149 |
+
content, constitutes a covered work. This License acknowledges your
|
| 150 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 151 |
+
|
| 152 |
+
You may make, run and propagate covered works that you do not
|
| 153 |
+
convey, without conditions so long as your license otherwise remains
|
| 154 |
+
in force. You may convey covered works to others for the sole purpose
|
| 155 |
+
of having them make modifications exclusively for you, or provide you
|
| 156 |
+
with facilities for running those works, provided that you comply with
|
| 157 |
+
the terms of this License in conveying all material for which you do
|
| 158 |
+
not control copyright. Those thus making or running the covered works
|
| 159 |
+
for you must do so exclusively on your behalf, under your direction
|
| 160 |
+
and control, on terms that prohibit them from making any copies of
|
| 161 |
+
your copyrighted material outside their relationship with you.
|
| 162 |
+
|
| 163 |
+
Conveying under any other circumstances is permitted solely under
|
| 164 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 165 |
+
makes it unnecessary.
|
| 166 |
+
|
| 167 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 168 |
+
|
| 169 |
+
No covered work shall be deemed part of an effective technological
|
| 170 |
+
measure under any applicable law fulfilling obligations under article
|
| 171 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 172 |
+
similar laws prohibiting or restricting circumvention of such
|
| 173 |
+
measures.
|
| 174 |
+
|
| 175 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 176 |
+
circumvention of technological measures to the extent such circumvention
|
| 177 |
+
is effected by exercising rights under this License with respect to
|
| 178 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 179 |
+
modification of the work as a means of enforcing, against the work's
|
| 180 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 181 |
+
technological measures.
|
| 182 |
+
|
| 183 |
+
4. Conveying Verbatim Copies.
|
| 184 |
+
|
| 185 |
+
You may convey verbatim copies of the Program's source code as you
|
| 186 |
+
receive it, in any medium, provided that you conspicuously and
|
| 187 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 188 |
+
keep intact all notices stating that this License and any
|
| 189 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 190 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 191 |
+
recipients a copy of this License along with the Program.
|
| 192 |
+
|
| 193 |
+
You may charge any price or no price for each copy that you convey,
|
| 194 |
+
and you may offer support or warranty protection for a fee.
|
| 195 |
+
|
| 196 |
+
5. Conveying Modified Source Versions.
|
| 197 |
+
|
| 198 |
+
You may convey a work based on the Program, or the modifications to
|
| 199 |
+
produce it from the Program, in the form of source code under the
|
| 200 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 201 |
+
|
| 202 |
+
a) The work must carry prominent notices stating that you modified
|
| 203 |
+
it, and giving a relevant date.
|
| 204 |
+
|
| 205 |
+
b) The work must carry prominent notices stating that it is
|
| 206 |
+
released under this License and any conditions added under section
|
| 207 |
+
7. This requirement modifies the requirement in section 4 to
|
| 208 |
+
"keep intact all notices".
|
| 209 |
+
|
| 210 |
+
c) You must license the entire work, as a whole, under this
|
| 211 |
+
License to anyone who comes into possession of a copy. This
|
| 212 |
+
License will therefore apply, along with any applicable section 7
|
| 213 |
+
additional terms, to the whole of the work, and all its parts,
|
| 214 |
+
regardless of how they are packaged. This License gives no
|
| 215 |
+
permission to license the work in any other way, but it does not
|
| 216 |
+
invalidate such permission if you have separately received it.
|
| 217 |
+
|
| 218 |
+
d) If the work has interactive user interfaces, each must display
|
| 219 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 220 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 221 |
+
work need not make them do so.
|
| 222 |
+
|
| 223 |
+
A compilation of a covered work with other separate and independent
|
| 224 |
+
works, which are not by their nature extensions of the covered work,
|
| 225 |
+
and which are not combined with it such as to form a larger program,
|
| 226 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 227 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 228 |
+
used to limit the access or legal rights of the compilation's users
|
| 229 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 230 |
+
in an aggregate does not cause this License to apply to the other
|
| 231 |
+
parts of the aggregate.
|
| 232 |
+
|
| 233 |
+
6. Conveying Non-Source Forms.
|
| 234 |
+
|
| 235 |
+
You may convey a covered work in object code form under the terms
|
| 236 |
+
of sections 4 and 5, provided that you also convey the
|
| 237 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 238 |
+
in one of these ways:
|
| 239 |
+
|
| 240 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 241 |
+
(including a physical distribution medium), accompanied by the
|
| 242 |
+
Corresponding Source fixed on a durable physical medium
|
| 243 |
+
customarily used for software interchange.
|
| 244 |
+
|
| 245 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 246 |
+
(including a physical distribution medium), accompanied by a
|
| 247 |
+
written offer, valid for at least three years and valid for as
|
| 248 |
+
long as you offer spare parts or customer support for that product
|
| 249 |
+
model, to give anyone who possesses the object code either (1) a
|
| 250 |
+
copy of the Corresponding Source for all the software in the
|
| 251 |
+
product that is covered by this License, on a durable physical
|
| 252 |
+
medium customarily used for software interchange, for a price no
|
| 253 |
+
more than your reasonable cost of physically performing this
|
| 254 |
+
conveying of source, or (2) access to copy the
|
| 255 |
+
Corresponding Source from a network server at no charge.
|
| 256 |
+
|
| 257 |
+
c) Convey individual copies of the object code with a copy of the
|
| 258 |
+
written offer to provide the Corresponding Source. This
|
| 259 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 260 |
+
only if you received the object code with such an offer, in accord
|
| 261 |
+
with subsection 6b.
|
| 262 |
+
|
| 263 |
+
d) Convey the object code by offering access from a designated
|
| 264 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 265 |
+
Corresponding Source in the same way through the same place at no
|
| 266 |
+
further charge. You need not require recipients to copy the
|
| 267 |
+
Corresponding Source along with the object code. If the place to
|
| 268 |
+
copy the object code is a network server, the Corresponding Source
|
| 269 |
+
may be on a different server (operated by you or a third party)
|
| 270 |
+
that supports equivalent copying facilities, provided you maintain
|
| 271 |
+
clear directions next to the object code saying where to find the
|
| 272 |
+
Corresponding Source. Regardless of what server hosts the
|
| 273 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 274 |
+
available for as long as needed to satisfy these requirements.
|
| 275 |
+
|
| 276 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 277 |
+
you inform other peers where the object code and Corresponding
|
| 278 |
+
Source of the work are being offered to the general public at no
|
| 279 |
+
charge under subsection 6d.
|
| 280 |
+
|
| 281 |
+
A separable portion of the object code, whose source code is excluded
|
| 282 |
+
from the Corresponding Source as a System Library, need not be
|
| 283 |
+
included in conveying the object code work.
|
| 284 |
+
|
| 285 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 286 |
+
tangible personal property which is normally used for personal, family,
|
| 287 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 288 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 289 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 290 |
+
product received by a particular user, "normally used" refers to a
|
| 291 |
+
typical or common use of that class of product, regardless of the status
|
| 292 |
+
of the particular user or of the way in which the particular user
|
| 293 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 294 |
+
is a consumer product regardless of whether the product has substantial
|
| 295 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 296 |
+
the only significant mode of use of the product.
|
| 297 |
+
|
| 298 |
+
"Installation Information" for a User Product means any methods,
|
| 299 |
+
procedures, authorization keys, or other information required to install
|
| 300 |
+
and execute modified versions of a covered work in that User Product from
|
| 301 |
+
a modified version of its Corresponding Source. The information must
|
| 302 |
+
suffice to ensure that the continued functioning of the modified object
|
| 303 |
+
code is in no case prevented or interfered with solely because
|
| 304 |
+
modification has been made.
|
| 305 |
+
|
| 306 |
+
If you convey an object code work under this section in, or with, or
|
| 307 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 308 |
+
part of a transaction in which the right of possession and use of the
|
| 309 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 310 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 311 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 312 |
+
by the Installation Information. But this requirement does not apply
|
| 313 |
+
if neither you nor any third party retains the ability to install
|
| 314 |
+
modified object code on the User Product (for example, the work has
|
| 315 |
+
been installed in ROM).
|
| 316 |
+
|
| 317 |
+
The requirement to provide Installation Information does not include a
|
| 318 |
+
requirement to continue to provide support service, warranty, or updates
|
| 319 |
+
for a work that has been modified or installed by the recipient, or for
|
| 320 |
+
the User Product in which it has been modified or installed. Access to a
|
| 321 |
+
network may be denied when the modification itself materially and
|
| 322 |
+
adversely affects the operation of the network or violates the rules and
|
| 323 |
+
protocols for communication across the network.
|
| 324 |
+
|
| 325 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 326 |
+
in accord with this section must be in a format that is publicly
|
| 327 |
+
documented (and with an implementation available to the public in
|
| 328 |
+
source code form), and must require no special password or key for
|
| 329 |
+
unpacking, reading or copying.
|
| 330 |
+
|
| 331 |
+
7. Additional Terms.
|
| 332 |
+
|
| 333 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 334 |
+
License by making exceptions from one or more of its conditions.
|
| 335 |
+
Additional permissions that are applicable to the entire Program shall
|
| 336 |
+
be treated as though they were included in this License, to the extent
|
| 337 |
+
that they are valid under applicable law. If additional permissions
|
| 338 |
+
apply only to part of the Program, that part may be used separately
|
| 339 |
+
under those permissions, but the entire Program remains governed by
|
| 340 |
+
this License without regard to the additional permissions.
|
| 341 |
+
|
| 342 |
+
When you convey a copy of a covered work, you may at your option
|
| 343 |
+
remove any additional permissions from that copy, or from any part of
|
| 344 |
+
it. (Additional permissions may be written to require their own
|
| 345 |
+
removal in certain cases when you modify the work.) You may place
|
| 346 |
+
additional permissions on material, added by you to a covered work,
|
| 347 |
+
for which you have or can give appropriate copyright permission.
|
| 348 |
+
|
| 349 |
+
Notwithstanding any other provision of this License, for material you
|
| 350 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 351 |
+
that material) supplement the terms of this License with terms:
|
| 352 |
+
|
| 353 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 354 |
+
terms of sections 15 and 16 of this License; or
|
| 355 |
+
|
| 356 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 357 |
+
author attributions in that material or in the Appropriate Legal
|
| 358 |
+
Notices displayed by works containing it; or
|
| 359 |
+
|
| 360 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 361 |
+
requiring that modified versions of such material be marked in
|
| 362 |
+
reasonable ways as different from the original version; or
|
| 363 |
+
|
| 364 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 365 |
+
authors of the material; or
|
| 366 |
+
|
| 367 |
+
e) Declining to grant rights under trademark law for use of some
|
| 368 |
+
trade names, trademarks, or service marks; or
|
| 369 |
+
|
| 370 |
+
f) Requiring indemnification of licensors and authors of that
|
| 371 |
+
material by anyone who conveys the material (or modified versions of
|
| 372 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 373 |
+
any liability that these contractual assumptions directly impose on
|
| 374 |
+
those licensors and authors.
|
| 375 |
+
|
| 376 |
+
All other non-permissive additional terms are considered "further
|
| 377 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 378 |
+
received it, or any part of it, contains a notice stating that it is
|
| 379 |
+
governed by this License along with a term that is a further
|
| 380 |
+
restriction, you may remove that term. If a license document contains
|
| 381 |
+
a further restriction but permits relicensing or conveying under this
|
| 382 |
+
License, you may add to a covered work material governed by the terms
|
| 383 |
+
of that license document, provided that the further restriction does
|
| 384 |
+
not survive such relicensing or conveying.
|
| 385 |
+
|
| 386 |
+
If you add terms to a covered work in accord with this section, you
|
| 387 |
+
must place, in the relevant source files, a statement of the
|
| 388 |
+
additional terms that apply to those files, or a notice indicating
|
| 389 |
+
where to find the applicable terms.
|
| 390 |
+
|
| 391 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 392 |
+
form of a separately written license, or stated as exceptions;
|
| 393 |
+
the above requirements apply either way.
|
| 394 |
+
|
| 395 |
+
8. Termination.
|
| 396 |
+
|
| 397 |
+
You may not propagate or modify a covered work except as expressly
|
| 398 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 399 |
+
modify it is void, and will automatically terminate your rights under
|
| 400 |
+
this License (including any patent licenses granted under the third
|
| 401 |
+
paragraph of section 11).
|
| 402 |
+
|
| 403 |
+
However, if you cease all violation of this License, then your
|
| 404 |
+
license from a particular copyright holder is reinstated (a)
|
| 405 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 406 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 407 |
+
holder fails to notify you of the violation by some reasonable means
|
| 408 |
+
prior to 60 days after the cessation.
|
| 409 |
+
|
| 410 |
+
Moreover, your license from a particular copyright holder is
|
| 411 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 412 |
+
violation by some reasonable means, this is the first time you have
|
| 413 |
+
received notice of violation of this License (for any work) from that
|
| 414 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 415 |
+
your receipt of the notice.
|
| 416 |
+
|
| 417 |
+
Termination of your rights under this section does not terminate the
|
| 418 |
+
licenses of parties who have received copies or rights from you under
|
| 419 |
+
this License. If your rights have been terminated and not permanently
|
| 420 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 421 |
+
material under section 10.
|
| 422 |
+
|
| 423 |
+
9. Acceptance Not Required for Having Copies.
|
| 424 |
+
|
| 425 |
+
You are not required to accept this License in order to receive or
|
| 426 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 427 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 428 |
+
to receive a copy likewise does not require acceptance. However,
|
| 429 |
+
nothing other than this License grants you permission to propagate or
|
| 430 |
+
modify any covered work. These actions infringe copyright if you do
|
| 431 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 432 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 433 |
+
|
| 434 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 435 |
+
|
| 436 |
+
Each time you convey a covered work, the recipient automatically
|
| 437 |
+
receives a license from the original licensors, to run, modify and
|
| 438 |
+
propagate that work, subject to this License. You are not responsible
|
| 439 |
+
for enforcing compliance by third parties with this License.
|
| 440 |
+
|
| 441 |
+
An "entity transaction" is a transaction transferring control of an
|
| 442 |
+
organization, or substantially all assets of one, or subdividing an
|
| 443 |
+
organization, or merging organizations. If propagation of a covered
|
| 444 |
+
work results from an entity transaction, each party to that
|
| 445 |
+
transaction who receives a copy of the work also receives whatever
|
| 446 |
+
licenses to the work the party's predecessor in interest had or could
|
| 447 |
+
give under the previous paragraph, plus a right to possession of the
|
| 448 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 449 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 450 |
+
|
| 451 |
+
You may not impose any further restrictions on the exercise of the
|
| 452 |
+
rights granted or affirmed under this License. For example, you may
|
| 453 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 454 |
+
rights granted under this License, and you may not initiate litigation
|
| 455 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 456 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 457 |
+
sale, or importing the Program or any portion of it.
|
| 458 |
+
|
| 459 |
+
11. Patents.
|
| 460 |
+
|
| 461 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 462 |
+
License of the Program or a work on which the Program is based. The
|
| 463 |
+
work thus licensed is called the contributor's "contributor version".
|
| 464 |
+
|
| 465 |
+
A contributor's "essential patent claims" are all patent claims
|
| 466 |
+
owned or controlled by the contributor, whether already acquired or
|
| 467 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 468 |
+
by this License, of making, using, or selling its contributor version,
|
| 469 |
+
but do not include claims that would be infringed only as a
|
| 470 |
+
consequence of further modification of the contributor version. For
|
| 471 |
+
purposes of this definition, "control" includes the right to grant
|
| 472 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 473 |
+
this License.
|
| 474 |
+
|
| 475 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 476 |
+
patent license under the contributor's essential patent claims, to
|
| 477 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 478 |
+
propagate the contents of its contributor version.
|
| 479 |
+
|
| 480 |
+
In the following three paragraphs, a "patent license" is any express
|
| 481 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 482 |
+
(such as an express permission to practice a patent or covenant not to
|
| 483 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 484 |
+
party means to make such an agreement or commitment not to enforce a
|
| 485 |
+
patent against the party.
|
| 486 |
+
|
| 487 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 488 |
+
and the Corresponding Source of the work is not available for anyone
|
| 489 |
+
to copy, free of charge and under the terms of this License, through a
|
| 490 |
+
publicly available network server or other readily accessible means,
|
| 491 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 492 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 493 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 494 |
+
consistent with the requirements of this License, to extend the patent
|
| 495 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 496 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 497 |
+
covered work in a country, or your recipient's use of the covered work
|
| 498 |
+
in a country, would infringe one or more identifiable patents in that
|
| 499 |
+
country that you have reason to believe are valid.
|
| 500 |
+
|
| 501 |
+
If, pursuant to or in connection with a single transaction or
|
| 502 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 503 |
+
covered work, and grant a patent license to some of the parties
|
| 504 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 505 |
+
or convey a specific copy of the covered work, then the patent license
|
| 506 |
+
you grant is automatically extended to all recipients of the covered
|
| 507 |
+
work and works based on it.
|
| 508 |
+
|
| 509 |
+
A patent license is "discriminatory" if it does not include within
|
| 510 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 511 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 512 |
+
specifically granted under this License. You may not convey a covered
|
| 513 |
+
work if you are a party to an arrangement with a third party that is
|
| 514 |
+
in the business of distributing software, under which you make payment
|
| 515 |
+
to the third party based on the extent of your activity of conveying
|
| 516 |
+
the work, and under which the third party grants, to any of the
|
| 517 |
+
parties who would receive the covered work from you, a discriminatory
|
| 518 |
+
patent license (a) in connection with copies of the covered work
|
| 519 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 520 |
+
for and in connection with specific products or compilations that
|
| 521 |
+
contain the covered work, unless you entered into that arrangement,
|
| 522 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 523 |
+
|
| 524 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 525 |
+
any implied license or other defenses to infringement that may
|
| 526 |
+
otherwise be available to you under applicable patent law.
|
| 527 |
+
|
| 528 |
+
12. No Surrender of Others' Freedom.
|
| 529 |
+
|
| 530 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 531 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 532 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 533 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 534 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 535 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 536 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 537 |
+
the Program, the only way you could satisfy both those terms and this
|
| 538 |
+
License would be to refrain entirely from conveying the Program.
|
| 539 |
+
|
| 540 |
+
13. Remote Network Interaction; Use with the GNU General Public License.
|
| 541 |
+
|
| 542 |
+
Notwithstanding any other provision of this License, if you modify the
|
| 543 |
+
Program, your modified version must prominently offer all users
|
| 544 |
+
interacting with it remotely through a computer network (if your version
|
| 545 |
+
supports such interaction) an opportunity to receive the Corresponding
|
| 546 |
+
Source of your version by providing access to the Corresponding Source
|
| 547 |
+
from a network server at no charge, through some standard or customary
|
| 548 |
+
means of facilitating copying of software. This Corresponding Source
|
| 549 |
+
shall include the Corresponding Source for any work covered by version 3
|
| 550 |
+
of the GNU General Public License that is incorporated pursuant to the
|
| 551 |
+
following paragraph.
|
| 552 |
+
|
| 553 |
+
Notwithstanding any other provision of this License, you have
|
| 554 |
+
permission to link or combine any covered work with a work licensed
|
| 555 |
+
under version 3 of the GNU General Public License into a single
|
| 556 |
+
combined work, and to convey the resulting work. The terms of this
|
| 557 |
+
License will continue to apply to the part which is the covered work,
|
| 558 |
+
but the work with which it is combined will remain governed by version
|
| 559 |
+
3 of the GNU General Public License.
|
| 560 |
+
|
| 561 |
+
14. Revised Versions of this License.
|
| 562 |
+
|
| 563 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 564 |
+
the GNU Affero General Public License from time to time. Such new versions
|
| 565 |
+
will be similar in spirit to the present version, but may differ in detail to
|
| 566 |
+
address new problems or concerns.
|
| 567 |
+
|
| 568 |
+
Each version is given a distinguishing version number. If the
|
| 569 |
+
Program specifies that a certain numbered version of the GNU Affero General
|
| 570 |
+
Public License "or any later version" applies to it, you have the
|
| 571 |
+
option of following the terms and conditions either of that numbered
|
| 572 |
+
version or of any later version published by the Free Software
|
| 573 |
+
Foundation. If the Program does not specify a version number of the
|
| 574 |
+
GNU Affero General Public License, you may choose any version ever published
|
| 575 |
+
by the Free Software Foundation.
|
| 576 |
+
|
| 577 |
+
If the Program specifies that a proxy can decide which future
|
| 578 |
+
versions of the GNU Affero General Public License can be used, that proxy's
|
| 579 |
+
public statement of acceptance of a version permanently authorizes you
|
| 580 |
+
to choose that version for the Program.
|
| 581 |
+
|
| 582 |
+
Later license versions may give you additional or different
|
| 583 |
+
permissions. However, no additional obligations are imposed on any
|
| 584 |
+
author or copyright holder as a result of your choosing to follow a
|
| 585 |
+
later version.
|
| 586 |
+
|
| 587 |
+
15. Disclaimer of Warranty.
|
| 588 |
+
|
| 589 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 590 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 591 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 592 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 593 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 594 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 595 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 596 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 597 |
+
|
| 598 |
+
16. Limitation of Liability.
|
| 599 |
+
|
| 600 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 601 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 602 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 603 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 604 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 605 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 606 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 607 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 608 |
+
SUCH DAMAGES.
|
| 609 |
+
|
| 610 |
+
17. Interpretation of Sections 15 and 16.
|
| 611 |
+
|
| 612 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 613 |
+
above cannot be given local legal effect according to their terms,
|
| 614 |
+
reviewing courts shall apply local law that most closely approximates
|
| 615 |
+
an absolute waiver of all civil liability in connection with the
|
| 616 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 617 |
+
copy of the Program in return for a fee.
|
| 618 |
+
|
| 619 |
+
END OF TERMS AND CONDITIONS
|
| 620 |
+
|
| 621 |
+
How to Apply These Terms to Your New Programs
|
| 622 |
+
|
| 623 |
+
If you develop a new program, and you want it to be of the greatest
|
| 624 |
+
possible use to the public, the best way to achieve this is to make it
|
| 625 |
+
free software which everyone can redistribute and change under these terms.
|
| 626 |
+
|
| 627 |
+
To do so, attach the following notices to the program. It is safest
|
| 628 |
+
to attach them to the start of each source file to most effectively
|
| 629 |
+
state the exclusion of warranty; and each file should have at least
|
| 630 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 631 |
+
|
| 632 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 633 |
+
Copyright (C) <year> <name of author>
|
| 634 |
+
|
| 635 |
+
This program is free software: you can redistribute it and/or modify
|
| 636 |
+
it under the terms of the GNU Affero General Public License as published
|
| 637 |
+
by the Free Software Foundation, either version 3 of the License, or
|
| 638 |
+
(at your option) any later version.
|
| 639 |
+
|
| 640 |
+
This program is distributed in the hope that it will be useful,
|
| 641 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 642 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 643 |
+
GNU Affero General Public License for more details.
|
| 644 |
+
|
| 645 |
+
You should have received a copy of the GNU Affero General Public License
|
| 646 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 647 |
+
|
| 648 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 649 |
+
|
| 650 |
+
If your software can interact with users remotely through a computer
|
| 651 |
+
network, you should also make sure that it provides a way for users to
|
| 652 |
+
get its source. For example, if your program is a web application, its
|
| 653 |
+
interface could display a "Source" link that leads users to an archive
|
| 654 |
+
of the code. There are many ways you could offer source, and different
|
| 655 |
+
solutions will be better for different programs; see section 13 for the
|
| 656 |
+
specific requirements.
|
| 657 |
+
|
| 658 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 659 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 660 |
+
For more information on this, and how to apply and follow the GNU AGPL, see
|
| 661 |
+
<https://www.gnu.org/licenses/>.
|
Makefile
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.PHONY: help install server clickhouse clickhouse-prod clickhouse-stop clickhouse-postgres-remote postgres postgres-client postgres-prod postgres-stop
|
| 2 |
+
|
| 3 |
+
require = \
|
| 4 |
+
$(foreach 1,$1,$(__require))
|
| 5 |
+
__require = \
|
| 6 |
+
$(if $(value $1),, \
|
| 7 |
+
$(error Provide required parameter: $1$(if $(value 2), ($(strip $2)))))
|
| 8 |
+
|
| 9 |
+
help:
|
| 10 |
+
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
| 11 |
+
|
| 12 |
+
install: ## Run the initial setup
|
| 13 |
+
mix deps.get
|
| 14 |
+
mix ecto.create
|
| 15 |
+
mix ecto.migrate
|
| 16 |
+
mix download_country_database
|
| 17 |
+
npm install --prefix assets
|
| 18 |
+
npm install --prefix tracker
|
| 19 |
+
npm run deploy --prefix tracker
|
| 20 |
+
|
| 21 |
+
server: ## Start the web server
|
| 22 |
+
mix phx.server
|
| 23 |
+
|
| 24 |
+
CH_FLAGS ?= --detach -p 8123:8123 -p 9000:9000 --ulimit nofile=262144:262144 --name plausible_clickhouse --env CLICKHOUSE_SKIP_USER_SETUP=1
|
| 25 |
+
|
| 26 |
+
clickhouse: ## Start a container with a recent version of clickhouse
|
| 27 |
+
docker run $(CH_FLAGS) --network host --volume=$$PWD/.clickhouse_db_vol:/var/lib/clickhouse --volume=$$PWD/.clickhouse_config:/etc/clickhouse-server/config.d clickhouse/clickhouse-server:latest-alpine
|
| 28 |
+
|
| 29 |
+
clickhouse-client: ## Connect to clickhouse
|
| 30 |
+
docker exec -it plausible_clickhouse clickhouse-client -d plausible_events_db
|
| 31 |
+
|
| 32 |
+
clickhouse-prod: ## Start a container with the same version of clickhouse as the one in prod
|
| 33 |
+
docker run $(CH_FLAGS) --volume=$$PWD/.clickhouse_db_vol_prod:/var/lib/clickhouse clickhouse/clickhouse-server:25.11.5.8-alpine
|
| 34 |
+
|
| 35 |
+
clickhouse-stop: ## Stop and remove the clickhouse container
|
| 36 |
+
docker stop plausible_clickhouse && docker rm plausible_clickhouse
|
| 37 |
+
|
| 38 |
+
clickhouse-postgres-remote: ## Create postgres_remote database in ClickHouse for querying PostgreSQL
|
| 39 |
+
$(eval POSTGRES_IP := $(shell docker inspect plausible_db --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'))
|
| 40 |
+
@docker exec plausible_clickhouse clickhouse-client --query "DROP DATABASE IF EXISTS postgres_remote; CREATE DATABASE postgres_remote ENGINE = PostgreSQL('$(POSTGRES_IP):5432', 'plausible_dev', 'postgres', 'postgres');"
|
| 41 |
+
|
| 42 |
+
PG_FLAGS ?= --detach -e POSTGRES_PASSWORD="postgres" -p 5432:5432 --name plausible_db
|
| 43 |
+
|
| 44 |
+
postgres: ## Start a container with a recent version of postgres
|
| 45 |
+
docker run $(PG_FLAGS) --volume=plausible_db:/var/lib/postgresql/docker postgres:latest
|
| 46 |
+
|
| 47 |
+
postgres-client: ## Connect to postgres
|
| 48 |
+
docker exec -it plausible_db psql -U postgres -d plausible_dev
|
| 49 |
+
|
| 50 |
+
postgres-prod: ## Start a container with the same version of postgres as the one in prod
|
| 51 |
+
docker run $(PG_FLAGS) --volume=plausible_db_prod:/var/lib/postgresql/docker postgres:18
|
| 52 |
+
|
| 53 |
+
postgres-stop: ## Stop and remove the postgres container
|
| 54 |
+
docker stop plausible_db && docker rm plausible_db
|
| 55 |
+
|
| 56 |
+
browserless:
|
| 57 |
+
docker run -e "TOKEN=dummy_token" -p 3000:3000 --network host ghcr.io/browserless/chromium
|
| 58 |
+
|
| 59 |
+
minio: ## Start a transient container with a recent version of minio (s3)
|
| 60 |
+
docker run -d --rm -p 10000:10000 -p 10001:10001 --name plausible_minio minio/minio server /data --address ":10000" --console-address ":10001"
|
| 61 |
+
while ! docker exec plausible_minio mc alias set local http://localhost:10000 minioadmin minioadmin; do sleep 1; done
|
| 62 |
+
docker exec plausible_minio sh -c 'mc mb local/dev-exports && mc ilm add --expiry-days 7 local/dev-exports'
|
| 63 |
+
docker exec plausible_minio sh -c 'mc mb local/dev-imports && mc ilm add --expiry-days 7 local/dev-imports'
|
| 64 |
+
docker exec plausible_minio sh -c 'mc mb local/test-exports && mc ilm add --expiry-days 7 local/test-exports'
|
| 65 |
+
docker exec plausible_minio sh -c 'mc mb local/test-imports && mc ilm add --expiry-days 7 local/test-imports'
|
| 66 |
+
|
| 67 |
+
minio-stop: ## Stop and remove the minio container
|
| 68 |
+
docker stop plausible_minio
|
| 69 |
+
|
| 70 |
+
sso:
|
| 71 |
+
$(call require, integration_id)
|
| 72 |
+
@echo "Setting up local IdP service..."
|
| 73 |
+
@docker run --name=idp \
|
| 74 |
+
-p 8080:8080 \
|
| 75 |
+
-e SIMPLESAMLPHP_SP_ENTITY_ID=http://localhost:8000/sso/$(integration_id) \
|
| 76 |
+
-e SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE=http://localhost:8000/sso/saml/consume/$(integration_id) \
|
| 77 |
+
-v $$PWD/extra/fixture/authsources.php:/var/www/simplesamlphp/config/authsources.php -d kenchan0130/simplesamlphp
|
| 78 |
+
|
| 79 |
+
@sleep 2
|
| 80 |
+
|
| 81 |
+
@echo "Use the following IdP configuration:"
|
| 82 |
+
@echo ""
|
| 83 |
+
@echo "Sign-in URL: http://localhost:8080/simplesaml/saml2/idp/SSOService.php"
|
| 84 |
+
@echo ""
|
| 85 |
+
@echo "Entity ID: http://localhost:8080/simplesaml/saml2/idp/metadata.php"
|
| 86 |
+
@echo ""
|
| 87 |
+
@echo "PEM Certificate:"
|
| 88 |
+
@curl http://localhost:8080/simplesaml/module.php/saml/idp/certs.php/idp.crt 2>/dev/null
|
| 89 |
+
@echo ""
|
| 90 |
+
@echo ""
|
| 91 |
+
@echo "Following accounts are configured:"
|
| 92 |
+
@echo "- user@plausible.test / plausible"
|
| 93 |
+
@echo "- user1@plausible.test / plausible"
|
| 94 |
+
@echo "- user2@plausible.test / plausible"
|
| 95 |
+
|
| 96 |
+
sso-stop:
|
| 97 |
+
docker stop idp
|
| 98 |
+
docker remove idp
|
| 99 |
+
|
| 100 |
+
generate-corefile:
|
| 101 |
+
$(call require, domain_id)
|
| 102 |
+
domain_id=$(domain_id) envsubst < $(PWD)/extra/fixture/Corefile.template > $(PWD)/extra/fixture/Corefile.gen.$(domain_id)
|
| 103 |
+
|
| 104 |
+
mock-dns: generate-corefile
|
| 105 |
+
$(call require, domain_id)
|
| 106 |
+
docker run --rm -p 5354:53/udp -v $(PWD)/extra/fixture/Corefile.gen.$(domain_id):/Corefile coredns/coredns:latest -conf Corefile
|
| 107 |
+
|
| 108 |
+
loadtest-server:
|
| 109 |
+
@echo "Ensure your OTP installation is built with --enable-lock-counter"
|
| 110 |
+
MIX_ENV=load ERL_FLAGS="-emu_type lcnt +Mdai max" iex -S mix do phx.digest + phx.server
|
| 111 |
+
|
| 112 |
+
loadtest-client:
|
| 113 |
+
@echo "Set your limits for file descriptors/ephemeral ports high... Test begins shortly"
|
| 114 |
+
@sleep 5
|
| 115 |
+
k6 run test/load/script.js
|
README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Plausible Analytics
|
| 3 |
+
emoji: 📈
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Plausible Analytics on Hugging Face Spaces
|
| 12 |
+
|
| 13 |
+
This is an optimized deployment of [Plausible Analytics Community Edition (CE)](https://github.com/plausible/analytics) on Hugging Face Spaces.
|
| 14 |
+
|
| 15 |
+
## Setup & Running
|
| 16 |
+
This Space is built using the Docker SDK with mandatory endpoints exposed.
|
| 17 |
+
- **Port:** `7860`
|
| 18 |
+
- **Health Endpoint:** `/health`
|
| 19 |
+
- **Documentation:** `/api-docs`
|
SECURITY.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Security Policy
|
| 2 |
+
|
| 3 |
+
## Supported Versions
|
| 4 |
+
|
| 5 |
+
We only add security updates to the latest MAJOR.MINOR version of the project. No security updates are backported to previous versions. If you
|
| 6 |
+
want be up to date on security patches, make sure your Plausible image is up to date with `plausible/analytics:latest`
|
| 7 |
+
|
| 8 |
+
## Reporting a Vulnerability
|
| 9 |
+
|
| 10 |
+
Our software is updated several times per week and we also have a way for you to [report any security vulnerabilities](https://plausible.io/vulnerability-disclosure-program). A more detailed overview about our security practices can be found on [plausible.io/security](https://plausible.io/security).
|
| 11 |
+
|
| 12 |
+
If you've found a security vulnerability with the Plausible codebase, you can disclose it responsibly by sending a summary to security@plausible.io.
|
| 13 |
+
We will review the potential threat and fix it as fast as we can.
|
| 14 |
+
|
| 15 |
+
While we do not have a bounty program in place yet, we are incredibly thankful for people who take the time to share their findings with us. Whether it's a tiny bug that you've found or a security vulnerability, all reports help us to continuously improve Plausible for everyone. Thank you!
|
assets/.prettierignore
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules/
|
| 2 |
+
static/images/
|
| 3 |
+
.*.json
|
| 4 |
+
.*rc
|
| 5 |
+
*.json
|
| 6 |
+
*.config.js
|
| 7 |
+
js/types/query-api.d.ts
|
assets/.prettierrc.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"singleQuote": true,
|
| 3 |
+
"trailingComma": "none",
|
| 4 |
+
"semi": false
|
| 5 |
+
}
|
assets/.stylelintrc.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"extends": ["stylelint-config-standard"],
|
| 3 |
+
"ignoreFiles": ["./node_modules/**/*.*"],
|
| 4 |
+
"rules": {
|
| 5 |
+
"import-notation": "string",
|
| 6 |
+
"at-rule-no-unknown": [true, { "ignoreAtRules": ["apply", "screen", "plugin", "source", "theme", "utility", "custom-variant"] }],
|
| 7 |
+
"at-rule-empty-line-before": [
|
| 8 |
+
"always",
|
| 9 |
+
{ "except": ["blockless-after-same-name-blockless"], "ignoreAtRules": ["apply"] }
|
| 10 |
+
],
|
| 11 |
+
"no-descending-specificity": null
|
| 12 |
+
}
|
| 13 |
+
}
|
assets/css/app.css
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import 'tailwindcss' source(none);
|
| 2 |
+
@import 'flatpickr/dist/flatpickr.min.css' layer(components);
|
| 3 |
+
@import './modal.css' layer(components);
|
| 4 |
+
@import './loader.css' layer(components);
|
| 5 |
+
@import './tooltip.css' layer(components);
|
| 6 |
+
@import './flatpickr-colors.css' layer(components);
|
| 7 |
+
|
| 8 |
+
@plugin "@tailwindcss/forms";
|
| 9 |
+
|
| 10 |
+
@source "../css";
|
| 11 |
+
@source "../js";
|
| 12 |
+
@source "../../lib/plausible_web";
|
| 13 |
+
@source "../../extra/lib/plausible_web";
|
| 14 |
+
|
| 15 |
+
/* Tailwind v3 compatibility: restore v3 default border and ring styling */
|
| 16 |
+
|
| 17 |
+
@layer base {
|
| 18 |
+
*,
|
| 19 |
+
::after,
|
| 20 |
+
::before,
|
| 21 |
+
::backdrop,
|
| 22 |
+
::file-selector-button {
|
| 23 |
+
border-color: var(--color-gray-200, currentColor);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
button:not(:disabled),
|
| 27 |
+
[role='button']:not(:disabled) {
|
| 28 |
+
cursor: pointer;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
*:focus-visible {
|
| 32 |
+
@apply ring-2 ring-indigo-500 ring-offset-2 dark:ring-offset-gray-900 outline-none;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
:focus:not(:focus-visible) {
|
| 36 |
+
@apply outline-none;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
@layer components {
|
| 41 |
+
/* Replace Tailwind form plugin's focus with focus-visible */
|
| 42 |
+
[type='checkbox']:focus,
|
| 43 |
+
[type='radio']:focus {
|
| 44 |
+
outline: none;
|
| 45 |
+
box-shadow: none;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
[type='checkbox']:focus-visible,
|
| 49 |
+
[type='radio']:focus-visible {
|
| 50 |
+
@apply ring-2 ring-indigo-500 ring-offset-2 outline-none;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
@layer components {
|
| 55 |
+
/*
|
| 56 |
+
* Button component classes shared between the React `Button` component
|
| 57 |
+
* (assets/js/dashboard/components/button.tsx) and the Phoenix `button`
|
| 58 |
+
* component (lib/plausible_web/components/generic.ex). Update here only.
|
| 59 |
+
*/
|
| 60 |
+
.btn-base {
|
| 61 |
+
@apply whitespace-nowrap truncate inline-flex items-center justify-center
|
| 62 |
+
gap-x-2 text-sm font-medium rounded-md cursor-pointer
|
| 63 |
+
disabled:cursor-not-allowed;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.btn-xs {
|
| 67 |
+
@apply px-2 py-1;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.btn-sm {
|
| 71 |
+
@apply px-3 py-2;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.btn-md {
|
| 75 |
+
@apply px-3.5 py-2.5;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.btn-theme-primary {
|
| 79 |
+
@apply border border-indigo-600 bg-indigo-600 text-white
|
| 80 |
+
hover:bg-indigo-700 focus-visible:outline-indigo-600
|
| 81 |
+
disabled:border-transparent disabled:bg-indigo-400/60
|
| 82 |
+
disabled:dark:bg-indigo-600/30 disabled:dark:text-white/35;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.btn-theme-secondary {
|
| 86 |
+
@apply border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-700
|
| 87 |
+
text-gray-800 dark:text-gray-100 hover:bg-gray-50 hover:text-gray-900
|
| 88 |
+
dark:hover:bg-gray-600 dark:hover:border-gray-600 dark:hover:text-white
|
| 89 |
+
disabled:text-gray-700/40 dark:disabled:text-gray-500
|
| 90 |
+
dark:disabled:bg-gray-800 dark:disabled:border-gray-800;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.btn-theme-yellow {
|
| 94 |
+
@apply border border-yellow-600/90 bg-yellow-600/90 text-white
|
| 95 |
+
hover:bg-yellow-600 focus-visible:outline-yellow-600
|
| 96 |
+
disabled:border-yellow-400/60 disabled:bg-yellow-400/60
|
| 97 |
+
disabled:dark:border-yellow-600/30 disabled:dark:bg-yellow-600/30
|
| 98 |
+
disabled:dark:text-white/35;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.btn-theme-danger {
|
| 102 |
+
@apply border border-gray-300 dark:border-gray-800 text-red-600 bg-white
|
| 103 |
+
dark:bg-gray-800 hover:text-red-700 dark:hover:text-red-400
|
| 104 |
+
dark:text-red-500 active:text-red-800 disabled:text-red-700/40
|
| 105 |
+
disabled:hover:shadow-none dark:disabled:text-red-500/35
|
| 106 |
+
dark:disabled:bg-gray-800;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
.btn-theme-ghost {
|
| 110 |
+
@apply border border-transparent text-gray-700 dark:text-gray-300
|
| 111 |
+
hover:text-gray-900 dark:hover:text-gray-100 hover:bg-gray-100
|
| 112 |
+
dark:hover:bg-gray-800 hover:border-gray-100 dark:hover:border-gray-800
|
| 113 |
+
disabled:text-gray-500 disabled:dark:text-gray-600
|
| 114 |
+
disabled:hover:bg-transparent disabled:hover:border-transparent;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.btn-theme-icon {
|
| 118 |
+
@apply border border-transparent text-gray-400 dark:text-gray-400
|
| 119 |
+
hover:text-gray-900 dark:hover:text-gray-100;
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
@theme {
|
| 124 |
+
/* Color aliases from tailwind.config.js */
|
| 125 |
+
|
| 126 |
+
/* yellow: colors.amber - Map yellow to amber colors */
|
| 127 |
+
--color-yellow-50: var(--color-amber-50);
|
| 128 |
+
--color-yellow-100: var(--color-amber-100);
|
| 129 |
+
--color-yellow-200: var(--color-amber-200);
|
| 130 |
+
--color-yellow-300: var(--color-amber-300);
|
| 131 |
+
--color-yellow-400: var(--color-amber-400);
|
| 132 |
+
--color-yellow-500: var(--color-amber-500);
|
| 133 |
+
--color-yellow-600: var(--color-amber-600);
|
| 134 |
+
--color-yellow-700: var(--color-amber-700);
|
| 135 |
+
--color-yellow-800: var(--color-amber-800);
|
| 136 |
+
--color-yellow-900: var(--color-amber-900);
|
| 137 |
+
--color-yellow-950: var(--color-amber-950);
|
| 138 |
+
|
| 139 |
+
/* green: colors.emerald - Map green to emerald colors */
|
| 140 |
+
--color-green-50: var(--color-emerald-50);
|
| 141 |
+
--color-green-100: var(--color-emerald-100);
|
| 142 |
+
--color-green-200: var(--color-emerald-200);
|
| 143 |
+
--color-green-300: var(--color-emerald-300);
|
| 144 |
+
--color-green-400: var(--color-emerald-400);
|
| 145 |
+
--color-green-500: var(--color-emerald-500);
|
| 146 |
+
--color-green-600: var(--color-emerald-600);
|
| 147 |
+
--color-green-700: var(--color-emerald-700);
|
| 148 |
+
--color-green-800: var(--color-emerald-800);
|
| 149 |
+
--color-green-900: var(--color-emerald-900);
|
| 150 |
+
--color-green-950: var(--color-emerald-950);
|
| 151 |
+
|
| 152 |
+
/* gray: colors.zinc - Map gray to zinc colors */
|
| 153 |
+
--color-gray-50: var(--color-zinc-50);
|
| 154 |
+
--color-gray-100: var(--color-zinc-100);
|
| 155 |
+
--color-gray-200: var(--color-zinc-200);
|
| 156 |
+
--color-gray-300: var(--color-zinc-300);
|
| 157 |
+
--color-gray-400: var(--color-zinc-400);
|
| 158 |
+
--color-gray-500: var(--color-zinc-500);
|
| 159 |
+
--color-gray-600: var(--color-zinc-600);
|
| 160 |
+
--color-gray-700: var(--color-zinc-700);
|
| 161 |
+
--color-gray-800: var(--color-zinc-800);
|
| 162 |
+
--color-gray-900: var(--color-zinc-900);
|
| 163 |
+
--color-gray-950: var(--color-zinc-950);
|
| 164 |
+
|
| 165 |
+
/* Custom gray shades from config (override some zinc values) */
|
| 166 |
+
--color-gray-75: rgb(247 247 248);
|
| 167 |
+
--color-gray-150: rgb(236 236 238);
|
| 168 |
+
--color-gray-750: rgb(50 50 54);
|
| 169 |
+
--color-gray-825: rgb(35 35 38);
|
| 170 |
+
--color-gray-850: rgb(34 34 38);
|
| 171 |
+
|
| 172 |
+
/* Custom indigo shades */
|
| 173 |
+
--color-indigo-150: rgb(212 220 255);
|
| 174 |
+
|
| 175 |
+
/* Set v3 default ring behavior */
|
| 176 |
+
--default-ring-width: 2px;
|
| 177 |
+
--default-ring-color: var(--color-indigo-500);
|
| 178 |
+
--animate-pulse: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
@media print {
|
| 182 |
+
canvas {
|
| 183 |
+
width: 100% !important;
|
| 184 |
+
height: auto !important;
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
@utility container {
|
| 189 |
+
margin-inline: auto;
|
| 190 |
+
padding-inline: 1rem;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
@custom-variant dark (&:where(.dark, .dark *));
|
| 194 |
+
@custom-variant phx-click-loading (.phx-click-loading&, .phx-click-loading &);
|
| 195 |
+
@custom-variant phx-hook-loading (.phx-hook-loading&, .phx-hook-loading &);
|
| 196 |
+
@custom-variant phx-submit-loading (.phx-submit-loading&, .phx-submit-loading &);
|
| 197 |
+
@custom-variant phx-change-loading (.phx-change-loading&, .phx-change-loading &);
|
| 198 |
+
|
| 199 |
+
[x-cloak] {
|
| 200 |
+
display: none;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.button {
|
| 204 |
+
@apply inline-flex justify-center px-3.5 py-2.5 text-sm font-medium text-white bg-indigo-600 border border-transparent rounded-md leading-5 transition hover:bg-indigo-700;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.button[disabled] {
|
| 208 |
+
@apply bg-gray-400 dark:bg-gray-600;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
html {
|
| 212 |
+
@apply text-gray-800;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
body {
|
| 216 |
+
-webkit-font-smoothing: antialiased;
|
| 217 |
+
-moz-osx-font-smoothing: grayscale;
|
| 218 |
+
width: 100vw; /* Prevents content from jumping when scrollbar is added/removed due to vertical overflow */
|
| 219 |
+
overflow-x: hidden;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
@media (width >= 1280px) {
|
| 223 |
+
.container {
|
| 224 |
+
max-width: 70rem;
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.transition {
|
| 229 |
+
transition: all 0.1s ease-in;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
.pulsating-circle {
|
| 233 |
+
position: absolute;
|
| 234 |
+
width: 10px;
|
| 235 |
+
height: 10px;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
.pulsating-circle::before {
|
| 239 |
+
content: '';
|
| 240 |
+
position: relative;
|
| 241 |
+
display: block;
|
| 242 |
+
width: 300%;
|
| 243 |
+
height: 300%;
|
| 244 |
+
box-sizing: border-box;
|
| 245 |
+
margin-left: -100%;
|
| 246 |
+
margin-top: -100%;
|
| 247 |
+
border-radius: 45px;
|
| 248 |
+
background-color: #9ae6b4;
|
| 249 |
+
animation: pulse-ring 3s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
|
| 250 |
+
@apply bg-green-500;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
.pulsating-circle::after {
|
| 254 |
+
content: '';
|
| 255 |
+
position: absolute;
|
| 256 |
+
left: 0;
|
| 257 |
+
top: 0;
|
| 258 |
+
display: block;
|
| 259 |
+
width: 100%;
|
| 260 |
+
height: 100%;
|
| 261 |
+
background-color: white;
|
| 262 |
+
border-radius: 15px;
|
| 263 |
+
animation: pulse-dot 3s cubic-bezier(0.455, 0.03, 0.515, 0.955) -0.4s infinite;
|
| 264 |
+
@apply bg-green-500;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
@keyframes pulse-ring {
|
| 268 |
+
0% {
|
| 269 |
+
transform: scale(0.33);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
50% {
|
| 273 |
+
transform: scale(1);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
40%,
|
| 277 |
+
100% {
|
| 278 |
+
opacity: 0;
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
@keyframes pulse-dot {
|
| 283 |
+
0% {
|
| 284 |
+
transform: scale(0.8);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
25% {
|
| 288 |
+
transform: scale(1);
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
50%,
|
| 292 |
+
100% {
|
| 293 |
+
transform: scale(0.8);
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
.feather {
|
| 298 |
+
height: 1em;
|
| 299 |
+
width: 1em;
|
| 300 |
+
overflow: visible;
|
| 301 |
+
display: inline;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
.feather-sm {
|
| 305 |
+
height: 1em;
|
| 306 |
+
width: 1em;
|
| 307 |
+
overflow: visible;
|
| 308 |
+
display: inline;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
.table-striped tbody tr:nth-child(odd) td {
|
| 312 |
+
background-color: var(--color-gray-75);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
.dark .table-striped tbody tr:nth-child(odd) td {
|
| 316 |
+
background-color: var(--color-gray-850);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
.fade-enter {
|
| 320 |
+
opacity: 0;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.fade-enter-active {
|
| 324 |
+
opacity: 1;
|
| 325 |
+
transition: opacity 100ms ease-in;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
iframe[hidden] {
|
| 329 |
+
display: none;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
.pagination-link[disabled] {
|
| 333 |
+
@apply cursor-default bg-gray-100 dark:bg-gray-300 pointer-events-none;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
/* This class is used for styling embedded dashboards. Do not remove. */
|
| 337 |
+
/* stylelint-disable */
|
| 338 |
+
/* prettier-ignore */
|
| 339 |
+
.date-option-group { }
|
| 340 |
+
/* stylelint-enable */
|
assets/css/flatpickr-colors.css
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* stylelint-disable selector-class-pattern */
|
| 2 |
+
/* stylelint-disable at-rule-no-unknown */
|
| 3 |
+
|
| 4 |
+
/* Because Flatpickr offers zero support for dynamic theming on its own (outside of third-party plugins) */
|
| 5 |
+
|
| 6 |
+
/* Calendar container */
|
| 7 |
+
.flatpickr-calendar {
|
| 8 |
+
@apply w-72 px-2 pt-1 pb-2 rounded-md bg-white dark:bg-gray-800 shadow-lg
|
| 9 |
+
ring-1 ring-black/5 dark:ring-gray-750 font-sans;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
.flatpickr-calendar.inline {
|
| 13 |
+
@apply top-0;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.flatpickr-days,
|
| 17 |
+
.flatpickr-days .dayContainer {
|
| 18 |
+
@apply w-full min-w-0 max-w-none;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
/* Hader */
|
| 22 |
+
.flatpickr-months {
|
| 23 |
+
@apply relative items-center py-1;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
.flatpickr-months .flatpickr-month {
|
| 27 |
+
@apply h-8 overflow-visible fill-current text-sm
|
| 28 |
+
text-gray-800 dark:text-gray-100;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.flatpickr-months .flatpickr-prev-month,
|
| 32 |
+
.flatpickr-months .flatpickr-next-month {
|
| 33 |
+
@apply absolute top-1/2 flex size-7 -translate-y-1/2 items-center
|
| 34 |
+
justify-center rounded-sm p-0 fill-current
|
| 35 |
+
text-gray-500 dark:text-gray-300
|
| 36 |
+
hover:bg-gray-100 hover:text-gray-900
|
| 37 |
+
dark:hover:bg-gray-700 dark:hover:text-gray-100;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.flatpickr-months .flatpickr-prev-month {
|
| 41 |
+
@apply left-1;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.flatpickr-months .flatpickr-next-month {
|
| 45 |
+
@apply right-1;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.flatpickr-months .flatpickr-prev-month svg,
|
| 49 |
+
.flatpickr-months .flatpickr-next-month svg {
|
| 50 |
+
@apply size-2.5;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.flatpickr-months .flatpickr-prev-month svg path,
|
| 54 |
+
.flatpickr-months .flatpickr-next-month svg path {
|
| 55 |
+
@apply fill-inherit stroke-1 stroke-current;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.flatpickr-months .flatpickr-prev-month:hover svg,
|
| 59 |
+
.flatpickr-months .flatpickr-next-month:hover svg {
|
| 60 |
+
@apply !fill-current;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.flatpickr-months .flatpickr-prev-month.flatpickr-disabled,
|
| 64 |
+
.flatpickr-months .flatpickr-next-month.flatpickr-disabled {
|
| 65 |
+
@apply flex text-gray-300 dark:text-gray-500 pointer-events-none;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.flatpickr-current-month {
|
| 69 |
+
@apply inline-flex h-8 w-auto -translate-x-1/2 items-center justify-center
|
| 70 |
+
gap-1 left-1/2 p-0 text-sm font-medium;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.flatpickr-current-month .flatpickr-monthDropdown-months {
|
| 74 |
+
--month-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z' clip-rule='evenodd'/%3E%3C/svg%3E");
|
| 75 |
+
|
| 76 |
+
background: transparent var(--month-chevron) no-repeat right 0.5rem center /
|
| 77 |
+
1rem 1rem;
|
| 78 |
+
|
| 79 |
+
@apply w-30 m-0 cursor-pointer appearance-none rounded-md border border-gray-300
|
| 80 |
+
py-1 pl-2.5 pr-8 font-sans text-sm font-medium text-gray-800 text-inherit
|
| 81 |
+
dark:border-gray-600 dark:text-gray-100
|
| 82 |
+
focus:outline-none focus:ring-0 focus:ring-offset-0;
|
| 83 |
+
|
| 84 |
+
&:hover {
|
| 85 |
+
background: transparent var(--month-chevron) no-repeat right 0.5rem center /
|
| 86 |
+
1rem 1rem;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/* Dark-mode chevron: `currentColor` doesn't cascade into a CSS-referenced
|
| 90 |
+
SVG, so we swap in a copy with a lighter hex fill. */
|
| 91 |
+
&:where(.dark, .dark *) {
|
| 92 |
+
--month-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23d1d5db'%3E%3Cpath fill-rule='evenodd' d='M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z' clip-rule='evenodd'/%3E%3C/svg%3E");
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.flatpickr-current-month
|
| 97 |
+
.flatpickr-monthDropdown-months
|
| 98 |
+
.flatpickr-monthDropdown-month {
|
| 99 |
+
@apply dark:bg-gray-800 dark:text-gray-100;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.flatpickr-current-month .numInputWrapper {
|
| 103 |
+
@apply w-18 rounded-md border border-gray-300 dark:border-gray-600 hover:bg-transparent
|
| 104 |
+
focus-within:border-indigo-500 focus-within:ring-3 focus-within:ring-indigo-500/20
|
| 105 |
+
dark:focus-within:ring-indigo-500/25;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.flatpickr-current-month input.cur-year {
|
| 109 |
+
@apply rounded-md px-2.5 py-1 font-sans text-sm font-medium
|
| 110 |
+
focus:outline-none focus:ring-0 focus:ring-offset-0;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.flatpickr-current-month input.cur-year[disabled],
|
| 114 |
+
.flatpickr-current-month input.cur-year[disabled]:hover {
|
| 115 |
+
@apply text-gray-500;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.numInputWrapper span {
|
| 119 |
+
@apply w-3.5 border-0 opacity-0 hover:bg-transparent;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.numInputWrapper:hover span {
|
| 123 |
+
@apply opacity-100;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.numInputWrapper span.arrowUp {
|
| 127 |
+
@apply after:top-[40%] after:!border-b-gray-500 dark:after:!border-b-gray-300;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.numInputWrapper span.arrowDown {
|
| 131 |
+
@apply after:top-[30%] after:!border-t-gray-500 dark:after:!border-t-gray-300;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/* Weekday names */
|
| 135 |
+
.flatpickr-weekdays {
|
| 136 |
+
@apply h-8;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.flatpickr-weekdaycontainer {
|
| 140 |
+
@apply gap-0;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
span.flatpickr-weekday {
|
| 144 |
+
@apply text-xs font-medium normal-case text-gray-400 dark:text-gray-400/75;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/* Day cells */
|
| 148 |
+
.flatpickr-day {
|
| 149 |
+
@apply mx-0 my-px h-9 max-w-none rounded-md border border-transparent
|
| 150 |
+
bg-transparent text-sm font-medium leading-[35px]
|
| 151 |
+
text-gray-800 dark:text-gray-100;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.flatpickr-day:hover,
|
| 155 |
+
.flatpickr-day:focus,
|
| 156 |
+
.flatpickr-day.prevMonthDay:hover,
|
| 157 |
+
.flatpickr-day.prevMonthDay:focus,
|
| 158 |
+
.flatpickr-day.nextMonthDay:hover,
|
| 159 |
+
.flatpickr-day.nextMonthDay:focus {
|
| 160 |
+
@apply bg-gray-100 border-gray-100 text-gray-900
|
| 161 |
+
dark:bg-gray-700 dark:border-gray-700 dark:text-gray-50;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/* Days outside the current month */
|
| 165 |
+
.flatpickr-day.prevMonthDay,
|
| 166 |
+
.flatpickr-day.nextMonthDay {
|
| 167 |
+
@apply text-gray-400 dark:text-gray-400/75;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/* Disabled days */
|
| 171 |
+
.flatpickr-day.flatpickr-disabled,
|
| 172 |
+
.flatpickr-day.flatpickr-disabled:hover {
|
| 173 |
+
@apply border-transparent bg-transparent text-gray-300 dark:text-gray-500/75;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/* Today dot */
|
| 177 |
+
.flatpickr-day.today {
|
| 178 |
+
@apply border-transparent bg-transparent
|
| 179 |
+
after:content-[''] after:absolute after:bottom-0.5 after:left-1/2
|
| 180 |
+
after:size-1 after:-translate-x-1/2 after:rounded-full
|
| 181 |
+
after:bg-indigo-500 dark:after:bg-indigo-400;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.flatpickr-day.today:hover,
|
| 185 |
+
.flatpickr-day.today:focus {
|
| 186 |
+
@apply bg-gray-100 border-gray-100 text-gray-900
|
| 187 |
+
dark:bg-gray-700 dark:border-gray-700 dark:text-gray-50;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/* Selected day & range endpoints */
|
| 191 |
+
.flatpickr-day.selected,
|
| 192 |
+
.flatpickr-day.startRange,
|
| 193 |
+
.flatpickr-day.endRange,
|
| 194 |
+
.flatpickr-day.selected.inRange,
|
| 195 |
+
.flatpickr-day.startRange.inRange,
|
| 196 |
+
.flatpickr-day.endRange.inRange,
|
| 197 |
+
.flatpickr-day.selected:focus,
|
| 198 |
+
.flatpickr-day.startRange:focus,
|
| 199 |
+
.flatpickr-day.endRange:focus,
|
| 200 |
+
.flatpickr-day.selected.prevMonthDay,
|
| 201 |
+
.flatpickr-day.startRange.prevMonthDay,
|
| 202 |
+
.flatpickr-day.endRange.prevMonthDay,
|
| 203 |
+
.flatpickr-day.selected.nextMonthDay,
|
| 204 |
+
.flatpickr-day.startRange.nextMonthDay,
|
| 205 |
+
.flatpickr-day.endRange.nextMonthDay {
|
| 206 |
+
@apply relative bg-indigo-600 dark:bg-indigo-500 border-indigo-600 dark:border-indigo-500 text-white;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.flatpickr-day.selected:hover,
|
| 210 |
+
.flatpickr-day.startRange:hover,
|
| 211 |
+
.flatpickr-day.endRange:hover {
|
| 212 |
+
@apply bg-indigo-600 border-indigo-600 dark:bg-indigo-500 dark:border-indigo-500 text-white;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.flatpickr-day.today.selected::after,
|
| 216 |
+
.flatpickr-day.today.startRange::after,
|
| 217 |
+
.flatpickr-day.today.endRange::after,
|
| 218 |
+
.flatpickr-day.today.inRange::after {
|
| 219 |
+
@apply bg-white;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
.flatpickr-day.selected.startRange,
|
| 223 |
+
.flatpickr-day.startRange.startRange,
|
| 224 |
+
.flatpickr-day.endRange.startRange {
|
| 225 |
+
@apply rounded-l-md rounded-r-none;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.flatpickr-day.selected.endRange,
|
| 229 |
+
.flatpickr-day.startRange.endRange,
|
| 230 |
+
.flatpickr-day.endRange.endRange {
|
| 231 |
+
@apply rounded-r-md rounded-l-none;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
.flatpickr-day.selected.startRange.endRange,
|
| 235 |
+
.flatpickr-day.startRange.startRange.endRange,
|
| 236 |
+
.flatpickr-day.endRange.startRange.endRange {
|
| 237 |
+
@apply rounded-md;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/* In-range days */
|
| 241 |
+
.flatpickr-day.inRange,
|
| 242 |
+
.flatpickr-day.prevMonthDay.inRange,
|
| 243 |
+
.flatpickr-day.nextMonthDay.inRange {
|
| 244 |
+
@apply rounded-none shadow-none border-transparent bg-indigo-50
|
| 245 |
+
dark:bg-indigo-500/25 hover:border-transparent;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
.flatpickr-day.selected.startRange + .endRange:not(:nth-child(7n + 1)),
|
| 249 |
+
.flatpickr-day.startRange.startRange + .endRange:not(:nth-child(7n + 1)),
|
| 250 |
+
.flatpickr-day.endRange.startRange + .endRange:not(:nth-child(7n + 1)) {
|
| 251 |
+
@apply shadow-none;
|
| 252 |
+
}
|
assets/css/loader.css
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.loading {
|
| 2 |
+
width: 50px;
|
| 3 |
+
height: 50px;
|
| 4 |
+
animation: loader-fade-in 0.2s ease-in;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
.loading.sm {
|
| 8 |
+
width: 20px;
|
| 9 |
+
height: 20px;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
.loading div {
|
| 13 |
+
display: inline-block;
|
| 14 |
+
width: 50px;
|
| 15 |
+
height: 50px;
|
| 16 |
+
border: 3px solid #dae1e7;
|
| 17 |
+
border-radius: 50%;
|
| 18 |
+
border-top-color: #606f7b;
|
| 19 |
+
animation: spin 1s ease-in-out infinite;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.dark .loading div {
|
| 23 |
+
border: 3px solid #606f7b;
|
| 24 |
+
border-top-color: #dae1e7;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.loading.sm div {
|
| 28 |
+
width: 20px;
|
| 29 |
+
height: 20px;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
@keyframes spin {
|
| 33 |
+
to {
|
| 34 |
+
transform: rotate(360deg);
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
@keyframes loader-fade-in {
|
| 39 |
+
0% {
|
| 40 |
+
opacity: 0;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
50% {
|
| 44 |
+
opacity: 0;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
100% {
|
| 48 |
+
opacity: 1;
|
| 49 |
+
}
|
| 50 |
+
}
|
assets/css/modal.css
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* stylelint-disable selector-class-pattern */
|
| 2 |
+
.modal {
|
| 3 |
+
display: none;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
.modal.is-open {
|
| 7 |
+
display: block;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
.modal[aria-hidden='false'] .modal__overlay {
|
| 11 |
+
animation: mm-fade-in 0.2s ease-in;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
.modal[aria-hidden='true'] .modal__overlay {
|
| 15 |
+
animation: mm-fade-out 0.2s ease-in;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
.modal-enter {
|
| 19 |
+
opacity: 0;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.modal-enter-active {
|
| 23 |
+
opacity: 1;
|
| 24 |
+
transition: opacity 100ms ease-in;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.modal__overlay {
|
| 28 |
+
position: fixed;
|
| 29 |
+
inset: 0;
|
| 30 |
+
background: rgb(0 0 0 / 60%);
|
| 31 |
+
z-index: 999;
|
| 32 |
+
overflow: auto;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
@keyframes mm-fade-in {
|
| 36 |
+
from {
|
| 37 |
+
opacity: 0;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
to {
|
| 41 |
+
opacity: 1;
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
@keyframes mm-fade-out {
|
| 46 |
+
from {
|
| 47 |
+
opacity: 1;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
to {
|
| 51 |
+
opacity: 0;
|
| 52 |
+
}
|
| 53 |
+
}
|
assets/css/tooltip.css
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tooltip] {
|
| 2 |
+
position: relative;
|
| 3 |
+
display: inline-block;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
[tooltip]::before {
|
| 7 |
+
transition: 0.3s;
|
| 8 |
+
content: '';
|
| 9 |
+
position: absolute;
|
| 10 |
+
top: -6px;
|
| 11 |
+
left: 50%;
|
| 12 |
+
transform: translateX(-50%);
|
| 13 |
+
border-width: 4px 6px 0;
|
| 14 |
+
border-style: solid;
|
| 15 |
+
border-color: rgba(25 30 56) transparent transparent;
|
| 16 |
+
z-index: 99;
|
| 17 |
+
opacity: 0;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
[tooltip]::after {
|
| 21 |
+
transition: 0.3s;
|
| 22 |
+
white-space: nowrap;
|
| 23 |
+
content: attr(tooltip);
|
| 24 |
+
position: absolute;
|
| 25 |
+
left: 50%;
|
| 26 |
+
top: -6px;
|
| 27 |
+
transform: translateX(-50%) translateY(-100%);
|
| 28 |
+
background: rgba(25 30 56);
|
| 29 |
+
text-align: center;
|
| 30 |
+
color: #fff;
|
| 31 |
+
font-size: 0.875rem;
|
| 32 |
+
min-width: 80px;
|
| 33 |
+
max-width: 420px;
|
| 34 |
+
border-radius: 3px;
|
| 35 |
+
pointer-events: none;
|
| 36 |
+
padding: 4px 8px;
|
| 37 |
+
z-index: 99;
|
| 38 |
+
opacity: 0;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
[tooltip]:hover::after,
|
| 42 |
+
[tooltip]:hover::before {
|
| 43 |
+
opacity: 1;
|
| 44 |
+
}
|
assets/data/countries_meta.json
ADDED
|
@@ -0,0 +1,1006 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
],
|
| 18 |
+
"AF": [
|
| 19 |
+
"AFG",
|
| 20 |
+
"🇦🇫"
|
| 21 |
+
],
|
| 22 |
+
"AO": [
|
| 23 |
+
"AGO",
|
| 24 |
+
"🇦🇴"
|
| 25 |
+
],
|
| 26 |
+
"BT": [
|
| 27 |
+
"BTN",
|
| 28 |
+
"🇧🇹"
|
| 29 |
+
],
|
| 30 |
+
"HK": [
|
| 31 |
+
"HKG",
|
| 32 |
+
"🇭🇰"
|
| 33 |
+
],
|
| 34 |
+
"CU": [
|
| 35 |
+
"CUB",
|
| 36 |
+
"🇨🇺"
|
| 37 |
+
],
|
| 38 |
+
"HU": [
|
| 39 |
+
"HUN",
|
| 40 |
+
"🇭🇺"
|
| 41 |
+
],
|
| 42 |
+
"AZ": [
|
| 43 |
+
"AZE",
|
| 44 |
+
"🇦🇿"
|
| 45 |
+
],
|
| 46 |
+
"SS": [
|
| 47 |
+
"SSD",
|
| 48 |
+
"🇸🇸"
|
| 49 |
+
],
|
| 50 |
+
"BY": [
|
| 51 |
+
"BLR",
|
| 52 |
+
"🇧🇾"
|
| 53 |
+
],
|
| 54 |
+
"MA": [
|
| 55 |
+
"MAR",
|
| 56 |
+
"🇲🇦"
|
| 57 |
+
],
|
| 58 |
+
"MZ": [
|
| 59 |
+
"MOZ",
|
| 60 |
+
"🇲🇿"
|
| 61 |
+
],
|
| 62 |
+
"TR": [
|
| 63 |
+
"TUR",
|
| 64 |
+
"🇹🇷"
|
| 65 |
+
],
|
| 66 |
+
"PL": [
|
| 67 |
+
"POL",
|
| 68 |
+
"🇵🇱"
|
| 69 |
+
],
|
| 70 |
+
"US": [
|
| 71 |
+
"USA",
|
| 72 |
+
"🇺🇸"
|
| 73 |
+
],
|
| 74 |
+
"SR": [
|
| 75 |
+
"SUR",
|
| 76 |
+
"🇸🇷"
|
| 77 |
+
],
|
| 78 |
+
"LR": [
|
| 79 |
+
"LBR",
|
| 80 |
+
"🇱🇷"
|
| 81 |
+
],
|
| 82 |
+
"OM": [
|
| 83 |
+
"OMN",
|
| 84 |
+
"🇴🇲"
|
| 85 |
+
],
|
| 86 |
+
"MH": [
|
| 87 |
+
"MHL",
|
| 88 |
+
"🇲🇭"
|
| 89 |
+
],
|
| 90 |
+
"TG": [
|
| 91 |
+
"TGO",
|
| 92 |
+
"🇹🇬"
|
| 93 |
+
],
|
| 94 |
+
"CW": [
|
| 95 |
+
"CUW",
|
| 96 |
+
"🇨🇼"
|
| 97 |
+
],
|
| 98 |
+
"AT": [
|
| 99 |
+
"AUT",
|
| 100 |
+
"🇦🇹"
|
| 101 |
+
],
|
| 102 |
+
"CO": [
|
| 103 |
+
"COL",
|
| 104 |
+
"🇨🇴"
|
| 105 |
+
],
|
| 106 |
+
"SV": [
|
| 107 |
+
"SLV",
|
| 108 |
+
"🇸🇻"
|
| 109 |
+
],
|
| 110 |
+
"RE": [
|
| 111 |
+
"REU",
|
| 112 |
+
"🇷🇪"
|
| 113 |
+
],
|
| 114 |
+
"LI": [
|
| 115 |
+
"LIE",
|
| 116 |
+
"🇱🇮"
|
| 117 |
+
],
|
| 118 |
+
"PR": [
|
| 119 |
+
"PRI",
|
| 120 |
+
"🇵🇷"
|
| 121 |
+
],
|
| 122 |
+
"GI": [
|
| 123 |
+
"GIB",
|
| 124 |
+
"🇬🇮"
|
| 125 |
+
],
|
| 126 |
+
"CV": [
|
| 127 |
+
"CPV",
|
| 128 |
+
"🇨🇻"
|
| 129 |
+
],
|
| 130 |
+
"KG": [
|
| 131 |
+
"KGZ",
|
| 132 |
+
"🇰🇬"
|
| 133 |
+
],
|
| 134 |
+
"SK": [
|
| 135 |
+
"SVK",
|
| 136 |
+
"🇸🇰"
|
| 137 |
+
],
|
| 138 |
+
"LT": [
|
| 139 |
+
"LTU",
|
| 140 |
+
"🇱🇹"
|
| 141 |
+
],
|
| 142 |
+
"AL": [
|
| 143 |
+
"ALB",
|
| 144 |
+
"🇦🇱"
|
| 145 |
+
],
|
| 146 |
+
"BL": [
|
| 147 |
+
"BLM",
|
| 148 |
+
"🇧🇱"
|
| 149 |
+
],
|
| 150 |
+
"FK": [
|
| 151 |
+
"FLK",
|
| 152 |
+
"🇫🇰"
|
| 153 |
+
],
|
| 154 |
+
"TV": [
|
| 155 |
+
"TUV",
|
| 156 |
+
"🇹🇻"
|
| 157 |
+
],
|
| 158 |
+
"SJ": [
|
| 159 |
+
"SJM",
|
| 160 |
+
"🇸🇯"
|
| 161 |
+
],
|
| 162 |
+
"CX": [
|
| 163 |
+
"CXR",
|
| 164 |
+
"🇨🇽"
|
| 165 |
+
],
|
| 166 |
+
"VG": [
|
| 167 |
+
"VGB",
|
| 168 |
+
"🇻🇬"
|
| 169 |
+
],
|
| 170 |
+
"VI": [
|
| 171 |
+
"VIR",
|
| 172 |
+
"🇻🇮"
|
| 173 |
+
],
|
| 174 |
+
"TT": [
|
| 175 |
+
"TTO",
|
| 176 |
+
"🇹🇹"
|
| 177 |
+
],
|
| 178 |
+
"AI": [
|
| 179 |
+
"AIA",
|
| 180 |
+
"🇦🇮"
|
| 181 |
+
],
|
| 182 |
+
"GE": [
|
| 183 |
+
"GEO",
|
| 184 |
+
"🇬🇪"
|
| 185 |
+
],
|
| 186 |
+
"GB": [
|
| 187 |
+
"GBR",
|
| 188 |
+
"🇬🇧"
|
| 189 |
+
],
|
| 190 |
+
"TW": [
|
| 191 |
+
"TWN",
|
| 192 |
+
"🇹🇼"
|
| 193 |
+
],
|
| 194 |
+
"BV": [
|
| 195 |
+
"BVT",
|
| 196 |
+
"🇧🇻"
|
| 197 |
+
],
|
| 198 |
+
"AU": [
|
| 199 |
+
"AUS",
|
| 200 |
+
"🇦🇺"
|
| 201 |
+
],
|
| 202 |
+
"CD": [
|
| 203 |
+
"COD",
|
| 204 |
+
"🇨🇩"
|
| 205 |
+
],
|
| 206 |
+
"IL": [
|
| 207 |
+
"ISR",
|
| 208 |
+
"🇮🇱"
|
| 209 |
+
],
|
| 210 |
+
"FJ": [
|
| 211 |
+
"FJI",
|
| 212 |
+
"🇫🇯"
|
| 213 |
+
],
|
| 214 |
+
"HM": [
|
| 215 |
+
"HMD",
|
| 216 |
+
"🇭🇲"
|
| 217 |
+
],
|
| 218 |
+
"MO": [
|
| 219 |
+
"MAC",
|
| 220 |
+
"🇲🇴"
|
| 221 |
+
],
|
| 222 |
+
"LU": [
|
| 223 |
+
"LUX",
|
| 224 |
+
"🇱🇺"
|
| 225 |
+
],
|
| 226 |
+
"TH": [
|
| 227 |
+
"THA",
|
| 228 |
+
"🇹🇭"
|
| 229 |
+
],
|
| 230 |
+
"TZ": [
|
| 231 |
+
"TZA",
|
| 232 |
+
"🇹🇿"
|
| 233 |
+
],
|
| 234 |
+
"MC": [
|
| 235 |
+
"MCO",
|
| 236 |
+
"🇲🇨"
|
| 237 |
+
],
|
| 238 |
+
"AD": [
|
| 239 |
+
"AND",
|
| 240 |
+
"🇦🇩"
|
| 241 |
+
],
|
| 242 |
+
"IQ": [
|
| 243 |
+
"IRQ",
|
| 244 |
+
"🇮🇶"
|
| 245 |
+
],
|
| 246 |
+
"NI": [
|
| 247 |
+
"NIC",
|
| 248 |
+
"🇳🇮"
|
| 249 |
+
],
|
| 250 |
+
"KW": [
|
| 251 |
+
"KWT",
|
| 252 |
+
"🇰🇼"
|
| 253 |
+
],
|
| 254 |
+
"MW": [
|
| 255 |
+
"MWI",
|
| 256 |
+
"🇲🇼"
|
| 257 |
+
],
|
| 258 |
+
"GH": [
|
| 259 |
+
"GHA",
|
| 260 |
+
"🇬🇭"
|
| 261 |
+
],
|
| 262 |
+
"DM": [
|
| 263 |
+
"DMA",
|
| 264 |
+
"🇩🇲"
|
| 265 |
+
],
|
| 266 |
+
"EE": [
|
| 267 |
+
"EST",
|
| 268 |
+
"🇪🇪"
|
| 269 |
+
],
|
| 270 |
+
"IS": [
|
| 271 |
+
"ISL",
|
| 272 |
+
"🇮🇸"
|
| 273 |
+
],
|
| 274 |
+
"BM": [
|
| 275 |
+
"BMU",
|
| 276 |
+
"🇧🇲"
|
| 277 |
+
],
|
| 278 |
+
"EC": [
|
| 279 |
+
"ECU",
|
| 280 |
+
"🇪🇨"
|
| 281 |
+
],
|
| 282 |
+
"KM": [
|
| 283 |
+
"COM",
|
| 284 |
+
"🇰🇲"
|
| 285 |
+
],
|
| 286 |
+
"SB": [
|
| 287 |
+
"SLB",
|
| 288 |
+
"🇸🇧"
|
| 289 |
+
],
|
| 290 |
+
"AE": [
|
| 291 |
+
"ARE",
|
| 292 |
+
"🇦🇪"
|
| 293 |
+
],
|
| 294 |
+
"CM": [
|
| 295 |
+
"CMR",
|
| 296 |
+
"🇨🇲"
|
| 297 |
+
],
|
| 298 |
+
"EH": [
|
| 299 |
+
"ESH",
|
| 300 |
+
"🇪🇭"
|
| 301 |
+
],
|
| 302 |
+
"CC": [
|
| 303 |
+
"CCK",
|
| 304 |
+
"🇨🇨"
|
| 305 |
+
],
|
| 306 |
+
"AS": [
|
| 307 |
+
"ASM",
|
| 308 |
+
"🇦🇸"
|
| 309 |
+
],
|
| 310 |
+
"KH": [
|
| 311 |
+
"KHM",
|
| 312 |
+
"🇰🇭"
|
| 313 |
+
],
|
| 314 |
+
"MD": [
|
| 315 |
+
"MDA",
|
| 316 |
+
"🇲🇩"
|
| 317 |
+
],
|
| 318 |
+
"NA": [
|
| 319 |
+
"NAM",
|
| 320 |
+
"🇳🇦"
|
| 321 |
+
],
|
| 322 |
+
"SA": [
|
| 323 |
+
"SAU",
|
| 324 |
+
"🇸🇦"
|
| 325 |
+
],
|
| 326 |
+
"HN": [
|
| 327 |
+
"HND",
|
| 328 |
+
"🇭🇳"
|
| 329 |
+
],
|
| 330 |
+
"MK": [
|
| 331 |
+
"MKD",
|
| 332 |
+
"🇲🇰"
|
| 333 |
+
],
|
| 334 |
+
"LC": [
|
| 335 |
+
"LCA",
|
| 336 |
+
"🇱🇨"
|
| 337 |
+
],
|
| 338 |
+
"PA": [
|
| 339 |
+
"PAN",
|
| 340 |
+
"🇵🇦"
|
| 341 |
+
],
|
| 342 |
+
"VC": [
|
| 343 |
+
"VCT",
|
| 344 |
+
"🇻🇨"
|
| 345 |
+
],
|
| 346 |
+
"TM": [
|
| 347 |
+
"TKM",
|
| 348 |
+
"🇹🇲"
|
| 349 |
+
],
|
| 350 |
+
"SI": [
|
| 351 |
+
"SVN",
|
| 352 |
+
"🇸🇮"
|
| 353 |
+
],
|
| 354 |
+
"GQ": [
|
| 355 |
+
"GNQ",
|
| 356 |
+
"🇬🇶"
|
| 357 |
+
],
|
| 358 |
+
"PH": [
|
| 359 |
+
"PHL",
|
| 360 |
+
"🇵🇭"
|
| 361 |
+
],
|
| 362 |
+
"CZ": [
|
| 363 |
+
"CZE",
|
| 364 |
+
"🇨🇿"
|
| 365 |
+
],
|
| 366 |
+
"BO": [
|
| 367 |
+
"BOL",
|
| 368 |
+
"🇧🇴"
|
| 369 |
+
],
|
| 370 |
+
"SY": [
|
| 371 |
+
"SYR",
|
| 372 |
+
"🇸🇾"
|
| 373 |
+
],
|
| 374 |
+
"NO": [
|
| 375 |
+
"NOR",
|
| 376 |
+
"🇳🇴"
|
| 377 |
+
],
|
| 378 |
+
"IM": [
|
| 379 |
+
"IMN",
|
| 380 |
+
"🇮🇲"
|
| 381 |
+
],
|
| 382 |
+
"SX": [
|
| 383 |
+
"SXM",
|
| 384 |
+
"🇸🇽"
|
| 385 |
+
],
|
| 386 |
+
"GG": [
|
| 387 |
+
"GGY",
|
| 388 |
+
"🇬🇬"
|
| 389 |
+
],
|
| 390 |
+
"GW": [
|
| 391 |
+
"GNB",
|
| 392 |
+
"🇬🇼"
|
| 393 |
+
],
|
| 394 |
+
"SH": [
|
| 395 |
+
"SHN",
|
| 396 |
+
"🇸🇭"
|
| 397 |
+
],
|
| 398 |
+
"NC": [
|
| 399 |
+
"NCL",
|
| 400 |
+
"🇳🇨"
|
| 401 |
+
],
|
| 402 |
+
"BE": [
|
| 403 |
+
"BEL",
|
| 404 |
+
"🇧🇪"
|
| 405 |
+
],
|
| 406 |
+
"JP": [
|
| 407 |
+
"JPN",
|
| 408 |
+
"🇯🇵"
|
| 409 |
+
],
|
| 410 |
+
"LV": [
|
| 411 |
+
"LVA",
|
| 412 |
+
"🇱🇻"
|
| 413 |
+
],
|
| 414 |
+
"AM": [
|
| 415 |
+
"ARM",
|
| 416 |
+
"🇦🇲"
|
| 417 |
+
],
|
| 418 |
+
"SD": [
|
| 419 |
+
"SDN",
|
| 420 |
+
"🇸🇩"
|
| 421 |
+
],
|
| 422 |
+
"GT": [
|
| 423 |
+
"GTM",
|
| 424 |
+
"🇬🇹"
|
| 425 |
+
],
|
| 426 |
+
"PY": [
|
| 427 |
+
"PRY",
|
| 428 |
+
"🇵🇾"
|
| 429 |
+
],
|
| 430 |
+
"MN": [
|
| 431 |
+
"MNG",
|
| 432 |
+
"🇲🇳"
|
| 433 |
+
],
|
| 434 |
+
"TK": [
|
| 435 |
+
"TKL",
|
| 436 |
+
"🇹🇰"
|
| 437 |
+
],
|
| 438 |
+
"DZ": [
|
| 439 |
+
"DZA",
|
| 440 |
+
"🇩🇿"
|
| 441 |
+
],
|
| 442 |
+
"KZ": [
|
| 443 |
+
"KAZ",
|
| 444 |
+
"🇰🇿"
|
| 445 |
+
],
|
| 446 |
+
"LY": [
|
| 447 |
+
"LBY",
|
| 448 |
+
"🇱🇾"
|
| 449 |
+
],
|
| 450 |
+
"AW": [
|
| 451 |
+
"ABW",
|
| 452 |
+
"🇦🇼"
|
| 453 |
+
],
|
| 454 |
+
"UY": [
|
| 455 |
+
"URY",
|
| 456 |
+
"🇺🇾"
|
| 457 |
+
],
|
| 458 |
+
"GL": [
|
| 459 |
+
"GRL",
|
| 460 |
+
"🇬🇱"
|
| 461 |
+
],
|
| 462 |
+
"SN": [
|
| 463 |
+
"SEN",
|
| 464 |
+
"🇸🇳"
|
| 465 |
+
],
|
| 466 |
+
"UM": [
|
| 467 |
+
"UMI",
|
| 468 |
+
"🇺🇲"
|
| 469 |
+
],
|
| 470 |
+
"JO": [
|
| 471 |
+
"JOR",
|
| 472 |
+
"🇯🇴"
|
| 473 |
+
],
|
| 474 |
+
"MT": [
|
| 475 |
+
"MLT",
|
| 476 |
+
"🇲🇹"
|
| 477 |
+
],
|
| 478 |
+
"BS": [
|
| 479 |
+
"BHS",
|
| 480 |
+
"🇧🇸"
|
| 481 |
+
],
|
| 482 |
+
"BI": [
|
| 483 |
+
"BDI",
|
| 484 |
+
"🇧🇮"
|
| 485 |
+
],
|
| 486 |
+
"BA": [
|
| 487 |
+
"BIH",
|
| 488 |
+
"🇧🇦"
|
| 489 |
+
],
|
| 490 |
+
"MQ": [
|
| 491 |
+
"MTQ",
|
| 492 |
+
"🇲🇶"
|
| 493 |
+
],
|
| 494 |
+
"MU": [
|
| 495 |
+
"MUS",
|
| 496 |
+
"🇲🇺"
|
| 497 |
+
],
|
| 498 |
+
"MS": [
|
| 499 |
+
"MSR",
|
| 500 |
+
"🇲🇸"
|
| 501 |
+
],
|
| 502 |
+
"BW": [
|
| 503 |
+
"BWA",
|
| 504 |
+
"🇧🇼"
|
| 505 |
+
],
|
| 506 |
+
"YT": [
|
| 507 |
+
"MYT",
|
| 508 |
+
"🇾🇹"
|
| 509 |
+
],
|
| 510 |
+
"PN": [
|
| 511 |
+
"PCN",
|
| 512 |
+
"🇵🇳"
|
| 513 |
+
],
|
| 514 |
+
"MP": [
|
| 515 |
+
"MNP",
|
| 516 |
+
"🇲🇵"
|
| 517 |
+
],
|
| 518 |
+
"ML": [
|
| 519 |
+
"MLI",
|
| 520 |
+
"🇲🇱"
|
| 521 |
+
],
|
| 522 |
+
"BH": [
|
| 523 |
+
"BHR",
|
| 524 |
+
"🇧🇭"
|
| 525 |
+
],
|
| 526 |
+
"LB": [
|
| 527 |
+
"LBN",
|
| 528 |
+
"🇱🇧"
|
| 529 |
+
],
|
| 530 |
+
"AR": [
|
| 531 |
+
"ARG",
|
| 532 |
+
"🇦🇷"
|
| 533 |
+
],
|
| 534 |
+
"PG": [
|
| 535 |
+
"PNG",
|
| 536 |
+
"🇵🇬"
|
| 537 |
+
],
|
| 538 |
+
"GR": [
|
| 539 |
+
"GRC",
|
| 540 |
+
"🇬🇷"
|
| 541 |
+
],
|
| 542 |
+
"HT": [
|
| 543 |
+
"HTI",
|
| 544 |
+
"🇭🇹"
|
| 545 |
+
],
|
| 546 |
+
"WS": [
|
| 547 |
+
"WSM",
|
| 548 |
+
"🇼🇸"
|
| 549 |
+
],
|
| 550 |
+
"SG": [
|
| 551 |
+
"SGP",
|
| 552 |
+
"🇸🇬"
|
| 553 |
+
],
|
| 554 |
+
"GP": [
|
| 555 |
+
"GLP",
|
| 556 |
+
"🇬🇵"
|
| 557 |
+
],
|
| 558 |
+
"BF": [
|
| 559 |
+
"BFA",
|
| 560 |
+
"🇧🇫"
|
| 561 |
+
],
|
| 562 |
+
"ME": [
|
| 563 |
+
"MNE",
|
| 564 |
+
"🇲🇪"
|
| 565 |
+
],
|
| 566 |
+
"AQ": [
|
| 567 |
+
"ATA",
|
| 568 |
+
"🇦🇶"
|
| 569 |
+
],
|
| 570 |
+
"PK": [
|
| 571 |
+
"PAK",
|
| 572 |
+
"🇵🇰"
|
| 573 |
+
],
|
| 574 |
+
"FM": [
|
| 575 |
+
"FSM",
|
| 576 |
+
"🇫🇲"
|
| 577 |
+
],
|
| 578 |
+
"MV": [
|
| 579 |
+
"MDV",
|
| 580 |
+
"🇲🇻"
|
| 581 |
+
],
|
| 582 |
+
"GS": [
|
| 583 |
+
"SGS",
|
| 584 |
+
"🇬🇸"
|
| 585 |
+
],
|
| 586 |
+
"BN": [
|
| 587 |
+
"BRN",
|
| 588 |
+
"🇧🇳"
|
| 589 |
+
],
|
| 590 |
+
"CK": [
|
| 591 |
+
"COK",
|
| 592 |
+
"🇨🇰"
|
| 593 |
+
],
|
| 594 |
+
"IO": [
|
| 595 |
+
"IOT",
|
| 596 |
+
"🇮🇴"
|
| 597 |
+
],
|
| 598 |
+
"SE": [
|
| 599 |
+
"SWE",
|
| 600 |
+
"🇸🇪"
|
| 601 |
+
],
|
| 602 |
+
"SC": [
|
| 603 |
+
"SYC",
|
| 604 |
+
"🇸🇨"
|
| 605 |
+
],
|
| 606 |
+
"ZW": [
|
| 607 |
+
"ZWE",
|
| 608 |
+
"🇿🇼"
|
| 609 |
+
],
|
| 610 |
+
"SL": [
|
| 611 |
+
"SLE",
|
| 612 |
+
"🇸🇱"
|
| 613 |
+
],
|
| 614 |
+
"AG": [
|
| 615 |
+
"ATG",
|
| 616 |
+
"🇦🇬"
|
| 617 |
+
],
|
| 618 |
+
"PF": [
|
| 619 |
+
"PYF",
|
| 620 |
+
"🇵🇫"
|
| 621 |
+
],
|
| 622 |
+
"CF": [
|
| 623 |
+
"CAF",
|
| 624 |
+
"🇨🇫"
|
| 625 |
+
],
|
| 626 |
+
"BD": [
|
| 627 |
+
"BGD",
|
| 628 |
+
"🇧🇩"
|
| 629 |
+
],
|
| 630 |
+
"AX": [
|
| 631 |
+
"ALA",
|
| 632 |
+
"🇦🇽"
|
| 633 |
+
],
|
| 634 |
+
"SZ": [
|
| 635 |
+
"SWZ",
|
| 636 |
+
"🇸🇿"
|
| 637 |
+
],
|
| 638 |
+
"HR": [
|
| 639 |
+
"HRV",
|
| 640 |
+
"🇭🇷"
|
| 641 |
+
],
|
| 642 |
+
"RS": [
|
| 643 |
+
"SRB",
|
| 644 |
+
"🇷🇸"
|
| 645 |
+
],
|
| 646 |
+
"NF": [
|
| 647 |
+
"NFK",
|
| 648 |
+
"🇳🇫"
|
| 649 |
+
],
|
| 650 |
+
"IE": [
|
| 651 |
+
"IRL",
|
| 652 |
+
"🇮🇪"
|
| 653 |
+
],
|
| 654 |
+
"NR": [
|
| 655 |
+
"NRU",
|
| 656 |
+
"🇳🇷"
|
| 657 |
+
],
|
| 658 |
+
"ZA": [
|
| 659 |
+
"ZAF",
|
| 660 |
+
"🇿🇦"
|
| 661 |
+
],
|
| 662 |
+
"CA": [
|
| 663 |
+
"CAN",
|
| 664 |
+
"🇨🇦"
|
| 665 |
+
],
|
| 666 |
+
"KR": [
|
| 667 |
+
"KOR",
|
| 668 |
+
"🇰🇷"
|
| 669 |
+
],
|
| 670 |
+
"A1": [
|
| 671 |
+
null,
|
| 672 |
+
"🏳️"
|
| 673 |
+
],
|
| 674 |
+
"VA": [
|
| 675 |
+
"VAT",
|
| 676 |
+
"🇻🇦"
|
| 677 |
+
],
|
| 678 |
+
"NU": [
|
| 679 |
+
"NIU",
|
| 680 |
+
"🇳🇺"
|
| 681 |
+
],
|
| 682 |
+
"JE": [
|
| 683 |
+
"JEY",
|
| 684 |
+
"🇯🇪"
|
| 685 |
+
],
|
| 686 |
+
"TD": [
|
| 687 |
+
"TCD",
|
| 688 |
+
"🇹🇩"
|
| 689 |
+
],
|
| 690 |
+
"IR": [
|
| 691 |
+
"IRN",
|
| 692 |
+
"🇮🇷"
|
| 693 |
+
],
|
| 694 |
+
"NL": [
|
| 695 |
+
"NLD",
|
| 696 |
+
"🇳🇱"
|
| 697 |
+
],
|
| 698 |
+
"BB": [
|
| 699 |
+
"BRB",
|
| 700 |
+
"🇧🇧"
|
| 701 |
+
],
|
| 702 |
+
"FI": [
|
| 703 |
+
"FIN",
|
| 704 |
+
"🇫🇮"
|
| 705 |
+
],
|
| 706 |
+
"UA": [
|
| 707 |
+
"UKR",
|
| 708 |
+
"🇺🇦"
|
| 709 |
+
],
|
| 710 |
+
"ID": [
|
| 711 |
+
"IDN",
|
| 712 |
+
"🇮🇩"
|
| 713 |
+
],
|
| 714 |
+
"ST": [
|
| 715 |
+
"STP",
|
| 716 |
+
"🇸🇹"
|
| 717 |
+
],
|
| 718 |
+
"VU": [
|
| 719 |
+
"VUT",
|
| 720 |
+
"🇻🇺"
|
| 721 |
+
],
|
| 722 |
+
"RU": [
|
| 723 |
+
"RUS",
|
| 724 |
+
"🇷🇺"
|
| 725 |
+
],
|
| 726 |
+
"NE": [
|
| 727 |
+
"NER",
|
| 728 |
+
"🇳🇪"
|
| 729 |
+
],
|
| 730 |
+
"TO": [
|
| 731 |
+
"TON",
|
| 732 |
+
"🇹🇴"
|
| 733 |
+
],
|
| 734 |
+
"UZ": [
|
| 735 |
+
"UZB",
|
| 736 |
+
"🇺🇿"
|
| 737 |
+
],
|
| 738 |
+
"GN": [
|
| 739 |
+
"GIN",
|
| 740 |
+
"🇬🇳"
|
| 741 |
+
],
|
| 742 |
+
"JM": [
|
| 743 |
+
"JAM",
|
| 744 |
+
"🇯🇲"
|
| 745 |
+
],
|
| 746 |
+
"FR": [
|
| 747 |
+
"FRA",
|
| 748 |
+
"🇫🇷"
|
| 749 |
+
],
|
| 750 |
+
"TL": [
|
| 751 |
+
"TLS",
|
| 752 |
+
"🇹🇱"
|
| 753 |
+
],
|
| 754 |
+
"ET": [
|
| 755 |
+
"ETH",
|
| 756 |
+
"🇪🇹"
|
| 757 |
+
],
|
| 758 |
+
"KI": [
|
| 759 |
+
"KIR",
|
| 760 |
+
"🇰🇮"
|
| 761 |
+
],
|
| 762 |
+
"CG": [
|
| 763 |
+
"COG",
|
| 764 |
+
"🇨🇬"
|
| 765 |
+
],
|
| 766 |
+
"DE": [
|
| 767 |
+
"DEU",
|
| 768 |
+
"🇩🇪"
|
| 769 |
+
],
|
| 770 |
+
"RW": [
|
| 771 |
+
"RWA",
|
| 772 |
+
"🇷🇼"
|
| 773 |
+
],
|
| 774 |
+
"DO": [
|
| 775 |
+
"DOM",
|
| 776 |
+
"🇩🇴"
|
| 777 |
+
],
|
| 778 |
+
"VE": [
|
| 779 |
+
"VEN",
|
| 780 |
+
"🇻🇪"
|
| 781 |
+
],
|
| 782 |
+
"PW": [
|
| 783 |
+
"PLW",
|
| 784 |
+
"🇵🇼"
|
| 785 |
+
],
|
| 786 |
+
"TC": [
|
| 787 |
+
"TCA",
|
| 788 |
+
"🇹🇨"
|
| 789 |
+
],
|
| 790 |
+
"ZM": [
|
| 791 |
+
"ZMB",
|
| 792 |
+
"🇿🇲"
|
| 793 |
+
],
|
| 794 |
+
"NG": [
|
| 795 |
+
"NGA",
|
| 796 |
+
"🇳🇬"
|
| 797 |
+
],
|
| 798 |
+
"WF": [
|
| 799 |
+
"WLF",
|
| 800 |
+
"🇼🇫"
|
| 801 |
+
],
|
| 802 |
+
"GF": [
|
| 803 |
+
"GUF",
|
| 804 |
+
"🇬🇫"
|
| 805 |
+
],
|
| 806 |
+
"KN": [
|
| 807 |
+
"KNA",
|
| 808 |
+
"🇰🇳"
|
| 809 |
+
],
|
| 810 |
+
"ES": [
|
| 811 |
+
"ESP",
|
| 812 |
+
"🇪🇸"
|
| 813 |
+
],
|
| 814 |
+
"GM": [
|
| 815 |
+
"GMB",
|
| 816 |
+
"🇬🇲"
|
| 817 |
+
],
|
| 818 |
+
"KP": [
|
| 819 |
+
"PRK",
|
| 820 |
+
"🇰🇵"
|
| 821 |
+
],
|
| 822 |
+
"GY": [
|
| 823 |
+
"GUY",
|
| 824 |
+
"🇬🇾"
|
| 825 |
+
],
|
| 826 |
+
"MX": [
|
| 827 |
+
"MEX",
|
| 828 |
+
"🇲🇽"
|
| 829 |
+
],
|
| 830 |
+
"IN": [
|
| 831 |
+
"IND",
|
| 832 |
+
"🇮🇳"
|
| 833 |
+
],
|
| 834 |
+
"SM": [
|
| 835 |
+
"SMR",
|
| 836 |
+
"🇸🇲"
|
| 837 |
+
],
|
| 838 |
+
"BG": [
|
| 839 |
+
"BGR",
|
| 840 |
+
"🇧🇬"
|
| 841 |
+
],
|
| 842 |
+
"MF": [
|
| 843 |
+
"MAF",
|
| 844 |
+
"🇲🇫"
|
| 845 |
+
],
|
| 846 |
+
"CL": [
|
| 847 |
+
"CHL",
|
| 848 |
+
"🇨🇱"
|
| 849 |
+
],
|
| 850 |
+
"VN": [
|
| 851 |
+
"VNM",
|
| 852 |
+
"🇻🇳"
|
| 853 |
+
],
|
| 854 |
+
"NP": [
|
| 855 |
+
"NPL",
|
| 856 |
+
"🇳🇵"
|
| 857 |
+
],
|
| 858 |
+
"CR": [
|
| 859 |
+
"CRI",
|
| 860 |
+
"🇨🇷"
|
| 861 |
+
],
|
| 862 |
+
"ER": [
|
| 863 |
+
"ERI",
|
| 864 |
+
"🇪🇷"
|
| 865 |
+
],
|
| 866 |
+
"LK": [
|
| 867 |
+
"LKA",
|
| 868 |
+
"🇱🇰"
|
| 869 |
+
],
|
| 870 |
+
"CI": [
|
| 871 |
+
"CIV",
|
| 872 |
+
"🇨🇮"
|
| 873 |
+
],
|
| 874 |
+
"PT": [
|
| 875 |
+
"PRT",
|
| 876 |
+
"🇵🇹"
|
| 877 |
+
],
|
| 878 |
+
"TJ": [
|
| 879 |
+
"TJK",
|
| 880 |
+
"🇹🇯"
|
| 881 |
+
],
|
| 882 |
+
"MY": [
|
| 883 |
+
"MYS",
|
| 884 |
+
"🇲🇾"
|
| 885 |
+
],
|
| 886 |
+
"PS": [
|
| 887 |
+
"PSE",
|
| 888 |
+
"🇵🇸"
|
| 889 |
+
],
|
| 890 |
+
"PE": [
|
| 891 |
+
"PER",
|
| 892 |
+
"🇵🇪"
|
| 893 |
+
],
|
| 894 |
+
"LS": [
|
| 895 |
+
"LSO",
|
| 896 |
+
"🇱🇸"
|
| 897 |
+
],
|
| 898 |
+
"CY": [
|
| 899 |
+
"CYP",
|
| 900 |
+
"🇨🇾"
|
| 901 |
+
],
|
| 902 |
+
"TN": [
|
| 903 |
+
"TUN",
|
| 904 |
+
"🇹🇳"
|
| 905 |
+
],
|
| 906 |
+
"XK": [
|
| 907 |
+
"XKX",
|
| 908 |
+
"🇽🇰"
|
| 909 |
+
],
|
| 910 |
+
"KY": [
|
| 911 |
+
"CYM",
|
| 912 |
+
"🇰🇾"
|
| 913 |
+
],
|
| 914 |
+
"DK": [
|
| 915 |
+
"DNK",
|
| 916 |
+
"🇩🇰"
|
| 917 |
+
],
|
| 918 |
+
"BZ": [
|
| 919 |
+
"BLZ",
|
| 920 |
+
"🇧🇿"
|
| 921 |
+
],
|
| 922 |
+
"FO": [
|
| 923 |
+
"FRO",
|
| 924 |
+
"🇫🇴"
|
| 925 |
+
],
|
| 926 |
+
"LA": [
|
| 927 |
+
"LAO",
|
| 928 |
+
"🇱🇦"
|
| 929 |
+
],
|
| 930 |
+
"RO": [
|
| 931 |
+
"ROU",
|
| 932 |
+
"🇷🇴"
|
| 933 |
+
],
|
| 934 |
+
"DJ": [
|
| 935 |
+
"DJI",
|
| 936 |
+
"🇩🇯"
|
| 937 |
+
],
|
| 938 |
+
"EG": [
|
| 939 |
+
"EGY",
|
| 940 |
+
"🇪🇬"
|
| 941 |
+
],
|
| 942 |
+
"KE": [
|
| 943 |
+
"KEN",
|
| 944 |
+
"🇰🇪"
|
| 945 |
+
],
|
| 946 |
+
"UG": [
|
| 947 |
+
"UGA",
|
| 948 |
+
"🇺🇬"
|
| 949 |
+
],
|
| 950 |
+
"MM": [
|
| 951 |
+
"MMR",
|
| 952 |
+
"🇲🇲"
|
| 953 |
+
],
|
| 954 |
+
"BQ": [
|
| 955 |
+
"BES",
|
| 956 |
+
"🇧🇶"
|
| 957 |
+
],
|
| 958 |
+
"PM": [
|
| 959 |
+
"SPM",
|
| 960 |
+
"🇵🇲"
|
| 961 |
+
],
|
| 962 |
+
"GD": [
|
| 963 |
+
"GRD",
|
| 964 |
+
"🇬🇩"
|
| 965 |
+
],
|
| 966 |
+
"GU": [
|
| 967 |
+
"GUM",
|
| 968 |
+
"🇬🇺"
|
| 969 |
+
],
|
| 970 |
+
"CN": [
|
| 971 |
+
"CHN",
|
| 972 |
+
"🇨🇳"
|
| 973 |
+
],
|
| 974 |
+
"SO": [
|
| 975 |
+
"SOM",
|
| 976 |
+
"🇸🇴"
|
| 977 |
+
],
|
| 978 |
+
"BJ": [
|
| 979 |
+
"BEN",
|
| 980 |
+
"🇧🇯"
|
| 981 |
+
],
|
| 982 |
+
"BR": [
|
| 983 |
+
"BRA",
|
| 984 |
+
"🇧🇷"
|
| 985 |
+
],
|
| 986 |
+
"GA": [
|
| 987 |
+
"GAB",
|
| 988 |
+
"🇬🇦"
|
| 989 |
+
],
|
| 990 |
+
"NZ": [
|
| 991 |
+
"NZL",
|
| 992 |
+
"🇳🇿"
|
| 993 |
+
],
|
| 994 |
+
"MG": [
|
| 995 |
+
"MDG",
|
| 996 |
+
"🇲🇬"
|
| 997 |
+
],
|
| 998 |
+
"IT": [
|
| 999 |
+
"ITA",
|
| 1000 |
+
"🇮🇹"
|
| 1001 |
+
],
|
| 1002 |
+
"TF": [
|
| 1003 |
+
"ATF",
|
| 1004 |
+
"🇹🇫"
|
| 1005 |
+
]
|
| 1006 |
+
}
|
assets/eslint.config.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from 'eslint/config'
|
| 2 |
+
import globals from 'globals'
|
| 3 |
+
import pluginJs from '@eslint/js'
|
| 4 |
+
import { configs as pluginTypescriptEslintConfigs } from 'typescript-eslint'
|
| 5 |
+
import pluginReact from 'eslint-plugin-react'
|
| 6 |
+
import pluginReactHooks from 'eslint-plugin-react-hooks'
|
| 7 |
+
import pluginA11y from 'eslint-plugin-jsx-a11y'
|
| 8 |
+
import pluginImport from 'eslint-plugin-import'
|
| 9 |
+
import pluginJest from 'eslint-plugin-jest'
|
| 10 |
+
import prettierEslintInteroperabilityConfig from 'eslint-config-prettier/flat'
|
| 11 |
+
|
| 12 |
+
export default defineConfig([
|
| 13 |
+
{
|
| 14 |
+
files: ['**/*.{js,ts,jsx,tsx}'],
|
| 15 |
+
languageOptions: { globals: globals.browser }
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
files: ['**/*.{js,ts,jsx,tsx}'],
|
| 19 |
+
plugins: { js: pluginJs },
|
| 20 |
+
extends: ['js/recommended']
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
rules: {
|
| 24 |
+
'no-prototype-builtins': ['off'],
|
| 25 |
+
'no-unused-expressions': ['warn', { allowShortCircuit: true }]
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
|
| 29 |
+
{
|
| 30 |
+
files: ['**/*.test.{js,ts,jsx,tsx}'],
|
| 31 |
+
plugins: { jest: pluginJest },
|
| 32 |
+
languageOptions: {
|
| 33 |
+
globals: pluginJest.environments.globals.globals
|
| 34 |
+
},
|
| 35 |
+
rules: {
|
| 36 |
+
'jest/no-disabled-tests': 'warn',
|
| 37 |
+
'jest/no-focused-tests': 'error',
|
| 38 |
+
'jest/no-identical-title': 'error',
|
| 39 |
+
'jest/prefer-to-have-length': 'warn',
|
| 40 |
+
'jest/valid-expect': 'error'
|
| 41 |
+
}
|
| 42 |
+
},
|
| 43 |
+
|
| 44 |
+
pluginTypescriptEslintConfigs.recommended,
|
| 45 |
+
{
|
| 46 |
+
rules: {
|
| 47 |
+
'@typescript-eslint/no-unused-vars': [
|
| 48 |
+
'error',
|
| 49 |
+
{
|
| 50 |
+
args: 'all',
|
| 51 |
+
argsIgnorePattern: '^_',
|
| 52 |
+
caughtErrors: 'all',
|
| 53 |
+
caughtErrorsIgnorePattern: '^_',
|
| 54 |
+
destructuredArrayIgnorePattern: '^_',
|
| 55 |
+
varsIgnorePattern: '^_',
|
| 56 |
+
ignoreRestSiblings: true
|
| 57 |
+
}
|
| 58 |
+
]
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
|
| 62 |
+
pluginImport.flatConfigs.recommended,
|
| 63 |
+
pluginImport.flatConfigs.typescript,
|
| 64 |
+
{
|
| 65 |
+
settings: {
|
| 66 |
+
'import/resolver': { typescript: true, node: { paths: ['../deps'] } }
|
| 67 |
+
}
|
| 68 |
+
},
|
| 69 |
+
|
| 70 |
+
pluginReact.configs.flat.recommended,
|
| 71 |
+
{
|
| 72 |
+
settings: {
|
| 73 |
+
react: {
|
| 74 |
+
version: 'detect'
|
| 75 |
+
}
|
| 76 |
+
},
|
| 77 |
+
rules: {
|
| 78 |
+
'react/destructuring-assignment': ['off'],
|
| 79 |
+
'react/self-closing-comp': ['off'],
|
| 80 |
+
'react/jsx-props-no-spreading': ['off'],
|
| 81 |
+
'react/jsx-one-expression-per-line': ['off'],
|
| 82 |
+
'react/display-name': ['off'],
|
| 83 |
+
'react/prop-types': ['off'],
|
| 84 |
+
'react/no-unknown-property': ['error', { ignore: ['tooltip'] }],
|
| 85 |
+
'react/no-did-update-set-state': ['off']
|
| 86 |
+
}
|
| 87 |
+
},
|
| 88 |
+
pluginReactHooks.configs['recommended-latest'],
|
| 89 |
+
|
| 90 |
+
pluginA11y.flatConfigs.recommended,
|
| 91 |
+
{
|
| 92 |
+
rules: {
|
| 93 |
+
'jsx-a11y/click-events-have-key-events': ['off'],
|
| 94 |
+
'jsx-a11y/no-static-element-interactions': ['off']
|
| 95 |
+
}
|
| 96 |
+
},
|
| 97 |
+
|
| 98 |
+
prettierEslintInteroperabilityConfig
|
| 99 |
+
])
|
assets/jest.config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"clearMocks": true,
|
| 3 |
+
"coverageDirectory": "coverage",
|
| 4 |
+
"coverageProvider": "v8",
|
| 5 |
+
"testEnvironment": "jsdom",
|
| 6 |
+
"globals": {
|
| 7 |
+
"BUILD_EXTRA": true
|
| 8 |
+
},
|
| 9 |
+
"setupFilesAfterEnv": [
|
| 10 |
+
"<rootDir>/test-utils/extend-expect.ts",
|
| 11 |
+
"<rootDir>/test-utils/jsdom-mocks.ts",
|
| 12 |
+
"<rootDir>/test-utils/reset-state.ts"
|
| 13 |
+
],
|
| 14 |
+
"transform": {
|
| 15 |
+
"^.+.[tj]sx?$": ["ts-jest", {}]
|
| 16 |
+
},
|
| 17 |
+
"moduleNameMapper": {
|
| 18 |
+
"d3": "<rootDir>/node_modules/d3/dist/d3.min.js"
|
| 19 |
+
}
|
| 20 |
+
}
|
assets/js/app.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import './polyfills/closest'
|
| 2 |
+
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
|
| 3 |
+
import Alpine from 'alpinejs'
|
| 4 |
+
import './liveview/live_socket'
|
| 5 |
+
import comboBox from './liveview/combo-box'
|
| 6 |
+
import dropdown from './liveview/dropdown'
|
| 7 |
+
import './liveview/phx_events'
|
| 8 |
+
|
| 9 |
+
Alpine.data('dropdown', dropdown)
|
| 10 |
+
Alpine.data('comboBox', comboBox)
|
| 11 |
+
Alpine.start()
|
| 12 |
+
|
| 13 |
+
if (document.querySelectorAll('[data-modal]').length > 0) {
|
| 14 |
+
window.addEventListener(`phx:close-modal`, (e) => {
|
| 15 |
+
document
|
| 16 |
+
.getElementById(e.detail.id)
|
| 17 |
+
.dispatchEvent(
|
| 18 |
+
new CustomEvent('close-modal', { bubbles: true, detail: e.detail.id })
|
| 19 |
+
)
|
| 20 |
+
})
|
| 21 |
+
window.addEventListener(`phx:open-modal`, (e) => {
|
| 22 |
+
document
|
| 23 |
+
.getElementById(e.detail.id)
|
| 24 |
+
.dispatchEvent(
|
| 25 |
+
new CustomEvent('open-modal', { bubbles: true, detail: e.detail.id })
|
| 26 |
+
)
|
| 27 |
+
})
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
const triggers = document.querySelectorAll('[data-dropdown-trigger]')
|
| 31 |
+
|
| 32 |
+
for (const trigger of triggers) {
|
| 33 |
+
trigger.addEventListener('click', function (e) {
|
| 34 |
+
e.stopPropagation()
|
| 35 |
+
e.currentTarget.nextElementSibling.classList.remove('hidden')
|
| 36 |
+
})
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (triggers.length > 0) {
|
| 40 |
+
document.addEventListener('click', function (e) {
|
| 41 |
+
const dropdown = e.target.closest('[data-dropdown]')
|
| 42 |
+
|
| 43 |
+
if (dropdown && e.target.tagName === 'A') {
|
| 44 |
+
dropdown.classList.add('hidden')
|
| 45 |
+
}
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
document.addEventListener('click', function (e) {
|
| 49 |
+
const clickedInDropdown = e.target.closest('[data-dropdown]')
|
| 50 |
+
|
| 51 |
+
if (!clickedInDropdown) {
|
| 52 |
+
for (const dropdown of document.querySelectorAll('[data-dropdown]')) {
|
| 53 |
+
dropdown.classList.add('hidden')
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
})
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
const changelogNotification = document.getElementById('changelog-notification')
|
| 60 |
+
|
| 61 |
+
if (changelogNotification) {
|
| 62 |
+
showChangelogNotification(changelogNotification)
|
| 63 |
+
|
| 64 |
+
fetch('https://plausible.io/changes.txt', {
|
| 65 |
+
headers: { 'Content-Type': 'text/plain' }
|
| 66 |
+
})
|
| 67 |
+
.then((res) => res.text())
|
| 68 |
+
.then((res) => {
|
| 69 |
+
localStorage.lastChangelogUpdate = new Date(res).getTime()
|
| 70 |
+
showChangelogNotification(changelogNotification)
|
| 71 |
+
})
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function showChangelogNotification(el) {
|
| 75 |
+
const lastUpdated = Number(localStorage.lastChangelogUpdate)
|
| 76 |
+
const lastChecked = Number(localStorage.lastChangelogClick)
|
| 77 |
+
|
| 78 |
+
const hasNewUpdateSinceLastClicked = lastUpdated > lastChecked
|
| 79 |
+
const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72
|
| 80 |
+
if ((!lastChecked || hasNewUpdateSinceLastClicked) && notOlderThanThreeDays) {
|
| 81 |
+
el.innerHTML = `
|
| 82 |
+
<a href="https://plausible.io/changelog" target="_blank">
|
| 83 |
+
<svg class="w-5 h-5 text-gray-600 dark:text-gray-100" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
| 84 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v13m0-13V6a2 2 0 112 2h-2zm0 0V5.5A2.5 2.5 0 109.5 8H12zm-7 4h14M5 12a2 2 0 110-4h14a2 2 0 110 4M5 12v7a2 2 0 002 2h10a2 2 0 002-2v-7"></path>
|
| 85 |
+
</svg>
|
| 86 |
+
<svg class="w-4 h-4 text-pink-500 absolute" style="left: 14px; top: 2px;" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
| 87 |
+
<circle cx="8" cy="8" r="4" fill="currentColor" />
|
| 88 |
+
</svg>
|
| 89 |
+
</a>
|
| 90 |
+
`
|
| 91 |
+
const link = el.getElementsByTagName('a')[0]
|
| 92 |
+
link.addEventListener('click', function () {
|
| 93 |
+
localStorage.lastChangelogClick = Date.now()
|
| 94 |
+
setTimeout(() => {
|
| 95 |
+
link.remove()
|
| 96 |
+
}, 100)
|
| 97 |
+
})
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
const embedButton = document.getElementById('generate-embed')
|
| 102 |
+
|
| 103 |
+
if (embedButton) {
|
| 104 |
+
embedButton.addEventListener('click', function (_e) {
|
| 105 |
+
const baseUrl = document.getElementById('base-url').value
|
| 106 |
+
const embedCode = document.getElementById('embed-code')
|
| 107 |
+
const theme = document.getElementById('theme').value.toLowerCase()
|
| 108 |
+
const background = document.getElementById('background').value
|
| 109 |
+
|
| 110 |
+
try {
|
| 111 |
+
const embedLink = new URL(document.getElementById('embed-link').value)
|
| 112 |
+
embedLink.searchParams.set('embed', 'true')
|
| 113 |
+
embedLink.searchParams.set('theme', theme)
|
| 114 |
+
if (background) {
|
| 115 |
+
embedLink.searchParams.set('background', background)
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
embedCode.value = `<iframe plausible-embed src="${embedLink.toString()}" scrolling="no" frameborder="0" loading="lazy" style="width: 1px; min-width: 100%; height: 1600px; color-scheme: auto;"></iframe>
|
| 119 |
+
<div style="font-size: 14px; padding-bottom: 14px;">Stats powered by <a target="_blank" style="color: #4F46E5; text-decoration: underline;" href="https://plausible.io">Plausible Analytics</a></div>
|
| 120 |
+
<script async src="${baseUrl}/js/embed.host.js"></script>`
|
| 121 |
+
} catch (e) {
|
| 122 |
+
console.error(e)
|
| 123 |
+
embedCode.value =
|
| 124 |
+
'ERROR: Please enter a valid URL in the shared link field'
|
| 125 |
+
}
|
| 126 |
+
})
|
| 127 |
+
}
|
assets/js/dashboard/annotations/annotation-list-items.tsx
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode } from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
import {
|
| 4 |
+
Annotation,
|
| 5 |
+
getAnnotationAuthorship,
|
| 6 |
+
getAttributionDateLabel
|
| 7 |
+
} from './annotations'
|
| 8 |
+
|
| 9 |
+
export const AnnotationsListContainer = ({
|
| 10 |
+
children
|
| 11 |
+
}: {
|
| 12 |
+
children: ReactNode
|
| 13 |
+
}) => (
|
| 14 |
+
<div className="text-sm font-normal text-gray-100 flex flex-col gap-2">
|
| 15 |
+
{children}
|
| 16 |
+
</div>
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
const VerticalBar = () => (
|
| 20 |
+
<div className="rounded-xs w-[3px] bg-green-500 shrink-0" />
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
export const AnnotationItemRow = ({ children }: { children: ReactNode }) => (
|
| 24 |
+
<div className="group flex flex-row gap-x-2">
|
| 25 |
+
<VerticalBar />
|
| 26 |
+
{children}
|
| 27 |
+
</div>
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
export const AnnotationAuthorshipLine = ({
|
| 31 |
+
annotation
|
| 32 |
+
}: {
|
| 33 |
+
annotation: Annotation
|
| 34 |
+
}) => (
|
| 35 |
+
<div className="flex items-baseline text-xs text-gray-300 pr-8">
|
| 36 |
+
<span className="truncate min-w-0">
|
| 37 |
+
{getAnnotationAuthorship(annotation)}
|
| 38 |
+
</span>
|
| 39 |
+
<span className="whitespace-nowrap shrink-0">
|
| 40 |
+
{` • ${getAttributionDateLabel(annotation)}`}
|
| 41 |
+
</span>
|
| 42 |
+
</div>
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
export const AnnotationNote = ({
|
| 46 |
+
note,
|
| 47 |
+
clamp
|
| 48 |
+
}: {
|
| 49 |
+
note: string
|
| 50 |
+
clamp?: boolean
|
| 51 |
+
}) => (
|
| 52 |
+
<div
|
| 53 |
+
className={classNames(
|
| 54 |
+
'text-left whitespace-pre-wrap [overflow-wrap:anywhere] [word-break:normal]',
|
| 55 |
+
{ 'line-clamp-2': clamp }
|
| 56 |
+
)}
|
| 57 |
+
>
|
| 58 |
+
{note}
|
| 59 |
+
</div>
|
| 60 |
+
)
|
assets/js/dashboard/annotations/annotations-modals.tsx
ADDED
|
@@ -0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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode, useState } from 'react'
|
| 2 |
+
import {
|
| 3 |
+
Annotation,
|
| 4 |
+
ANNOTATION_TYPE_LABELS,
|
| 5 |
+
AnnotationGranularity,
|
| 6 |
+
AnnotationPayload,
|
| 7 |
+
AnnotationType,
|
| 8 |
+
canEditAnnotation,
|
| 9 |
+
NOTE_MAX_LENGTH
|
| 10 |
+
} from './annotations'
|
| 11 |
+
import { MutationStatus } from '@tanstack/react-query'
|
| 12 |
+
import { ApiError } from '../api'
|
| 13 |
+
import { ErrorPanel } from '../components/error-panel'
|
| 14 |
+
import {
|
| 15 |
+
ModalLayout,
|
| 16 |
+
ModalFooter,
|
| 17 |
+
SaveButton
|
| 18 |
+
} from '../components/modal-layout'
|
| 19 |
+
import {
|
| 20 |
+
LabeledTextarea,
|
| 21 |
+
TypeSelector,
|
| 22 |
+
getOptionDisabledMessage,
|
| 23 |
+
isOverMaxLength,
|
| 24 |
+
OptionDisabledMessageType
|
| 25 |
+
} from '../components/form-elements'
|
| 26 |
+
import { Button } from '../components/button'
|
| 27 |
+
import { UpgradePill } from '../components/pill'
|
| 28 |
+
import { Role, UserContextValue } from '../user-context'
|
| 29 |
+
import {
|
| 30 |
+
formatDay,
|
| 31 |
+
formatTime,
|
| 32 |
+
is12HourClock,
|
| 33 |
+
parseUTCDate
|
| 34 |
+
} from '../util/date'
|
| 35 |
+
|
| 36 |
+
const formatAnnotationDatetime = (
|
| 37 |
+
datetime: string,
|
| 38 |
+
granularity: AnnotationGranularity
|
| 39 |
+
): string => {
|
| 40 |
+
const date = parseUTCDate(datetime)
|
| 41 |
+
if (granularity === AnnotationGranularity.minute) {
|
| 42 |
+
const time = formatTime(date, {
|
| 43 |
+
use12HourClock: is12HourClock(),
|
| 44 |
+
includeMinutes: true
|
| 45 |
+
})
|
| 46 |
+
return `${formatDay(date)} at ${time}`
|
| 47 |
+
}
|
| 48 |
+
return formatDay(date)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
interface ApiRequestProps {
|
| 52 |
+
status: MutationStatus
|
| 53 |
+
error?: unknown
|
| 54 |
+
reset: () => void
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
interface AnnotationModalProps {
|
| 58 |
+
user: UserContextValue
|
| 59 |
+
siteAnnotationsAvailable: boolean
|
| 60 |
+
onClose: () => void
|
| 61 |
+
notePlaceholder: string
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export const CreateAnnotationModal = ({
|
| 65 |
+
onClose,
|
| 66 |
+
onSave,
|
| 67 |
+
user,
|
| 68 |
+
siteAnnotationsAvailable,
|
| 69 |
+
notePlaceholder,
|
| 70 |
+
initialDatetime,
|
| 71 |
+
initialGranularity,
|
| 72 |
+
initialType,
|
| 73 |
+
error,
|
| 74 |
+
reset,
|
| 75 |
+
status
|
| 76 |
+
}: AnnotationModalProps &
|
| 77 |
+
ApiRequestProps & {
|
| 78 |
+
initialDatetime: AnnotationPayload['datetime']
|
| 79 |
+
initialGranularity: AnnotationPayload['granularity']
|
| 80 |
+
initialType: AnnotationPayload['type']
|
| 81 |
+
} & {
|
| 82 |
+
onSave: (input: AnnotationPayload) => void
|
| 83 |
+
}) => {
|
| 84 |
+
const [note, setNote] = useState('')
|
| 85 |
+
const [type, setType] = useState(initialType)
|
| 86 |
+
const trimmedNote = note.trim()
|
| 87 |
+
const granularity = initialGranularity
|
| 88 |
+
const datetime = initialDatetime
|
| 89 |
+
|
| 90 |
+
const siteOptionDisabledMessage = getAnnotationTypeDisabledMessage({
|
| 91 |
+
siteAnnotationsAvailable,
|
| 92 |
+
user
|
| 93 |
+
})
|
| 94 |
+
|
| 95 |
+
const disabledMessage =
|
| 96 |
+
type === AnnotationType.site ? siteOptionDisabledMessage : null
|
| 97 |
+
|
| 98 |
+
return (
|
| 99 |
+
<ModalLayout
|
| 100 |
+
title={`Add note for ${formatAnnotationDatetime(datetime, granularity)}`}
|
| 101 |
+
onClose={onClose}
|
| 102 |
+
>
|
| 103 |
+
<LabeledTextarea
|
| 104 |
+
label="Note"
|
| 105 |
+
id="note"
|
| 106 |
+
value={note}
|
| 107 |
+
onChange={setNote}
|
| 108 |
+
placeholder={notePlaceholder}
|
| 109 |
+
maxLength={NOTE_MAX_LENGTH}
|
| 110 |
+
/>
|
| 111 |
+
<AnnotationTypeSelector
|
| 112 |
+
value={type}
|
| 113 |
+
onChange={setType}
|
| 114 |
+
siteOptionDisabledMessage={siteOptionDisabledMessage}
|
| 115 |
+
/>
|
| 116 |
+
<ModalFooter>
|
| 117 |
+
<Button theme="secondary" size="sm" onClick={onClose}>
|
| 118 |
+
Cancel
|
| 119 |
+
</Button>
|
| 120 |
+
<SaveButton
|
| 121 |
+
disabled={isSaveButtonDisabled({
|
| 122 |
+
requestStatus: status,
|
| 123 |
+
disabledMessage,
|
| 124 |
+
trimmedNote
|
| 125 |
+
})}
|
| 126 |
+
onSave={() =>
|
| 127 |
+
onSave({
|
| 128 |
+
note: trimmedNote,
|
| 129 |
+
type,
|
| 130 |
+
datetime,
|
| 131 |
+
granularity
|
| 132 |
+
})
|
| 133 |
+
}
|
| 134 |
+
/>
|
| 135 |
+
</ModalFooter>
|
| 136 |
+
{error !== null && (
|
| 137 |
+
<ErrorPanel
|
| 138 |
+
className="mt-4"
|
| 139 |
+
errorMessage={
|
| 140 |
+
error instanceof ApiError
|
| 141 |
+
? error.message
|
| 142 |
+
: 'Something went wrong adding the note'
|
| 143 |
+
}
|
| 144 |
+
onClose={reset}
|
| 145 |
+
/>
|
| 146 |
+
)}
|
| 147 |
+
</ModalLayout>
|
| 148 |
+
)
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
const AnnotationTypeSelector = ({
|
| 152 |
+
value,
|
| 153 |
+
onChange,
|
| 154 |
+
siteOptionDisabledMessage
|
| 155 |
+
}: {
|
| 156 |
+
value: AnnotationType
|
| 157 |
+
onChange: (value: AnnotationType) => void
|
| 158 |
+
siteOptionDisabledMessage: OptionDisabledMessageType | null
|
| 159 |
+
}) => (
|
| 160 |
+
<TypeSelector<AnnotationType>
|
| 161 |
+
idPrefix="annotation-type"
|
| 162 |
+
value={value}
|
| 163 |
+
onChange={onChange}
|
| 164 |
+
options={[
|
| 165 |
+
{
|
| 166 |
+
type: AnnotationType.personal,
|
| 167 |
+
name: ANNOTATION_TYPE_LABELS[AnnotationType.personal],
|
| 168 |
+
description: 'Visible only to you'
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
type: AnnotationType.site,
|
| 172 |
+
name: ANNOTATION_TYPE_LABELS[AnnotationType.site],
|
| 173 |
+
description: 'Visible to others on the site',
|
| 174 |
+
disabled: siteOptionDisabledMessage !== null,
|
| 175 |
+
pill:
|
| 176 |
+
siteOptionDisabledMessage === 'upgrade-subscription-yourself' ||
|
| 177 |
+
siteOptionDisabledMessage === 'upgrade-subscription-reach-out' ? (
|
| 178 |
+
<UpgradePill
|
| 179 |
+
plan="Upgrade needed"
|
| 180 |
+
linked={
|
| 181 |
+
siteOptionDisabledMessage === 'upgrade-subscription-yourself'
|
| 182 |
+
}
|
| 183 |
+
/>
|
| 184 |
+
) : null,
|
| 185 |
+
tooltipContent:
|
| 186 |
+
siteOptionDisabledMessage !== null ? (
|
| 187 |
+
<AnnotationTypeDisabledMessage
|
| 188 |
+
messageType={siteOptionDisabledMessage}
|
| 189 |
+
/>
|
| 190 |
+
) : null
|
| 191 |
+
}
|
| 192 |
+
]}
|
| 193 |
+
/>
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
const AnnotationTypeDisabledMessage = ({
|
| 197 |
+
messageType
|
| 198 |
+
}: {
|
| 199 |
+
messageType: OptionDisabledMessageType
|
| 200 |
+
}): Exclude<ReactNode, undefined> => {
|
| 201 |
+
switch (messageType) {
|
| 202 |
+
case 'no-permissions':
|
| 203 |
+
return "You don't have enough permissions to change note to this type"
|
| 204 |
+
case 'upgrade-subscription-yourself':
|
| 205 |
+
return 'Upgrade your plan to make notes visible to others.'
|
| 206 |
+
case 'upgrade-subscription-reach-out':
|
| 207 |
+
return 'Ask a team owner to upgrade your plan to make notes visible to others.'
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
const getAnnotationTypeDisabledMessage = ({
|
| 212 |
+
siteAnnotationsAvailable,
|
| 213 |
+
user
|
| 214 |
+
}: {
|
| 215 |
+
siteAnnotationsAvailable: boolean
|
| 216 |
+
user: UserContextValue
|
| 217 |
+
}): OptionDisabledMessageType | null =>
|
| 218 |
+
getOptionDisabledMessage({
|
| 219 |
+
optionAvailable: siteAnnotationsAvailable,
|
| 220 |
+
userHasOptionPermissions: canEditAnnotation({
|
| 221 |
+
type: AnnotationType.site,
|
| 222 |
+
user
|
| 223 |
+
}),
|
| 224 |
+
userCanUpgradeSubscription: user.role === Role.owner
|
| 225 |
+
})
|
| 226 |
+
|
| 227 |
+
export const DeleteAnnotationModal = ({
|
| 228 |
+
annotation,
|
| 229 |
+
onClose,
|
| 230 |
+
onSave,
|
| 231 |
+
status,
|
| 232 |
+
error,
|
| 233 |
+
reset
|
| 234 |
+
}: {
|
| 235 |
+
onClose: () => void
|
| 236 |
+
onSave: (input: Pick<Annotation, 'id'>) => void
|
| 237 |
+
annotation: Annotation
|
| 238 |
+
} & ApiRequestProps) => {
|
| 239 |
+
const deleteDisabled = status === 'pending'
|
| 240 |
+
|
| 241 |
+
return (
|
| 242 |
+
<ModalLayout
|
| 243 |
+
title={
|
| 244 |
+
<>
|
| 245 |
+
Delete {ANNOTATION_TYPE_LABELS[annotation.type].toLowerCase()}
|
| 246 |
+
<span className="break-all">{` "${annotation.note}"?`}</span>
|
| 247 |
+
</>
|
| 248 |
+
}
|
| 249 |
+
onClose={onClose}
|
| 250 |
+
>
|
| 251 |
+
<ModalFooter>
|
| 252 |
+
<Button theme="secondary" size="sm" onClick={onClose}>
|
| 253 |
+
Cancel
|
| 254 |
+
</Button>
|
| 255 |
+
<Button
|
| 256 |
+
theme="danger"
|
| 257 |
+
size="sm"
|
| 258 |
+
disabled={deleteDisabled}
|
| 259 |
+
onClick={
|
| 260 |
+
deleteDisabled
|
| 261 |
+
? () => {}
|
| 262 |
+
: () => {
|
| 263 |
+
onSave({ id: annotation.id })
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
>
|
| 267 |
+
Delete
|
| 268 |
+
</Button>
|
| 269 |
+
</ModalFooter>
|
| 270 |
+
{error !== null && (
|
| 271 |
+
<ErrorPanel
|
| 272 |
+
className="mt-4"
|
| 273 |
+
errorMessage={
|
| 274 |
+
error instanceof ApiError
|
| 275 |
+
? error.message
|
| 276 |
+
: 'Something went wrong deleting annotation'
|
| 277 |
+
}
|
| 278 |
+
onClose={reset}
|
| 279 |
+
/>
|
| 280 |
+
)}
|
| 281 |
+
</ModalLayout>
|
| 282 |
+
)
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
export const UpdateAnnotationModal = ({
|
| 286 |
+
onClose,
|
| 287 |
+
onSave,
|
| 288 |
+
onDelete,
|
| 289 |
+
annotation,
|
| 290 |
+
siteAnnotationsAvailable,
|
| 291 |
+
user,
|
| 292 |
+
notePlaceholder,
|
| 293 |
+
status,
|
| 294 |
+
error,
|
| 295 |
+
reset
|
| 296 |
+
}: AnnotationModalProps &
|
| 297 |
+
ApiRequestProps & {
|
| 298 |
+
onSave: (input: Pick<Annotation, 'id' | 'note' | 'type'>) => void
|
| 299 |
+
onDelete: (annotation: Annotation) => void
|
| 300 |
+
annotation: Annotation
|
| 301 |
+
}) => {
|
| 302 |
+
const [note, setNote] = useState(annotation.note)
|
| 303 |
+
const [type, setType] = useState<AnnotationType>(annotation.type)
|
| 304 |
+
const trimmedNote = note.trim()
|
| 305 |
+
|
| 306 |
+
const siteOptionDisabledMessage = getAnnotationTypeDisabledMessage({
|
| 307 |
+
siteAnnotationsAvailable,
|
| 308 |
+
user
|
| 309 |
+
})
|
| 310 |
+
|
| 311 |
+
const disabledMessage =
|
| 312 |
+
type === AnnotationType.site ? siteOptionDisabledMessage : null
|
| 313 |
+
|
| 314 |
+
return (
|
| 315 |
+
<ModalLayout
|
| 316 |
+
title={`Update note for ${formatAnnotationDatetime(annotation.datetime, annotation.granularity)}`}
|
| 317 |
+
onClose={onClose}
|
| 318 |
+
>
|
| 319 |
+
<LabeledTextarea
|
| 320 |
+
label="Note"
|
| 321 |
+
id="note"
|
| 322 |
+
value={note}
|
| 323 |
+
onChange={setNote}
|
| 324 |
+
placeholder={notePlaceholder}
|
| 325 |
+
maxLength={NOTE_MAX_LENGTH}
|
| 326 |
+
/>
|
| 327 |
+
<AnnotationTypeSelector
|
| 328 |
+
value={type}
|
| 329 |
+
onChange={setType}
|
| 330 |
+
siteOptionDisabledMessage={siteOptionDisabledMessage}
|
| 331 |
+
/>
|
| 332 |
+
<ModalFooter>
|
| 333 |
+
<Button
|
| 334 |
+
theme="danger"
|
| 335 |
+
size="sm"
|
| 336 |
+
className="mr-auto"
|
| 337 |
+
onClick={() => onDelete(annotation)}
|
| 338 |
+
>
|
| 339 |
+
Delete note
|
| 340 |
+
</Button>
|
| 341 |
+
<Button theme="secondary" size="sm" onClick={onClose}>
|
| 342 |
+
Cancel
|
| 343 |
+
</Button>
|
| 344 |
+
<SaveButton
|
| 345 |
+
disabled={isSaveButtonDisabled({
|
| 346 |
+
requestStatus: status,
|
| 347 |
+
disabledMessage,
|
| 348 |
+
trimmedNote
|
| 349 |
+
})}
|
| 350 |
+
onSave={() => onSave({ id: annotation.id, note: trimmedNote, type })}
|
| 351 |
+
/>
|
| 352 |
+
</ModalFooter>
|
| 353 |
+
{error !== null && (
|
| 354 |
+
<ErrorPanel
|
| 355 |
+
className="mt-4"
|
| 356 |
+
errorMessage={
|
| 357 |
+
error instanceof ApiError
|
| 358 |
+
? error.message
|
| 359 |
+
: 'Something went wrong updating note'
|
| 360 |
+
}
|
| 361 |
+
onClose={reset}
|
| 362 |
+
/>
|
| 363 |
+
)}
|
| 364 |
+
</ModalLayout>
|
| 365 |
+
)
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
const isSaveButtonDisabled = ({
|
| 369 |
+
requestStatus,
|
| 370 |
+
disabledMessage,
|
| 371 |
+
trimmedNote
|
| 372 |
+
}: {
|
| 373 |
+
requestStatus: MutationStatus
|
| 374 |
+
trimmedNote: string
|
| 375 |
+
disabledMessage: string | null
|
| 376 |
+
}) =>
|
| 377 |
+
requestStatus === 'pending' ||
|
| 378 |
+
isOverMaxLength(trimmedNote, NOTE_MAX_LENGTH) ||
|
| 379 |
+
disabledMessage !== null ||
|
| 380 |
+
!trimmedNote.length
|
assets/js/dashboard/annotations/annotations.test.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
AnnotationGranularity,
|
| 3 |
+
AnnotationType,
|
| 4 |
+
canAddAnnotation,
|
| 5 |
+
canEditAnnotation,
|
| 6 |
+
getAnnotationAuthorship,
|
| 7 |
+
getAnnotationGranularity,
|
| 8 |
+
getAnnotationTimeLabel,
|
| 9 |
+
groupAnnotationsByTimeLabel
|
| 10 |
+
} from './annotations'
|
| 11 |
+
import { Interval } from '../stats/graph/intervals'
|
| 12 |
+
import { Role, UserContextValue } from '../user-context'
|
| 13 |
+
|
| 14 |
+
const loggedInUser = (role: Role, id: number = 42): UserContextValue => ({
|
| 15 |
+
loggedIn: true,
|
| 16 |
+
id,
|
| 17 |
+
role,
|
| 18 |
+
team: { identifier: null, hasConsolidatedView: false }
|
| 19 |
+
})
|
| 20 |
+
|
| 21 |
+
const publicUser: UserContextValue = {
|
| 22 |
+
loggedIn: false,
|
| 23 |
+
id: null,
|
| 24 |
+
role: Role.public,
|
| 25 |
+
team: { identifier: null, hasConsolidatedView: false }
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
describe(`${getAnnotationAuthorship.name}`, () => {
|
| 29 |
+
it('returns the owner name for a site annotation with an owner', () => {
|
| 30 |
+
expect(
|
| 31 |
+
getAnnotationAuthorship({
|
| 32 |
+
type: AnnotationType.site,
|
| 33 |
+
owner_name: 'Alice'
|
| 34 |
+
})
|
| 35 |
+
).toBe('Alice')
|
| 36 |
+
})
|
| 37 |
+
|
| 38 |
+
it('returns "Site note" for a site annotation with a dangling owner', () => {
|
| 39 |
+
expect(
|
| 40 |
+
getAnnotationAuthorship({
|
| 41 |
+
type: AnnotationType.site,
|
| 42 |
+
owner_name: null
|
| 43 |
+
})
|
| 44 |
+
).toBe('Site note')
|
| 45 |
+
})
|
| 46 |
+
|
| 47 |
+
it('returns "Personal note" for a personal annotation regardless of owner (we assume personal notes are served only to the author)', () => {
|
| 48 |
+
expect(
|
| 49 |
+
getAnnotationAuthorship({
|
| 50 |
+
type: AnnotationType.personal,
|
| 51 |
+
owner_name: 'Alice'
|
| 52 |
+
})
|
| 53 |
+
).toBe('Personal note')
|
| 54 |
+
})
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
describe(`${canAddAnnotation.name}`, () => {
|
| 58 |
+
it.each([[Role.admin], [Role.editor], [Role.owner]])(
|
| 59 |
+
'allows adding a site annotation if the user is logged in, in role %p, and the site-annotations feature is available',
|
| 60 |
+
(role) => {
|
| 61 |
+
expect(
|
| 62 |
+
canAddAnnotation({
|
| 63 |
+
type: AnnotationType.site,
|
| 64 |
+
user: loggedInUser(role),
|
| 65 |
+
siteAnnotationsAvailable: true
|
| 66 |
+
})
|
| 67 |
+
).toBe(true)
|
| 68 |
+
}
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
it.each([[Role.admin], [Role.editor], [Role.owner]])(
|
| 72 |
+
'forbids adding a site annotation in role %p when the feature is unavailable (billing gate)',
|
| 73 |
+
(role) => {
|
| 74 |
+
expect(
|
| 75 |
+
canAddAnnotation({
|
| 76 |
+
type: AnnotationType.site,
|
| 77 |
+
user: loggedInUser(role),
|
| 78 |
+
siteAnnotationsAvailable: false
|
| 79 |
+
})
|
| 80 |
+
).toBe(false)
|
| 81 |
+
}
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
it.each([[Role.viewer], [Role.billing]])(
|
| 85 |
+
'forbids adding a site annotation in role %p even when the feature is available',
|
| 86 |
+
(role) => {
|
| 87 |
+
expect(
|
| 88 |
+
canAddAnnotation({
|
| 89 |
+
type: AnnotationType.site,
|
| 90 |
+
user: loggedInUser(role),
|
| 91 |
+
siteAnnotationsAvailable: true
|
| 92 |
+
})
|
| 93 |
+
).toBe(false)
|
| 94 |
+
}
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
it.each([
|
| 98 |
+
[Role.viewer],
|
| 99 |
+
[Role.billing],
|
| 100 |
+
[Role.editor],
|
| 101 |
+
[Role.admin],
|
| 102 |
+
[Role.owner]
|
| 103 |
+
])(
|
| 104 |
+
'allows adding a personal annotation in role %p regardless of site-annotations availability',
|
| 105 |
+
(role) => {
|
| 106 |
+
expect(
|
| 107 |
+
canAddAnnotation({
|
| 108 |
+
type: AnnotationType.personal,
|
| 109 |
+
user: loggedInUser(role),
|
| 110 |
+
siteAnnotationsAvailable: true
|
| 111 |
+
})
|
| 112 |
+
).toBe(true)
|
| 113 |
+
expect(
|
| 114 |
+
canAddAnnotation({
|
| 115 |
+
type: AnnotationType.personal,
|
| 116 |
+
user: loggedInUser(role),
|
| 117 |
+
siteAnnotationsAvailable: false
|
| 118 |
+
})
|
| 119 |
+
).toBe(true)
|
| 120 |
+
}
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
it.each([[AnnotationType.personal], [AnnotationType.site]])(
|
| 124 |
+
'forbids the public role from adding %s annotations',
|
| 125 |
+
(type) => {
|
| 126 |
+
expect(
|
| 127 |
+
canAddAnnotation({
|
| 128 |
+
type,
|
| 129 |
+
user: publicUser,
|
| 130 |
+
siteAnnotationsAvailable: true
|
| 131 |
+
})
|
| 132 |
+
).toBe(false)
|
| 133 |
+
}
|
| 134 |
+
)
|
| 135 |
+
})
|
| 136 |
+
|
| 137 |
+
describe(`${canEditAnnotation.name}`, () => {
|
| 138 |
+
it.each([[Role.admin], [Role.editor], [Role.owner]])(
|
| 139 |
+
'allows editing a site annotation if the user is logged in and in role %p',
|
| 140 |
+
(role) => {
|
| 141 |
+
expect(
|
| 142 |
+
canEditAnnotation({
|
| 143 |
+
type: AnnotationType.site,
|
| 144 |
+
user: loggedInUser(role)
|
| 145 |
+
})
|
| 146 |
+
).toBe(true)
|
| 147 |
+
}
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
it.each([[Role.viewer], [Role.billing]])(
|
| 151 |
+
'forbids editing site annotations in role %p',
|
| 152 |
+
(role) => {
|
| 153 |
+
expect(
|
| 154 |
+
canEditAnnotation({
|
| 155 |
+
type: AnnotationType.site,
|
| 156 |
+
user: loggedInUser(role)
|
| 157 |
+
})
|
| 158 |
+
).toBe(false)
|
| 159 |
+
}
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
it.each([
|
| 163 |
+
[Role.viewer],
|
| 164 |
+
[Role.billing],
|
| 165 |
+
[Role.editor],
|
| 166 |
+
[Role.admin],
|
| 167 |
+
[Role.owner]
|
| 168 |
+
])('allows editing a personal annotation when in role %p', (role) => {
|
| 169 |
+
expect(
|
| 170 |
+
canEditAnnotation({
|
| 171 |
+
type: AnnotationType.personal,
|
| 172 |
+
user: loggedInUser(role)
|
| 173 |
+
})
|
| 174 |
+
).toBe(true)
|
| 175 |
+
})
|
| 176 |
+
|
| 177 |
+
it.each([[AnnotationType.personal], [AnnotationType.site]])(
|
| 178 |
+
'forbids the public role from editing %s annotations',
|
| 179 |
+
(type) => {
|
| 180 |
+
expect(
|
| 181 |
+
canEditAnnotation({
|
| 182 |
+
type,
|
| 183 |
+
user: publicUser
|
| 184 |
+
})
|
| 185 |
+
).toBe(false)
|
| 186 |
+
}
|
| 187 |
+
)
|
| 188 |
+
})
|
| 189 |
+
|
| 190 |
+
describe(`${getAnnotationGranularity.name}`, () => {
|
| 191 |
+
it.each<[Interval, AnnotationGranularity]>([
|
| 192 |
+
[Interval.minute, AnnotationGranularity.minute],
|
| 193 |
+
[Interval.hour, AnnotationGranularity.minute],
|
| 194 |
+
[Interval.day, AnnotationGranularity.date],
|
| 195 |
+
[Interval.week, AnnotationGranularity.date],
|
| 196 |
+
[Interval.month, AnnotationGranularity.date]
|
| 197 |
+
])('maps interval %s to granularity %s', (interval, granularity) => {
|
| 198 |
+
expect(getAnnotationGranularity(interval)).toBe(granularity)
|
| 199 |
+
})
|
| 200 |
+
})
|
| 201 |
+
|
| 202 |
+
describe(`${getAnnotationTimeLabel.name}`, () => {
|
| 203 |
+
// 2025-02-26 is a Wednesday
|
| 204 |
+
const dateAnnotation = {
|
| 205 |
+
datetime: '2025-02-26',
|
| 206 |
+
granularity: AnnotationGranularity.date
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
it.each<[Interval, string]>([
|
| 210 |
+
[Interval.minute, '2025-02-26'],
|
| 211 |
+
[Interval.hour, '2025-02-26'],
|
| 212 |
+
[Interval.day, '2025-02-26'],
|
| 213 |
+
[Interval.week, '2025-02-24'],
|
| 214 |
+
[Interval.month, '2025-02-01']
|
| 215 |
+
])(
|
| 216 |
+
`date-granularity annotation on ${dateAnnotation.datetime} bucketed to %s yields %s`,
|
| 217 |
+
(interval, expected) => {
|
| 218 |
+
expect(getAnnotationTimeLabel(dateAnnotation, interval)).toBe(expected)
|
| 219 |
+
}
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
const minuteAnnotation = {
|
| 223 |
+
datetime: '2025-02-26T10:30:00',
|
| 224 |
+
granularity: AnnotationGranularity.minute
|
| 225 |
+
}
|
| 226 |
+
it.each<[Interval, string]>([
|
| 227 |
+
[Interval.month, '2025-02-01'],
|
| 228 |
+
[Interval.week, '2025-02-24'],
|
| 229 |
+
[Interval.day, '2025-02-26'],
|
| 230 |
+
[Interval.hour, '2025-02-26 10:00:00'],
|
| 231 |
+
[Interval.minute, '2025-02-26 10:30:00']
|
| 232 |
+
])(
|
| 233 |
+
`minute granularity annotation with datetime ${minuteAnnotation.datetime} bucketed to %s yields %s`,
|
| 234 |
+
(interval, expected) => {
|
| 235 |
+
expect(getAnnotationTimeLabel(minuteAnnotation, interval)).toBe(expected)
|
| 236 |
+
}
|
| 237 |
+
)
|
| 238 |
+
})
|
| 239 |
+
|
| 240 |
+
describe(`${groupAnnotationsByTimeLabel.name}`, () => {
|
| 241 |
+
const dateGranularity = AnnotationGranularity.date
|
| 242 |
+
const annotations = [
|
| 243 |
+
{ id: 1, datetime: '2025-02-24 00:00:00', granularity: dateGranularity }, // Mon
|
| 244 |
+
{ id: 2, datetime: '2025-02-26 00:00:00', granularity: dateGranularity }, // Wed (same week)
|
| 245 |
+
{ id: 3, datetime: '2025-03-05 00:00:00', granularity: dateGranularity } // following month
|
| 246 |
+
]
|
| 247 |
+
|
| 248 |
+
it('groups annotations by day when the interval is day', () => {
|
| 249 |
+
const grouped = groupAnnotationsByTimeLabel(annotations, Interval.day)
|
| 250 |
+
|
| 251 |
+
expect(Object.keys(grouped).sort()).toEqual([
|
| 252 |
+
'2025-02-24',
|
| 253 |
+
'2025-02-26',
|
| 254 |
+
'2025-03-05'
|
| 255 |
+
])
|
| 256 |
+
expect(grouped['2025-02-24']!.map((a) => a.id)).toEqual([1])
|
| 257 |
+
expect(grouped['2025-02-26']!.map((a) => a.id)).toEqual([2])
|
| 258 |
+
expect(grouped['2025-03-05']!.map((a) => a.id)).toEqual([3])
|
| 259 |
+
})
|
| 260 |
+
|
| 261 |
+
it('collapses annotations from the same week into one bucket', () => {
|
| 262 |
+
const grouped = groupAnnotationsByTimeLabel(annotations, Interval.week)
|
| 263 |
+
|
| 264 |
+
expect(Object.keys(grouped).sort()).toEqual(['2025-02-24', '2025-03-03'])
|
| 265 |
+
expect(grouped['2025-02-24']!.map((a) => a.id)).toEqual([1, 2])
|
| 266 |
+
expect(grouped['2025-03-03']!.map((a) => a.id)).toEqual([3])
|
| 267 |
+
})
|
| 268 |
+
|
| 269 |
+
it('collapses annotations from the same month into one bucket', () => {
|
| 270 |
+
const grouped = groupAnnotationsByTimeLabel(annotations, Interval.month)
|
| 271 |
+
|
| 272 |
+
expect(Object.keys(grouped).sort()).toEqual(['2025-02-01', '2025-03-01'])
|
| 273 |
+
expect(grouped['2025-02-01']!.map((a) => a.id)).toEqual([1, 2])
|
| 274 |
+
expect(grouped['2025-03-01']!.map((a) => a.id)).toEqual([3])
|
| 275 |
+
})
|
| 276 |
+
|
| 277 |
+
it('preserves insertion order within a bucket', () => {
|
| 278 |
+
const sameDay = [
|
| 279 |
+
{ id: 10, datetime: '2025-02-26 08:00:00', granularity: dateGranularity },
|
| 280 |
+
{ id: 11, datetime: '2025-02-26 09:00:00', granularity: dateGranularity },
|
| 281 |
+
{ id: 12, datetime: '2025-02-26 10:00:00', granularity: dateGranularity }
|
| 282 |
+
]
|
| 283 |
+
|
| 284 |
+
const grouped = groupAnnotationsByTimeLabel(sameDay, Interval.day)
|
| 285 |
+
|
| 286 |
+
expect(grouped['2025-02-26']!.map((a) => a.id)).toEqual([10, 11, 12])
|
| 287 |
+
})
|
| 288 |
+
|
| 289 |
+
it('returns an empty object when there are no annotations', () => {
|
| 290 |
+
expect(
|
| 291 |
+
groupAnnotationsByTimeLabel(
|
| 292 |
+
[] as { datetime: string; granularity: AnnotationGranularity }[],
|
| 293 |
+
Interval.day
|
| 294 |
+
)
|
| 295 |
+
).toEqual({})
|
| 296 |
+
})
|
| 297 |
+
})
|
assets/js/dashboard/annotations/annotations.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 2 |
+
import { Role, UserContextValue } from '../user-context'
|
| 3 |
+
import {
|
| 4 |
+
formatDayShort,
|
| 5 |
+
formatTime,
|
| 6 |
+
is12HourClock,
|
| 7 |
+
parseUTCDate
|
| 8 |
+
} from '../util/date'
|
| 9 |
+
|
| 10 |
+
export enum AnnotationType {
|
| 11 |
+
personal = 'personal',
|
| 12 |
+
site = 'site'
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
/** This type signifies that the owner can't be shown. */
|
| 16 |
+
// type AnnotationOwnershipHidden = { owner_id: null; owner_name: null }
|
| 17 |
+
|
| 18 |
+
/** This type signifies that the original owner has been removed from the site. */
|
| 19 |
+
type AnnotationOwnershipDangling = { owner_id: null; owner_name: null }
|
| 20 |
+
|
| 21 |
+
type AnnotationOwnership =
|
| 22 |
+
| AnnotationOwnershipDangling
|
| 23 |
+
| { owner_id: number; owner_name: string }
|
| 24 |
+
|
| 25 |
+
export enum AnnotationGranularity {
|
| 26 |
+
date = 'date',
|
| 27 |
+
minute = 'minute'
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// the DB side limit is 255, but this looks better in the UI
|
| 31 |
+
export const NOTE_MAX_LENGTH = 250
|
| 32 |
+
|
| 33 |
+
export type Annotation = {
|
| 34 |
+
datetime: string
|
| 35 |
+
granularity: AnnotationGranularity
|
| 36 |
+
type: AnnotationType
|
| 37 |
+
note: string
|
| 38 |
+
|
| 39 |
+
id: number
|
| 40 |
+
/** datetime in site timezone, example 2025-02-26 10:00:00 */
|
| 41 |
+
inserted_at: string
|
| 42 |
+
/** datetime in site timezone, example 2025-02-26 10:00:00 */
|
| 43 |
+
updated_at: string
|
| 44 |
+
} & AnnotationOwnership
|
| 45 |
+
|
| 46 |
+
export type AnnotationPayload = Pick<
|
| 47 |
+
Annotation,
|
| 48 |
+
'note' | 'datetime' | 'granularity' | 'type'
|
| 49 |
+
>
|
| 50 |
+
|
| 51 |
+
export const ANNOTATION_TYPE_LABELS = {
|
| 52 |
+
[AnnotationType.personal]: 'Personal note',
|
| 53 |
+
[AnnotationType.site]: 'Site note'
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export const getAnnotationAuthorship = (
|
| 57 |
+
annotation: Pick<Annotation, 'type' | 'owner_name'>
|
| 58 |
+
): string => {
|
| 59 |
+
if (annotation.type === AnnotationType.site && annotation.owner_name) {
|
| 60 |
+
return annotation.owner_name
|
| 61 |
+
}
|
| 62 |
+
return ANNOTATION_TYPE_LABELS[annotation.type]
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
export const getAttributionDateLabel = (
|
| 66 |
+
annotation: Pick<Annotation, 'datetime' | 'granularity'>
|
| 67 |
+
): string => {
|
| 68 |
+
const date = parseUTCDate(annotation.datetime)
|
| 69 |
+
const dayLabel = formatDayShort(date)
|
| 70 |
+
if (annotation.granularity === AnnotationGranularity.minute) {
|
| 71 |
+
const time = formatTime(date, {
|
| 72 |
+
use12HourClock: is12HourClock(),
|
| 73 |
+
includeMinutes: true
|
| 74 |
+
})
|
| 75 |
+
return `${dayLabel} ${time}`
|
| 76 |
+
}
|
| 77 |
+
return dayLabel
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/** keep in sync with Plausible.Annotations */
|
| 81 |
+
const ROLES_WITH_MAYBE_SITE_ANNOTATIONS = [Role.admin, Role.editor, Role.owner]
|
| 82 |
+
const ROLES_WITH_PERSONAL_ANNOTATIONS = [
|
| 83 |
+
Role.billing,
|
| 84 |
+
Role.viewer,
|
| 85 |
+
Role.admin,
|
| 86 |
+
Role.editor,
|
| 87 |
+
Role.owner
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
export function canEditAnnotation({
|
| 91 |
+
type,
|
| 92 |
+
user
|
| 93 |
+
}: {
|
| 94 |
+
type: AnnotationType
|
| 95 |
+
user: UserContextValue
|
| 96 |
+
}) {
|
| 97 |
+
if (!user.loggedIn) {
|
| 98 |
+
return false
|
| 99 |
+
}
|
| 100 |
+
switch (type) {
|
| 101 |
+
case AnnotationType.site:
|
| 102 |
+
// we don't check whether site annotations are available here:
|
| 103 |
+
// even when site annotations aren't available,
|
| 104 |
+
// the user should be able to downgrade them to personal, or delete them
|
| 105 |
+
return ROLES_WITH_MAYBE_SITE_ANNOTATIONS.includes(user.role)
|
| 106 |
+
case AnnotationType.personal:
|
| 107 |
+
return ROLES_WITH_PERSONAL_ANNOTATIONS.includes(user.role)
|
| 108 |
+
default:
|
| 109 |
+
return false
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
export function canShowAddAnnotationButton(props: {
|
| 114 |
+
user: UserContextValue
|
| 115 |
+
siteAnnotationsAvailable: boolean
|
| 116 |
+
}) {
|
| 117 |
+
return (
|
| 118 |
+
canAddAnnotation({ type: AnnotationType.personal, ...props }) ||
|
| 119 |
+
canAddAnnotation({ type: AnnotationType.site, ...props })
|
| 120 |
+
)
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
export function canAddAnnotation({
|
| 124 |
+
type,
|
| 125 |
+
user,
|
| 126 |
+
siteAnnotationsAvailable
|
| 127 |
+
}: {
|
| 128 |
+
type: AnnotationType
|
| 129 |
+
user: UserContextValue
|
| 130 |
+
siteAnnotationsAvailable: boolean
|
| 131 |
+
}) {
|
| 132 |
+
switch (type) {
|
| 133 |
+
case AnnotationType.site:
|
| 134 |
+
return siteAnnotationsAvailable && canEditAnnotation({ type, user })
|
| 135 |
+
case AnnotationType.personal:
|
| 136 |
+
return canEditAnnotation({ type, user })
|
| 137 |
+
default:
|
| 138 |
+
return false
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
export const getAnnotationTimeLabel = (
|
| 143 |
+
annotation: Pick<Annotation, 'datetime' | 'granularity'>,
|
| 144 |
+
interval: Interval
|
| 145 |
+
): string => {
|
| 146 |
+
const dateString = annotation.datetime.substring(0, 'YYYY-MM-DD'.length)
|
| 147 |
+
switch (annotation.granularity) {
|
| 148 |
+
case AnnotationGranularity.date: {
|
| 149 |
+
switch (interval) {
|
| 150 |
+
case Interval.month:
|
| 151 |
+
// floors to closest start of month for the date
|
| 152 |
+
return parseUTCDate(dateString).startOf('month').format('YYYY-MM-DD')
|
| 153 |
+
case Interval.week:
|
| 154 |
+
// floors to closest start of week for the date
|
| 155 |
+
return parseUTCDate(dateString).startOf('week').format('YYYY-MM-DD')
|
| 156 |
+
case Interval.day:
|
| 157 |
+
case Interval.hour:
|
| 158 |
+
case Interval.minute:
|
| 159 |
+
// floors to date
|
| 160 |
+
return dateString
|
| 161 |
+
}
|
| 162 |
+
break
|
| 163 |
+
}
|
| 164 |
+
case AnnotationGranularity.minute: {
|
| 165 |
+
switch (interval) {
|
| 166 |
+
case Interval.month:
|
| 167 |
+
// floors to closest start of month for the date
|
| 168 |
+
return parseUTCDate(dateString).startOf('month').format('YYYY-MM-DD')
|
| 169 |
+
case Interval.week:
|
| 170 |
+
// floors to closest start of week for the date
|
| 171 |
+
return parseUTCDate(dateString).startOf('week').format('YYYY-MM-DD')
|
| 172 |
+
case Interval.day:
|
| 173 |
+
// floors to date
|
| 174 |
+
return dateString
|
| 175 |
+
case Interval.hour: {
|
| 176 |
+
const [dateYYYYMMDD, timeHHMMSS] = annotation.datetime.split('T')
|
| 177 |
+
// floors time to hour
|
| 178 |
+
return `${dateYYYYMMDD} ${timeHHMMSS.substring(0, 'HH'.length)}:00:00`
|
| 179 |
+
}
|
| 180 |
+
case Interval.minute:
|
| 181 |
+
return annotation.datetime.split('T').join(' ')
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
export const groupAnnotationsByTimeLabel = <
|
| 188 |
+
T extends Pick<Annotation, 'datetime' | 'granularity'>
|
| 189 |
+
>(
|
| 190 |
+
annotations: T[],
|
| 191 |
+
interval: Interval
|
| 192 |
+
): Record<string, T[] | undefined> => {
|
| 193 |
+
return annotations.reduce<Record<string, T[]>>((acc, annotation) => {
|
| 194 |
+
const timeLabel = getAnnotationTimeLabel(annotation, interval)
|
| 195 |
+
return { ...acc, [timeLabel]: [...(acc[timeLabel] ?? []), annotation] }
|
| 196 |
+
}, {})
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
export const getAnnotationGranularity = (
|
| 200 |
+
interval: Interval
|
| 201 |
+
): AnnotationGranularity => {
|
| 202 |
+
switch (interval) {
|
| 203 |
+
case Interval.minute:
|
| 204 |
+
case Interval.hour:
|
| 205 |
+
return AnnotationGranularity.minute
|
| 206 |
+
case Interval.day:
|
| 207 |
+
case Interval.week:
|
| 208 |
+
case Interval.month:
|
| 209 |
+
return AnnotationGranularity.date
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
export const getApiFormattedPayload = ({
|
| 214 |
+
granularity,
|
| 215 |
+
datetime,
|
| 216 |
+
...payload
|
| 217 |
+
}: AnnotationPayload) => {
|
| 218 |
+
switch (granularity) {
|
| 219 |
+
case AnnotationGranularity.date:
|
| 220 |
+
return { date: datetime, granularity, ...payload }
|
| 221 |
+
case AnnotationGranularity.minute:
|
| 222 |
+
return { datetime, granularity, ...payload }
|
| 223 |
+
}
|
| 224 |
+
}
|
assets/js/dashboard/annotations/hover-annotations-list.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import { Annotation } from './annotations'
|
| 3 |
+
import {
|
| 4 |
+
AnnotationAuthorshipLine,
|
| 5 |
+
AnnotationItemRow,
|
| 6 |
+
AnnotationNote,
|
| 7 |
+
AnnotationsListContainer
|
| 8 |
+
} from './annotation-list-items'
|
| 9 |
+
|
| 10 |
+
const MAX_PREVIEW = 2
|
| 11 |
+
|
| 12 |
+
export const HoverAnnotationsList = ({
|
| 13 |
+
annotations
|
| 14 |
+
}: {
|
| 15 |
+
annotations: Annotation[]
|
| 16 |
+
}) => {
|
| 17 |
+
const preview = annotations.slice(0, MAX_PREVIEW)
|
| 18 |
+
const extra = annotations.length - MAX_PREVIEW
|
| 19 |
+
|
| 20 |
+
return (
|
| 21 |
+
<>
|
| 22 |
+
<AnnotationsListContainer>
|
| 23 |
+
{preview.map((annotation) => (
|
| 24 |
+
<AnnotationItemRow key={annotation.id}>
|
| 25 |
+
<div className="relative flex flex-col gap-y-px w-full max-w-64">
|
| 26 |
+
<AnnotationAuthorshipLine annotation={annotation} />
|
| 27 |
+
<AnnotationNote note={annotation.note} clamp />
|
| 28 |
+
</div>
|
| 29 |
+
</AnnotationItemRow>
|
| 30 |
+
))}
|
| 31 |
+
</AnnotationsListContainer>
|
| 32 |
+
{extra === 1 && `and 1 more note`}
|
| 33 |
+
{extra > 1 && `and ${extra} more notes`}
|
| 34 |
+
</>
|
| 35 |
+
)
|
| 36 |
+
}
|
assets/js/dashboard/annotations/interactive-annotations-list.tsx
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode } from 'react'
|
| 2 |
+
import { Annotation, canEditAnnotation } from './annotations'
|
| 3 |
+
import {
|
| 4 |
+
AnnotationAuthorshipLine,
|
| 5 |
+
AnnotationItemRow,
|
| 6 |
+
AnnotationNote,
|
| 7 |
+
AnnotationsListContainer
|
| 8 |
+
} from './annotation-list-items'
|
| 9 |
+
import { useRoutelessModalsContext } from '../navigation/routeless-modals-context'
|
| 10 |
+
import { useUserContext } from '../user-context'
|
| 11 |
+
import { PencilIcon } from '../components/icons'
|
| 12 |
+
|
| 13 |
+
const ScrollableArea = (props: { children: ReactNode }) => (
|
| 14 |
+
<div className="max-h-25 sm:max-h-40 overflow-y-auto overflow-x-hidden -mr-2.5 pr-2.5 [scrollbar-width:thin] [scrollbar-color:theme(colors.gray.600)_transparent]">
|
| 15 |
+
{props.children}
|
| 16 |
+
</div>
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
export const InteractiveAnnotationsList = ({
|
| 20 |
+
annotations,
|
| 21 |
+
isTouchDevice,
|
| 22 |
+
closeTooltip
|
| 23 |
+
}: {
|
| 24 |
+
annotations: Annotation[]
|
| 25 |
+
isTouchDevice: boolean
|
| 26 |
+
closeTooltip: () => void
|
| 27 |
+
}) => {
|
| 28 |
+
const { setModal } = useRoutelessModalsContext()
|
| 29 |
+
const user = useUserContext()
|
| 30 |
+
const openEdit = (annotation: Annotation) => {
|
| 31 |
+
closeTooltip()
|
| 32 |
+
setModal({ type: 'update-annotation', annotation })
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return (
|
| 36 |
+
<ScrollableArea>
|
| 37 |
+
<AnnotationsListContainer>
|
| 38 |
+
{annotations.map((annotation) => {
|
| 39 |
+
const editable = canEditAnnotation({ type: annotation.type, user })
|
| 40 |
+
const content = (
|
| 41 |
+
<>
|
| 42 |
+
<AnnotationAuthorshipLine annotation={annotation} />
|
| 43 |
+
<AnnotationNote note={annotation.note} />
|
| 44 |
+
{editable && !isTouchDevice && (
|
| 45 |
+
<button
|
| 46 |
+
aria-label="Edit note"
|
| 47 |
+
className="absolute top-px right-0 opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity text-gray-300 hover:text-gray-100 focus:outline-none"
|
| 48 |
+
onClick={() => openEdit(annotation)}
|
| 49 |
+
>
|
| 50 |
+
<PencilIcon className="size-4" />
|
| 51 |
+
</button>
|
| 52 |
+
)}
|
| 53 |
+
</>
|
| 54 |
+
)
|
| 55 |
+
return (
|
| 56 |
+
<AnnotationItemRow key={annotation.id}>
|
| 57 |
+
{editable && isTouchDevice ? (
|
| 58 |
+
<button
|
| 59 |
+
className="relative flex flex-col gap-y-px w-full max-w-64 text-left focus:outline-none"
|
| 60 |
+
onClick={() => openEdit(annotation)}
|
| 61 |
+
>
|
| 62 |
+
{content}
|
| 63 |
+
</button>
|
| 64 |
+
) : (
|
| 65 |
+
<div className="relative flex flex-col gap-y-px w-full max-w-64">
|
| 66 |
+
{content}
|
| 67 |
+
</div>
|
| 68 |
+
)}
|
| 69 |
+
</AnnotationItemRow>
|
| 70 |
+
)
|
| 71 |
+
})}
|
| 72 |
+
</AnnotationsListContainer>
|
| 73 |
+
</ScrollableArea>
|
| 74 |
+
)
|
| 75 |
+
}
|
assets/js/dashboard/annotations/routeless-annotations-modals.tsx
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
| 3 |
+
import { useSiteContext } from '../site-context'
|
| 4 |
+
import { useUserContext } from '../user-context'
|
| 5 |
+
import { get, mutation } from '../api'
|
| 6 |
+
import { useRoutelessModalsContext } from '../navigation/routeless-modals-context'
|
| 7 |
+
import {
|
| 8 |
+
CreateAnnotationModal,
|
| 9 |
+
DeleteAnnotationModal,
|
| 10 |
+
UpdateAnnotationModal
|
| 11 |
+
} from './annotations-modals'
|
| 12 |
+
import {
|
| 13 |
+
Annotation,
|
| 14 |
+
AnnotationPayload,
|
| 15 |
+
getApiFormattedPayload
|
| 16 |
+
} from './annotations'
|
| 17 |
+
import { useDashboardStateContext } from '../dashboard-state-context'
|
| 18 |
+
import { createDateRange } from '../stats-query'
|
| 19 |
+
import { formatISO } from '../util/date'
|
| 20 |
+
import { DashboardState } from '../dashboard-state'
|
| 21 |
+
|
| 22 |
+
export const useGetAnnotations = () => {
|
| 23 |
+
const site = useSiteContext()
|
| 24 |
+
const { dashboardState } = useDashboardStateContext()
|
| 25 |
+
const date_range = createDateRange(dashboardState)
|
| 26 |
+
const relative_date = dashboardState.date
|
| 27 |
+
? formatISO(dashboardState.date)
|
| 28 |
+
: null
|
| 29 |
+
|
| 30 |
+
const dateRangeParams: Record<string, string> = Array.isArray(date_range)
|
| 31 |
+
? { date_range_start: date_range[0], date_range_end: date_range[1] }
|
| 32 |
+
: { date_range }
|
| 33 |
+
|
| 34 |
+
const annotationsIndexQuery = useQuery({
|
| 35 |
+
queryKey: ['annotations', { date_range, relative_date }],
|
| 36 |
+
queryFn: async () => {
|
| 37 |
+
const response: Annotation[] = await get(
|
| 38 |
+
`/api/${encodeURIComponent(site.domain)}/annotations`,
|
| 39 |
+
// workaround to allow custom params to be defined
|
| 40 |
+
// without passing the whole dashboard state
|
| 41 |
+
{} as unknown as DashboardState,
|
| 42 |
+
{
|
| 43 |
+
...dateRangeParams,
|
| 44 |
+
...(relative_date ? { relative_date } : {})
|
| 45 |
+
}
|
| 46 |
+
)
|
| 47 |
+
return response
|
| 48 |
+
}
|
| 49 |
+
})
|
| 50 |
+
return annotationsIndexQuery
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export type RoutelessAnnotationModal =
|
| 54 |
+
| {
|
| 55 |
+
type: 'create-annotation'
|
| 56 |
+
annotation: Pick<Annotation, 'datetime' | 'granularity' | 'type'>
|
| 57 |
+
}
|
| 58 |
+
| { type: 'update-annotation'; annotation: Annotation }
|
| 59 |
+
| { type: 'delete-annotation'; annotation: Annotation }
|
| 60 |
+
|
| 61 |
+
export const RoutelessAnnotationModals = () => {
|
| 62 |
+
const queryClient = useQueryClient()
|
| 63 |
+
const site = useSiteContext()
|
| 64 |
+
const { modal, setModal } = useRoutelessModalsContext()
|
| 65 |
+
const user = useUserContext()
|
| 66 |
+
|
| 67 |
+
const patchAnnotation = useMutation({
|
| 68 |
+
mutationFn: async ({
|
| 69 |
+
id,
|
| 70 |
+
note,
|
| 71 |
+
type
|
| 72 |
+
}: Pick<Annotation, 'id'> & Partial<Pick<Annotation, 'note' | 'type'>>) => {
|
| 73 |
+
const response: Annotation = await mutation(
|
| 74 |
+
`/api/${encodeURIComponent(site.domain)}/annotations/${id}`,
|
| 75 |
+
{
|
| 76 |
+
method: 'PATCH',
|
| 77 |
+
body: {
|
| 78 |
+
note,
|
| 79 |
+
type
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
return response
|
| 85 |
+
},
|
| 86 |
+
onSuccess: async () => {
|
| 87 |
+
queryClient.invalidateQueries({ queryKey: ['annotations'] })
|
| 88 |
+
setModal(null)
|
| 89 |
+
}
|
| 90 |
+
})
|
| 91 |
+
|
| 92 |
+
const createAnnotation = useMutation({
|
| 93 |
+
mutationFn: async (payload: AnnotationPayload) => {
|
| 94 |
+
const response: Annotation = await mutation(
|
| 95 |
+
`/api/${encodeURIComponent(site.domain)}/annotations`,
|
| 96 |
+
{
|
| 97 |
+
method: 'POST',
|
| 98 |
+
body: getApiFormattedPayload(payload)
|
| 99 |
+
}
|
| 100 |
+
)
|
| 101 |
+
return response
|
| 102 |
+
},
|
| 103 |
+
onSuccess: async () => {
|
| 104 |
+
queryClient.invalidateQueries({ queryKey: ['annotations'] })
|
| 105 |
+
setModal(null)
|
| 106 |
+
}
|
| 107 |
+
})
|
| 108 |
+
|
| 109 |
+
const deleteAnnotation = useMutation({
|
| 110 |
+
mutationFn: async (data: Pick<Annotation, 'id'>) => {
|
| 111 |
+
const response: Annotation = await mutation(
|
| 112 |
+
`/api/${encodeURIComponent(site.domain)}/annotations/${data.id}`,
|
| 113 |
+
{
|
| 114 |
+
method: 'DELETE'
|
| 115 |
+
}
|
| 116 |
+
)
|
| 117 |
+
return response
|
| 118 |
+
},
|
| 119 |
+
onSuccess: (): void => {
|
| 120 |
+
queryClient.invalidateQueries({ queryKey: ['annotations'] })
|
| 121 |
+
setModal(null)
|
| 122 |
+
}
|
| 123 |
+
})
|
| 124 |
+
|
| 125 |
+
if (!user.loggedIn) {
|
| 126 |
+
return null
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
return (
|
| 130 |
+
<>
|
| 131 |
+
{modal?.type === 'delete-annotation' && (
|
| 132 |
+
<DeleteAnnotationModal
|
| 133 |
+
annotation={modal.annotation}
|
| 134 |
+
onClose={() => {
|
| 135 |
+
setModal(null)
|
| 136 |
+
deleteAnnotation.reset()
|
| 137 |
+
}}
|
| 138 |
+
onSave={({ id }) => deleteAnnotation.mutate({ id })}
|
| 139 |
+
status={deleteAnnotation.status}
|
| 140 |
+
error={deleteAnnotation.error}
|
| 141 |
+
reset={deleteAnnotation.reset}
|
| 142 |
+
/>
|
| 143 |
+
)}
|
| 144 |
+
|
| 145 |
+
{modal?.type === 'update-annotation' && (
|
| 146 |
+
<UpdateAnnotationModal
|
| 147 |
+
user={user}
|
| 148 |
+
siteAnnotationsAvailable={site.siteAnnotationsAvailable}
|
| 149 |
+
annotation={modal.annotation}
|
| 150 |
+
notePlaceholder={''}
|
| 151 |
+
onClose={() => {
|
| 152 |
+
setModal(null)
|
| 153 |
+
patchAnnotation.reset()
|
| 154 |
+
}}
|
| 155 |
+
onSave={({ id, note, type }) =>
|
| 156 |
+
patchAnnotation.mutate({
|
| 157 |
+
id,
|
| 158 |
+
note,
|
| 159 |
+
type
|
| 160 |
+
})
|
| 161 |
+
}
|
| 162 |
+
onDelete={(annotation) =>
|
| 163 |
+
setModal({ type: 'delete-annotation', annotation })
|
| 164 |
+
}
|
| 165 |
+
status={patchAnnotation.status}
|
| 166 |
+
error={patchAnnotation.error}
|
| 167 |
+
reset={patchAnnotation.reset}
|
| 168 |
+
/>
|
| 169 |
+
)}
|
| 170 |
+
{modal?.type === 'create-annotation' && (
|
| 171 |
+
<CreateAnnotationModal
|
| 172 |
+
user={user}
|
| 173 |
+
siteAnnotationsAvailable={site.siteAnnotationsAvailable}
|
| 174 |
+
notePlaceholder={`E.g. 'Campaign started' or 'Feature released'`}
|
| 175 |
+
initialType={modal.annotation.type}
|
| 176 |
+
initialDatetime={modal.annotation.datetime}
|
| 177 |
+
initialGranularity={modal.annotation.granularity}
|
| 178 |
+
onClose={() => {
|
| 179 |
+
setModal(null)
|
| 180 |
+
createAnnotation.reset()
|
| 181 |
+
}}
|
| 182 |
+
onSave={(payload) => createAnnotation.mutate(payload)}
|
| 183 |
+
status={createAnnotation.status}
|
| 184 |
+
error={createAnnotation.error}
|
| 185 |
+
reset={createAnnotation.reset}
|
| 186 |
+
/>
|
| 187 |
+
)}
|
| 188 |
+
</>
|
| 189 |
+
)
|
| 190 |
+
}
|
assets/js/dashboard/api.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Metric } from './stats/metrics'
|
| 2 |
+
import { DashboardState } from './dashboard-state'
|
| 3 |
+
import { PlausibleSite } from './site-context'
|
| 4 |
+
import { StatsQuery } from './stats-query'
|
| 5 |
+
import { formatISO } from './util/date'
|
| 6 |
+
import { serializeApiFilters } from './util/filters'
|
| 7 |
+
import * as url from './util/url'
|
| 8 |
+
import { MainGraphResponse } from './stats/graph/fetch-main-graph'
|
| 9 |
+
import { CsvExportRequestBody } from './stats/csv-export/csv-export-body'
|
| 10 |
+
import { maybeReloadForApiVersion } from './util/url-search-params'
|
| 11 |
+
|
| 12 |
+
let abortController = new AbortController()
|
| 13 |
+
let SHARED_LINK_AUTH: null | string = null
|
| 14 |
+
|
| 15 |
+
export type RevenueMetricValue = {
|
| 16 |
+
short: string
|
| 17 |
+
value: number
|
| 18 |
+
long: string
|
| 19 |
+
currency: string
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
export type MetricValue = null | number | RevenueMetricValue
|
| 23 |
+
|
| 24 |
+
export type QueryResultQuery = {
|
| 25 |
+
metrics: Metric[]
|
| 26 |
+
dimensions: string[]
|
| 27 |
+
date_range: [string, string]
|
| 28 |
+
comparison_date_range?: [string, string] | null
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export type QueryResultMeta = {
|
| 32 |
+
metric_warnings?: Record<string, Record<string, string>>
|
| 33 |
+
imports_included?: boolean
|
| 34 |
+
imports_skip_reason?: string
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
export type QueryResultRow = {
|
| 38 |
+
metrics: Array<MetricValue>
|
| 39 |
+
dimensions: Array<string>
|
| 40 |
+
comparison?: { metrics: Array<number>; change: Array<number> }
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// Added client-side in the queryFn before storing to TanStack cache.
|
| 44 |
+
// Needed to make sure that the time/metric labels we're constructing
|
| 45 |
+
// in stats reports are in sync with the dashboardState that was used
|
| 46 |
+
// to make that query. Otherwise, relying on current dashboardState
|
| 47 |
+
// while rendering previous (placeholder) data, it'd be out of sync.
|
| 48 |
+
export type ExtraContext = {
|
| 49 |
+
isRealtime: boolean
|
| 50 |
+
hasConversionGoalFilter: boolean
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export type QueryApiResponse = {
|
| 54 |
+
query: QueryResultQuery
|
| 55 |
+
meta: QueryResultMeta
|
| 56 |
+
results: QueryResultRow[]
|
| 57 |
+
extraContext: ExtraContext
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
export class ApiError extends Error {
|
| 61 |
+
payload: unknown
|
| 62 |
+
status: number
|
| 63 |
+
constructor(message: string, payload: unknown, status: number) {
|
| 64 |
+
super(message)
|
| 65 |
+
this.name = 'ApiError'
|
| 66 |
+
this.payload = payload
|
| 67 |
+
this.status = status
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function serializeUrlParams(params: Record<string, string | boolean | number>) {
|
| 72 |
+
const str: string[] = []
|
| 73 |
+
for (const p in params)
|
| 74 |
+
if (params.hasOwnProperty(p)) {
|
| 75 |
+
str.push(`${encodeURIComponent(p)}=${encodeURIComponent(params[p])}`)
|
| 76 |
+
}
|
| 77 |
+
return str.join('&')
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
export function setSharedLinkAuth(auth: string) {
|
| 81 |
+
SHARED_LINK_AUTH = auth
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
export function cancelAll() {
|
| 85 |
+
abortController.abort()
|
| 86 |
+
abortController = new AbortController()
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
export function dashboardStateToSearchParams(
|
| 90 |
+
dashboardState: DashboardState,
|
| 91 |
+
extraQuery: unknown[] = []
|
| 92 |
+
): string {
|
| 93 |
+
return serializeUrlParams(dashboardStateToParams(dashboardState, extraQuery))
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
export function dashboardStateToParams(
|
| 97 |
+
dashboardState: DashboardState,
|
| 98 |
+
extraQuery: unknown[] = []
|
| 99 |
+
): Record<string, string> {
|
| 100 |
+
const queryObj: Record<string, string> = {}
|
| 101 |
+
if (dashboardState.period) {
|
| 102 |
+
queryObj.period = dashboardState.period
|
| 103 |
+
}
|
| 104 |
+
if (dashboardState.date) {
|
| 105 |
+
queryObj.date = formatISO(dashboardState.date)
|
| 106 |
+
}
|
| 107 |
+
if (dashboardState.from) {
|
| 108 |
+
queryObj.from = formatISO(dashboardState.from)
|
| 109 |
+
}
|
| 110 |
+
if (dashboardState.to) {
|
| 111 |
+
queryObj.to = formatISO(dashboardState.to)
|
| 112 |
+
}
|
| 113 |
+
if (dashboardState.filters) {
|
| 114 |
+
queryObj.filters = serializeApiFilters(dashboardState.filters)
|
| 115 |
+
}
|
| 116 |
+
if (dashboardState.with_imported) {
|
| 117 |
+
queryObj.with_imported = String(dashboardState.with_imported)
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if (dashboardState.comparison) {
|
| 121 |
+
queryObj.comparison = dashboardState.comparison
|
| 122 |
+
queryObj.compare_from = dashboardState.compare_from
|
| 123 |
+
? formatISO(dashboardState.compare_from)
|
| 124 |
+
: undefined
|
| 125 |
+
queryObj.compare_to = dashboardState.compare_to
|
| 126 |
+
? formatISO(dashboardState.compare_to)
|
| 127 |
+
: undefined
|
| 128 |
+
queryObj.match_day_of_week = String(dashboardState.match_day_of_week)
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
const sharedLinkParams = getSharedLinkSearchParams()
|
| 132 |
+
if (sharedLinkParams.auth) {
|
| 133 |
+
queryObj.auth = sharedLinkParams.auth
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
Object.assign(queryObj, ...extraQuery)
|
| 137 |
+
|
| 138 |
+
return queryObj
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
function getHeaders(): Record<string, string> {
|
| 142 |
+
return SHARED_LINK_AUTH ? { 'X-Shared-Link-Auth': SHARED_LINK_AUTH } : {}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
async function throwApiErrorIfNotOk(response: Response) {
|
| 146 |
+
if (!response.ok) {
|
| 147 |
+
const payload = await response.json()
|
| 148 |
+
throw new ApiError(payload.error, payload, response.status)
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
async function handleApiResponse(
|
| 153 |
+
response: Response,
|
| 154 |
+
opts: Record<'idempotent', boolean> = { idempotent: true }
|
| 155 |
+
) {
|
| 156 |
+
if (opts.idempotent) {
|
| 157 |
+
maybeReloadForApiVersion(window.location, response.headers)
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
await throwApiErrorIfNotOk(response)
|
| 161 |
+
return response.json()
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
function getSharedLinkSearchParams(): Record<string, string> {
|
| 165 |
+
return SHARED_LINK_AUTH ? { auth: SHARED_LINK_AUTH } : {}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
export async function stats<
|
| 169 |
+
TResponse extends QueryApiResponse | MainGraphResponse
|
| 170 |
+
>(site: PlausibleSite, statsQuery: StatsQuery) {
|
| 171 |
+
const sharedLinkParams = getSharedLinkSearchParams()
|
| 172 |
+
const queryString = sharedLinkParams.auth
|
| 173 |
+
? new URLSearchParams(sharedLinkParams).toString()
|
| 174 |
+
: ''
|
| 175 |
+
const path = url.apiPath(site, '/query')
|
| 176 |
+
const response = await fetch(queryString ? `${path}?${queryString}` : path, {
|
| 177 |
+
method: 'POST',
|
| 178 |
+
signal: abortController.signal,
|
| 179 |
+
headers: {
|
| 180 |
+
...getHeaders(),
|
| 181 |
+
'Content-Type': 'application/json',
|
| 182 |
+
Accept: 'application/json'
|
| 183 |
+
},
|
| 184 |
+
body: JSON.stringify(statsQuery)
|
| 185 |
+
})
|
| 186 |
+
|
| 187 |
+
return (await handleApiResponse(response)) as TResponse
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
export async function csvExport(
|
| 191 |
+
site: PlausibleSite,
|
| 192 |
+
body: CsvExportRequestBody
|
| 193 |
+
): Promise<Blob> {
|
| 194 |
+
const sharedLinkParams = getSharedLinkSearchParams()
|
| 195 |
+
const queryString = sharedLinkParams.auth
|
| 196 |
+
? new URLSearchParams(sharedLinkParams).toString()
|
| 197 |
+
: ''
|
| 198 |
+
const path = url.apiPath(site, '/export')
|
| 199 |
+
const response = await fetch(queryString ? `${path}?${queryString}` : path, {
|
| 200 |
+
method: 'POST',
|
| 201 |
+
headers: { ...getHeaders(), 'Content-Type': 'application/json' },
|
| 202 |
+
body: JSON.stringify(body)
|
| 203 |
+
})
|
| 204 |
+
await throwApiErrorIfNotOk(response)
|
| 205 |
+
return response.blob()
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
export async function get(
|
| 209 |
+
url: string,
|
| 210 |
+
dashboardState?: DashboardState,
|
| 211 |
+
...extraQueryParams: unknown[]
|
| 212 |
+
) {
|
| 213 |
+
const queryString = dashboardState
|
| 214 |
+
? dashboardStateToSearchParams(dashboardState, [...extraQueryParams])
|
| 215 |
+
: serializeUrlParams(getSharedLinkSearchParams())
|
| 216 |
+
|
| 217 |
+
const response = await fetch(queryString ? `${url}?${queryString}` : url, {
|
| 218 |
+
signal: abortController.signal,
|
| 219 |
+
headers: { ...getHeaders(), Accept: 'application/json' }
|
| 220 |
+
})
|
| 221 |
+
|
| 222 |
+
return handleApiResponse(response)
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
export async function post(
|
| 226 |
+
url: string,
|
| 227 |
+
dashboardState: DashboardState,
|
| 228 |
+
...extraBodyParams: unknown[]
|
| 229 |
+
) {
|
| 230 |
+
const queryString = serializeUrlParams(getSharedLinkSearchParams())
|
| 231 |
+
const response = await fetch(queryString ? `${url}?${queryString}` : url, {
|
| 232 |
+
method: 'POST',
|
| 233 |
+
signal: abortController.signal,
|
| 234 |
+
headers: {
|
| 235 |
+
...getHeaders(),
|
| 236 |
+
'Content-Type': 'application/json',
|
| 237 |
+
Accept: 'application/json'
|
| 238 |
+
},
|
| 239 |
+
body: JSON.stringify(
|
| 240 |
+
dashboardStateToParams(dashboardState, [...extraBodyParams])
|
| 241 |
+
)
|
| 242 |
+
})
|
| 243 |
+
|
| 244 |
+
return handleApiResponse(response)
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
export const mutation = async <
|
| 248 |
+
TBody extends Record<string, unknown> = Record<string, unknown>
|
| 249 |
+
>(
|
| 250 |
+
url: string,
|
| 251 |
+
options:
|
| 252 |
+
| { body: TBody; method: 'PATCH' | 'PUT' | 'POST' }
|
| 253 |
+
| { method: 'DELETE' }
|
| 254 |
+
) => {
|
| 255 |
+
const queryString = serializeUrlParams(getSharedLinkSearchParams())
|
| 256 |
+
const fetchOptions =
|
| 257 |
+
options.method === 'DELETE'
|
| 258 |
+
? {}
|
| 259 |
+
: {
|
| 260 |
+
headers: { 'Content-Type': 'application/json' },
|
| 261 |
+
body: JSON.stringify(options.body)
|
| 262 |
+
}
|
| 263 |
+
const response = await fetch(queryString ? `${url}?${queryString}` : url, {
|
| 264 |
+
method: options.method,
|
| 265 |
+
headers: {
|
| 266 |
+
...getHeaders(),
|
| 267 |
+
...fetchOptions.headers,
|
| 268 |
+
Accept: 'application/json'
|
| 269 |
+
},
|
| 270 |
+
body: fetchOptions.body,
|
| 271 |
+
signal: abortController.signal
|
| 272 |
+
})
|
| 273 |
+
return handleApiResponse(response, { idempotent: false })
|
| 274 |
+
}
|
assets/js/dashboard/components/button.tsx
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Themes and sizes are kept in sync with the Phoenix `button` component in
|
| 6 |
+
* `lib/plausible_web/components/generic.ex`. The actual Tailwind classes live
|
| 7 |
+
* in `assets/css/app.css` (.btn-base, .btn-{xs,sm,md}, .btn-theme-*).
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
export type ButtonTheme =
|
| 11 |
+
| 'primary'
|
| 12 |
+
| 'secondary'
|
| 13 |
+
| 'danger'
|
| 14 |
+
| 'yellow'
|
| 15 |
+
| 'ghost'
|
| 16 |
+
| 'icon'
|
| 17 |
+
|
| 18 |
+
export type ButtonSize = 'xs' | 'sm' | 'md'
|
| 19 |
+
|
| 20 |
+
const buttonBaseClass = 'btn-base'
|
| 21 |
+
|
| 22 |
+
const buttonSizes: Record<ButtonSize, string> = {
|
| 23 |
+
xs: 'btn-xs',
|
| 24 |
+
sm: 'btn-sm',
|
| 25 |
+
md: 'btn-md'
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const buttonThemes: Record<ButtonTheme, string> = {
|
| 29 |
+
primary: 'btn-theme-primary',
|
| 30 |
+
secondary: 'btn-theme-secondary',
|
| 31 |
+
yellow: 'btn-theme-yellow',
|
| 32 |
+
danger: 'btn-theme-danger',
|
| 33 |
+
ghost: 'btn-theme-ghost',
|
| 34 |
+
icon: 'btn-theme-icon'
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
export const buttonClassName = ({
|
| 38 |
+
theme = 'primary',
|
| 39 |
+
size = 'md',
|
| 40 |
+
className
|
| 41 |
+
}: {
|
| 42 |
+
theme?: ButtonTheme
|
| 43 |
+
size?: ButtonSize
|
| 44 |
+
className?: string
|
| 45 |
+
} = {}): string =>
|
| 46 |
+
classNames(buttonBaseClass, buttonSizes[size], buttonThemes[theme], className)
|
| 47 |
+
|
| 48 |
+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
| 49 |
+
theme?: ButtonTheme
|
| 50 |
+
size?: ButtonSize
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export const Button = ({
|
| 54 |
+
theme = 'primary',
|
| 55 |
+
size = 'md',
|
| 56 |
+
type = 'button',
|
| 57 |
+
className,
|
| 58 |
+
...rest
|
| 59 |
+
}: ButtonProps) => (
|
| 60 |
+
<button
|
| 61 |
+
type={type}
|
| 62 |
+
className={buttonClassName({ theme, size, className })}
|
| 63 |
+
{...rest}
|
| 64 |
+
/>
|
| 65 |
+
)
|
assets/js/dashboard/components/combobox.js
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
| 1 |
+
import React, {
|
| 2 |
+
Fragment,
|
| 3 |
+
useState,
|
| 4 |
+
useCallback,
|
| 5 |
+
useEffect,
|
| 6 |
+
useRef
|
| 7 |
+
} from 'react'
|
| 8 |
+
import { Spinner } from './icons'
|
| 9 |
+
import { Transition } from '@headlessui/react'
|
| 10 |
+
import { ChevronDownIcon } from '@heroicons/react/20/solid'
|
| 11 |
+
import classNames from 'classnames'
|
| 12 |
+
import { useMountedEffect, useDebounce } from '../custom-hooks'
|
| 13 |
+
|
| 14 |
+
function Option({ isHighlighted, onClick, onMouseEnter, text, id }) {
|
| 15 |
+
const className = classNames(
|
| 16 |
+
'relative cursor-pointer select-none py-2 px-3 text-gray-900 dark:text-gray-300',
|
| 17 |
+
{
|
| 18 |
+
'bg-gray-100 dark:bg-gray-700': isHighlighted
|
| 19 |
+
}
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
return (
|
| 23 |
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
| 24 |
+
<li
|
| 25 |
+
className={className}
|
| 26 |
+
id={id}
|
| 27 |
+
onClick={onClick}
|
| 28 |
+
onMouseEnter={onMouseEnter}
|
| 29 |
+
>
|
| 30 |
+
<span className="block truncate">{text}</span>
|
| 31 |
+
</li>
|
| 32 |
+
)
|
| 33 |
+
}
|
| 34 |
+
function scrollTo(wrapper, id) {
|
| 35 |
+
if (wrapper) {
|
| 36 |
+
const el = wrapper.querySelector('#' + id)
|
| 37 |
+
|
| 38 |
+
if (el) {
|
| 39 |
+
el.scrollIntoView({ block: 'center' })
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function optionId(index) {
|
| 45 |
+
return `plausible-combobox-option-${index}`
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
export default function PlausibleCombobox({
|
| 49 |
+
values,
|
| 50 |
+
fetchOptions,
|
| 51 |
+
singleOption,
|
| 52 |
+
isDisabled,
|
| 53 |
+
autoFocus,
|
| 54 |
+
freeChoice,
|
| 55 |
+
disabledOptions,
|
| 56 |
+
onSelect,
|
| 57 |
+
placeholder,
|
| 58 |
+
forceLoading,
|
| 59 |
+
className,
|
| 60 |
+
boxClass
|
| 61 |
+
}) {
|
| 62 |
+
const isEmpty = values.length === 0
|
| 63 |
+
const [options, setOptions] = useState([])
|
| 64 |
+
const [isLoading, setLoading] = useState(false)
|
| 65 |
+
const [isOpen, setOpen] = useState(false)
|
| 66 |
+
const [search, setSearch] = useState('')
|
| 67 |
+
const [highlightedIndex, setHighlightedIndex] = useState(0)
|
| 68 |
+
const searchRef = useRef(null)
|
| 69 |
+
const containerRef = useRef(null)
|
| 70 |
+
const listRef = useRef(null)
|
| 71 |
+
|
| 72 |
+
const loading = isLoading || !!forceLoading
|
| 73 |
+
|
| 74 |
+
const visibleOptions = [...options]
|
| 75 |
+
if (
|
| 76 |
+
freeChoice &&
|
| 77 |
+
search.length > 0 &&
|
| 78 |
+
options.every((option) => option.value !== search)
|
| 79 |
+
) {
|
| 80 |
+
visibleOptions.push({ value: search, label: search, freeChoice: true })
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
const afterFetchOptions = useCallback((loadedOptions) => {
|
| 84 |
+
setLoading(false)
|
| 85 |
+
setHighlightedIndex(0)
|
| 86 |
+
setOptions(loadedOptions)
|
| 87 |
+
}, [])
|
| 88 |
+
|
| 89 |
+
const initialFetchOptions = useCallback(() => {
|
| 90 |
+
setLoading(true)
|
| 91 |
+
fetchOptions('').then(afterFetchOptions)
|
| 92 |
+
}, [fetchOptions, afterFetchOptions])
|
| 93 |
+
|
| 94 |
+
const searchOptions = useCallback(() => {
|
| 95 |
+
if (isOpen) {
|
| 96 |
+
setLoading(true)
|
| 97 |
+
fetchOptions(search).then(afterFetchOptions)
|
| 98 |
+
}
|
| 99 |
+
}, [search, isOpen, fetchOptions, afterFetchOptions])
|
| 100 |
+
|
| 101 |
+
const debouncedSearchOptions = useDebounce(searchOptions)
|
| 102 |
+
|
| 103 |
+
useEffect(() => {
|
| 104 |
+
if (isOpen) {
|
| 105 |
+
initialFetchOptions()
|
| 106 |
+
}
|
| 107 |
+
}, [isOpen, initialFetchOptions])
|
| 108 |
+
|
| 109 |
+
useMountedEffect(() => {
|
| 110 |
+
debouncedSearchOptions()
|
| 111 |
+
}, [search])
|
| 112 |
+
|
| 113 |
+
function highLight(index) {
|
| 114 |
+
let newIndex = index
|
| 115 |
+
|
| 116 |
+
if (index < 0) {
|
| 117 |
+
newIndex = visibleOptions.length - 1
|
| 118 |
+
} else if (index >= visibleOptions.length) {
|
| 119 |
+
newIndex = 0
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
setHighlightedIndex(newIndex)
|
| 123 |
+
scrollTo(listRef.current, optionId(newIndex))
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
function onKeyDown(e) {
|
| 127 |
+
if (e.key === 'Enter') {
|
| 128 |
+
if (!isOpen || loading || visibleOptions.length === 0) return null
|
| 129 |
+
selectOption(visibleOptions[highlightedIndex])
|
| 130 |
+
e.preventDefault()
|
| 131 |
+
}
|
| 132 |
+
if (e.key === 'Escape') {
|
| 133 |
+
if (!isOpen || loading) return null
|
| 134 |
+
setOpen(false)
|
| 135 |
+
searchRef.current?.focus()
|
| 136 |
+
e.preventDefault()
|
| 137 |
+
}
|
| 138 |
+
if (e.key === 'ArrowDown') {
|
| 139 |
+
if (isOpen) {
|
| 140 |
+
highLight(highlightedIndex + 1)
|
| 141 |
+
} else {
|
| 142 |
+
setOpen(true)
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
if (e.key === 'ArrowUp') {
|
| 146 |
+
if (isOpen) {
|
| 147 |
+
highLight(highlightedIndex - 1)
|
| 148 |
+
} else {
|
| 149 |
+
setOpen(true)
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
function isOptionDisabled(option) {
|
| 155 |
+
const optionAlreadySelected = values.some(
|
| 156 |
+
(val) => val.value === option.value
|
| 157 |
+
)
|
| 158 |
+
const optionDisabled = (disabledOptions || []).some(
|
| 159 |
+
(val) => val?.value === option.value
|
| 160 |
+
)
|
| 161 |
+
return optionAlreadySelected || optionDisabled
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
function onInput(e) {
|
| 165 |
+
if (!isOpen) {
|
| 166 |
+
setOpen(true)
|
| 167 |
+
}
|
| 168 |
+
setSearch(e.target.value)
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
function toggleOpen() {
|
| 172 |
+
if (!isOpen) {
|
| 173 |
+
setOpen(true)
|
| 174 |
+
searchRef.current.focus()
|
| 175 |
+
} else {
|
| 176 |
+
setSearch('')
|
| 177 |
+
setOpen(false)
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
function selectOption(option) {
|
| 182 |
+
if (singleOption) {
|
| 183 |
+
onSelect([option])
|
| 184 |
+
} else {
|
| 185 |
+
searchRef.current.focus()
|
| 186 |
+
onSelect([...values, option])
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
setOpen(false)
|
| 190 |
+
setSearch('')
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
function removeOption(option, e) {
|
| 194 |
+
e.stopPropagation()
|
| 195 |
+
const newValues = values.filter((val) => val.value !== option.value)
|
| 196 |
+
onSelect(newValues)
|
| 197 |
+
searchRef.current.focus()
|
| 198 |
+
setOpen(false)
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
const handleClick = useCallback((e) => {
|
| 202 |
+
if (containerRef.current && containerRef.current.contains(e.target)) {
|
| 203 |
+
return
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
setSearch('')
|
| 207 |
+
setOpen(false)
|
| 208 |
+
}, [])
|
| 209 |
+
|
| 210 |
+
useEffect(() => {
|
| 211 |
+
document.addEventListener('mousedown', handleClick, false)
|
| 212 |
+
return () => {
|
| 213 |
+
document.removeEventListener('mousedown', handleClick, false)
|
| 214 |
+
}
|
| 215 |
+
}, [handleClick])
|
| 216 |
+
|
| 217 |
+
useEffect(() => {
|
| 218 |
+
if (singleOption && isEmpty && autoFocus) {
|
| 219 |
+
searchRef.current.focus()
|
| 220 |
+
}
|
| 221 |
+
}, [isEmpty, singleOption, autoFocus])
|
| 222 |
+
|
| 223 |
+
const searchBoxClass =
|
| 224 |
+
'border-none py-1 px-0 w-full inline-block rounded-md focus:outline-hidden focus:ring-0 text-sm'
|
| 225 |
+
|
| 226 |
+
const containerClass = classNames('relative w-full', {
|
| 227 |
+
[className]: !!className,
|
| 228 |
+
'opacity-30 cursor-default pointer-events-none': isDisabled
|
| 229 |
+
})
|
| 230 |
+
|
| 231 |
+
function renderSingleOptionContent() {
|
| 232 |
+
const itemSelected = values.length === 1
|
| 233 |
+
|
| 234 |
+
return (
|
| 235 |
+
<div className="flex items-center truncate">
|
| 236 |
+
{itemSelected && renderSingleSelectedItem()}
|
| 237 |
+
<input
|
| 238 |
+
className={searchBoxClass}
|
| 239 |
+
ref={searchRef}
|
| 240 |
+
value={search}
|
| 241 |
+
style={{ backgroundColor: 'inherit' }}
|
| 242 |
+
placeholder={itemSelected ? '' : placeholder}
|
| 243 |
+
type="text"
|
| 244 |
+
onChange={onInput}
|
| 245 |
+
></input>
|
| 246 |
+
</div>
|
| 247 |
+
)
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
function renderSingleSelectedItem() {
|
| 251 |
+
if (search === '') {
|
| 252 |
+
return (
|
| 253 |
+
<span className="dark:text-gray-300 text-sm w-0">
|
| 254 |
+
{values[0].label}
|
| 255 |
+
</span>
|
| 256 |
+
)
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
function renderMultiOptionContent() {
|
| 261 |
+
return (
|
| 262 |
+
<>
|
| 263 |
+
{values.map((value) => {
|
| 264 |
+
return (
|
| 265 |
+
<div
|
| 266 |
+
key={value.value}
|
| 267 |
+
className="bg-indigo-100 dark:bg-indigo-600 flex justify-between w-full rounded-xs px-2 py-0.5 m-0.5 text-sm"
|
| 268 |
+
>
|
| 269 |
+
<span className="break-all">{value.label}</span>
|
| 270 |
+
<span
|
| 271 |
+
onClick={(e) => removeOption(value, e)}
|
| 272 |
+
className="cursor-pointer font-bold ml-1"
|
| 273 |
+
>
|
| 274 |
+
×
|
| 275 |
+
</span>
|
| 276 |
+
</div>
|
| 277 |
+
)
|
| 278 |
+
})}
|
| 279 |
+
<input
|
| 280 |
+
className={searchBoxClass}
|
| 281 |
+
ref={searchRef}
|
| 282 |
+
value={search}
|
| 283 |
+
style={{ backgroundColor: 'inherit' }}
|
| 284 |
+
placeholder={placeholder}
|
| 285 |
+
type="text"
|
| 286 |
+
onChange={onInput}
|
| 287 |
+
></input>
|
| 288 |
+
</>
|
| 289 |
+
)
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
function renderDropDownContent() {
|
| 293 |
+
const matchesFound =
|
| 294 |
+
visibleOptions.length > 0 &&
|
| 295 |
+
visibleOptions.some((option) => !isOptionDisabled(option))
|
| 296 |
+
|
| 297 |
+
if (loading) {
|
| 298 |
+
return (
|
| 299 |
+
<div className="relative cursor-default select-none py-2 px-4 text-gray-700 dark:text-gray-300">
|
| 300 |
+
Loading options...
|
| 301 |
+
</div>
|
| 302 |
+
)
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
if (matchesFound) {
|
| 306 |
+
return visibleOptions
|
| 307 |
+
.filter((option) => !isOptionDisabled(option))
|
| 308 |
+
.map((option, i) => {
|
| 309 |
+
const text = option.freeChoice
|
| 310 |
+
? `Filter by '${option.label}'`
|
| 311 |
+
: option.label
|
| 312 |
+
|
| 313 |
+
return (
|
| 314 |
+
<Option
|
| 315 |
+
key={option.value}
|
| 316 |
+
id={optionId(i)}
|
| 317 |
+
isHighlighted={highlightedIndex === i}
|
| 318 |
+
onClick={() => selectOption(option)}
|
| 319 |
+
onMouseEnter={() => setHighlightedIndex(i)}
|
| 320 |
+
text={text}
|
| 321 |
+
/>
|
| 322 |
+
)
|
| 323 |
+
})
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
if (freeChoice) {
|
| 327 |
+
return (
|
| 328 |
+
<div className="relative cursor-default select-none py-2 px-4 text-gray-700 dark:text-gray-300">
|
| 329 |
+
Start typing to apply filter
|
| 330 |
+
</div>
|
| 331 |
+
)
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
return (
|
| 335 |
+
<div className="relative cursor-default select-none py-2 px-4 text-gray-700 dark:text-gray-300">
|
| 336 |
+
No matches found in the current dashboard. Try selecting a different
|
| 337 |
+
time range or searching for something different
|
| 338 |
+
</div>
|
| 339 |
+
)
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
const defaultBoxClass =
|
| 343 |
+
'pl-2 pr-8 py-1 w-full dark:bg-gray-750 dark:text-gray-300 rounded-md shadow-xs border border-gray-300 dark:border-gray-750'
|
| 344 |
+
const finalBoxClass = classNames(boxClass || defaultBoxClass, {
|
| 345 |
+
'ring-3 ring-indigo-500/20 dark:ring-indigo-500/25 border !border-indigo-500':
|
| 346 |
+
isOpen
|
| 347 |
+
})
|
| 348 |
+
|
| 349 |
+
return (
|
| 350 |
+
<div onKeyDown={onKeyDown} ref={containerRef} className={containerClass}>
|
| 351 |
+
<div onClick={toggleOpen} className={finalBoxClass}>
|
| 352 |
+
{singleOption && renderSingleOptionContent()}
|
| 353 |
+
{!singleOption && renderMultiOptionContent()}
|
| 354 |
+
<div className="cursor-pointer absolute inset-y-0 right-0 flex items-center pr-2">
|
| 355 |
+
{!loading && <ChevronDownIcon className="h-4 w-4 text-gray-500" />}
|
| 356 |
+
{loading && (
|
| 357 |
+
<Spinner className="animate-spin size-4 text-indigo-500" />
|
| 358 |
+
)}
|
| 359 |
+
</div>
|
| 360 |
+
</div>
|
| 361 |
+
{isOpen && (
|
| 362 |
+
<Transition
|
| 363 |
+
as={Fragment}
|
| 364 |
+
leave="transition ease-in duration-100"
|
| 365 |
+
leaveFrom="opacity-100"
|
| 366 |
+
leaveTo="opacity-0"
|
| 367 |
+
show={isOpen}
|
| 368 |
+
>
|
| 369 |
+
<ul
|
| 370 |
+
ref={listRef}
|
| 371 |
+
className="z-50 absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1/5 ring-black focus:outline-hidden sm:text-sm dark:bg-gray-800"
|
| 372 |
+
>
|
| 373 |
+
{renderDropDownContent()}
|
| 374 |
+
</ul>
|
| 375 |
+
</Transition>
|
| 376 |
+
)}
|
| 377 |
+
</div>
|
| 378 |
+
)
|
| 379 |
+
}
|
assets/js/dashboard/components/drilldown-link.tsx
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode } from 'react'
|
| 2 |
+
import {
|
| 3 |
+
AppNavigationLink,
|
| 4 |
+
AppNavigationLinkProps
|
| 5 |
+
} from '../navigation/use-app-navigate'
|
| 6 |
+
import classNames from 'classnames'
|
| 7 |
+
import { cleanLabels, replaceFilterByPrefix } from '../util/filters'
|
| 8 |
+
import { plainFilterText } from '../util/filter-text'
|
| 9 |
+
import { useDashboardStateContext } from '../dashboard-state-context'
|
| 10 |
+
import { Filter, FilterClauseLabels } from '../dashboard-state'
|
| 11 |
+
|
| 12 |
+
export type FilterInfo = {
|
| 13 |
+
prefix: string
|
| 14 |
+
filter: Filter
|
| 15 |
+
labels?: FilterClauseLabels
|
| 16 |
+
extraFilters?: Array<{ prefix: string; filter: Filter }>
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
export function DrilldownLink({
|
| 20 |
+
path,
|
| 21 |
+
filterInfo,
|
| 22 |
+
onClick,
|
| 23 |
+
children,
|
| 24 |
+
icon,
|
| 25 |
+
className,
|
| 26 |
+
textClassName
|
| 27 |
+
}: Pick<AppNavigationLinkProps, 'path' | 'onClick' | 'children'> & {
|
| 28 |
+
className?: string
|
| 29 |
+
textClassName?: string
|
| 30 |
+
icon?: ReactNode
|
| 31 |
+
filterInfo: FilterInfo | null
|
| 32 |
+
}) {
|
| 33 |
+
const { dashboardState } = useDashboardStateContext()
|
| 34 |
+
|
| 35 |
+
if (filterInfo) {
|
| 36 |
+
const { prefix, filter, labels, extraFilters = [] } = filterInfo
|
| 37 |
+
let newFilters = replaceFilterByPrefix(dashboardState, prefix, filter)
|
| 38 |
+
let newLabels = cleanLabels(
|
| 39 |
+
newFilters,
|
| 40 |
+
dashboardState.labels,
|
| 41 |
+
filter[1],
|
| 42 |
+
labels
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
for (const ef of extraFilters) {
|
| 46 |
+
newFilters = replaceFilterByPrefix(
|
| 47 |
+
{ ...dashboardState, filters: newFilters },
|
| 48 |
+
ef.prefix,
|
| 49 |
+
ef.filter
|
| 50 |
+
)
|
| 51 |
+
newLabels = cleanLabels(newFilters, newLabels, ef.filter[1], undefined)
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
const allFilters = [filter, ...extraFilters.map((ef) => ef.filter)]
|
| 55 |
+
const title = allFilters
|
| 56 |
+
.map((f) => plainFilterText({ ...dashboardState, labels: newLabels }, f))
|
| 57 |
+
.join(' and ')
|
| 58 |
+
|
| 59 |
+
return (
|
| 60 |
+
<AppNavigationLink
|
| 61 |
+
data-testid="dimension-value"
|
| 62 |
+
title={`Add filter: ${title}`}
|
| 63 |
+
className={classNames(className, 'group')}
|
| 64 |
+
path={path}
|
| 65 |
+
onClick={onClick}
|
| 66 |
+
search={(search) => ({
|
| 67 |
+
...search,
|
| 68 |
+
filters: newFilters,
|
| 69 |
+
labels: newLabels
|
| 70 |
+
})}
|
| 71 |
+
>
|
| 72 |
+
{icon}
|
| 73 |
+
<span className={classNames(textClassName, 'group-hover:underline')}>
|
| 74 |
+
{children}
|
| 75 |
+
</span>
|
| 76 |
+
</AppNavigationLink>
|
| 77 |
+
)
|
| 78 |
+
} else {
|
| 79 |
+
return (
|
| 80 |
+
<span data-testid="dimension-value" className={className}>
|
| 81 |
+
{icon}
|
| 82 |
+
<span className={textClassName}>{children}</span>
|
| 83 |
+
</span>
|
| 84 |
+
)
|
| 85 |
+
}
|
| 86 |
+
}
|
assets/js/dashboard/components/error-panel.tsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode } from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
import {
|
| 4 |
+
ArrowPathIcon,
|
| 5 |
+
ExclamationTriangleIcon,
|
| 6 |
+
XMarkIcon
|
| 7 |
+
} from '@heroicons/react/24/outline'
|
| 8 |
+
|
| 9 |
+
export const ErrorPanel = ({
|
| 10 |
+
errorMessage,
|
| 11 |
+
className,
|
| 12 |
+
onClose,
|
| 13 |
+
onRetry
|
| 14 |
+
}: {
|
| 15 |
+
errorMessage: ReactNode
|
| 16 |
+
className?: string
|
| 17 |
+
onClose?: () => void
|
| 18 |
+
onRetry?: () => void
|
| 19 |
+
}) => (
|
| 20 |
+
<div
|
| 21 |
+
className={classNames(
|
| 22 |
+
'flex gap-x-1 rounded bg-red-100 text-red-600 dark:bg-red-200 dark:text-red-800 p-4',
|
| 23 |
+
className
|
| 24 |
+
)}
|
| 25 |
+
>
|
| 26 |
+
<div className="mt-1 flex">
|
| 27 |
+
<ExclamationTriangleIcon className="block w-4 h-4 shrink-0" />
|
| 28 |
+
</div>
|
| 29 |
+
<div className="break-all text-sm/5">{errorMessage}</div>
|
| 30 |
+
{typeof onClose === 'function' && (
|
| 31 |
+
<button
|
| 32 |
+
className="flex ml-auto w-5 h-5 items-center justify-center hover:text-red-700 dark:hover:text-red-900"
|
| 33 |
+
onClick={onClose}
|
| 34 |
+
title="Close notice"
|
| 35 |
+
>
|
| 36 |
+
<XMarkIcon className="block w-4 h-4 shrink-0" />
|
| 37 |
+
</button>
|
| 38 |
+
)}
|
| 39 |
+
{typeof onRetry === 'function' && (
|
| 40 |
+
<button
|
| 41 |
+
className="flex ml-auto w-5 h-5 items-center justify-center hover:text-red-700 dark:hover:text-red-900"
|
| 42 |
+
onClick={onRetry}
|
| 43 |
+
title="Retry"
|
| 44 |
+
>
|
| 45 |
+
<ArrowPathIcon className="block w-4 h-4 shrink-0" />
|
| 46 |
+
</button>
|
| 47 |
+
)}
|
| 48 |
+
</div>
|
| 49 |
+
)
|
assets/js/dashboard/components/feature-preview-mocks.tsx
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
|
| 4 |
+
/*
|
| 5 |
+
* Non-interactive previews of the Funnels / Properties / Exploration reports,
|
| 6 |
+
* rendered behind the CTA when the feature isn't available on the current
|
| 7 |
+
* plan. They give users an at-a-glance idea of what the report looks like
|
| 8 |
+
* without needing to navigate elsewhere. Always heavily blurred in their
|
| 9 |
+
* parent container, so the goal is to be suggestive rather than pixel-perfect.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
export function PropertiesPreviewMock() {
|
| 13 |
+
const rows = [98, 82, 68, 60, 45, 21, 12, 8, 5, 2]
|
| 14 |
+
|
| 15 |
+
return (
|
| 16 |
+
<div className="size-full flex flex-col gap-1.5 pt-9">
|
| 17 |
+
{rows.map((width, i) => (
|
| 18 |
+
<div
|
| 19 |
+
key={i}
|
| 20 |
+
className="h-7.5 bg-red-200/70 dark:bg-gray-500/30 rounded-sm"
|
| 21 |
+
style={{ width: `${width}%` }}
|
| 22 |
+
/>
|
| 23 |
+
))}
|
| 24 |
+
</div>
|
| 25 |
+
)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
export function FunnelsPreviewMock() {
|
| 29 |
+
const steps = [{ visitors: 100 }, { visitors: 55 }, { visitors: 24 }]
|
| 30 |
+
|
| 31 |
+
return (
|
| 32 |
+
<div className="size-full flex flex-col pt-5">
|
| 33 |
+
<div className="h-4 w-32 bg-gray-400/60 dark:bg-gray-600 rounded-md mb-8" />
|
| 34 |
+
|
| 35 |
+
<div className="flex-1 flex items-end justify-between lg:justify-around gap-6">
|
| 36 |
+
{steps.map((step, i) => (
|
| 37 |
+
<div
|
| 38 |
+
key={i}
|
| 39 |
+
className="relative h-full flex-1 max-w-[160px] flex flex-col justify-end rounded-md overflow-hidden"
|
| 40 |
+
>
|
| 41 |
+
<div
|
| 42 |
+
className="w-full bg-indigo-100 dark:bg-gray-700"
|
| 43 |
+
style={{ height: `${100 - step.visitors}%` }}
|
| 44 |
+
/>
|
| 45 |
+
<div
|
| 46 |
+
className="w-full bg-indigo-500"
|
| 47 |
+
style={{ height: `${step.visitors}%` }}
|
| 48 |
+
/>
|
| 49 |
+
</div>
|
| 50 |
+
))}
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<div className="flex justify-around gap-6 pt-4 pb-2">
|
| 54 |
+
{steps.map((_, i) => (
|
| 55 |
+
<div key={i} className="flex-1 max-w-[160px] flex justify-center">
|
| 56 |
+
<div className="h-3 w-3/5 bg-gray-400/70 dark:bg-gray-600 rounded-md" />
|
| 57 |
+
</div>
|
| 58 |
+
))}
|
| 59 |
+
</div>
|
| 60 |
+
</div>
|
| 61 |
+
)
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export function ExplorationPreviewMock() {
|
| 65 |
+
const columns = [
|
| 66 |
+
[98, 96, 54, 42, 27, 18, 15, 10, 5],
|
| 67 |
+
[88, 70, 68, 30, 18, 16, 10, 9, 5],
|
| 68 |
+
[82, 78, 48, 35, 25, 14, 12, 10, 5]
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
return (
|
| 72 |
+
<div className="size-full flex gap-3 pt-3">
|
| 73 |
+
{columns.map((rows, colIdx) => (
|
| 74 |
+
<div
|
| 75 |
+
key={colIdx}
|
| 76 |
+
className={classNames(
|
| 77 |
+
'flex-1 flex-col rounded-lg border border-gray-400 dark:border-gray-500 overflow-hidden',
|
| 78 |
+
colIdx === 2 ? 'hidden lg:flex' : 'flex'
|
| 79 |
+
)}
|
| 80 |
+
>
|
| 81 |
+
<div className="h-12 shrink-0 flex items-center px-3">
|
| 82 |
+
<div className="h-2.5 w-20 bg-gray-400/70 dark:bg-gray-500/80 rounded" />
|
| 83 |
+
</div>
|
| 84 |
+
<div className="flex flex-col gap-1.5 px-2 pb-2">
|
| 85 |
+
{rows.map((width, i) => (
|
| 86 |
+
<div
|
| 87 |
+
key={i}
|
| 88 |
+
className={
|
| 89 |
+
i === 0 && colIdx === 0
|
| 90 |
+
? 'h-7.5 bg-indigo-300/80 dark:bg-indigo-500/70 rounded-sm'
|
| 91 |
+
: 'h-7.5 bg-indigo-200/70 dark:bg-indigo-500/30 rounded-sm'
|
| 92 |
+
}
|
| 93 |
+
style={{ width: `${width}%` }}
|
| 94 |
+
/>
|
| 95 |
+
))}
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
))}
|
| 99 |
+
</div>
|
| 100 |
+
)
|
| 101 |
+
}
|
assets/js/dashboard/components/feature-setup-notice.tsx
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
import { MODES } from '../stats/behaviours/modes-context'
|
| 4 |
+
import * as api from '../api'
|
| 5 |
+
import { useSiteContext } from '../site-context'
|
| 6 |
+
import { UpgradePill } from './pill'
|
| 7 |
+
import { buttonClassName } from './button'
|
| 8 |
+
|
| 9 |
+
export function FeatureSetupNotice({
|
| 10 |
+
feature,
|
| 11 |
+
title,
|
| 12 |
+
info,
|
| 13 |
+
callToAction,
|
| 14 |
+
secondaryCallToAction,
|
| 15 |
+
onHideAction,
|
| 16 |
+
previewMock
|
| 17 |
+
}: {
|
| 18 |
+
feature: keyof typeof MODES
|
| 19 |
+
title: React.ReactNode
|
| 20 |
+
info: React.ReactNode
|
| 21 |
+
callToAction: { link: string; action: string }
|
| 22 |
+
secondaryCallToAction?: { link: string; action: string }
|
| 23 |
+
onHideAction: (() => void) | null
|
| 24 |
+
previewMock?: React.ReactNode
|
| 25 |
+
}) {
|
| 26 |
+
const site = useSiteContext()
|
| 27 |
+
const sectionTitle = MODES[feature].title
|
| 28 |
+
|
| 29 |
+
const requestHideSection = () => {
|
| 30 |
+
if (
|
| 31 |
+
window.confirm(
|
| 32 |
+
`Are you sure you want to hide ${sectionTitle}? You can make it visible again in your site settings later.`
|
| 33 |
+
)
|
| 34 |
+
) {
|
| 35 |
+
api
|
| 36 |
+
.mutation(`/api/${encodeURIComponent(site.domain)}/disable-feature`, {
|
| 37 |
+
method: 'PUT',
|
| 38 |
+
body: { feature: feature }
|
| 39 |
+
})
|
| 40 |
+
.then(() => onHideAction?.())
|
| 41 |
+
.catch((error) => {
|
| 42 |
+
if (!(error instanceof api.ApiError)) {
|
| 43 |
+
throw error
|
| 44 |
+
}
|
| 45 |
+
})
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function renderCallToAction() {
|
| 50 |
+
return (
|
| 51 |
+
<a
|
| 52 |
+
href={callToAction.link}
|
| 53 |
+
className={buttonClassName({
|
| 54 |
+
theme: 'primary',
|
| 55 |
+
className: 'ml-2 sm:ml-4'
|
| 56 |
+
})}
|
| 57 |
+
>
|
| 58 |
+
{callToAction.action} →
|
| 59 |
+
</a>
|
| 60 |
+
)
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
function renderHideButton() {
|
| 64 |
+
return (
|
| 65 |
+
<button
|
| 66 |
+
onClick={requestHideSection}
|
| 67 |
+
className={buttonClassName({ theme: 'secondary' })}
|
| 68 |
+
>
|
| 69 |
+
Hide this report
|
| 70 |
+
</button>
|
| 71 |
+
)
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function renderSecondaryCallToAction() {
|
| 75 |
+
if (!secondaryCallToAction) {
|
| 76 |
+
return null
|
| 77 |
+
}
|
| 78 |
+
return (
|
| 79 |
+
<a
|
| 80 |
+
href={secondaryCallToAction.link}
|
| 81 |
+
className={buttonClassName({
|
| 82 |
+
theme: 'secondary'
|
| 83 |
+
})}
|
| 84 |
+
>
|
| 85 |
+
{secondaryCallToAction.action}
|
| 86 |
+
</a>
|
| 87 |
+
)
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
return (
|
| 91 |
+
<div
|
| 92 |
+
className={classNames(
|
| 93 |
+
'relative size-full flex items-center justify-center',
|
| 94 |
+
previewMock && 'md:h-[400px]'
|
| 95 |
+
)}
|
| 96 |
+
>
|
| 97 |
+
{previewMock && (
|
| 98 |
+
<div
|
| 99 |
+
aria-hidden="true"
|
| 100 |
+
className="hidden md:block pointer-events-none absolute inset-0 blur-sm opacity-50"
|
| 101 |
+
>
|
| 102 |
+
{previewMock}
|
| 103 |
+
</div>
|
| 104 |
+
)}
|
| 105 |
+
<div
|
| 106 |
+
className={classNames(
|
| 107 |
+
'relative py-3 max-w-2xl',
|
| 108 |
+
previewMock &&
|
| 109 |
+
'max-w-lg md:p-8 md:bg-white md:dark:bg-gray-800 md:border md:border-gray-100 md:dark:border-gray-750 md:rounded-lg md:shadow-xl'
|
| 110 |
+
)}
|
| 111 |
+
>
|
| 112 |
+
{previewMock && (
|
| 113 |
+
<div className="flex justify-center mb-3">
|
| 114 |
+
<UpgradePill plan="Business" color="yellow" />
|
| 115 |
+
</div>
|
| 116 |
+
)}
|
| 117 |
+
<div className="text-center mt-2 text-gray-800 dark:text-gray-200 font-medium text-pretty">
|
| 118 |
+
{title}
|
| 119 |
+
</div>
|
| 120 |
+
<div className="text-center mt-4 font-small text-sm text-gray-500 dark:text-gray-300 text-pretty">
|
| 121 |
+
{info}
|
| 122 |
+
</div>
|
| 123 |
+
<div className="text-xs sm:text-sm flex mt-6 mb-1 justify-center">
|
| 124 |
+
{typeof onHideAction === 'function' && renderHideButton()}
|
| 125 |
+
{renderSecondaryCallToAction()}
|
| 126 |
+
{renderCallToAction()}
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
)
|
| 131 |
+
}
|
assets/js/dashboard/components/filter-operator-selector.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useRef } from 'react'
|
| 2 |
+
|
| 3 |
+
import {
|
| 4 |
+
FILTER_OPERATIONS,
|
| 5 |
+
FILTER_OPERATIONS_DISPLAY_NAMES,
|
| 6 |
+
supportsContains,
|
| 7 |
+
supportsIsNot,
|
| 8 |
+
supportsHasDoneNot
|
| 9 |
+
} from '../util/filters'
|
| 10 |
+
import { Transition, Popover } from '@headlessui/react'
|
| 11 |
+
import { ChevronDownIcon } from '@heroicons/react/20/solid'
|
| 12 |
+
import classNames from 'classnames'
|
| 13 |
+
import { popover, BlurMenuButtonOnEscape } from './popover'
|
| 14 |
+
|
| 15 |
+
export default function FilterOperatorSelector(props) {
|
| 16 |
+
const filterName = props.forFilter
|
| 17 |
+
const buttonRef = useRef()
|
| 18 |
+
|
| 19 |
+
return (
|
| 20 |
+
<div
|
| 21 |
+
className={classNames('w-full', {
|
| 22 |
+
'opacity-20 cursor-default pointer-events-none': props.isDisabled
|
| 23 |
+
})}
|
| 24 |
+
>
|
| 25 |
+
<Popover className="relative w-full">
|
| 26 |
+
{({ close: closeDropdown }) => (
|
| 27 |
+
<>
|
| 28 |
+
<BlurMenuButtonOnEscape targetRef={buttonRef} />
|
| 29 |
+
<Popover.Button
|
| 30 |
+
ref={buttonRef}
|
| 31 |
+
className="relative flex justify-between items-center w-full rounded-md border border-gray-300 dark:border-gray-750 px-4 py-2 bg-white dark:bg-gray-750 text-sm text-gray-700 dark:text-gray-200 dark:hover:bg-gray-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 dark:focus:ring-offset-gray-900 focus:ring-indigo-500 text-left"
|
| 32 |
+
>
|
| 33 |
+
<span data-testid="filter-operator">
|
| 34 |
+
{FILTER_OPERATIONS_DISPLAY_NAMES[props.selectedType]}
|
| 35 |
+
</span>
|
| 36 |
+
<ChevronDownIcon
|
| 37 |
+
className="-mr-2 ml-2 h-4 w-4 text-gray-500 dark:text-gray-400"
|
| 38 |
+
aria-hidden="true"
|
| 39 |
+
/>
|
| 40 |
+
</Popover.Button>
|
| 41 |
+
<Transition
|
| 42 |
+
as="div"
|
| 43 |
+
{...popover.transition.props}
|
| 44 |
+
className={classNames(popover.transition.classNames.left, 'mt-2')}
|
| 45 |
+
>
|
| 46 |
+
<Popover.Panel
|
| 47 |
+
className={classNames(
|
| 48 |
+
popover.panel.classNames.roundedSheet,
|
| 49 |
+
'font-normal'
|
| 50 |
+
)}
|
| 51 |
+
>
|
| 52 |
+
{[
|
| 53 |
+
[FILTER_OPERATIONS.is, true],
|
| 54 |
+
[FILTER_OPERATIONS.isNot, supportsIsNot(filterName)],
|
| 55 |
+
[
|
| 56 |
+
FILTER_OPERATIONS.has_not_done,
|
| 57 |
+
supportsHasDoneNot(filterName)
|
| 58 |
+
],
|
| 59 |
+
[FILTER_OPERATIONS.contains, supportsContains(filterName)],
|
| 60 |
+
[
|
| 61 |
+
FILTER_OPERATIONS.contains_not,
|
| 62 |
+
supportsContains(filterName) && supportsIsNot(filterName)
|
| 63 |
+
]
|
| 64 |
+
]
|
| 65 |
+
.filter(([_operation, supported]) => supported)
|
| 66 |
+
.map(([operation]) => (
|
| 67 |
+
<button
|
| 68 |
+
data-testid="filter-operator-option"
|
| 69 |
+
key={operation}
|
| 70 |
+
data-selected={operation === props.selectedType}
|
| 71 |
+
onClick={(e) => {
|
| 72 |
+
// Prevent the click propagating and closing modal
|
| 73 |
+
e.preventDefault()
|
| 74 |
+
e.stopPropagation()
|
| 75 |
+
props.onSelect(operation)
|
| 76 |
+
closeDropdown()
|
| 77 |
+
}}
|
| 78 |
+
className={classNames(
|
| 79 |
+
'w-full text-left ',
|
| 80 |
+
popover.items.classNames.navigationLink,
|
| 81 |
+
popover.items.classNames.selectedOption,
|
| 82 |
+
popover.items.classNames.hoverLink
|
| 83 |
+
)}
|
| 84 |
+
>
|
| 85 |
+
{FILTER_OPERATIONS_DISPLAY_NAMES[operation]}
|
| 86 |
+
</button>
|
| 87 |
+
))}
|
| 88 |
+
</Popover.Panel>
|
| 89 |
+
</Transition>
|
| 90 |
+
</>
|
| 91 |
+
)}
|
| 92 |
+
</Popover>
|
| 93 |
+
</div>
|
| 94 |
+
)
|
| 95 |
+
}
|
assets/js/dashboard/components/form-elements.tsx
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode } from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
import { Tooltip } from '../util/tooltip'
|
| 4 |
+
|
| 5 |
+
export const getCharacterCount = (value: string): number => [...value].length
|
| 6 |
+
|
| 7 |
+
export const isOverMaxLength = (value: string, maxLength: number): boolean =>
|
| 8 |
+
getCharacterCount(value) > maxLength
|
| 9 |
+
|
| 10 |
+
const fieldClassName =
|
| 11 |
+
'block px-3.5 py-2.5 w-full text-sm dark:text-gray-300 rounded-md border border-gray-300 dark:border-gray-750 dark:bg-gray-750 focus:outline-none focus:ring-3 focus:ring-indigo-500/20 dark:focus:ring-indigo-500/25 focus:border-indigo-500'
|
| 12 |
+
|
| 13 |
+
interface LabeledFieldProps {
|
| 14 |
+
label: string
|
| 15 |
+
id: string
|
| 16 |
+
value: string
|
| 17 |
+
onChange: (value: string) => void
|
| 18 |
+
placeholder: string
|
| 19 |
+
maxLength?: number
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
const LabeledField = ({
|
| 23 |
+
label,
|
| 24 |
+
id,
|
| 25 |
+
value,
|
| 26 |
+
maxLength,
|
| 27 |
+
children
|
| 28 |
+
}: Pick<LabeledFieldProps, 'label' | 'id' | 'value' | 'maxLength'> & {
|
| 29 |
+
children: ReactNode
|
| 30 |
+
}) => (
|
| 31 |
+
<div className="flex flex-col">
|
| 32 |
+
<label
|
| 33 |
+
htmlFor={id}
|
| 34 |
+
className="block mb-1.5 text-sm font-medium dark:text-gray-100 text-gray-700 dark:text-gray-300"
|
| 35 |
+
>
|
| 36 |
+
{label}
|
| 37 |
+
</label>
|
| 38 |
+
{children}
|
| 39 |
+
{maxLength !== undefined && (
|
| 40 |
+
<CharacterCounter
|
| 41 |
+
id={`${id}-counter`}
|
| 42 |
+
length={getCharacterCount(value)}
|
| 43 |
+
maxLength={maxLength}
|
| 44 |
+
/>
|
| 45 |
+
)}
|
| 46 |
+
</div>
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
export const LabeledTextInput = ({
|
| 50 |
+
label,
|
| 51 |
+
id,
|
| 52 |
+
value,
|
| 53 |
+
onChange,
|
| 54 |
+
placeholder,
|
| 55 |
+
maxLength
|
| 56 |
+
}: LabeledFieldProps) => (
|
| 57 |
+
<LabeledField label={label} id={id} value={value} maxLength={maxLength}>
|
| 58 |
+
<input
|
| 59 |
+
autoComplete="off"
|
| 60 |
+
id={id}
|
| 61 |
+
value={value}
|
| 62 |
+
onChange={(e) => onChange(e.target.value)}
|
| 63 |
+
placeholder={placeholder}
|
| 64 |
+
aria-describedby={maxLength !== undefined ? `${id}-counter` : undefined}
|
| 65 |
+
className={fieldClassName}
|
| 66 |
+
/>
|
| 67 |
+
</LabeledField>
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
export const LabeledTextarea = ({
|
| 71 |
+
label,
|
| 72 |
+
id,
|
| 73 |
+
value,
|
| 74 |
+
onChange,
|
| 75 |
+
placeholder,
|
| 76 |
+
maxLength,
|
| 77 |
+
rows = 3
|
| 78 |
+
}: LabeledFieldProps & {
|
| 79 |
+
rows?: number
|
| 80 |
+
}) => (
|
| 81 |
+
<LabeledField label={label} id={id} value={value} maxLength={maxLength}>
|
| 82 |
+
<textarea
|
| 83 |
+
autoComplete="off"
|
| 84 |
+
id={id}
|
| 85 |
+
value={value}
|
| 86 |
+
onChange={(e) => onChange(e.target.value)}
|
| 87 |
+
placeholder={placeholder}
|
| 88 |
+
rows={rows}
|
| 89 |
+
aria-describedby={maxLength !== undefined ? `${id}-counter` : undefined}
|
| 90 |
+
className={classNames(fieldClassName, 'resize-y leading-5')}
|
| 91 |
+
/>
|
| 92 |
+
</LabeledField>
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
const CharacterCounter = ({
|
| 96 |
+
id,
|
| 97 |
+
length,
|
| 98 |
+
maxLength
|
| 99 |
+
}: {
|
| 100 |
+
id: string
|
| 101 |
+
length: number
|
| 102 |
+
maxLength: number
|
| 103 |
+
}) => {
|
| 104 |
+
const closeToLimit = length > maxLength * 0.8
|
| 105 |
+
const visible = closeToLimit
|
| 106 |
+
const overLimit = length > maxLength
|
| 107 |
+
return (
|
| 108 |
+
<p
|
| 109 |
+
id={id}
|
| 110 |
+
className="mt-1.5 text-xs text-gray-500 dark:text-gray-400"
|
| 111 |
+
aria-live="polite"
|
| 112 |
+
>
|
| 113 |
+
{visible ? (
|
| 114 |
+
<span>
|
| 115 |
+
{`Max: ${maxLength} characters. You've used `}
|
| 116 |
+
<span
|
| 117 |
+
className={classNames('font-semibold', {
|
| 118 |
+
'text-red-500 dark:text-red-400': overLimit
|
| 119 |
+
})}
|
| 120 |
+
>
|
| 121 |
+
{length}
|
| 122 |
+
</span>
|
| 123 |
+
</span>
|
| 124 |
+
) : (
|
| 125 |
+
// reserve 1 line worth of room to avoid layout jumps when the count appears
|
| 126 |
+
<span className="opacity-0 select-none"> </span>
|
| 127 |
+
)}
|
| 128 |
+
</p>
|
| 129 |
+
)
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
export const TypeSelector = <T extends string>({
|
| 133 |
+
value,
|
| 134 |
+
onChange,
|
| 135 |
+
options,
|
| 136 |
+
idPrefix
|
| 137 |
+
}: {
|
| 138 |
+
value: T
|
| 139 |
+
onChange: (value: T) => void
|
| 140 |
+
options: {
|
| 141 |
+
type: T
|
| 142 |
+
name: string
|
| 143 |
+
description: string
|
| 144 |
+
disabled?: boolean
|
| 145 |
+
pill?: ReactNode
|
| 146 |
+
tooltipContent?: ReactNode
|
| 147 |
+
}[]
|
| 148 |
+
idPrefix: string
|
| 149 |
+
}) => {
|
| 150 |
+
return (
|
| 151 |
+
<div className="flex flex-col gap-y-2">
|
| 152 |
+
{options.map(
|
| 153 |
+
({ type, name, description, disabled, pill, tooltipContent }) => {
|
| 154 |
+
const row = (
|
| 155 |
+
<label
|
| 156 |
+
htmlFor={`${idPrefix}-${type}`}
|
| 157 |
+
className={classNames(
|
| 158 |
+
'flex flex-col text-sm font-medium dark:text-gray-100',
|
| 159 |
+
disabled && 'cursor-not-allowed'
|
| 160 |
+
)}
|
| 161 |
+
>
|
| 162 |
+
<div className="flex items-center gap-x-3">
|
| 163 |
+
<input
|
| 164 |
+
checked={value === type}
|
| 165 |
+
id={`${idPrefix}-${type}`}
|
| 166 |
+
type="radio"
|
| 167 |
+
value=""
|
| 168 |
+
onChange={() => onChange(type)}
|
| 169 |
+
disabled={disabled}
|
| 170 |
+
className={classNames(
|
| 171 |
+
'size-4.5 text-indigo-600 dark:bg-transparent border-gray-400 dark:border-gray-600 checked:border-indigo-600 dark:checked:border-white',
|
| 172 |
+
disabled
|
| 173 |
+
? 'cursor-not-allowed opacity-50'
|
| 174 |
+
: 'cursor-pointer'
|
| 175 |
+
)}
|
| 176 |
+
/>
|
| 177 |
+
<div className="flex items-center gap-x-2">
|
| 178 |
+
<span className={classNames(disabled && 'opacity-50')}>
|
| 179 |
+
{name}
|
| 180 |
+
</span>
|
| 181 |
+
{pill}
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
<div
|
| 185 |
+
className={classNames(
|
| 186 |
+
'ml-[1.875rem] text-gray-500 dark:text-gray-400 text-sm font-normal',
|
| 187 |
+
disabled && 'opacity-50'
|
| 188 |
+
)}
|
| 189 |
+
>
|
| 190 |
+
{description}
|
| 191 |
+
</div>
|
| 192 |
+
</label>
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
return (
|
| 196 |
+
<div key={type}>
|
| 197 |
+
{tooltipContent ? (
|
| 198 |
+
<Tooltip info={tooltipContent}>{row}</Tooltip>
|
| 199 |
+
) : (
|
| 200 |
+
row
|
| 201 |
+
)}
|
| 202 |
+
</div>
|
| 203 |
+
)
|
| 204 |
+
}
|
| 205 |
+
)}
|
| 206 |
+
</div>
|
| 207 |
+
)
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
export type OptionDisabledMessageType =
|
| 211 |
+
| 'upgrade-subscription-yourself'
|
| 212 |
+
| 'upgrade-subscription-reach-out'
|
| 213 |
+
| 'no-permissions'
|
| 214 |
+
|
| 215 |
+
export const getOptionDisabledMessage = ({
|
| 216 |
+
optionAvailable,
|
| 217 |
+
userHasOptionPermissions,
|
| 218 |
+
userCanUpgradeSubscription
|
| 219 |
+
}: {
|
| 220 |
+
optionAvailable: boolean
|
| 221 |
+
userHasOptionPermissions: boolean
|
| 222 |
+
userCanUpgradeSubscription: boolean
|
| 223 |
+
}): null | OptionDisabledMessageType => {
|
| 224 |
+
if (!userHasOptionPermissions) {
|
| 225 |
+
return 'no-permissions'
|
| 226 |
+
}
|
| 227 |
+
if (!optionAvailable) {
|
| 228 |
+
if (userCanUpgradeSubscription) {
|
| 229 |
+
return 'upgrade-subscription-yourself'
|
| 230 |
+
}
|
| 231 |
+
return 'upgrade-subscription-reach-out'
|
| 232 |
+
}
|
| 233 |
+
return null
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
/** Keep this component styled the same as checkboxes in PlausibleWeb.Live.Installation.Instructions */
|
| 237 |
+
export const Checkbox = ({
|
| 238 |
+
id,
|
| 239 |
+
checked,
|
| 240 |
+
onChange,
|
| 241 |
+
children
|
| 242 |
+
}: React.DetailedHTMLProps<
|
| 243 |
+
React.InputHTMLAttributes<HTMLInputElement>,
|
| 244 |
+
HTMLInputElement
|
| 245 |
+
>) => {
|
| 246 |
+
return (
|
| 247 |
+
<label
|
| 248 |
+
className="text-sm block font-medium dark:text-gray-100 font-normal gap-x-2 flex flex-inline items-center justify-start"
|
| 249 |
+
htmlFor={id}
|
| 250 |
+
>
|
| 251 |
+
<input
|
| 252 |
+
className="block size-5 rounded-sm dark:bg-gray-600 border-gray-300 dark:border-gray-600 text-indigo-600"
|
| 253 |
+
id={id}
|
| 254 |
+
type="checkbox"
|
| 255 |
+
checked={checked}
|
| 256 |
+
onChange={onChange}
|
| 257 |
+
/>
|
| 258 |
+
{children}
|
| 259 |
+
</label>
|
| 260 |
+
)
|
| 261 |
+
}
|
assets/js/dashboard/components/graph-tooltip.tsx
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode, RefObject, useLayoutEffect, useState } from 'react'
|
| 2 |
+
import {
|
| 3 |
+
Transition,
|
| 4 |
+
TransitionClasses,
|
| 5 |
+
TransitionEvents
|
| 6 |
+
} from '@headlessui/react'
|
| 7 |
+
|
| 8 |
+
type GraphTooltipWrapperProps = {
|
| 9 |
+
verticalAnchor: 'topEdge' | 'bottomEdge'
|
| 10 |
+
horizontalAnchor: 'start' | 'middle'
|
| 11 |
+
x: number
|
| 12 |
+
y: number
|
| 13 |
+
maxX: number
|
| 14 |
+
minWidth: number
|
| 15 |
+
children: ReactNode
|
| 16 |
+
className?: string
|
| 17 |
+
transition?: TransitionClasses & TransitionEvents
|
| 18 |
+
wrapperRef: RefObject<HTMLDivElement>
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export const GraphTooltipWrapper = ({
|
| 22 |
+
verticalAnchor,
|
| 23 |
+
horizontalAnchor,
|
| 24 |
+
x,
|
| 25 |
+
y,
|
| 26 |
+
maxX,
|
| 27 |
+
minWidth,
|
| 28 |
+
children,
|
| 29 |
+
className,
|
| 30 |
+
transition,
|
| 31 |
+
wrapperRef
|
| 32 |
+
}: GraphTooltipWrapperProps) => {
|
| 33 |
+
const minX = 0
|
| 34 |
+
const xOffsetFromStart = 12
|
| 35 |
+
|
| 36 |
+
const [measuredWidth, setMeasuredWidth] = useState(minWidth)
|
| 37 |
+
|
| 38 |
+
const leftByAlignment = {
|
| 39 |
+
start: {
|
| 40 |
+
alignedRight: x + xOffsetFromStart,
|
| 41 |
+
alignedLeft: x - xOffsetFromStart - measuredWidth,
|
| 42 |
+
alignedRightClamped: Math.max(0, Math.min(x, maxX - measuredWidth))
|
| 43 |
+
},
|
| 44 |
+
middle: {
|
| 45 |
+
alignedRight: x - measuredWidth / 2,
|
| 46 |
+
alignedLeft: x - measuredWidth / 2,
|
| 47 |
+
alignedRightClamped: Math.max(
|
| 48 |
+
minX,
|
| 49 |
+
Math.min(x - measuredWidth / 2, maxX - measuredWidth)
|
| 50 |
+
)
|
| 51 |
+
}
|
| 52 |
+
}[horizontalAnchor]
|
| 53 |
+
|
| 54 |
+
const canFitRight = {
|
| 55 |
+
start: leftByAlignment.alignedRight + measuredWidth <= maxX,
|
| 56 |
+
middle: x - measuredWidth / 2 >= minX && x + measuredWidth / 2 <= maxX
|
| 57 |
+
}[horizontalAnchor]
|
| 58 |
+
|
| 59 |
+
const canFitLeft = {
|
| 60 |
+
start: leftByAlignment.alignedLeft >= minX,
|
| 61 |
+
middle: false
|
| 62 |
+
}[horizontalAnchor]
|
| 63 |
+
|
| 64 |
+
const position = canFitRight
|
| 65 |
+
? 'alignedRight'
|
| 66 |
+
: canFitLeft
|
| 67 |
+
? 'alignedLeft'
|
| 68 |
+
: 'alignedRightClamped'
|
| 69 |
+
|
| 70 |
+
useLayoutEffect(() => {
|
| 71 |
+
if (!wrapperRef?.current) {
|
| 72 |
+
return
|
| 73 |
+
}
|
| 74 |
+
const el = wrapperRef.current
|
| 75 |
+
const w = el.getBoundingClientRect().width
|
| 76 |
+
setMeasuredWidth(w)
|
| 77 |
+
}, [x, maxX, minWidth, className, children, wrapperRef])
|
| 78 |
+
|
| 79 |
+
const extraStyleByVerticalAnchor = {
|
| 80 |
+
topEdge: {},
|
| 81 |
+
bottomEdge: { transform: 'translateY(-100%)' }
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
return (
|
| 85 |
+
<Transition as={React.Fragment} appear show {...transition}>
|
| 86 |
+
<div
|
| 87 |
+
ref={wrapperRef}
|
| 88 |
+
className={className}
|
| 89 |
+
style={{
|
| 90 |
+
minWidth,
|
| 91 |
+
left: leftByAlignment[position],
|
| 92 |
+
top: y,
|
| 93 |
+
...extraStyleByVerticalAnchor[verticalAnchor]
|
| 94 |
+
}}
|
| 95 |
+
>
|
| 96 |
+
{children}
|
| 97 |
+
</div>
|
| 98 |
+
</Transition>
|
| 99 |
+
)
|
| 100 |
+
}
|
assets/js/dashboard/components/graph.test.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getSuggestedXTickValues, getXDomain } from './graph'
|
| 2 |
+
import * as d3 from 'd3'
|
| 3 |
+
|
| 4 |
+
describe(`${getXDomain.name}`, () => {
|
| 5 |
+
it('returns [0, 1] for a single bucket to avoid a zero-width domain', () => {
|
| 6 |
+
expect(getXDomain(1)).toEqual([0, 1])
|
| 7 |
+
})
|
| 8 |
+
it('returns [0, bucketCount - 1] for multiple buckets', () => {
|
| 9 |
+
expect(getXDomain(5)).toEqual([0, 4])
|
| 10 |
+
})
|
| 11 |
+
})
|
| 12 |
+
|
| 13 |
+
const anyRange = [0, 100]
|
| 14 |
+
describe(`${getSuggestedXTickValues.name}`, () => {
|
| 15 |
+
it('handles 1 bucket', () => {
|
| 16 |
+
const data = new Array(1).fill(0)
|
| 17 |
+
expect(
|
| 18 |
+
getSuggestedXTickValues(
|
| 19 |
+
d3.scaleLinear(getXDomain(data.length), anyRange),
|
| 20 |
+
data.length
|
| 21 |
+
)
|
| 22 |
+
).toEqual([[0, 1]])
|
| 23 |
+
})
|
| 24 |
+
|
| 25 |
+
it('handles 2 buckets', () => {
|
| 26 |
+
const data = new Array(2).fill(0)
|
| 27 |
+
expect(
|
| 28 |
+
getSuggestedXTickValues(
|
| 29 |
+
d3.scaleLinear(getXDomain(data.length), anyRange),
|
| 30 |
+
data.length
|
| 31 |
+
)
|
| 32 |
+
).toEqual([[0, 1]])
|
| 33 |
+
})
|
| 34 |
+
|
| 35 |
+
it('handles 7 buckets', () => {
|
| 36 |
+
const data = new Array(7).fill(0)
|
| 37 |
+
expect(
|
| 38 |
+
getSuggestedXTickValues(
|
| 39 |
+
d3.scaleLinear(getXDomain(data.length), anyRange),
|
| 40 |
+
data.length
|
| 41 |
+
)
|
| 42 |
+
).toEqual([
|
| 43 |
+
[0, 1, 2, 3, 4, 5, 6],
|
| 44 |
+
[0, 2, 4, 6],
|
| 45 |
+
[0, 5]
|
| 46 |
+
])
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
it('handles 24 buckets (day by hours)', () => {
|
| 50 |
+
const data = new Array(24).fill(0)
|
| 51 |
+
expect(
|
| 52 |
+
getSuggestedXTickValues(
|
| 53 |
+
d3.scaleLinear(getXDomain(data.length), anyRange),
|
| 54 |
+
data.length
|
| 55 |
+
)
|
| 56 |
+
).toEqual([
|
| 57 |
+
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],
|
| 58 |
+
[0, 5, 10, 15, 20],
|
| 59 |
+
[0, 10, 20],
|
| 60 |
+
[0, 20]
|
| 61 |
+
])
|
| 62 |
+
})
|
| 63 |
+
|
| 64 |
+
it('handles 28 buckets', () => {
|
| 65 |
+
const data = new Array(28).fill(0)
|
| 66 |
+
expect(
|
| 67 |
+
getSuggestedXTickValues(
|
| 68 |
+
d3.scaleLinear(getXDomain(data.length), anyRange),
|
| 69 |
+
data.length
|
| 70 |
+
)
|
| 71 |
+
).toEqual([
|
| 72 |
+
[0, 5, 10, 15, 20, 25],
|
| 73 |
+
[0, 10, 20],
|
| 74 |
+
[0, 20]
|
| 75 |
+
])
|
| 76 |
+
})
|
| 77 |
+
|
| 78 |
+
it('handles 91 buckets', () => {
|
| 79 |
+
const data = new Array(91).fill(0)
|
| 80 |
+
expect(
|
| 81 |
+
getSuggestedXTickValues(
|
| 82 |
+
d3.scaleLinear(getXDomain(data.length), anyRange),
|
| 83 |
+
data.length
|
| 84 |
+
)
|
| 85 |
+
).toEqual([
|
| 86 |
+
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90],
|
| 87 |
+
[0, 20, 40, 60, 80],
|
| 88 |
+
[0, 50],
|
| 89 |
+
[0]
|
| 90 |
+
])
|
| 91 |
+
})
|
| 92 |
+
|
| 93 |
+
it('handles 700 buckets', () => {
|
| 94 |
+
const data = new Array(700).fill(0)
|
| 95 |
+
expect(
|
| 96 |
+
getSuggestedXTickValues(
|
| 97 |
+
d3.scaleLinear(getXDomain(data.length), anyRange),
|
| 98 |
+
data.length
|
| 99 |
+
)
|
| 100 |
+
).toEqual([
|
| 101 |
+
[0, 100, 200, 300, 400, 500, 600],
|
| 102 |
+
[0, 200, 400, 600],
|
| 103 |
+
[0, 500]
|
| 104 |
+
])
|
| 105 |
+
})
|
| 106 |
+
})
|
assets/js/dashboard/components/graph.tsx
ADDED
|
@@ -0,0 +1,992 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, {
|
| 2 |
+
ReactNode,
|
| 3 |
+
useCallback,
|
| 4 |
+
useEffect,
|
| 5 |
+
useRef,
|
| 6 |
+
useState
|
| 7 |
+
} from 'react'
|
| 8 |
+
import * as d3 from 'd3'
|
| 9 |
+
import classNames from 'classnames'
|
| 10 |
+
|
| 11 |
+
const ANNOTATION_DIAMOND_SIZE_PX = 3
|
| 12 |
+
const IDEAL_Y_TICK_COUNT = 5
|
| 13 |
+
const MAX_X_TICK_COUNT = 8
|
| 14 |
+
const X_TICK_LENGTH_PX = 4
|
| 15 |
+
const MINIMUM_X_LABEL_GAP_PX = 8
|
| 16 |
+
const HIGHLIGHT_LINE_VERTICAL_SPILL_PX = 4
|
| 17 |
+
|
| 18 |
+
type GraphYValues = ReadonlyArray<number | null>
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* To ensure the effect to redraw the chart only runs when needed,
|
| 22 |
+
* make sure these props don't change on every render of the parent.
|
| 23 |
+
*/
|
| 24 |
+
type GraphProps<
|
| 25 |
+
T extends GraphYValues,
|
| 26 |
+
U = { [K in keyof T]: SeriesConfig }
|
| 27 |
+
> = {
|
| 28 |
+
className: string
|
| 29 |
+
width: number
|
| 30 |
+
height: number
|
| 31 |
+
/** pixels off the chart area that data is still hovered */
|
| 32 |
+
hoverBuffer: number
|
| 33 |
+
marginTop: number
|
| 34 |
+
marginRight: number
|
| 35 |
+
marginBottom: number
|
| 36 |
+
/** initial guess for left margin, automatically enlarged to fit y tick texts */
|
| 37 |
+
defaultMarginLeft: number
|
| 38 |
+
data: Datum<T>[]
|
| 39 |
+
annotationsByIndex: { count: number }[]
|
| 40 |
+
yMax: number
|
| 41 |
+
onPointerEnter: (event: unknown) => void
|
| 42 |
+
onPointerMove: PointerHandler<T>
|
| 43 |
+
onPointerLeave: (event: unknown) => void
|
| 44 |
+
onGotPointerCapture: (event: unknown) => void
|
| 45 |
+
onClick?: PointerHandler<T>
|
| 46 |
+
onContextMenu?: PointerHandler<T>
|
| 47 |
+
yFormat: (domainValue: d3.NumberValue, index: number) => string
|
| 48 |
+
/**
|
| 49 |
+
* Things are drawn in the order of settings,
|
| 50 |
+
* so if one series needs to be drawn on top of the other,
|
| 51 |
+
* it has to be after the other in the settings array.
|
| 52 |
+
*/
|
| 53 |
+
settings: U
|
| 54 |
+
gradients: {
|
| 55 |
+
id: string
|
| 56 |
+
stopTop: { color: string; opacity: number }
|
| 57 |
+
stopBottom: { color: string; opacity: number }
|
| 58 |
+
}[]
|
| 59 |
+
children?: ReactNode
|
| 60 |
+
highlightedIndex?: number | null
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* Usage:
|
| 65 |
+
* By setting `T` to `Readonly<[number | null, number | null, number | null]>>`
|
| 66 |
+
* the graph is configured to draw 3 series.
|
| 67 |
+
*/
|
| 68 |
+
export function Graph<T extends GraphYValues>({
|
| 69 |
+
children,
|
| 70 |
+
...rest
|
| 71 |
+
}: GraphProps<T>) {
|
| 72 |
+
const { height, width } = rest
|
| 73 |
+
return (
|
| 74 |
+
<div
|
| 75 |
+
className="relative flex justify-center items-center w-full"
|
| 76 |
+
style={{ height: height, maxWidth: width }}
|
| 77 |
+
>
|
| 78 |
+
<InnerGraph {...rest} />
|
| 79 |
+
{children}
|
| 80 |
+
</div>
|
| 81 |
+
)
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
const highlightIndicatorGroupId = 'highlight-indicator'
|
| 85 |
+
const annotationsGroupId = 'annotations'
|
| 86 |
+
|
| 87 |
+
function InnerGraph<T extends GraphYValues>({
|
| 88 |
+
className,
|
| 89 |
+
width,
|
| 90 |
+
height,
|
| 91 |
+
hoverBuffer,
|
| 92 |
+
marginBottom,
|
| 93 |
+
marginTop,
|
| 94 |
+
defaultMarginLeft,
|
| 95 |
+
marginRight,
|
| 96 |
+
data,
|
| 97 |
+
yMax,
|
| 98 |
+
onPointerMove,
|
| 99 |
+
onPointerLeave,
|
| 100 |
+
onGotPointerCapture,
|
| 101 |
+
onPointerEnter,
|
| 102 |
+
onClick,
|
| 103 |
+
onContextMenu,
|
| 104 |
+
yFormat,
|
| 105 |
+
settings,
|
| 106 |
+
gradients,
|
| 107 |
+
highlightedIndex,
|
| 108 |
+
annotationsByIndex
|
| 109 |
+
}: GraphProps<T>) {
|
| 110 |
+
const [extraMarginLeft, setExtraMarginLeft] = useState(0)
|
| 111 |
+
const [points, setPoints] = useState<Point<T>[]>([])
|
| 112 |
+
const marginLeft = defaultMarginLeft + extraMarginLeft
|
| 113 |
+
const xLeftEdge = marginLeft
|
| 114 |
+
const xRightEdge = width - marginRight
|
| 115 |
+
const yTopEdge = marginTop
|
| 116 |
+
const yBottomEdge = height - marginBottom
|
| 117 |
+
|
| 118 |
+
const svgRef = useRef<SVGSVGElement | null>(null)
|
| 119 |
+
|
| 120 |
+
// Effect to redraw the chart from scratch
|
| 121 |
+
useEffect(() => {
|
| 122 |
+
if (!svgRef.current) {
|
| 123 |
+
return
|
| 124 |
+
}
|
| 125 |
+
const svgBoundingClientRect = svgRef.current.getBoundingClientRect()
|
| 126 |
+
const minClientX = svgBoundingClientRect.left
|
| 127 |
+
const maxClientX = svgBoundingClientRect.right
|
| 128 |
+
|
| 129 |
+
// Declare the y (vertical position) scale.
|
| 130 |
+
const y = getYScale({ yMax, yBottomEdge, yTopEdge })
|
| 131 |
+
|
| 132 |
+
const optimalYTickValues = getOptimalYTickValues(y, yMax)
|
| 133 |
+
|
| 134 |
+
const svg = d3.select(svgRef.current)
|
| 135 |
+
|
| 136 |
+
const cleanup = () => {
|
| 137 |
+
setPoints([])
|
| 138 |
+
svg.selectAll('*').remove()
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// Hide svg until ready
|
| 142 |
+
svg.attr('opacity', 0)
|
| 143 |
+
const { textOffset } = fitYAxis({
|
| 144 |
+
buildAxis: () =>
|
| 145 |
+
svg
|
| 146 |
+
.append('g')
|
| 147 |
+
.attr('class', 'y-axis--container')
|
| 148 |
+
.attr('transform', `translate(${xLeftEdge}, 0)`)
|
| 149 |
+
.call(
|
| 150 |
+
d3
|
| 151 |
+
.axisLeft(y)
|
| 152 |
+
.tickFormat(yFormat)
|
| 153 |
+
.tickSize(0)
|
| 154 |
+
.tickValues(optimalYTickValues)
|
| 155 |
+
)
|
| 156 |
+
.call((g) => g.select('.domain').remove())
|
| 157 |
+
.call((g) => g.selectAll('.tick').attr('class', 'tick group'))
|
| 158 |
+
.call((g) => g.selectAll('.tick text').attr('class', tickTextClass))
|
| 159 |
+
.call((g) =>
|
| 160 |
+
g
|
| 161 |
+
.selectAll('.tick line')
|
| 162 |
+
.clone()
|
| 163 |
+
.attr(
|
| 164 |
+
'x2',
|
| 165 |
+
getChartAreaWidth({
|
| 166 |
+
width,
|
| 167 |
+
marginLeft,
|
| 168 |
+
marginRight
|
| 169 |
+
})
|
| 170 |
+
)
|
| 171 |
+
.attr('class', yTickLineClass)
|
| 172 |
+
),
|
| 173 |
+
minClientX
|
| 174 |
+
})
|
| 175 |
+
const adjustmentIncrement = 4
|
| 176 |
+
if (textOffset < 0) {
|
| 177 |
+
const adjustmentSteps = Math.ceil(-textOffset / adjustmentIncrement)
|
| 178 |
+
setExtraMarginLeft((curr) => curr + adjustmentSteps * adjustmentIncrement)
|
| 179 |
+
return cleanup
|
| 180 |
+
} else if (extraMarginLeft !== 0 && textOffset > 1 * adjustmentIncrement) {
|
| 181 |
+
const adjustmentSteps = Math.floor(textOffset / adjustmentIncrement)
|
| 182 |
+
setExtraMarginLeft((curr) =>
|
| 183 |
+
Math.max(curr - adjustmentSteps * adjustmentIncrement, 0)
|
| 184 |
+
)
|
| 185 |
+
return cleanup
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
const bucketCount = data.length
|
| 189 |
+
const x = getXScale({
|
| 190 |
+
domain: getXDomain(bucketCount),
|
| 191 |
+
xLeftEdge,
|
| 192 |
+
xRightEdge
|
| 193 |
+
})
|
| 194 |
+
const suggestedXTickValues = getSuggestedXTickValues(x, bucketCount)
|
| 195 |
+
|
| 196 |
+
// Add the x-axis
|
| 197 |
+
const xAxisSelection = svg
|
| 198 |
+
.append('g')
|
| 199 |
+
.attr('class', 'x-axis--container')
|
| 200 |
+
.attr('transform', `translate(0,${yBottomEdge})`)
|
| 201 |
+
|
| 202 |
+
fitXAxis({
|
| 203 |
+
xAxisSelection,
|
| 204 |
+
buildAxis: (xTickValues) =>
|
| 205 |
+
xAxisSelection
|
| 206 |
+
.append('g')
|
| 207 |
+
.attr('class', 'x-axis')
|
| 208 |
+
.call(
|
| 209 |
+
d3
|
| 210 |
+
.axisBottom(x)
|
| 211 |
+
.tickValues(xTickValues)
|
| 212 |
+
.tickSize(X_TICK_LENGTH_PX)
|
| 213 |
+
.tickFormat(getXTickFormat(data))
|
| 214 |
+
)
|
| 215 |
+
.call((g) => g.select('.domain').remove())
|
| 216 |
+
.call((g) => g.selectAll('.tick').attr('class', 'tick group'))
|
| 217 |
+
.call((g) =>
|
| 218 |
+
g.selectAll('.tick line').attr('class', classNames(xTickLineClass))
|
| 219 |
+
)
|
| 220 |
+
.call((g) =>
|
| 221 |
+
g
|
| 222 |
+
.selectAll('.tick text')
|
| 223 |
+
.attr('class', classNames(tickTextClass, 'translate-y-2'))
|
| 224 |
+
),
|
| 225 |
+
suggestedXTickValues,
|
| 226 |
+
minClientX,
|
| 227 |
+
maxClientX
|
| 228 |
+
})
|
| 229 |
+
|
| 230 |
+
for (const gradient of gradients) {
|
| 231 |
+
addGradient({
|
| 232 |
+
svg,
|
| 233 |
+
id: gradient.id,
|
| 234 |
+
stopTop: gradient.stopTop,
|
| 235 |
+
stopBottom: gradient.stopBottom
|
| 236 |
+
})
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// must be on top of gradients, but under lines and points
|
| 240 |
+
svg.append('g').attr('id', highlightIndicatorGroupId)
|
| 241 |
+
|
| 242 |
+
const points: Point<T>[] = []
|
| 243 |
+
for (const [seriesIndex, series] of settings.entries()) {
|
| 244 |
+
if (series.underline) {
|
| 245 |
+
drawAreaUnderLine({
|
| 246 |
+
svg,
|
| 247 |
+
gradientId: series.underline.gradientId,
|
| 248 |
+
datum: data,
|
| 249 |
+
isDefined: (d) => d.values[seriesIndex] !== null,
|
| 250 |
+
xAccessor: (_d, index) => x(index),
|
| 251 |
+
y0Accessor: yBottomEdge,
|
| 252 |
+
y1Accessor: (d) => y(d.values[seriesIndex]!)
|
| 253 |
+
})
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
for (const [seriesIndex, series] of settings.entries()) {
|
| 258 |
+
if (series.lines) {
|
| 259 |
+
for (const line of series.lines) {
|
| 260 |
+
drawLine({
|
| 261 |
+
svg,
|
| 262 |
+
datum: data,
|
| 263 |
+
isDefined: (d, i) => {
|
| 264 |
+
const valueDefined = d.values[seriesIndex] !== null
|
| 265 |
+
const atOrOverStart =
|
| 266 |
+
line.startIndexInclusive !== undefined
|
| 267 |
+
? i >= line.startIndexInclusive
|
| 268 |
+
: true
|
| 269 |
+
const beforeEnd =
|
| 270 |
+
line.stopIndexExclusive !== undefined
|
| 271 |
+
? i < line.stopIndexExclusive
|
| 272 |
+
: true
|
| 273 |
+
return valueDefined && atOrOverStart && beforeEnd
|
| 274 |
+
},
|
| 275 |
+
xAccessor: (_d, index) => x(index),
|
| 276 |
+
yAccessor: (d) => y(d.values[seriesIndex]!),
|
| 277 |
+
className: line.lineClassName
|
| 278 |
+
})
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
for (const [i, d] of data.entries()) {
|
| 283 |
+
const point =
|
| 284 |
+
points[i] ?? getPoint({ index: i, datum: d, xScale: x, yScale: y })
|
| 285 |
+
const dotForSeries = drawDot({
|
| 286 |
+
svg,
|
| 287 |
+
series,
|
| 288 |
+
x: point.x,
|
| 289 |
+
y: point.values[seriesIndex],
|
| 290 |
+
seriesIndex,
|
| 291 |
+
bucketIndex: i
|
| 292 |
+
})
|
| 293 |
+
points[i] = {
|
| 294 |
+
...point,
|
| 295 |
+
dots: [...point.dots, dotForSeries] as {
|
| 296 |
+
[K in keyof T]: SelectedGroup
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
svg.append('g').attr('id', annotationsGroupId)
|
| 303 |
+
|
| 304 |
+
setPoints(points)
|
| 305 |
+
|
| 306 |
+
// Unhide chart
|
| 307 |
+
svg.attr('opacity', 1)
|
| 308 |
+
|
| 309 |
+
return cleanup
|
| 310 |
+
}, [
|
| 311 |
+
data,
|
| 312 |
+
gradients,
|
| 313 |
+
height,
|
| 314 |
+
marginRight,
|
| 315 |
+
defaultMarginLeft,
|
| 316 |
+
extraMarginLeft,
|
| 317 |
+
marginTop,
|
| 318 |
+
settings,
|
| 319 |
+
width,
|
| 320 |
+
yFormat,
|
| 321 |
+
yMax,
|
| 322 |
+
marginLeft,
|
| 323 |
+
yBottomEdge,
|
| 324 |
+
yTopEdge,
|
| 325 |
+
xLeftEdge,
|
| 326 |
+
xRightEdge
|
| 327 |
+
])
|
| 328 |
+
|
| 329 |
+
const isInHoverableArea = useCallback(
|
| 330 |
+
(xPointer: number, yPointer: number): boolean => {
|
| 331 |
+
return (
|
| 332 |
+
xPointer >= xLeftEdge - hoverBuffer &&
|
| 333 |
+
xPointer <= xRightEdge + hoverBuffer &&
|
| 334 |
+
yPointer >= yTopEdge - hoverBuffer &&
|
| 335 |
+
// chart is interactive even over x-axis labels
|
| 336 |
+
yPointer <= height
|
| 337 |
+
)
|
| 338 |
+
},
|
| 339 |
+
[height, hoverBuffer, xLeftEdge, xRightEdge, yTopEdge]
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
useEffect(() => {
|
| 343 |
+
const currentSvg = svgRef.current
|
| 344 |
+
if (currentSvg && points.length) {
|
| 345 |
+
const svg = d3.select(currentSvg)
|
| 346 |
+
|
| 347 |
+
svg.on(
|
| 348 |
+
'pointermove',
|
| 349 |
+
(event) => {
|
| 350 |
+
const { xPointer, yPointer } = getPosition(event)
|
| 351 |
+
const inHoverableArea = isInHoverableArea(xPointer, yPointer)
|
| 352 |
+
const closestIndexToPointer = inHoverableArea
|
| 353 |
+
? getClosestIndexToPointer(xPointer, points)
|
| 354 |
+
: null
|
| 355 |
+
onPointerMove({
|
| 356 |
+
inHoverableArea,
|
| 357 |
+
closestPoint:
|
| 358 |
+
closestIndexToPointer !== null
|
| 359 |
+
? {
|
| 360 |
+
index: closestIndexToPointer,
|
| 361 |
+
x: points[closestIndexToPointer].x,
|
| 362 |
+
values: points[closestIndexToPointer].values
|
| 363 |
+
}
|
| 364 |
+
: null,
|
| 365 |
+
xPointer,
|
| 366 |
+
yPointer,
|
| 367 |
+
event
|
| 368 |
+
})
|
| 369 |
+
},
|
| 370 |
+
{ passive: true }
|
| 371 |
+
)
|
| 372 |
+
return () => {
|
| 373 |
+
if (currentSvg) {
|
| 374 |
+
const svg = d3.select(currentSvg)
|
| 375 |
+
svg.on('pointermove', null)
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
}
|
| 379 |
+
}, [onPointerMove, isInHoverableArea, points])
|
| 380 |
+
|
| 381 |
+
useEffect(() => {
|
| 382 |
+
const currentSvg = svgRef.current
|
| 383 |
+
if (currentSvg && points.length) {
|
| 384 |
+
const svg = d3.select(currentSvg)
|
| 385 |
+
svg.on(
|
| 386 |
+
'gotpointercapture',
|
| 387 |
+
(event) => {
|
| 388 |
+
onGotPointerCapture(event)
|
| 389 |
+
},
|
| 390 |
+
{ passive: true }
|
| 391 |
+
)
|
| 392 |
+
}
|
| 393 |
+
return () => {
|
| 394 |
+
if (currentSvg) {
|
| 395 |
+
const svg = d3.select(currentSvg)
|
| 396 |
+
svg.on('gotpointercapture', null)
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
}, [onGotPointerCapture, points])
|
| 400 |
+
|
| 401 |
+
useEffect(() => {
|
| 402 |
+
const currentSvg = svgRef.current
|
| 403 |
+
if (currentSvg && points.length) {
|
| 404 |
+
const svg = d3.select(currentSvg)
|
| 405 |
+
svg.on(
|
| 406 |
+
'pointerenter',
|
| 407 |
+
(event) => {
|
| 408 |
+
onPointerEnter(event)
|
| 409 |
+
},
|
| 410 |
+
{ passive: true }
|
| 411 |
+
)
|
| 412 |
+
}
|
| 413 |
+
return () => {
|
| 414 |
+
if (currentSvg) {
|
| 415 |
+
const svg = d3.select(currentSvg)
|
| 416 |
+
svg.on('pointerenter', null)
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
}, [onPointerEnter, points])
|
| 420 |
+
|
| 421 |
+
useEffect(() => {
|
| 422 |
+
const currentSvg = svgRef.current
|
| 423 |
+
if (currentSvg && points.length) {
|
| 424 |
+
const svg = d3.select(currentSvg)
|
| 425 |
+
svg.on(
|
| 426 |
+
'lostpointercapture pointerleave',
|
| 427 |
+
(event) => {
|
| 428 |
+
onPointerLeave(event)
|
| 429 |
+
},
|
| 430 |
+
{ passive: true }
|
| 431 |
+
)
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
return () => {
|
| 435 |
+
if (currentSvg) {
|
| 436 |
+
const svg = d3.select(currentSvg)
|
| 437 |
+
svg.on('lostpointercapture pointerleave', null)
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
}, [onPointerLeave, points])
|
| 441 |
+
|
| 442 |
+
useEffect(() => {
|
| 443 |
+
const currentSvg = svgRef.current
|
| 444 |
+
if (currentSvg && points.length) {
|
| 445 |
+
const svg = d3.select(currentSvg)
|
| 446 |
+
if (typeof onClick !== 'function') {
|
| 447 |
+
svg.on('click', null)
|
| 448 |
+
} else {
|
| 449 |
+
svg.on('click', (event) => {
|
| 450 |
+
const { xPointer, yPointer } = getPosition(event)
|
| 451 |
+
const inHoverableArea = isInHoverableArea(xPointer, yPointer)
|
| 452 |
+
const closestIndexToPointer = inHoverableArea
|
| 453 |
+
? getClosestIndexToPointer(xPointer, points)
|
| 454 |
+
: null
|
| 455 |
+
onClick({
|
| 456 |
+
inHoverableArea,
|
| 457 |
+
closestPoint:
|
| 458 |
+
closestIndexToPointer !== null
|
| 459 |
+
? {
|
| 460 |
+
index: closestIndexToPointer,
|
| 461 |
+
x: points[closestIndexToPointer].x,
|
| 462 |
+
values: points[closestIndexToPointer].values
|
| 463 |
+
}
|
| 464 |
+
: null,
|
| 465 |
+
xPointer,
|
| 466 |
+
yPointer,
|
| 467 |
+
event
|
| 468 |
+
})
|
| 469 |
+
})
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
return () => {
|
| 473 |
+
if (currentSvg) {
|
| 474 |
+
const svg = d3.select(currentSvg)
|
| 475 |
+
svg.on('click', null)
|
| 476 |
+
}
|
| 477 |
+
}
|
| 478 |
+
}, [onClick, isInHoverableArea, points])
|
| 479 |
+
|
| 480 |
+
useEffect(() => {
|
| 481 |
+
const currentSvg = svgRef.current
|
| 482 |
+
if (currentSvg && points.length) {
|
| 483 |
+
const svg = d3.select(currentSvg)
|
| 484 |
+
if (typeof onContextMenu !== 'function') {
|
| 485 |
+
svg.on('contextmenu', null)
|
| 486 |
+
} else {
|
| 487 |
+
svg.on('contextmenu', (event) => {
|
| 488 |
+
const { xPointer, yPointer } = getPosition(event)
|
| 489 |
+
const inHoverableArea = isInHoverableArea(xPointer, yPointer)
|
| 490 |
+
const closestIndexToPointer = inHoverableArea
|
| 491 |
+
? getClosestIndexToPointer(xPointer, points)
|
| 492 |
+
: null
|
| 493 |
+
onContextMenu({
|
| 494 |
+
inHoverableArea,
|
| 495 |
+
closestPoint:
|
| 496 |
+
closestIndexToPointer !== null
|
| 497 |
+
? {
|
| 498 |
+
index: closestIndexToPointer,
|
| 499 |
+
x: points[closestIndexToPointer].x,
|
| 500 |
+
values: points[closestIndexToPointer].values
|
| 501 |
+
}
|
| 502 |
+
: null,
|
| 503 |
+
xPointer,
|
| 504 |
+
yPointer,
|
| 505 |
+
event
|
| 506 |
+
})
|
| 507 |
+
})
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
return () => {
|
| 511 |
+
if (currentSvg) {
|
| 512 |
+
const svg = d3.select(currentSvg)
|
| 513 |
+
svg.on('contextmenu', null)
|
| 514 |
+
}
|
| 515 |
+
}
|
| 516 |
+
}, [onContextMenu, isInHoverableArea, points])
|
| 517 |
+
|
| 518 |
+
useEffect(() => {
|
| 519 |
+
points.forEach(({ dots }, index) =>
|
| 520 |
+
dots.forEach((g) =>
|
| 521 |
+
g.attr(
|
| 522 |
+
'data-active',
|
| 523 |
+
highlightedIndex !== null && index === highlightedIndex ? '' : null
|
| 524 |
+
)
|
| 525 |
+
)
|
| 526 |
+
)
|
| 527 |
+
|
| 528 |
+
if (svgRef.current) {
|
| 529 |
+
const svg = d3.select(svgRef.current)
|
| 530 |
+
let line = svg.select<SVGLineElement>(
|
| 531 |
+
`#${highlightIndicatorGroupId} line`
|
| 532 |
+
)
|
| 533 |
+
const shouldShowLine =
|
| 534 |
+
typeof highlightedIndex === 'number' && points[highlightedIndex]
|
| 535 |
+
if (shouldShowLine) {
|
| 536 |
+
const { x } = points[highlightedIndex]
|
| 537 |
+
if (line.empty()) {
|
| 538 |
+
line = svg.select(`#${highlightIndicatorGroupId}`).append('line')
|
| 539 |
+
}
|
| 540 |
+
line
|
| 541 |
+
.attr('x1', 0)
|
| 542 |
+
.attr('x2', 0)
|
| 543 |
+
.attr('y1', marginTop - HIGHLIGHT_LINE_VERTICAL_SPILL_PX)
|
| 544 |
+
.attr('y2', height - marginBottom + HIGHLIGHT_LINE_VERTICAL_SPILL_PX)
|
| 545 |
+
.attr('class', currentlySelectedLineClass)
|
| 546 |
+
.attr('transform', `translate(${x}, 0)`)
|
| 547 |
+
}
|
| 548 |
+
if (!shouldShowLine && !line.empty()) {
|
| 549 |
+
line.remove()
|
| 550 |
+
}
|
| 551 |
+
}
|
| 552 |
+
}, [height, highlightedIndex, marginBottom, marginTop, points])
|
| 553 |
+
|
| 554 |
+
useEffect(() => {
|
| 555 |
+
if (!svgRef.current) {
|
| 556 |
+
return
|
| 557 |
+
}
|
| 558 |
+
const svg = d3.select(svgRef.current)
|
| 559 |
+
const cleanup = () => {
|
| 560 |
+
svg.selectAll(`#${annotationsGroupId} g`).remove()
|
| 561 |
+
}
|
| 562 |
+
if (!points.length || points.length !== annotationsByIndex.length) {
|
| 563 |
+
return cleanup()
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
const pointsWithAnnotations = points.map((point, index) => {
|
| 567 |
+
return { ...point, index, annotations: annotationsByIndex[index] }
|
| 568 |
+
})
|
| 569 |
+
|
| 570 |
+
for (const point of pointsWithAnnotations) {
|
| 571 |
+
if (point.annotations.count > 0) {
|
| 572 |
+
svg
|
| 573 |
+
.select(`#${annotationsGroupId}`)
|
| 574 |
+
.append('g')
|
| 575 |
+
.call((g) =>
|
| 576 |
+
g
|
| 577 |
+
.append('polygon')
|
| 578 |
+
.attr(
|
| 579 |
+
'points',
|
| 580 |
+
`${-ANNOTATION_DIAMOND_SIZE_PX},0 0,${ANNOTATION_DIAMOND_SIZE_PX} ${ANNOTATION_DIAMOND_SIZE_PX},0 0,${-ANNOTATION_DIAMOND_SIZE_PX}`
|
| 581 |
+
)
|
| 582 |
+
.attr('transform', `translate(${point.x}, ${yBottomEdge})`)
|
| 583 |
+
.attr('class', annotationDiamondClass)
|
| 584 |
+
.attr('data-testid', `annotation-marker-on-bucket-${point.index}`)
|
| 585 |
+
)
|
| 586 |
+
}
|
| 587 |
+
}
|
| 588 |
+
return cleanup
|
| 589 |
+
}, [points, annotationsByIndex, yBottomEdge])
|
| 590 |
+
|
| 591 |
+
return (
|
| 592 |
+
<svg
|
| 593 |
+
ref={svgRef}
|
| 594 |
+
viewBox={`0 0 ${width} ${height}`}
|
| 595 |
+
className={classNames('w-full h-auto', className)}
|
| 596 |
+
/>
|
| 597 |
+
)
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
const currentlySelectedLineClass =
|
| 601 |
+
'stroke-1 stroke-gray-300 dark:stroke-gray-700'
|
| 602 |
+
const yTickLineClass =
|
| 603 |
+
'stroke-gray-150 dark:stroke-gray-800/75 group-first:stroke-gray-300 dark:group-first:stroke-gray-700'
|
| 604 |
+
const tickTextClass = 'fill-gray-500 dark:fill-gray-400 text-xs select-none'
|
| 605 |
+
const xTickLineClass = 'stroke-gray-300 dark:stroke-gray-700'
|
| 606 |
+
const annotationDiamondClass = 'fill-indigo-500 stroke-indigo-500'
|
| 607 |
+
|
| 608 |
+
export const getXDomain = (bucketCount: number): [number, number] => {
|
| 609 |
+
const xMin = 0
|
| 610 |
+
const xMax = Math.max(bucketCount - 1, 1)
|
| 611 |
+
return [xMin, xMax]
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
const getXScale = ({
|
| 615 |
+
domain,
|
| 616 |
+
xLeftEdge,
|
| 617 |
+
xRightEdge
|
| 618 |
+
}: {
|
| 619 |
+
domain: [number, number]
|
| 620 |
+
xLeftEdge: number
|
| 621 |
+
xRightEdge: number
|
| 622 |
+
}): d3.ScaleLinear<number, number, never> =>
|
| 623 |
+
d3.scaleLinear(domain, [xLeftEdge, xRightEdge])
|
| 624 |
+
|
| 625 |
+
const getYScale = ({
|
| 626 |
+
yMax,
|
| 627 |
+
yBottomEdge,
|
| 628 |
+
yTopEdge
|
| 629 |
+
}: {
|
| 630 |
+
yMax: number
|
| 631 |
+
yBottomEdge: number
|
| 632 |
+
yTopEdge: number
|
| 633 |
+
}): d3.ScaleLinear<number, number, never> =>
|
| 634 |
+
d3.scaleLinear([0, yMax], [yBottomEdge, yTopEdge]).nice(IDEAL_Y_TICK_COUNT)
|
| 635 |
+
|
| 636 |
+
const fitXAxis = ({
|
| 637 |
+
buildAxis,
|
| 638 |
+
suggestedXTickValues,
|
| 639 |
+
minClientX,
|
| 640 |
+
maxClientX
|
| 641 |
+
}: {
|
| 642 |
+
xAxisSelection: d3.Selection<SVGGElement, unknown, null, undefined>
|
| 643 |
+
buildAxis: (
|
| 644 |
+
xTickValues: number[]
|
| 645 |
+
) => d3.Selection<SVGGElement, unknown, null, undefined>
|
| 646 |
+
suggestedXTickValues: number[][]
|
| 647 |
+
minClientX: number
|
| 648 |
+
maxClientX: number
|
| 649 |
+
}) => {
|
| 650 |
+
for (const [index, xTickValues] of suggestedXTickValues.entries()) {
|
| 651 |
+
const isLastAttempt = index === suggestedXTickValues.length - 1
|
| 652 |
+
const axis = buildAxis(xTickValues)
|
| 653 |
+
|
| 654 |
+
let overlapCount = 0
|
| 655 |
+
let lastTickTextRightEdge = 0
|
| 656 |
+
axis.call((g) =>
|
| 657 |
+
g.selectAll('.tick text').each(function (_, i, groups) {
|
| 658 |
+
const { isOverlappingPrevious, rightEdge } = handleXTickText({
|
| 659 |
+
elem: this as SVGGraphicsElement,
|
| 660 |
+
position:
|
| 661 |
+
i === 0 ? 'first' : i === groups.length - 1 ? 'last' : 'neither',
|
| 662 |
+
minClientX,
|
| 663 |
+
maxClientX,
|
| 664 |
+
lastTickTextRightEdge
|
| 665 |
+
})
|
| 666 |
+
if (isOverlappingPrevious) {
|
| 667 |
+
overlapCount++
|
| 668 |
+
}
|
| 669 |
+
lastTickTextRightEdge = rightEdge
|
| 670 |
+
})
|
| 671 |
+
)
|
| 672 |
+
|
| 673 |
+
if (overlapCount > 0 && !isLastAttempt) {
|
| 674 |
+
axis.remove()
|
| 675 |
+
} else {
|
| 676 |
+
break
|
| 677 |
+
}
|
| 678 |
+
}
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
const fitYAxis = ({
|
| 682 |
+
buildAxis,
|
| 683 |
+
minClientX
|
| 684 |
+
}: {
|
| 685 |
+
buildAxis: () => d3.Selection<SVGGElement, unknown, null, undefined>
|
| 686 |
+
minClientX: number
|
| 687 |
+
}): { textOffset: number } => {
|
| 688 |
+
let leftMostYTickText: number | null = null
|
| 689 |
+
|
| 690 |
+
buildAxis().call((g) =>
|
| 691 |
+
g.selectAll('.tick').each(function () {
|
| 692 |
+
const rect = (this as SVGGraphicsElement).getBoundingClientRect()
|
| 693 |
+
if (leftMostYTickText === null || rect.left < leftMostYTickText)
|
| 694 |
+
leftMostYTickText = rect.left
|
| 695 |
+
})
|
| 696 |
+
)
|
| 697 |
+
return leftMostYTickText !== null
|
| 698 |
+
? { textOffset: leftMostYTickText - minClientX }
|
| 699 |
+
: { textOffset: 0 }
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
export const getSuggestedXTickValues = (
|
| 703 |
+
scale: d3.ScaleLinear<number, number>,
|
| 704 |
+
bucketCount: number
|
| 705 |
+
): number[][] => {
|
| 706 |
+
const maxXTicks = Math.min(bucketCount, MAX_X_TICK_COUNT)
|
| 707 |
+
const minTicks = 1
|
| 708 |
+
const result = new Set<string>()
|
| 709 |
+
for (let tickCount = maxXTicks; tickCount >= minTicks; tickCount--) {
|
| 710 |
+
const tickValues = scale.ticks(tickCount)
|
| 711 |
+
if (tickValues.every(isWholeNumber)) {
|
| 712 |
+
// needs serialization to be comparable for uniqueness in Set
|
| 713 |
+
const serializedArray = JSON.stringify(tickValues)
|
| 714 |
+
result.add(serializedArray)
|
| 715 |
+
}
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
return [...result].map((serializedArray) => JSON.parse(serializedArray))
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
const areIdealYTickValues = (tickValues: number[], yMax: number) =>
|
| 722 |
+
Math.max(...tickValues) >= yMax && tickValues.every(isWholeNumber)
|
| 723 |
+
|
| 724 |
+
const getOptimalYTickValues = (
|
| 725 |
+
scale: d3.ScaleLinear<number, number>,
|
| 726 |
+
yMax: number
|
| 727 |
+
) => {
|
| 728 |
+
const maxYTicks = IDEAL_Y_TICK_COUNT
|
| 729 |
+
const minTicks = 1
|
| 730 |
+
const suggested: number[][] = []
|
| 731 |
+
for (let tickCount = maxYTicks; tickCount >= minTicks; tickCount--) {
|
| 732 |
+
const tickValues = scale.ticks(tickCount)
|
| 733 |
+
suggested.push(tickValues)
|
| 734 |
+
}
|
| 735 |
+
return (
|
| 736 |
+
suggested.find((tickValues) => areIdealYTickValues(tickValues, yMax)) ??
|
| 737 |
+
suggested[0]
|
| 738 |
+
)
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
const handleXTickText = ({
|
| 742 |
+
elem,
|
| 743 |
+
position,
|
| 744 |
+
minClientX,
|
| 745 |
+
maxClientX,
|
| 746 |
+
lastTickTextRightEdge
|
| 747 |
+
}: {
|
| 748 |
+
elem: SVGGraphicsElement
|
| 749 |
+
position: 'first' | 'last' | 'neither'
|
| 750 |
+
minClientX: number
|
| 751 |
+
maxClientX: number
|
| 752 |
+
lastTickTextRightEdge: number
|
| 753 |
+
}): { isOverlappingPrevious: boolean; rightEdge: number } => {
|
| 754 |
+
const textContent = elem.textContent
|
| 755 |
+
// empty texts can't overlap
|
| 756 |
+
if (!textContent?.length) {
|
| 757 |
+
return { isOverlappingPrevious: false, rightEdge: lastTickTextRightEdge }
|
| 758 |
+
}
|
| 759 |
+
let textRect = elem.getBoundingClientRect()
|
| 760 |
+
|
| 761 |
+
if (position === 'first') {
|
| 762 |
+
const distanceFromAxisEdge = textRect.left - minClientX
|
| 763 |
+
if (distanceFromAxisEdge < 0) {
|
| 764 |
+
d3.select(elem).attr('dx', -distanceFromAxisEdge)
|
| 765 |
+
textRect = elem.getBoundingClientRect()
|
| 766 |
+
}
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
if (position === 'last') {
|
| 770 |
+
const distanceFromAxisEdge = maxClientX - textRect.right
|
| 771 |
+
if (distanceFromAxisEdge < 0) {
|
| 772 |
+
d3.select(elem).attr('dx', distanceFromAxisEdge)
|
| 773 |
+
textRect = elem.getBoundingClientRect()
|
| 774 |
+
}
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
return {
|
| 778 |
+
isOverlappingPrevious:
|
| 779 |
+
textRect.left < lastTickTextRightEdge + MINIMUM_X_LABEL_GAP_PX,
|
| 780 |
+
rightEdge: textRect.right
|
| 781 |
+
}
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
const getXTickFormat =
|
| 785 |
+
<T extends { xLabel: string }>(data: T[]) =>
|
| 786 |
+
(bucketIndex: d3.NumberValue) => {
|
| 787 |
+
// for low tick counts, it may try to render ticks
|
| 788 |
+
// with the value 0.5, 1.5, etc that don't have data defined
|
| 789 |
+
const datum = data[bucketIndex.valueOf()]
|
| 790 |
+
if (!datum) return ''
|
| 791 |
+
return datum.xLabel
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
const getChartAreaWidth = ({
|
| 795 |
+
width,
|
| 796 |
+
marginLeft,
|
| 797 |
+
marginRight
|
| 798 |
+
}: {
|
| 799 |
+
width: number
|
| 800 |
+
marginLeft: number
|
| 801 |
+
marginRight: number
|
| 802 |
+
}) => width - marginLeft - marginRight
|
| 803 |
+
|
| 804 |
+
const addGradient = ({
|
| 805 |
+
svg,
|
| 806 |
+
id,
|
| 807 |
+
stopTop,
|
| 808 |
+
stopBottom
|
| 809 |
+
}: {
|
| 810 |
+
svg: SelectedSVG
|
| 811 |
+
id: string
|
| 812 |
+
stopTop: { color: string; opacity: number }
|
| 813 |
+
stopBottom: { color: string; opacity: number }
|
| 814 |
+
}): void => {
|
| 815 |
+
const grad = svg
|
| 816 |
+
.append('defs')
|
| 817 |
+
.append('linearGradient')
|
| 818 |
+
.attr('id', id)
|
| 819 |
+
.attr('x1', '0%')
|
| 820 |
+
.attr('y1', '0%') // top
|
| 821 |
+
.attr('x2', '0%')
|
| 822 |
+
.attr('y2', `100%`) // bottom
|
| 823 |
+
|
| 824 |
+
grad
|
| 825 |
+
.append('stop')
|
| 826 |
+
.attr('offset', '0%')
|
| 827 |
+
.attr('stop-color', stopTop.color)
|
| 828 |
+
.attr('stop-opacity', stopTop.opacity)
|
| 829 |
+
|
| 830 |
+
grad
|
| 831 |
+
.append('stop')
|
| 832 |
+
.attr('offset', '100%')
|
| 833 |
+
.attr('stop-color', stopBottom.color)
|
| 834 |
+
.attr('stop-opacity', stopBottom.opacity)
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
function drawAreaUnderLine<T extends GraphYValues>({
|
| 838 |
+
svg,
|
| 839 |
+
gradientId,
|
| 840 |
+
isDefined,
|
| 841 |
+
xAccessor,
|
| 842 |
+
y0Accessor,
|
| 843 |
+
y1Accessor,
|
| 844 |
+
datum
|
| 845 |
+
}: {
|
| 846 |
+
svg: SelectedSVG
|
| 847 |
+
gradientId: string
|
| 848 |
+
isDefined: (d: Datum<T>, index: number) => boolean
|
| 849 |
+
xAccessor: (d: Datum<T>, index: number) => number
|
| 850 |
+
y0Accessor: number
|
| 851 |
+
y1Accessor: (d: Datum<T>, index: number) => number
|
| 852 |
+
datum: Datum<T>[]
|
| 853 |
+
}) {
|
| 854 |
+
const area = d3
|
| 855 |
+
.area<Datum<T>>()
|
| 856 |
+
.x(xAccessor)
|
| 857 |
+
.defined(isDefined)
|
| 858 |
+
.y0(y0Accessor) // bottom edge
|
| 859 |
+
.y1(y1Accessor) // top edge follows the data
|
| 860 |
+
|
| 861 |
+
// draw the filled area with the gradient
|
| 862 |
+
svg
|
| 863 |
+
.append('path')
|
| 864 |
+
.datum(datum)
|
| 865 |
+
.attr('fill', `url(#${gradientId})`)
|
| 866 |
+
.attr('d', area)
|
| 867 |
+
}
|
| 868 |
+
|
| 869 |
+
function drawLine<T extends GraphYValues>({
|
| 870 |
+
svg,
|
| 871 |
+
datum,
|
| 872 |
+
isDefined,
|
| 873 |
+
xAccessor,
|
| 874 |
+
yAccessor,
|
| 875 |
+
className
|
| 876 |
+
}: {
|
| 877 |
+
svg: SelectedSVG
|
| 878 |
+
datum: Datum<T>[]
|
| 879 |
+
isDefined: (d: Datum<T>, index: number) => boolean
|
| 880 |
+
xAccessor: (d: Datum<T>, index: number) => number
|
| 881 |
+
yAccessor: (d: Datum<T>, index: number) => number
|
| 882 |
+
className?: string
|
| 883 |
+
}) {
|
| 884 |
+
const line = d3.line<Datum<T>>().defined(isDefined).x(xAccessor).y(yAccessor)
|
| 885 |
+
|
| 886 |
+
svg
|
| 887 |
+
.append('path')
|
| 888 |
+
.attr('class', classNames(className))
|
| 889 |
+
.attr('data-testid', 'graph-line')
|
| 890 |
+
.datum(datum)
|
| 891 |
+
.attr('d', line)
|
| 892 |
+
}
|
| 893 |
+
|
| 894 |
+
function drawDot({
|
| 895 |
+
svg,
|
| 896 |
+
series,
|
| 897 |
+
x,
|
| 898 |
+
y,
|
| 899 |
+
seriesIndex,
|
| 900 |
+
bucketIndex
|
| 901 |
+
}: {
|
| 902 |
+
svg: SelectedSVG
|
| 903 |
+
series: SeriesConfig
|
| 904 |
+
x: number
|
| 905 |
+
y: number | null
|
| 906 |
+
seriesIndex: number
|
| 907 |
+
bucketIndex: number
|
| 908 |
+
}): SelectedGroup {
|
| 909 |
+
const group = svg.append('g').attr('class', 'group')
|
| 910 |
+
if (series.dot && y !== null) {
|
| 911 |
+
group
|
| 912 |
+
.append('circle')
|
| 913 |
+
.attr('r', 2.5)
|
| 914 |
+
.attr('class', series.dot.dotClassName)
|
| 915 |
+
.attr('transform', `translate(${x},${y})`)
|
| 916 |
+
.attr(
|
| 917 |
+
'data-testid',
|
| 918 |
+
`graph-dot-series-${seriesIndex}-bucket-${bucketIndex}`
|
| 919 |
+
)
|
| 920 |
+
}
|
| 921 |
+
return group
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
function getPoint<T extends GraphYValues>({
|
| 925 |
+
index,
|
| 926 |
+
datum,
|
| 927 |
+
xScale,
|
| 928 |
+
yScale
|
| 929 |
+
}: {
|
| 930 |
+
index: number
|
| 931 |
+
datum: Datum<T>
|
| 932 |
+
xScale: d3.ScaleLinear<number, number, never>
|
| 933 |
+
yScale: d3.ScaleLinear<number, number, never>
|
| 934 |
+
}): Point<T> {
|
| 935 |
+
return {
|
| 936 |
+
x: xScale(index),
|
| 937 |
+
values: datum.values.map((v): number | null =>
|
| 938 |
+
v !== null ? yScale(v) : null
|
| 939 |
+
) as unknown as T,
|
| 940 |
+
dots: [] as Point<T>['dots']
|
| 941 |
+
}
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
function getClosestIndexToPointer<T extends GraphYValues>(
|
| 945 |
+
xPointer: number,
|
| 946 |
+
points: Point<T>[]
|
| 947 |
+
): number {
|
| 948 |
+
return d3.bisector(({ x }: Point<T>) => x).center(points, xPointer)
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
const getPosition = (
|
| 952 |
+
event: unknown
|
| 953 |
+
): { xPointer: number; yPointer: number } => {
|
| 954 |
+
const [[xPointer, yPointer]] = d3.pointers(event)
|
| 955 |
+
return { xPointer, yPointer }
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
const isWholeNumber = (v: number) => v % 1 === 0
|
| 959 |
+
|
| 960 |
+
export type Datum<T extends GraphYValues> = {
|
| 961 |
+
values: T
|
| 962 |
+
xLabel: string
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
type XPos = number
|
| 966 |
+
type Point<T extends GraphYValues> = {
|
| 967 |
+
x: XPos
|
| 968 |
+
values: T
|
| 969 |
+
dots: { [K in keyof T]: SelectedGroup }
|
| 970 |
+
}
|
| 971 |
+
|
| 972 |
+
export type SeriesConfig = {
|
| 973 |
+
/** a single series can be drawn with multiple lines, like a solid line for some parts and a dashed line for other parts */
|
| 974 |
+
lines?: {
|
| 975 |
+
lineClassName: string
|
| 976 |
+
startIndexInclusive?: number
|
| 977 |
+
stopIndexExclusive?: number
|
| 978 |
+
}[]
|
| 979 |
+
underline?: { gradientId: string }
|
| 980 |
+
dot?: { dotClassName: string }
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
export type PointerHandler<T extends GraphYValues> = (opts: {
|
| 984 |
+
inHoverableArea: boolean
|
| 985 |
+
xPointer: number
|
| 986 |
+
yPointer: number
|
| 987 |
+
closestPoint: ({ index: number } & Pick<Point<T>, 'x' | 'values'>) | null
|
| 988 |
+
event: unknown
|
| 989 |
+
}) => void
|
| 990 |
+
|
| 991 |
+
type SelectedSVG = d3.Selection<SVGSVGElement, unknown, null, undefined>
|
| 992 |
+
type SelectedGroup = d3.Selection<SVGGElement, unknown, null, undefined>
|
assets/js/dashboard/components/icons.tsx
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
|
| 3 |
+
export const GlobeIcon = ({ className }: { className?: string }) => (
|
| 4 |
+
<svg
|
| 5 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 6 |
+
fill="none"
|
| 7 |
+
viewBox="0 0 24 24"
|
| 8 |
+
className={className}
|
| 9 |
+
>
|
| 10 |
+
<path
|
| 11 |
+
stroke="currentColor"
|
| 12 |
+
strokeLinecap="round"
|
| 13 |
+
strokeLinejoin="round"
|
| 14 |
+
strokeWidth="1.5"
|
| 15 |
+
d="M22 12H2M12 22c5.714-5.442 5.714-14.558 0-20M12 22C6.286 16.558 6.286 7.442 12 2"
|
| 16 |
+
/>
|
| 17 |
+
<path
|
| 18 |
+
stroke="currentColor"
|
| 19 |
+
strokeLinecap="round"
|
| 20 |
+
strokeLinejoin="round"
|
| 21 |
+
strokeWidth="1.5"
|
| 22 |
+
d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z"
|
| 23 |
+
/>
|
| 24 |
+
</svg>
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
export const FilterIcon = ({ className }: { className?: string }) => (
|
| 28 |
+
<svg
|
| 29 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 30 |
+
fill="none"
|
| 31 |
+
viewBox="0 0 24 24"
|
| 32 |
+
className={className}
|
| 33 |
+
>
|
| 34 |
+
<path
|
| 35 |
+
stroke="currentColor"
|
| 36 |
+
strokeLinecap="round"
|
| 37 |
+
strokeLinejoin="round"
|
| 38 |
+
strokeWidth="2"
|
| 39 |
+
d="M6 12h12M2 5h20M10 19h4"
|
| 40 |
+
/>
|
| 41 |
+
</svg>
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
export const RefreshIcon = ({ className }: { className?: string }) => (
|
| 45 |
+
<svg
|
| 46 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 47 |
+
viewBox="0 0 18 18"
|
| 48 |
+
fill="none"
|
| 49 |
+
className={className}
|
| 50 |
+
>
|
| 51 |
+
<path
|
| 52 |
+
stroke="currentColor"
|
| 53 |
+
strokeLinecap="round"
|
| 54 |
+
strokeLinejoin="round"
|
| 55 |
+
strokeWidth="1.5"
|
| 56 |
+
d="M5.25 9.5L3 7.25L0.75 9.5"
|
| 57 |
+
/>
|
| 58 |
+
<path
|
| 59 |
+
stroke="currentColor"
|
| 60 |
+
strokeLinecap="round"
|
| 61 |
+
strokeLinejoin="round"
|
| 62 |
+
strokeWidth="1.5"
|
| 63 |
+
d="M13.495 13.345C12.3587 14.5226 10.7641 15.25 9 15.25C5.548 15.25 2.75 12.45 2.75 9C2.75 8.4 2.834 7.83003 2.99 7.28003"
|
| 64 |
+
/>
|
| 65 |
+
<path
|
| 66 |
+
stroke="currentColor"
|
| 67 |
+
strokeLinecap="round"
|
| 68 |
+
strokeLinejoin="round"
|
| 69 |
+
strokeWidth="1.5"
|
| 70 |
+
d="M12.75 8.5L15 10.75L17.25 8.5"
|
| 71 |
+
/>
|
| 72 |
+
<path
|
| 73 |
+
stroke="currentColor"
|
| 74 |
+
strokeLinecap="round"
|
| 75 |
+
strokeLinejoin="round"
|
| 76 |
+
strokeWidth="1.5"
|
| 77 |
+
d="M4.50629 4.65564C5.64249 3.48544 7.23658 2.75 8.99998 2.75C12.452 2.75 15.25 5.55 15.25 9C15.25 9.58 15.171 10.14 15.024 10.67"
|
| 78 |
+
/>
|
| 79 |
+
</svg>
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
export const PencilIcon = ({ className }: { className?: string }) => (
|
| 83 |
+
<svg
|
| 84 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 85 |
+
viewBox="0 0 18 18"
|
| 86 |
+
fill="none"
|
| 87 |
+
className={className}
|
| 88 |
+
>
|
| 89 |
+
<path
|
| 90 |
+
stroke="currentColor"
|
| 91 |
+
strokeLinecap="round"
|
| 92 |
+
strokeLinejoin="round"
|
| 93 |
+
strokeWidth="1.5"
|
| 94 |
+
d="m10.547 4.422 3.031 3.031M2.75 15.25s3.599-.568 4.546-1.515l7.327-7.327a2.142 2.142 0 1 0-3.03-3.03l-7.327 7.327c-.947.947-1.515 4.546-1.515 4.546h0Z"
|
| 95 |
+
/>
|
| 96 |
+
</svg>
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
export const CursorIcon = ({ className }: { className?: string }) => (
|
| 100 |
+
<svg
|
| 101 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 102 |
+
viewBox="0 0 24 24"
|
| 103 |
+
fill="none"
|
| 104 |
+
className={className}
|
| 105 |
+
>
|
| 106 |
+
<path
|
| 107 |
+
stroke="currentColor"
|
| 108 |
+
strokeLinecap="round"
|
| 109 |
+
strokeLinejoin="round"
|
| 110 |
+
strokeWidth="1.5"
|
| 111 |
+
d="m4.63 3.711 15.23 5.565c.641.235.623 1.148-.028 1.358l-6.97 2.23-2.232 6.971c-.208.65-1.122.67-1.357.028L3.71 4.631a.717.717 0 0 1 .92-.92"
|
| 112 |
+
/>
|
| 113 |
+
</svg>
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
export const DocumentIcon = ({ className }: { className?: string }) => (
|
| 117 |
+
<svg
|
| 118 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 119 |
+
viewBox="0 0 24 24"
|
| 120 |
+
fill="none"
|
| 121 |
+
className={className}
|
| 122 |
+
>
|
| 123 |
+
<g
|
| 124 |
+
stroke="currentColor"
|
| 125 |
+
strokeLinecap="round"
|
| 126 |
+
strokeLinejoin="round"
|
| 127 |
+
strokeWidth="1.5"
|
| 128 |
+
>
|
| 129 |
+
<path d="M20.216 8.333h-4.547a1.334 1.334 0 0 1-1.333-1.334V2.47" />
|
| 130 |
+
<path d="M3.668 18.999v-14a2.666 2.666 0 0 1 2.667-2.667h7.448c.353 0 .693.14.942.39l5.219 5.22c.25.25.39.589.39.942v10.115a2.666 2.666 0 0 1-2.666 2.666H6.335A2.666 2.666 0 0 1 3.668 19" />
|
| 131 |
+
</g>
|
| 132 |
+
</svg>
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
export const FolderIcon = ({ className }: { className?: string }) => (
|
| 136 |
+
<svg
|
| 137 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 138 |
+
viewBox="0 0 24 24"
|
| 139 |
+
fill="none"
|
| 140 |
+
className={className}
|
| 141 |
+
>
|
| 142 |
+
<path
|
| 143 |
+
stroke="currentColor"
|
| 144 |
+
strokeLinecap="round"
|
| 145 |
+
strokeLinejoin="round"
|
| 146 |
+
strokeMiterlimit="10"
|
| 147 |
+
strokeWidth="1.5"
|
| 148 |
+
d="M2 5v13a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7l-3-3H4a2 2 0 0 0-2 2"
|
| 149 |
+
/>
|
| 150 |
+
</svg>
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
export const DiamondIcon = ({ className }: { className?: string }) => (
|
| 154 |
+
<svg
|
| 155 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 156 |
+
fill="none"
|
| 157 |
+
viewBox="0 0 24 24"
|
| 158 |
+
className={className}
|
| 159 |
+
>
|
| 160 |
+
<path
|
| 161 |
+
stroke="currentColor"
|
| 162 |
+
strokeLinecap="round"
|
| 163 |
+
strokeLinejoin="round"
|
| 164 |
+
strokeWidth="1.5"
|
| 165 |
+
d="M2.734 9h18.531M3.023 8.164l3.205-3.408c.255-.27.61-.424.984-.424h9.57c.374 0 .73.153.985.424l3.205 3.408c.44.468.48 1.18.093 1.693l-7.99 10.608a1.352 1.352 0 0 1-2.155 0L2.93 9.857a1.31 1.31 0 0 1 .093-1.693"
|
| 166 |
+
/>
|
| 167 |
+
</svg>
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
export const Spinner = ({ className }: { className?: string }) => (
|
| 171 |
+
<svg
|
| 172 |
+
className={className}
|
| 173 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 174 |
+
fill="none"
|
| 175 |
+
viewBox="0 0 24 24"
|
| 176 |
+
>
|
| 177 |
+
<circle
|
| 178 |
+
className="opacity-25"
|
| 179 |
+
cx="12"
|
| 180 |
+
cy="12"
|
| 181 |
+
r="10"
|
| 182 |
+
stroke="currentColor"
|
| 183 |
+
strokeWidth="4"
|
| 184 |
+
/>
|
| 185 |
+
<path
|
| 186 |
+
className="opacity-75"
|
| 187 |
+
fill="currentColor"
|
| 188 |
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
| 189 |
+
/>
|
| 190 |
+
</svg>
|
| 191 |
+
)
|
assets/js/dashboard/components/lazy-loader.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useEffect, useState } from 'react'
|
| 2 |
+
import { useInView } from 'react-intersection-observer'
|
| 3 |
+
|
| 4 |
+
export default function LazyLoader(props) {
|
| 5 |
+
const [hasBecomeVisibleYet, setHasBecomeVisibleYet] = useState(false)
|
| 6 |
+
const { ref, inView } = useInView({
|
| 7 |
+
threshold: 0
|
| 8 |
+
})
|
| 9 |
+
|
| 10 |
+
useEffect(() => {
|
| 11 |
+
if (inView && !hasBecomeVisibleYet) {
|
| 12 |
+
setHasBecomeVisibleYet(true)
|
| 13 |
+
if (props.onVisible) props.onVisible()
|
| 14 |
+
}
|
| 15 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 16 |
+
}, [inView])
|
| 17 |
+
|
| 18 |
+
return (
|
| 19 |
+
<div ref={ref} className="flex-1 flex flex-col">
|
| 20 |
+
{props.children}
|
| 21 |
+
</div>
|
| 22 |
+
)
|
| 23 |
+
}
|
assets/js/dashboard/components/modal-layout.tsx
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode } from 'react'
|
| 2 |
+
import { XMarkIcon } from '@heroicons/react/20/solid'
|
| 3 |
+
import ModalWithRouting from '../stats/modals/modal'
|
| 4 |
+
import { Button } from './button'
|
| 5 |
+
|
| 6 |
+
export function ModalLayout({
|
| 7 |
+
title,
|
| 8 |
+
onClose,
|
| 9 |
+
children,
|
| 10 |
+
maxWidth = '460px'
|
| 11 |
+
}: {
|
| 12 |
+
title: ReactNode
|
| 13 |
+
onClose: () => void
|
| 14 |
+
children: ReactNode
|
| 15 |
+
maxWidth?: string
|
| 16 |
+
}) {
|
| 17 |
+
return (
|
| 18 |
+
<ModalWithRouting maxWidth={maxWidth} grow onClose={onClose}>
|
| 19 |
+
<div className="flex flex-col gap-6 p-1 md:py-2 md:px-0">
|
| 20 |
+
<div className="flex items-center justify-between gap-3">
|
| 21 |
+
<h1 className="text-base font-bold leading-tight dark:text-gray-100">
|
| 22 |
+
{title}
|
| 23 |
+
</h1>
|
| 24 |
+
<button
|
| 25 |
+
type="button"
|
| 26 |
+
onClick={onClose}
|
| 27 |
+
aria-label="Close modal"
|
| 28 |
+
className="text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300"
|
| 29 |
+
>
|
| 30 |
+
<XMarkIcon className="size-4.5" />
|
| 31 |
+
</button>
|
| 32 |
+
</div>
|
| 33 |
+
{children}
|
| 34 |
+
</div>
|
| 35 |
+
</ModalWithRouting>
|
| 36 |
+
)
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
export function ModalFooter({ children }: { children: ReactNode }) {
|
| 40 |
+
return <div className="flex gap-x-3 items-center justify-end">{children}</div>
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export function SaveButton({
|
| 44 |
+
disabled,
|
| 45 |
+
onSave
|
| 46 |
+
}: {
|
| 47 |
+
disabled: boolean
|
| 48 |
+
onSave: () => void
|
| 49 |
+
}) {
|
| 50 |
+
return (
|
| 51 |
+
<Button
|
| 52 |
+
size="sm"
|
| 53 |
+
disabled={disabled}
|
| 54 |
+
onClick={disabled ? () => {} : onSave}
|
| 55 |
+
>
|
| 56 |
+
Save
|
| 57 |
+
</Button>
|
| 58 |
+
)
|
| 59 |
+
}
|
assets/js/dashboard/components/notice.tsx
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
|
| 4 |
+
export type NoticeProps = {
|
| 5 |
+
title: string
|
| 6 |
+
description?: string
|
| 7 |
+
className?: string
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export const Notice = ({ title, description, className }: NoticeProps) => (
|
| 11 |
+
<div
|
| 12 |
+
className={classNames(
|
| 13 |
+
'flex flex-col gap-y-0.5 rounded-md bg-yellow-100/60 dark:bg-yellow-700/30 px-3 py-2.5',
|
| 14 |
+
className
|
| 15 |
+
)}
|
| 16 |
+
>
|
| 17 |
+
<p className="text-sm font-semibold text-gray-900 dark:text-gray-100">
|
| 18 |
+
{title}
|
| 19 |
+
</p>
|
| 20 |
+
{description && (
|
| 21 |
+
<p className="text-sm text-gray-600 dark:text-gray-200/60">
|
| 22 |
+
{description}
|
| 23 |
+
</p>
|
| 24 |
+
)}
|
| 25 |
+
</div>
|
| 26 |
+
)
|
assets/js/dashboard/components/pill.tsx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { ReactNode } from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
import { DiamondIcon } from './icons'
|
| 4 |
+
|
| 5 |
+
export type PillColor = 'green' | 'yellow' | 'indigo'
|
| 6 |
+
|
| 7 |
+
const colorClasses: Record<PillColor, string> = {
|
| 8 |
+
green: 'bg-green-50 dark:bg-green-900/60 text-green-700 dark:text-green-300',
|
| 9 |
+
yellow:
|
| 10 |
+
'bg-yellow-100 dark:bg-yellow-900/40 text-yellow-600 dark:text-yellow-400',
|
| 11 |
+
indigo:
|
| 12 |
+
'bg-indigo-100/60 text-indigo-600 dark:bg-indigo-900/50 dark:text-indigo-300'
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export type PillProps = {
|
| 16 |
+
className?: string
|
| 17 |
+
color?: PillColor
|
| 18 |
+
children: ReactNode
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export function Pill({ className, color = 'green', children }: PillProps) {
|
| 22 |
+
return (
|
| 23 |
+
<div
|
| 24 |
+
className={classNames(
|
| 25 |
+
'flex items-center gap-x-1 shrink-0 h-fit rounded-md text-xs font-medium px-2 py-1',
|
| 26 |
+
colorClasses[color],
|
| 27 |
+
className
|
| 28 |
+
)}
|
| 29 |
+
>
|
| 30 |
+
{children}
|
| 31 |
+
</div>
|
| 32 |
+
)
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
export function UpgradePill({
|
| 36 |
+
plan,
|
| 37 |
+
color = 'indigo',
|
| 38 |
+
linked = false
|
| 39 |
+
}: {
|
| 40 |
+
plan: string
|
| 41 |
+
color?: PillColor
|
| 42 |
+
linked?: boolean
|
| 43 |
+
}) {
|
| 44 |
+
const pill = (
|
| 45 |
+
<Pill color={color}>
|
| 46 |
+
<DiamondIcon className="size-3.5 [&_path]:stroke-2" />
|
| 47 |
+
{plan}
|
| 48 |
+
</Pill>
|
| 49 |
+
)
|
| 50 |
+
if (!linked) {
|
| 51 |
+
return pill
|
| 52 |
+
}
|
| 53 |
+
return (
|
| 54 |
+
<a href="/billing/choose-plan" className="inline-block">
|
| 55 |
+
{pill}
|
| 56 |
+
</a>
|
| 57 |
+
)
|
| 58 |
+
}
|
assets/js/dashboard/components/placeholder.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import classNames from 'classnames'
|
| 2 |
+
import React, { ReactNode } from 'react'
|
| 3 |
+
|
| 4 |
+
export const Placeholder = ({
|
| 5 |
+
children,
|
| 6 |
+
placeholder
|
| 7 |
+
}: {
|
| 8 |
+
children: ReactNode | false
|
| 9 |
+
placeholder: ReactNode
|
| 10 |
+
}) => (
|
| 11 |
+
<span
|
| 12 |
+
className={classNames(
|
| 13 |
+
'rounded',
|
| 14 |
+
children === false &&
|
| 15 |
+
'bg-gray-100 dark:bg-gray-700 text-gray-100 dark:text-gray-700'
|
| 16 |
+
)}
|
| 17 |
+
>
|
| 18 |
+
{children === false ? placeholder : children}
|
| 19 |
+
</span>
|
| 20 |
+
)
|
assets/js/dashboard/components/popover.tsx
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { RefObject } from 'react'
|
| 2 |
+
import classNames from 'classnames'
|
| 3 |
+
import { CheckIcon } from '@heroicons/react/24/outline'
|
| 4 |
+
import { isModifierPressed, isTyping, Keybind } from '../keybinding'
|
| 5 |
+
import { TransitionClasses } from '@headlessui/react'
|
| 6 |
+
|
| 7 |
+
const TRANSITION_CONFIG: TransitionClasses = {
|
| 8 |
+
enter: 'transition ease-out duration-100',
|
| 9 |
+
enterFrom: 'opacity-0 scale-95',
|
| 10 |
+
enterTo: 'opacity-100 scale-100',
|
| 11 |
+
leave: 'transition ease-in duration-75',
|
| 12 |
+
leaveFrom: 'opacity-100 scale-100',
|
| 13 |
+
leaveTo: 'opacity-0 scale-95'
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
const transition = {
|
| 17 |
+
props: {
|
| 18 |
+
...TRANSITION_CONFIG
|
| 19 |
+
},
|
| 20 |
+
classNames: {
|
| 21 |
+
fullwidth: 'z-10 absolute left-0 right-0 origin-top',
|
| 22 |
+
left: 'z-10 absolute left-0 origin-top-left',
|
| 23 |
+
right: 'z-10 absolute right-0 origin-top-right'
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const panel = {
|
| 28 |
+
classNames: {
|
| 29 |
+
roundedSheet:
|
| 30 |
+
'flex flex-col gap-0.5 p-1 focus:outline-hidden rounded-md shadow-lg bg-white dark:bg-gray-800 ring-1 ring-black/5 font-medium text-gray-800 dark:text-gray-200'
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const toggleButton = {
|
| 35 |
+
classNames: {
|
| 36 |
+
rounded: 'flex items-center rounded-md text-sm leading-tight h-8',
|
| 37 |
+
shadow:
|
| 38 |
+
'bg-white dark:bg-gray-750 shadow-sm text-gray-800 dark:text-gray-200 dark:hover:bg-gray-700',
|
| 39 |
+
outline:
|
| 40 |
+
'border border-gray-300 dark:border-gray-750 bg-white dark:bg-gray-750 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 dark:hover:border-gray-700 dark:hover:text-gray-100',
|
| 41 |
+
ghost:
|
| 42 |
+
'gap-x-1.5 px-2.5 font-medium text-gray-700 dark:text-gray-100 hover:bg-gray-150/80 dark:hover:bg-gray-800 aria-expanded:bg-gray-150/80 dark:aria-expanded:bg-gray-800',
|
| 43 |
+
truncatedText: 'truncate block',
|
| 44 |
+
linkLike:
|
| 45 |
+
'text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 transition-colors duration-150'
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
const items = {
|
| 50 |
+
classNames: {
|
| 51 |
+
navigationLink: classNames(
|
| 52 |
+
'flex items-center justify-between',
|
| 53 |
+
'px-4 py-2.5 text-sm leading-tight rounded-md',
|
| 54 |
+
'cursor-pointer'
|
| 55 |
+
),
|
| 56 |
+
selectedOption: classNames(
|
| 57 |
+
'data-[selected=true]:bg-gray-100',
|
| 58 |
+
'data-[selected=true]:dark:bg-gray-700',
|
| 59 |
+
'data-[selected=true]:text-gray-900',
|
| 60 |
+
'data-[selected=true]:dark:text-gray-100'
|
| 61 |
+
),
|
| 62 |
+
hoverLink: classNames(
|
| 63 |
+
'hover:bg-gray-100',
|
| 64 |
+
'hover:text-gray-900',
|
| 65 |
+
'dark:hover:bg-gray-700',
|
| 66 |
+
'dark:hover:text-gray-100',
|
| 67 |
+
|
| 68 |
+
'focus-within:bg-gray-100',
|
| 69 |
+
'focus-within:text-gray-900',
|
| 70 |
+
'dark:focus-within:bg-gray-700',
|
| 71 |
+
'dark:focus-within:text-gray-100'
|
| 72 |
+
)
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
export const popover = {
|
| 77 |
+
toggleButton,
|
| 78 |
+
panel,
|
| 79 |
+
transition,
|
| 80 |
+
items
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
export function SelectedCheckmark({ selected }: { selected: boolean }) {
|
| 84 |
+
if (!selected) {
|
| 85 |
+
return null
|
| 86 |
+
}
|
| 87 |
+
return (
|
| 88 |
+
<CheckIcon className="size-3.5 shrink-0 ml-2 stroke-2" aria-hidden="true" />
|
| 89 |
+
)
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* Rendering this component captures the Escape key on targetRef.current, a PopoverButton,
|
| 94 |
+
* blurring the element on Escape, and stopping the event from propagating.
|
| 95 |
+
* Needed to prevent other Escape handlers that may exist from running.
|
| 96 |
+
*/
|
| 97 |
+
export function BlurMenuButtonOnEscape({
|
| 98 |
+
targetRef
|
| 99 |
+
}: {
|
| 100 |
+
targetRef: RefObject<HTMLElement>
|
| 101 |
+
}) {
|
| 102 |
+
return (
|
| 103 |
+
<Keybind
|
| 104 |
+
keyboardKey="Escape"
|
| 105 |
+
type="keyup"
|
| 106 |
+
handler={(event) => {
|
| 107 |
+
const t = event.target as HTMLElement | null
|
| 108 |
+
if (typeof t?.blur === 'function') {
|
| 109 |
+
if (t === targetRef.current) {
|
| 110 |
+
t.blur()
|
| 111 |
+
event.stopPropagation()
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
}}
|
| 115 |
+
targetRef={targetRef}
|
| 116 |
+
shouldIgnoreWhen={[isModifierPressed, isTyping]}
|
| 117 |
+
/>
|
| 118 |
+
)
|
| 119 |
+
}
|
assets/js/dashboard/components/search-input.tsx
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, {
|
| 2 |
+
ChangeEventHandler,
|
| 3 |
+
useCallback,
|
| 4 |
+
useState,
|
| 5 |
+
RefObject
|
| 6 |
+
} from 'react'
|
| 7 |
+
import { isModifierPressed, Keybind } from '../keybinding'
|
| 8 |
+
import { useDebounce } from '../custom-hooks'
|
| 9 |
+
import classNames from 'classnames'
|
| 10 |
+
|
| 11 |
+
export const SearchInput = ({
|
| 12 |
+
searchRef,
|
| 13 |
+
onSearch,
|
| 14 |
+
className,
|
| 15 |
+
placeholderFocusedOrMobile = 'Search',
|
| 16 |
+
placeholderUnfocusedOnlyDesktop = 'Press / to search'
|
| 17 |
+
}: {
|
| 18 |
+
searchRef: RefObject<HTMLInputElement>
|
| 19 |
+
onSearch: (value: string) => void
|
| 20 |
+
className?: string
|
| 21 |
+
placeholderFocusedOrMobile?: string
|
| 22 |
+
placeholderUnfocusedOnlyDesktop?: string
|
| 23 |
+
}) => {
|
| 24 |
+
const [isFocused, setIsFocused] = useState(false)
|
| 25 |
+
const [hasValue, setHasValue] = useState(false)
|
| 26 |
+
|
| 27 |
+
const onSearchInputChange: ChangeEventHandler<HTMLInputElement> = useCallback(
|
| 28 |
+
(event) => {
|
| 29 |
+
onSearch(event.target.value)
|
| 30 |
+
},
|
| 31 |
+
[onSearch]
|
| 32 |
+
)
|
| 33 |
+
const debouncedOnSearchInputChange = useDebounce(onSearchInputChange)
|
| 34 |
+
|
| 35 |
+
const handleInputChange: ChangeEventHandler<HTMLInputElement> = useCallback(
|
| 36 |
+
(event) => {
|
| 37 |
+
const value = event.target.value
|
| 38 |
+
setHasValue(value.length > 0)
|
| 39 |
+
debouncedOnSearchInputChange(event)
|
| 40 |
+
},
|
| 41 |
+
[debouncedOnSearchInputChange]
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
const blurSearchBox = useCallback(() => {
|
| 45 |
+
searchRef.current?.blur()
|
| 46 |
+
}, [searchRef])
|
| 47 |
+
|
| 48 |
+
const focusSearchBox = useCallback(
|
| 49 |
+
(event: KeyboardEvent) => {
|
| 50 |
+
searchRef.current?.focus()
|
| 51 |
+
event.stopPropagation()
|
| 52 |
+
},
|
| 53 |
+
[searchRef]
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
return (
|
| 57 |
+
<>
|
| 58 |
+
<Keybind
|
| 59 |
+
keyboardKey="Escape"
|
| 60 |
+
type="keyup"
|
| 61 |
+
handler={blurSearchBox}
|
| 62 |
+
shouldIgnoreWhen={[isModifierPressed, () => !isFocused]}
|
| 63 |
+
targetRef={searchRef}
|
| 64 |
+
/>
|
| 65 |
+
<Keybind
|
| 66 |
+
keyboardKey="/"
|
| 67 |
+
type="keyup"
|
| 68 |
+
handler={focusSearchBox}
|
| 69 |
+
shouldIgnoreWhen={[isModifierPressed, () => isFocused]}
|
| 70 |
+
targetRef="document"
|
| 71 |
+
/>
|
| 72 |
+
<div className={classNames('relative max-w-64 w-full', className)}>
|
| 73 |
+
<input
|
| 74 |
+
data-testid="search-input"
|
| 75 |
+
onBlur={() => setIsFocused(false)}
|
| 76 |
+
onFocus={() => setIsFocused(true)}
|
| 77 |
+
ref={searchRef}
|
| 78 |
+
type="text"
|
| 79 |
+
placeholder=" "
|
| 80 |
+
className="peer w-full text-sm dark:text-gray-100 block border-gray-300 dark:border-gray-750 rounded-md dark:bg-gray-750 dark:placeholder:text-gray-400 focus:outline-none focus:ring-3 focus:ring-indigo-500/20 dark:focus:ring-indigo-500/25 focus:border-indigo-500"
|
| 81 |
+
onChange={handleInputChange}
|
| 82 |
+
/>
|
| 83 |
+
{!hasValue && (
|
| 84 |
+
<>
|
| 85 |
+
<span className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-400 dark:text-gray-400 md:peer-[:not(:focus)]:hidden">
|
| 86 |
+
{placeholderFocusedOrMobile}
|
| 87 |
+
</span>
|
| 88 |
+
<span className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-400 dark:text-gray-400 hidden md:peer-[:not(:focus)]:block peer-focus:hidden">
|
| 89 |
+
{placeholderUnfocusedOnlyDesktop}
|
| 90 |
+
</span>
|
| 91 |
+
</>
|
| 92 |
+
)}
|
| 93 |
+
</div>
|
| 94 |
+
</>
|
| 95 |
+
)
|
| 96 |
+
}
|