Skip to content

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

Cleanup liveview dashboard code (#6027)

RobertJoonas66a2a3ec29f0
diff --git a/assets/js/dashboard/components/liveview-portal.tsx b/assets/js/dashboard/components/liveview-portal.tsx
deleted file mode 100644
index 838009f6d0..0000000000
--- a/assets/js/dashboard/components/liveview-portal.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Component used for embedding LiveView components inside React.
- *
- * The content of the portal is completely excluded from React re-renders with
- * a hardwired `React.memo`.
- */
-
-import React from 'react'
-import classNames from 'classnames'
-import { ReportHeader } from '../stats/reports/report-header'
-import { ReportLayout } from '../stats/reports/report-layout'
-import { TabButton, TabWrapper } from './tabs'
-import { MoreLinkState } from '../stats/more-link-state'
-import MoreLink from '../stats/more-link'
-
-const MIN_HEIGHT = 356
-
-type LiveViewPortalProps = {
- id: string
- tabs: { value: string; label: string }[]
- storageKey: string
- className?: string
-}
-
-export const LiveViewPortal = React.memo(
- function ({ id, tabs, storageKey, className }: LiveViewPortalProps) {
- const activeTab = localStorage.getItem(storageKey) || 'pages'
-
- return (
- <div
- id={id}
- className={classNames('group', className)}
- style={{ width: '100%', border: '0', minHeight: MIN_HEIGHT }}
- >
- <div className={'group-has-[[data-phx-teleported]]:hidden'}>
- <ReportLayout>
- <ReportHeader>
- <div className="flex gap-x-3">
- <TabWrapper>
- {tabs.map(({ value, label }) => (
- <TabButton
- key={value}
- active={activeTab === value}
- onClick={() => {}}
- >
- {label}
- </TabButton>
- ))}
- </TabWrapper>
- </div>
- <MoreLink state={MoreLinkState.LOADING} linkProps={undefined} />
- </ReportHeader>
- <div
- className="w-full flex flex-col justify-center"
- style={{ minHeight: `${MIN_HEIGHT}px` }}
- >
- <div className="mx-auto loading">
- <div></div>
- </div>
- </div>
- </ReportLayout>
- </div>
- </div>
- )
- },
- () => true
-)
diff --git a/assets/js/dashboard/index.tsx b/assets/js/dashboard/index.tsx
index 0262471c01..0820ac5e01 100644
--- a/assets/js/dashboard/index.tsx
+++ b/assets/js/dashboard/index.tsx
@@ -1,5 +1,4 @@
-import React, { useMemo, useState, useEffect, useCallback } from 'react'
-import { LiveViewPortal } from './components/liveview-portal'
+import React, { useMemo, useState } from 'react'
import VisitorGraph from './stats/graph/visitor-graph'
import Sources from './stats/sources'
import Pages from './stats/pages'
@@ -8,11 +7,7 @@ import Devices from './stats/devices'
import { TopBar } from './nav-menu/top-bar'
import Behaviours from './stats/behaviours'
import { useQueryContext } from './query-context'
-import { useSiteContext } from './site-context'
-import { hasConversionGoalFilter, isRealTimeDashboard } from './util/filters'
-import { useAppNavigate } from './navigation/use-app-navigate'
-import { parseSearch } from './util/url-search-params'
-import { getDomainScopedStorageKey } from './util/storage'
+import { isRealTimeDashboard } from './util/filters'
function DashboardStats({
importedDataInView,
@@ -21,61 +16,11 @@ function DashboardStats({
importedDataInView?: boolean
updateImportedDataInView?: (v: boolean) => void
}) {
- const navigate = useAppNavigate()
- const site = useSiteContext()
- const { query } = useQueryContext()
-
- // Handler for navigation events delegated from LiveView dashboard.
- // Necessary to emulate navigation events in LiveView with pushState
- // manipulation disabled.
- const onLiveNavigate = useCallback(
- (e: CustomEvent) => {
- navigate({
- path: e.detail.path,
- search: () => parseSearch(e.detail.search)
- })
- },
- [navigate]
- )
-
- useEffect(() => {
- window.addEventListener(
- 'dashboard:live-navigate',
- onLiveNavigate as EventListener
- )
-
- return () => {
- window.removeEventListener(
- 'dashboard:live-navigate',
- onLiveNavigate as EventListener
- )
- }
- }, [onLiveNavigate])
-
return (
<>
<VisitorGraph updateImportedDataInView={updateImportedDataInView} />
<Sources />
- {site.flags.live_dashboard ? (
- <LiveViewPortal
- id="pages-breakdown-live"
- tabs={[
- {
- label: hasConversionGoalFilter(query)
- ? 'Conversion pages'
- : 'Top pages',
- value: 'pages'
- },
- { label: 'Entry pages', value: 'entry-pages' },
- { label: 'Exit pages', value: 'exit-pages' }
- ]}
- storageKey={getDomainScopedStorageKey('pageTab', site.domain)}
- className="w-full h-full border-0 overflow-hidden"
- />
- ) : (
- <Pages />
- )}
-
+ <Pages />
<Locations />
<Devices />
<Behaviours importedDataInView={importedDataInView} />
diff --git a/assets/js/dashboard/navigation/use-app-navigate.tsx b/assets/js/dashboard/navigation/use-app-navigate.tsx
index c3d171ac81..1569dbedcf 100644
--- a/assets/js/dashboard/navigation/use-app-navigate.tsx
+++ b/assets/js/dashboard/navigation/use-app-navigate.tsx
@@ -78,15 +78,6 @@ export const useAppNavigate = () => {
search,
...options
}: AppNavigationTarget & NavigateOptions) => {
- // Event dispatched for handling by LiveView dashboard via hook.
- // Necessary to emulate navigation events in LiveView with pushState
- // manipulation disabled.
- window.dispatchEvent(
- new CustomEvent('dashboard:live-navigate-back', {
- detail: { search: window.location.search }
- })
- )
-
return _navigate(getToOptions({ path, params, search }), options)
},
[getToOptions, _navigate]
diff --git a/assets/js/dashboard/site-context.tsx b/assets/js/dashboard/site-context.tsx
index 7dc79fb9e8..ac6213b21c 100644
--- a/assets/js/dashboard/site-context.tsx
+++ b/assets/js/dashboard/site-context.tsx
@@ -27,9 +27,7 @@ export function parseSiteFromDataset(dataset: DOMStringMap): PlausibleSite {
}
// Update this object when new feature flags are added to the frontend.
-type FeatureFlags = {
- live_dashboard?: boolean
-}
+type FeatureFlags = Record<never, boolean>
export const siteContextDefaultValue = {
domain: '',
diff --git a/assets/js/liveview/dashboard_root.js b/assets/js/liveview/dashboard_root.js
deleted file mode 100644
index 769044bc44..0000000000
--- a/assets/js/liveview/dashboard_root.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Hook widget delegating navigation events to and from React.
- * Necessary to emulate navigation events in LiveView with pushState
- * manipulation disabled.
- */
-
-import { buildHook } from './hook_builder'
-
-function navigateWithLoader(url) {
- this.portalTargets.map((target) => {
- this.js().addClass(document.querySelector(target), 'phx-navigation-loading')
-
- this.pushEvent('handle_dashboard_params', { url: url }, () => {
- this.js().removeClass(
- document.querySelector(target),
- 'phx-navigation-loading'
- )
- })
- })
-}
-
-export default buildHook({
- initialize() {
- const portals = document.querySelectorAll('[data-phx-portal]')
- this.portalTargets = Array.from(portals, (p) => p.dataset.phxPortal)
- this.url = window.location.href
-
- this.addListener('click', document.body, (e) => {
- const type = e.target.dataset.type || null
-
- if (type === 'dashboard-link') {
- const uri = new URL(e.target.href)
- // Domain is dropped from URL prefix, because that's what react-dom-router
- // expects.
- const path = '/' + uri.pathname.split('/').slice(2).join('/')
- this.el.dispatchEvent(
- new CustomEvent('dashboard:live-navigate', {
- bubbles: true,
- detail: { path: path, search: uri.search }
- })
- )
-
- e.preventDefault()
- }
- })
-
- // Browser back and forward navigation triggers that event.
- this.addListener('popstate', window, () => {
- if (this.url !== window.location.href) {
- navigateWithLoader.bind(this)(window.location.href)
- }
- })
-
- // Navigation events triggered from liveview are propagated via this
- // handler.
- this.addListener('dashboard:live-navigate-back', window, (e) => {
- if (
- typeof e.detail.search === 'string' &&
- this.url !== window.location.href
- ) {
- navigateWithLoader.bind(this)(window.location.href)
- }
- })
- }
-})
diff --git a/assets/js/liveview/dashboard_tabs.js b/assets/js/liveview/dashboard_tabs.js
deleted file mode 100644
index 50b2725329..0000000000
--- a/assets/js/liveview/dashboard_tabs.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Hook widget for optimistic loading of tabs and
- * client-side persistence of selection using localStorage.
- */
-
-import { buildHook } from './hook_builder'
-
-function getDomain(url) {
- const uri = typeof url === 'object' ? url : new URL(url)
- return uri.pathname.split('/')[1]
-}
-
-export default buildHook({
- initialize() {
- const domain = getDomain(window.location.href)
-
- this.addListener('click', this.el, (e) => {
- const button = e.target.closest('button')
- const tabKey = button && button.dataset.tabKey
-
- if (button && button.closest('div').dataset.active === 'false') {
- const storageKey = button.dataset.storageKey
- const target = button.dataset.target
-
- this.el.querySelectorAll(`button[data-tab-key]`).forEach((b) => {
- if (b.dataset.tabKey === tabKey) {
- this.js().setAttribute(b.closest('div'), 'data-active', 'true')
- this.js().setAttribute(
- b.querySelector('span'),
- 'data-active',
- 'true'
- )
- } else {
- this.js().setAttribute(b.closest('div'), 'data-active', 'false')
- this.js().setAttribute(
- b.querySelector('span'),
- 'data-active',
- 'false'
- )
- }
- })
-
- if (storageKey) {
- localStorage.setItem(`${storageKey}__${domain}`, tabKey)
- }
-
- this.pushEventTo(target, 'set-tab', { tab: tabKey })
- }
- })
- }
-})
diff --git a/assets/js/liveview/hook_builder.js b/assets/js/liveview/hook_builder.js
deleted file mode 100644
index 48c998d7bf..0000000000
--- a/assets/js/liveview/hook_builder.js
+++ /dev/null
@@ -1,53 +0,0 @@
-export function buildHook({ initialize, cleanup }) {
- cleanup = cleanup || function () {}
-
- return {
- mounted() {
- this.initialize()
- },
-
- updated() {
- this.initialize()
- },
-
- reconnected() {
- this.initialize()
- },
-
- destroyed() {
- this.cleanup()
- },
-
- initialize() {
- this.cleanup()
- initialize.bind(this)()
- },
-
- cleanup() {
- this.removeListeners()
- cleanup.bind(this)()
- },
-
- addListener(eventName, listener, callback) {
- this.listeners = this.listeners || []
-
- listener.addEventListener(eventName, callback)
-
- this.listeners.push({
- element: listener,
- event: eventName,
- callback: callback
- })
- },
-
- removeListeners() {
- if (this.listeners) {
- this.listeners.forEach((l) => {
- l.element.removeEventListener(l.event, l.callback)
- })
-
- this.listeners = null
- }
- }
- }
-}
diff --git a/assets/js/liveview/live_socket.js b/assets/js/liveview/live_socket.js
index 60ae66a0cd..0551a8ccec 100644
--- a/assets/js/liveview/live_socket.js
+++ b/assets/js/liveview/live_socket.js
@@ -8,8 +8,6 @@ import 'phoenix_html'
import { Socket } from 'phoenix'
import { LiveSocket } from 'phoenix_live_view'
import { Modal, Dropdown } from 'prima'
-import DashboardRoot from './dashboard_root'
-import DashboardTabs from './dashboard_tabs.js'
import topbar from 'topbar'
/* eslint-enable import/no-unresolved */
@@ -17,12 +15,8 @@ import Alpine from 'alpinejs'
let csrfToken = document.querySelector("meta[name='csrf-token']")
let websocketUrl = document.querySelector("meta[name='websocket-url']")
-let disablePushStateFlag = document.querySelector(
- "meta[name='live-socket-disable-push-state']"
-)
-let domain = document.querySelector("meta[name='dashboard-domain']")
if (csrfToken && websocketUrl) {
- let Hooks = { Modal, Dropdown, DashboardRoot, DashboardTabs }
+ let Hooks = { Modal, Dropdown }
Hooks.Metrics = {
mounted() {
this.handleEvent('send-metrics', ({ event_name }) => {
@@ -55,14 +49,9 @@ if (csrfToken && websocketUrl) {
let token = csrfToken.getAttribute('content')
let url = websocketUrl.getAttribute('content')
let liveUrl = url === '' ? '/live' : new URL('/live', url).href
- let disablePushState =
- !!disablePushStateFlag &&
- disablePushStateFlag.getAttribute('content') === 'true'
- let domainName = domain && domain.getAttribute('content')
let liveSocket = new LiveSocket(liveUrl, Socket, {
- // For dashboard LV migration
- disablePushState: disablePushState,
heartbeatIntervalMs: 10000,
+ params: { _csrf_token: token },
hooks: Hooks,
uploaders: Uploaders,
dom: {
@@ -72,25 +61,6 @@ if (csrfToken && websocketUrl) {
Alpine.clone(from, to)
}
}
- },
- params: () => {
- if (domainName) {
- return {
- // The prefs are used by dashboard LiveView to persist
- // user preferences across the reloads.
- user_prefs: {
- pages_tab: localStorage.getItem(`pageTab__${domainName}`),
- period: localStorage.getItem(`period__${domainName}`),
- comparison: localStorage.getItem(`comparison_mode__${domainName}`),
- match_day_of_week: localStorage.getItem(
- `comparison_match_day_of_week__${domainName}`
- )
- },
- _csrf_token: token
- }
- } else {
- return { _csrf_token: token }
- }
}
})
diff --git a/lib/plausible/stats/dashboard/query_serializer.ex b/lib/plausible/stats/dashboard/query_serializer.ex
deleted file mode 100644
index dcaa2fac68..0000000000
--- a/lib/plausible/stats/dashboard/query_serializer.ex
+++ /dev/null
@@ -1,160 +0,0 @@
-defmodule Plausible.Stats.Dashboard.QuerySerializer do
- @moduledoc """
- Takes a `%ParsedQueryParams{}` struct and turns it into a query
- string.
- """
-
- alias Plausible.Stats.{ParsedQueryParams, Dashboard, QueryInclude}
-
- def serialize(%ParsedQueryParams{} = params, segments \\ []) do
- params
- |> Map.to_list()
- |> Enum.flat_map(fn pair -> get_serialized_fields(pair, segments) end)
- |> Enum.sort_by(&elem(&1, 0))
- |> Enum.map_join("&", fn {key, value} -> "#{key}=#{value}" end)
- end
-
- defp get_serialized_fields({_, nil}, _segments), do: []
- defp get_serialized_fields({_, []}, _segments), do: []
-
- defp get_serialized_fields({:input_date_range, {:date_range, from_date, to_date}}, _segments) do
- [
- {"period", "custom"},
- {"from", Date.to_iso8601(from_date)},
- {"to", Date.to_iso8601(to_date)}
- ]
- end
-
- defp get_serialized_fields({:input_date_range, input_date_range}, _segments) do
- period =
- case input_date_range do
- :realtime -> "realtime"
- :day -> "day"
- :month -> "month"
- :year -> "year"
- :all -> "all"
- {:last_n_days, 7} -> "7d"
- {:last_n_days, 28} -> "28d"
- {:last_n_days, 30} -> "30d"
- {:last_n_days, 91} -> "91d"
- {:last_n_months, 6} -> "6mo"
- {:last_n_months, 12} -> "12mo"
- end
-
- [{"period", period}]
- end
-
- defp get_serialized_fields({:relative_date, date}, _segments) do
- [{"date", Date.to_iso8601(date)}]
- end
-
- defp get_serialized_fields({:filters, [_ | _] = filters}, segments) do
- serialize_filters(filters) ++ serialize_labels(filters, segments)
- end
-
- defp get_serialized_fields({:include, %QueryInclude{} = include}, _segments) do
- [:imports, :compare, :compare_match_day_of_week]
- |> Enum.flat_map(fn include_key ->
- get_serialized_fields_from_include(include_key, include)
- end)
- end
-
- defp get_serialized_fields(_, _), do: []
-
- defp get_serialized_fields_from_include(:imports, %QueryInclude{} = include) do
- if include.imports == Dashboard.QueryParser.default_include().imports do
- []
- else
- [{"with_imported", to_string(include.imports)}]
- end
- end
-
- defp get_serialized_fields_from_include(:compare, %QueryInclude{} = include) do
- case include.compare do
- nil ->
- []
-
- mode when mode in [:previous_period, :year_over_year] ->
- [{"comparison", to_string(mode)}]
-
- {:date_range, from_date, to_date} ->
- [
- {"comparison", "custom"},
- {"compare_from", Date.to_iso8601(from_date)},
- {"compare_to", Date.to_iso8601(to_date)}
- ]
- end
- end
-
- defp get_serialized_fields_from_include(:compare_match_day_of_week, include) do
- if include.compare_match_day_of_week ==
- Dashboard.QueryParser.default_include().compare_match_day_of_week do
- []
- else
- [{"match_day_of_week", to_string(include.compare_match_day_of_week)}]
- end
- end
-
- defp serialize_filters(filters) do
- filters
- |> Enum.map(fn [operator, dimension, clauses] ->
- clauses = Enum.map_join(clauses, ",", &custom_uri_encode/1)
- dimension = String.split(dimension, ":", parts: 2) |> List.last()
- {"f", "#{operator},#{dimension},#{clauses}"}
- end)
- end
-
- # This is needed by the React dashboard during the migration phase.
- # In Elixir, we can do cheap location/segment lookups but React needs
- # URL labels to be able translate filters into a human-readable form.
- # E.g. `f=is,city,2950159&l=2950159,Berlin`.
- defp serialize_labels(filters, segments) do
- Enum.flat_map(filters, fn filter -> labels_for(filter, segments) end)
- end
-
- defp labels_for([_operator, dimension, clauses], segments) do
- name_lookup_fn =
- case dimension do
- "visit:country" ->
- &Location.get_country/1
-
- "visit:region" ->
- &Location.get_subdivision/1
-
- "visit:city" ->
- &Location.get_city/1
-
- "segment" ->
- fn segment_id ->
- Enum.find(segments, &(&1.id == segment_id))
- end
-
- _ ->
- fn _ -> nil end
- end
-
- Enum.reduce(clauses, [], fn code, acc ->
- case name_lookup_fn.(code) do
- %{name: name} -> acc ++ [{"l", "#{code},#{name}"}]
- nil -> acc
- end
- end)
- end
-
- # These characters are not URL encoded to have more readable URLs.
- # Browsers seem to handle this just fine. `?f=is,page,/my/page/:some_param`
- # vs `?f=is,page,%2Fmy%2Fpage%2F%3Asome_param`
- @do_not_url_encode [":", "/"]
- @do_not_url_encode_map Enum.into(@do_not_url_encode, %{}, fn char ->
- {URI.encode_www_form(char), char}
- end)
- defp custom_uri_encode(input) when is_integer(input) do
- to_string(input)
- end
-
- defp custom_uri_encode(input) do
- input
- |> URI.encode_www_form()
- |> String.replace(Map.keys(@do_not_url_encode_map), &@do_not_url_encode_map[&1])
- end
-end
diff --git a/lib/plausible/stats/dashboard/utils.ex b/lib/plausible/stats/dashboard/utils.ex
deleted file mode 100644
index 78ccdaa702..0000000000
--- a/lib/plausible/stats/dashboard/utils.ex
+++ /dev/null
@@ -1,47 +0,0 @@
-defmodule Plausible.Stats.Dashboard.Utils do
- @moduledoc """
- Shared utilities by different dashboard reports.
- """
-
- alias Plausible.Site
- alias Plausible.Stats.{Dashboard, ParsedQueryParams}
-
- def page_external_link_fn_for(site) do
- with true <- Plausible.Sites.regular?(site),
- [domain | _] <- String.split(site.domain, "/"),
- {:ok, domain} <- idna_encode(domain),
- {:ok, uri} <- URI.new("https://#{domain}/") do
- fn item ->
- "https://#{uri.host}#{hd(item.dimensions)}"
- end
- else
- _ -> nil
- end
- end
-
- def dashboard_route(%Site{} = site, %ParsedQueryParams{} = params, opts) do
- path = Keyword.get(opts, :path, "")
-
- params =
- case Keyword.get(opts, :filter) do
- nil -> params
- filter -> ParsedQueryParams.add_or_replace_filter(params, filter)
- end
-
- query_string =
- case Dashboard.QuerySerializer.serialize(params) do
- "" -> ""
- query_string -> "?" <> query_string
- end
-
- "/" <> site.domain <> path <> query_string
- end
-
- defp idna_encode(domain) do
- try do
- {:ok, domain |> String.to_charlist() |> :idna.encode() |> IO.iodata_to_binary()}
- catch
- _ -> {:error, :invalid_domain}
- end
- end
-end
diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.ex
index a69c15d3f1..de342a0932 100644
--- a/lib/plausible_web/controllers/stats_controller.ex
+++ b/lib/plausible_web/controllers/stats_controller.ex
@@ -101,8 +101,7 @@ defmodule PlausibleWeb.StatsController do
consolidated_view?: consolidated_view?,
consolidated_view_available?: consolidated_view_available?,
team_identifier: team_identifier,
- limited_to_segment_id: nil,
- connect_live_socket: PlausibleWeb.Live.Dashboard.enabled?(site)
+ limited_to_segment_id: nil
)
!stats_start_date && can_see_stats? ->
@@ -480,7 +479,7 @@ defmodule PlausibleWeb.StatsController do
defp get_flags(user, site),
do:
- [:live_dashboard]
+ []
|> Enum.map(fn flag ->
{flag, FunWithFlags.enabled?(flag, for: user) || FunWithFlags.enabled?(flag, for: site)}
end)
diff --git a/lib/plausible_web/live/components/dashboard/base.ex b/lib/plausible_web/live/components/dashboard/base.ex
deleted file mode 100644
index 096654daf9..0000000000
--- a/lib/plausible_web/live/components/dashboard/base.ex
+++ /dev/null
@@ -1,51 +0,0 @@
-defmodule PlausibleWeb.Components.Dashboard.Base do
- @moduledoc """
- Common components for dasbhaord.
- """
-
- use PlausibleWeb, :component
-
- attr :to, :string, required: true
- attr :class, :string, default: ""
- attr :rest, :global
-
- slot :inner_block, required: true
-
- def dashboard_link(assigns) do
- ~H"""
- <.link
- data-type="dashboard-link"
- patch={@to}
- class={@class}
- {@rest}
- >
- {render_slot(@inner_block)}
- </.link>
- """
- end
-
- attr :style, :string, default: ""
- attr :background_class, :string, default: ""
- attr :width, :integer, required: true
- attr :max_width, :integer, required: true
-
- slot :inner_block, required: true
-
- def bar(assigns) do
- width_percent = assigns.width / assigns.max_width * 100
-
- assigns = assign(assigns, :width_percent, width_percent)
-
- ~H"""
- <div class="w-full h-full relative" style={@style}>
- <div
- class={"absolute top-0 left-0 h-full rounded-sm transition-colors duration-150 #{@background_class || ""}"}
- data-test-id="bar-indicator"
- style={"width: #{@width_percent}%"}
- >
- </div>
- {render_slot(@inner_block)}
- </div>
- """
- end
-end
diff --git a/lib/plausible_web/live/components/dashboard/imported_data_warnings.ex b/lib/plausible_web/live/components/dashboard/imported_data_warnings.ex
deleted file mode 100644
index ce9f68518d..0000000000
--- a/lib/plausible_web/live/components/dashboard/imported_data_warnings.ex
+++ /dev/null
@@ -1,28 +0,0 @@
-defmodule PlausibleWeb.Components.Dashboard.ImportedDataWarnings do
- @moduledoc false
-
- use PlausibleWeb, :component
- alias Plausible.Stats.QueryResult
-
- def unsupported_filters(assigns) do
- show? =
- case assigns.query_result do
- %QueryResult{meta: meta} ->
- meta[:imports_skip_reason] == :unsupported_query
-
- _ ->
- false
- end
-
- assigns = assign(assigns, :show?, show?)
-
- ~H"""
- <div :if={@show?} data-test-id="unsupported-filters-warning">
- <span class="hidden">
- Imported data is excluded due to the applied filters
- </span>
- <Heroicons.exclamation_circle class="mb-1 size-4.5 text-gray-500 dark:text-gray-400" />
- </div>
- """
- end
-end
diff --git a/lib/plausible_web/live/components/dashboard/metric.ex b/lib/plausible_web/live/components/dashboard/metric.ex
deleted file mode 100644
index d7a191f84a..0000000000
--- a/lib/plausible_web/live/components/dashboard/metric.ex
+++ /dev/null
@@ -1,61 +0,0 @@
-defmodule PlausibleWeb.Components.Dashboard.Metric do
- @moduledoc """
- Components for rendering metric data.
- """
-
- use PlausibleWeb, :component
-
- @formatters %{
- visitors: :number_short,
- conversion_rate: :percentage,
- group_conversion_rate: :percentage
- }
-
- attr :name, :atom, required: true
- attr :value, :any
-
- def value(assigns) do
- ~H"""
- <div class="cursor-default">
- {format_value(@name, @value)}
- </div>
- """
- end
-
- defp format_value(name, value) do
- apply_format(@formatters[name], value)
- end
-
- @hundred_billion :math.pow(10, 11)
- @billion :math.pow(10, 9)
- @hundred_million :math.pow(10, 8)
- @million :math.pow(10, 6)
- @hundred_thousand :math.pow(10, 5)
- @thousand :math.pow(10, 3)
-
- defp apply_format(:number_short, value) when is_number(value) do
- cond do
- value >= @hundred_billion -> divided(value, @billion)
- value >= @billion -> divided(value, @billion, 2)
- value >= @hundred_million -> divided(value, @million)
- value >= @million -> divided(value, @million, 2)
- value >= @hundred_thousand -> divided(value, @thousand)
- value >= @thousand -> divided(value, @thousand, 2)
- true -> value
- end
- end
-
- defp apply_format(:number_short, _), do: "-"
-
- defp apply_format(:percentage, value) do
- if value do
- :erlang.float_to_binary(value, decimals: 2) <> "%"
- else
- "-"
- end
- end
-
- defp divided(value, divisor, precision \\ 0) do
- :erlang.float_to_binary(value / divisor, decimals: precision)
- end
-end
diff --git a/lib/plausible_web/live/components/dashboard/report_list.ex b/lib/plausible_web/live/components/dashboard/report_list.ex
deleted file mode 100644
index 81a1f3948e..0000000000
--- a/lib/plausible_web/live/components/dashboard/report_list.ex
+++ /dev/null
@@ -1,200 +0,0 @@
-defmodule PlausibleWeb.Components.Dashboard.ReportList do
- @moduledoc """
- ReportList component.
- """
-
- use PlausibleWeb, :component
-
- alias PlausibleWeb.Components.Dashboard.Base
- alias PlausibleWeb.Components.Dashboard.Metric
- alias Plausible.Stats.QueryResult
- alias Plausible.Stats.Dashboard.Utils
-
- @max_items 9
- @min_height 356
- @row_height 32
- @row_gap_height 4
- @data_container_height (@row_height + @row_gap_height) * (@max_items - 1) + @row_height
- @col_min_width 70
-
- def height, do: @min_height
-
- def report(assigns) do
- assigns =
- assign(assigns,
- max_items: @max_items,
- min_height: @min_height,
- row_height: @row_height,
- row_gap_height: @row_gap_height,
- data_container_height: @data_container_height,
- col_min_width: @col_min_width
- )
-
- %QueryResult{results: results, meta: meta, query: query} = assigns.query_result
-
- assigns =
- assign(assigns,
- results: results,
- metric_keys: query[:metrics],
- metric_labels: meta[:metric_labels],
- empty?: Enum.empty?(results)
- )
-
- ~H"""
- <.no_data :if={@empty?} min_height={@min_height} data_test_id={@data_test_id} />
-
- <div :if={not @empty?} class="h-full flex flex-col" data-test-id={@data_test_id}>
- <div style={"min-height: #{@row_height}px;"}>
- <.report_header
- key_label={@key_label}
- metric_labels={@metric_labels}
- col_min_width={@col_min_width}
- />
- </div>
-
- <div class="grow" style={"min-height: #{@data_container_height}px;"}>
- <.report_row
- :for={{item, item_index} <- Enum.with_index(@results)}
- link_fn={assigns[:external_link_fn]}
- item={item}
- item_index={item_index}
- item_name={List.first(item.dimensions)}
- metrics={Enum.zip(@metric_keys, item.metrics)}
- bar_max_value={bar_max_value(@results, @metric_keys)}
- site={@site}
- params={@params}
- dimension={@dimension}
- row_height={@row_height}
- row_gap_height={@row_gap_height}
- col_min_width={@col_min_width}
- />
- </div>
- </div>
- """
- end
-
- defp no_data(assigns) do
- ~H"""
- <div
- data-test-id={@data_test_id}
- class="w-full h-full flex flex-col justify-center group-has-[.tile-tabs.phx-hook-loading]:hidden"
- style={"min-height: #{@min_height}px;"}
- >
- <div class="mx-auto font-medium text-gray-500 dark:text-gray-400">
- No data yet
- </div>
- </div>
- """
- end
-
- defp external_link(assigns) do
- url = if(assigns[:link_fn], do: assigns.link_fn.(assigns.item))
-
- assigns = assign(assigns, :url, url)
-
- ~H"""
- <a
- :if={@url}
- target="_blank"
- rel="noreferrer"
- href={@url}
- class="invisible md:group-hover/row:visible"
- >
- <svg
- xmlns="http://www.w3.org/2000/svg"
- fill="none"
- viewBox="0 0 24 24"
- class="inline size-3.5 mb-0.5 text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200"
- >
- <path
- stroke="currentColor"
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M9 5H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4M12 12l9-9-.303.303M14 3h7v7"
- />
- </svg>
- </a>
- """
- end
-
- defp report_header(assigns) do
- ~H"""
- <div class="pt-3 w-full text-xs font-medium text-gray-500 flex items-center dark:text-gray-400">
- <span data-test-id="report-list-0-0" class="grow truncate">{@key_label}</span>
- <div
- :for={{metric_label, index} <- Enum.with_index(@metric_labels)}
- class="text-right"
- style={"min-width: #{@col_min_width}px;"}
- data-test-id={"report-list-0-#{1 + index}"}
- >
- {metric_label}
- </div>
- </div>
- """
- end
-
- def report_row(assigns) do
- ~H"""
- <div style={"min-height: #{@row_height}px;"}>
- <div
- class="group/row flex w-full items-center hover:bg-gray-100/60 dark:hover:bg-gray-850 rounded-sm transition-colors duration-150"
- style={"margin-top: #{@row_gap_height}px;"}
- >
- <div class="grow w-full overflow-hidden" data-test-id={"report-list-#{1 + @item_index}-0"}>
- <Base.bar
- width={@metrics[:visitors]}
- max_width={@bar_max_value}
- background_class="bg-green-50 group-hover/row:bg-green-100 dark:bg-gray-500/15 dark:group-hover/row:bg-gray-500/30"
- >
- <div class="flex justify-start items-center gap-x-1.5 px-2 py-1.5 text-sm dark:text-gray-300 relative z-9 break-all w-full">
- <Base.dashboard_link
- class="max-w-max w-full flex items-center md:overflow-hidden hover:underline"
- to={Utils.dashboard_route(@site, @params, filter: [:is, @dimension, [@item_name]])}
- >
- {trim_name(@item_name, @col_min_width)}
- </Base.dashboard_link>
- <.external_link item={@item} link_fn={assigns[:link_fn]} />
- </div>
- </Base.bar>
- </div>
- <div
- :for={{{metric_key, metric_value}, metric_index} <- Enum.with_index(@metrics)}
- class="text-right"
- style={"width: #{@col_min_width}px; min-width: #{@col_min_width}px;"}
- >
- <span
- class="font-medium text-sm dark:text-gray-200 text-right"
- data-test-id={"report-list-#{1 + @item_index}-#{1 + metric_index}"}
- >
- <Metric.value name={metric_key} value={metric_value} />
- </span>
- </div>
- </div>
- </div>
- """
- end
-
- @bar_metric :visitors
- defp bar_max_value(results, metrics) do
- index = Enum.find_index(metrics, &(&1 == @bar_metric))
-
- results
- |> Enum.map(&Enum.at(&1.metrics, index))
- |> Enum.max(&>=/2, fn -> 0 end)
- end
-
- defp trim_name(name, max_length) do
- if String.length(name) <= max_length do
- name
- else
- left_length = div(max_length, 2)
- right_length = max_length - left_length
-
- left_side = String.slice(name, 0..left_length)
- right_side = String.slice(name, -right_length..-1)
-
- left_side <> "..." <> right_side
- end
- end
-end
diff --git a/lib/plausible_web/live/components/dashboard/tile.ex b/lib/plausible_web/live/components/dashboard/tile.ex
deleted file mode 100644
index 4750325592..0000000000
--- a/lib/plausible_web/live/components/dashboard/tile.ex
+++ /dev/null
@@ -1,131 +0,0 @@
-defmodule PlausibleWeb.Components.Dashboard.Tile do
- @moduledoc """
- Components for rendering dashboard tile contents.
- """
-
- use PlausibleWeb, :component
- alias PlausibleWeb.Components.Dashboard.Base
-
- attr :id, :string, required: true
- attr :class, :string, default: ""
- attr :title, :string, required: true
- attr :height, :integer, required: true
- attr :connected?, :boolean, required: true
- attr :details_route, :string, required: true
- attr :target, :any, required: true
-
- slot :warnings
- slot :tabs
- slot :inner_block, required: true
-
- def tile(assigns) do
- ~H"""
- <div
- data-tile
- id={@id}
- class="relative min-h-[430px] w-full p-5 flex flex-col bg-white dark:bg-gray-900 shadow-sm rounded-md md:min-h-initial md:h-27.25rem"
- >
- <%!-- reportheader --%>
- <div class="w-full flex justify-between border-b border-gray-200 dark:border-gray-750">
- <div class="flex gap-x-3">
- <div
- :if={@tabs != []}
- id={@id <> "-tabs"}
- phx-hook="DashboardTabs"
- phx-target={@target}
- class="tile-tabs flex items-baseline gap-x-3.5 text-xs font-medium text-gray-500 dark:text-gray-400"
- >
- {render_slot(@tabs)}
- </div>
- <div class="group-[.phx-navigation-loading]:hidden group-has-[.tile-tabs.phx-hook-loading]:hidden">
- {render_slot(@warnings)}
- </div>
- </div>
- <.details_link details_route={@details_route} path="/pages" />
- </div>
- <%!-- reportbody --%>
- <div
- class="w-full flex-col justify-center group-[.phx-navigation-loading]:flex group-has-[.tile-tabs.phx-hook-loading]:flex hidden"
- style={"min-height: #{@height}px;"}
- >
- <div class="mx-auto loading">
- <div></div>
- </div>
- </div>
-
- <div class="group-[.phx-navigation-loading]:hidden group-has-[.tile-tabs.phx-hook-loading]:hidden">
- {render_slot(@inner_block)}
- </div>
- </div>
- """
- end
-
- attr :report_label, :string, required: true
- attr :tab_key, :string, required: true
- attr :active_tab, :string, required: true
- attr :target, :any, required: true
-
- def tab(assigns) do
- assigns =
- assign(
- assigns,
- data_attrs:
- if(assigns.tab_key == assigns.active_tab,
- do: %{"data-active": "true"},
- else: %{"data-active": "false"}
- )
- )
-
- ~H"""
- <div
- {@data_attrs}
- class="-mb-px pb-4 data-[active=true]:border-b-2 data-[active=true]:border-gray-900 data-[active=true]:dark:border-gray-100"
- >
- <button
- class="group/tab flex rounded-sm"
- data-tab-key={@tab_key}
- data-report-label={@report_label}
- data-storage-key="pageTab"
- data-target={@target}
- >
- <span
- {@data_attrs}
- class="
- truncate text-left text-xs uppercase text-gray-500 dark:text-gray-400 font-semibold cursor-pointer
- data-[active=false]:group-hover/tab:text-gray-800
- data-[active=false]:dark:group-hover/tab:text-gray-200
- data-[active=true]:text-gray-900
- data-[active=true]:dark:text-gray-100
- data-[active=true]:font-bold
- data-[active=true]:font-bold
- data-[active=true]:tracking-[-.01em]"
- >
- {@report_label}
- </span>
- </button>
- </div>
- """
- end
-
- defp details_link(assigns) do
- ~H"""
- <Base.dashboard_link
- class="flex mt-px text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-150"
- to={@details_route}
- >
- <svg
- class="feather"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- stroke-linecap="round"
- stroke-linejoin="round"
- >
- <path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
- </svg>
- </Base.dashboard_link>
- """
- end
-end
diff --git a/lib/plausible_web/live/dashboard.ex b/lib/plausible_web/live/dashboard.ex
deleted file mode 100644
index 96d85adfcd..0000000000
--- a/lib/plausible_web/live/dashboard.ex
+++ /dev/null
@@ -1,110 +0,0 @@
-defmodule PlausibleWeb.Live.Dashboard do
- @moduledoc """
- LiveView for site dashboard.
- """
-
- use PlausibleWeb, :live_view
-
- alias Plausible.Repo
- alias Plausible.Stats.Dashboard
- alias Plausible.Teams
-
- @spec enabled?(Plausible.Site.t() | nil) :: boolean()
- def enabled?(nil), do: false
-
- def enabled?(site) do
- FunWithFlags.enabled?(:live_dashboard, for: site)
- end
-
- def mount(_params, %{"domain" => domain, "url" => url}, socket) do
- user_prefs = get_connect_params(socket)["user_prefs"] || %{}
-
- # As domain is passed via session, the associated site has already passed
- # validation logic on plug level.
- site =
- Plausible.Site
- |> Repo.get_by!(domain: domain)
- |> Repo.preload([
- :owners,
- :completed_imports,
- team: [:owners, subscription: Teams.last_subscription_query()]
- ])
-
- socket =
- socket
- |> assign(:connected?, connected?(socket))
- |> assign(:site, site)
- |> assign(:user_prefs, user_prefs)
-
- {:noreply, socket} = handle_params_internal(%{}, url, socket)
-
- {:ok, socket}
- end
-
- def handle_params_internal(_params, url, socket) do
- uri = URI.parse(url)
- path = uri.path |> String.split("/") |> Enum.drop(2)
-
- {:ok, params} =
- Dashboard.QueryParser.parse(
- uri.query || "",
- socket.assigns.site,
- socket.assigns.user_prefs
- )
-
- socket =
- assign(socket,
- path: path,
- params: params
- )
-
- {:noreply, socket}
- end
-
- def render(assigns) do
- ~H"""
- <div id="live-dashboard-container" phx-hook="DashboardRoot">
- <.portal_wrapper id="pages-breakdown-live-container" target="#pages-breakdown-live">
- <.live_component
- module={PlausibleWeb.Live.Dashboard.Pages}
- id="pages-breakdown-component"
- site={@site}
- user_prefs={@user_prefs}
- connected?={@connected?}
- params={@params}
- />
- </.portal_wrapper>
- </div>
- """
- end
-
- def handle_event("handle_dashboard_params", %{"url" => url}, socket) do
- query =
- url
- |> URI.parse()
- |> Map.fetch!(:query)
-
- params = URI.decode_query(query || "")
-
- handle_params_internal(params, url, socket)
- end
-
- attr :id, :string, required: true
- attr :target, :string, required: true
-
- slot :inner_block
-
- if Mix.env() in [:test, :ce_test] do
- defp portal_wrapper(assigns) do
- ~H"""
- <div id={@id}>{render_slot(@inner_block)}</div>
- """
- end
- else
- defp portal_wrapper(assigns) do
- ~H"""
- <.portal id={@id} target={@target}>{render_slot(@inner_block)}</.portal>
- """
- end
- end
-end
diff --git a/lib/plausible_web/live/dashboard/pages.ex b/lib/plausible_web/live/dashboard/pages.ex
deleted file mode 100644
index d4763e987b..0000000000
--- a/lib/plausible_web/live/dashboard/pages.ex
+++ /dev/null
@@ -1,139 +0,0 @@
-defmodule PlausibleWeb.Live.Dashboard.Pages do
- @moduledoc """
- Pages breakdown component.
- """
-
- use PlausibleWeb, :live_component
-
- alias PlausibleWeb.Components.Dashboard.{ReportList, Tile, ImportedDataWarnings}
-
- alias Plausible.Stats
- alias Plausible.Stats.{ParsedQueryParams, QueryBuilder, QueryResult}
-
- import Plausible.Stats.Dashboard.Utils
-
- @tabs [
- %{
- tab_key: "pages",
- report_label: "Top pages",
- key_label: "Page",
- dimension: "event:page"
- },
- %{
- tab_key: "entry-pages",
- report_label: "Entry pages",
- key_label: "Entry page",
- dimension: "visit:entry_page"
- },
- %{
- tab_key: "exit-pages",
- report_label: "Exit pages",
- key_label: "Exit page",
- dimension: "visit:exit_page"
- }
- ]
-
- @pagination %{limit: 9, offset: 0}
-
- def update(assigns, socket) do
- active_tab = assigns.user_prefs["pages_tab"] || "pages"
-
- socket =
- assign(socket,
- site: assigns.site,
- params: assigns.params,
- tabs: @tabs,
- active_tab: active_tab,
- connected?: assigns.connected?
- )
- |> load_stats()
-
- {:ok, socket}
- end
-
- def render(assigns) do
- ~H"""
- <div>
- <Tile.tile
- id="breakdown-tile-pages"
- details_route={dashboard_route(@site, @params, path: "/#{@active_tab}")}
- title={get_tab_info(@active_tab, :report_label)}
- connected?={@connected?}
- target={@myself}
- height={ReportList.height()}
- >
- <:warnings>
- <ImportedDataWarnings.unsupported_filters query_result={@query_result} />
- </:warnings>
- <:tabs>
- <Tile.tab
- :for={%{tab_key: tab_key, report_label: report_label} <- @tabs}
- report_label={report_label}
- tab_key={tab_key}
- active_tab={@active_tab}
- target={@myself}
- />
- </:tabs>
-
- <ReportList.report
- site={@site}
- data_test_id={"#{@active_tab}-report-list"}
- key_label={get_tab_info(@active_tab, :key_label)}
- dimension={get_tab_info(@active_tab, :dimension)}
- params={@params}
- query_result={@query_result}
- external_link_fn={page_external_link_fn_for(@site)}
- />
- </Tile.tile>
- </div>
- """
- end
-
- def handle_event("set-tab", %{"tab" => tab}, socket) do
- if tab != socket.assigns.active_tab do
- socket =
- socket
- |> assign(:active_tab, tab)
- |> load_stats()
-
- {:noreply, socket}
- else
- {:noreply, socket}
- end
- end
-
- defp load_stats(socket) do
- %{active_tab: active_tab, site: site, params: params} = socket.assigns
-
- metrics = choose_metrics(params)
- dimension = get_tab_info(active_tab, :dimension)
-
- params =
- params
- |> ParsedQueryParams.set(
- metrics: metrics,
- dimensions: [dimension],
- pagination: @pagination
- )
-
- query = QueryBuilder.build!(site, params)
-
- %QueryResult{} = query_result = Stats.query(site, query)
-
- assign(socket, :query_result, query_result)
- end
-
- defp choose_metrics(%ParsedQueryParams{} = params) do
- if ParsedQueryParams.conversion_goal_filter?(params) do
- [:visitors, :group_conversion_rate]
- else
- [:visitors]
- end
- end
-
- defp get_tab_info(tab_key, field) do
- @tabs
- |> Enum.find(&(&1.tab_key == tab_key))
- |> Map.fetch!(field)
- end
-end
diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex
index bafaa080d8..587c2e3c08 100644
--- a/lib/plausible_web/router.ex
+++ b/lib/plausible_web/router.ex
@@ -700,10 +700,7 @@ defmodule PlausibleWeb.Router do
put "/:domain/settings", SiteController, :update_settings
get "/:domain/export", StatsController, :csv_export
-
- scope assigns: %{live_socket_disable_push_state: true} do
- get "/:domain/*path", StatsController, :stats
- end
+ get "/:domain/*path", StatsController, :stats
end
end
end
diff --git a/lib/plausible_web/templates/layout/app.html.heex b/lib/plausible_web/templates/layout/app.html.heex
index 3e121b0806..dc217ba23f 100644
--- a/lib/plausible_web/templates/layout/app.html.heex
+++ b/lib/plausible_web/templates/layout/app.html.heex
@@ -12,12 +12,6 @@
<meta name="csrf-token" content={Plug.CSRFProtection.get_csrf_token()} />
<meta name="websocket-url" content={websocket_url()} />
<% end %>
- <%= if PlausibleWeb.Live.Dashboard.enabled?(assigns[:site]) do %>
- <%= if assigns[:live_socket_disable_push_state] do %>
- <meta name="live-socket-disable-push-state" content="true" />
- <% end %>
- <meta name="dashboard-domain" content={@site.domain} />
- <% end %>
<meta name="robots" content={@conn.private.robots} />
<PlausibleWeb.Components.Layout.favicon conn={@conn} />
diff --git a/lib/plausible_web/templates/stats/stats.html.heex b/lib/plausible_web/templates/stats/stats.html.heex
index 0c698cc9b0..04d1e8d36e 100644
--- a/lib/plausible_web/templates/stats/stats.html.heex
+++ b/lib/plausible_web/templates/stats/stats.html.heex
@@ -55,15 +55,6 @@
data-limited-to-segment-id={Jason.encode!(@limited_to_segment_id)}
>
</div>
- <%= if PlausibleWeb.Live.Dashboard.enabled?(@site) do %>
- {live_render(@conn, PlausibleWeb.Live.Dashboard,
- id: "live-dashboard-lv",
- session: %{
- "domain" => @site.domain,
- "url" => Plug.Conn.request_url(@conn)
- }
- )}
- <% end %>
<div id="modal_root"></div>
<%= if [email protected][:current_user] && @conn.assigns[:demo] do %>
<div class="py-12 lg:py-16 lg:flex lg:items-center lg:justify-between">
diff --git a/mix.exs b/mix.exs
index ed2380e948..a70666b655 100644
--- a/mix.exs
+++ b/mix.exs
@@ -112,10 +112,7 @@ defmodule Plausible.MixProject do
{:phoenix_html, "~> 4.1"},
{:phoenix_live_reload, "~> 1.2", only: [:dev, :ce_dev]},
{:phoenix_pubsub, "~> 2.0"},
- {:phoenix_live_view,
- git: "https://github.com/plausible/phoenix_live_view.git",
- branch: "disable-push-state-v-1-1-18",
- override: true},
+ {:phoenix_live_view, "~> 1.1.17"},
{:php_serializer, "~> 2.0"},
{:plug, "~> 1.13", override: true},
{:prima, "~> 0.2.1"},
diff --git a/mix.lock b/mix.lock
index 4c50ed47af..f2e6acc109 100644
--- a/mix.lock
+++ b/mix.lock
@@ -125,7 +125,7 @@
"phoenix_html": {:hex, :phoenix_html, "4.3.0", "d3577a5df4b6954cd7890c84d955c470b5310bb49647f0a114a6eeecc850f7ad", [:mix], [], "hexpm", "3eaa290a78bab0f075f791a46a981bbe769d94bc776869f4f3063a14f30497ad"},
"phoenix_html_helpers": {:hex, :phoenix_html_helpers, "1.0.1", "7eed85c52eff80a179391036931791ee5d2f713d76a81d0d2c6ebafe1e11e5ec", [:mix], [{:phoenix_html, "~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cffd2385d1fa4f78b04432df69ab8da63dc5cf63e07b713a4dcf36a3740e3090"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.6.1", "05df733a09887a005ed0d69a7fc619d376aea2730bf64ce52ac51ce716cc1ef0", [:mix], [{:file_system, "~> 0.2.10 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "74273843d5a6e4fef0bbc17599f33e3ec63f08e69215623a0cd91eea4288e5a0"},
- "phoenix_live_view": {:git, "https://github.com/plausible/phoenix_live_view.git", "2c59a7da2f254ce789ee5924b34907870624ca3b", [branch: "disable-push-state-v-1-1-18"]},
+ "phoenix_live_view": {:hex, :phoenix_live_view, "1.1.20", "4f20850ee700b309b21906a0e510af1b916b454b4f810fb8581ada016eb42dfc", [:mix], [{:igniter, ">= 0.6.16 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:lazy_html, "~> 0.1.0", [hex: :lazy_html, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0 or ~> 1.8.0-rc", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c16abd605a21f778165cb0079946351ef20ef84eb1ef467a862fb9a173b1d27d"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"},
"phoenix_storybook": {:hex, :phoenix_storybook, "0.9.3", "4f94e731d4c40d4dd7d1eddf7d5c6914366da7d78552dc565b222e4036d0d76f", [:mix], [{:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: true]}, {:makeup_eex, "~> 2.0.2", [hex: :makeup_eex, repo: "hexpm", optional: false]}, {:makeup_html, "~> 0.2.0", [hex: :makeup_html, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.8.1", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html_helpers, "~> 1.0", [hex: :phoenix_html_helpers, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}], "hexpm", "4c8658b756fd8238f7e8e4343a0f12bdb91d4eba592b1c4e8118b37b6fd43e4b"},
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs
index 44df81d265..1522defcfc 100644
--- a/priv/repo/seeds.exs
+++ b/priv/repo/seeds.exs
@@ -55,8 +55,6 @@ long_random_urls =
"https://dummy.site#{path}"
end
-FunWithFlags.enable(:live_dashboard)
-
site =
new_site(
domain: "dummy.site",
diff --git a/test/plausible/stats/dashboard/query_serializer_test.exs b/test/plausible/stats/dashboard/query_serializer_test.exs
deleted file mode 100644
index ada5563c94..0000000000
--- a/test/plausible/stats/dashboard/query_serializer_test.exs
+++ /dev/null
@@ -1,214 +0,0 @@
-defmodule Plausible.Stats.Dashboard.QuerySerializerTest do
- use Plausible.DataCase
- import Plausible.Stats.Dashboard.{QueryParser, QuerySerializer}
- alias Plausible.Stats.ParsedQueryParams
-
- @default_include default_include()
-
- describe "parse -> serialize is a reversible transformation" do
- for query_string <- ["period=month", "date=2021-07-07&f=is,browser,Chrome,Firefox&period=day"] do
- test "with query string being '#{query_string}'" do
- {:ok, parsed} = parse(unquote(query_string), build(:site), %{})
- assert serialize(parsed) == unquote(query_string)
- end
- end
-
- test "but alphabetical ordering by key is enforced" do
- {:ok, parsed} = parse("period=day&date=2021-07-07", build(:site), %{})
- assert serialize(parsed) == "date=2021-07-07&period=day"
- end
-
- test "but redundant values get removed" do
- {:ok, parsed} = parse("period=all&with_imported=true", build(:site), %{})
- assert serialize(parsed) == "period=all"
- end
-
- test "but leading ? gets removed" do
- {:ok, parsed} = parse("?period=day", build(:site), %{})
- assert serialize(parsed) == "period=day"
- end
- end
-
- describe "input_date_range -> period (+ from, to)" do
- for input_date_range <- [:realtime, :day, :month, :year, :all] do
- test "serializes #{input_date_range} input_date_range" do
- params = %ParsedQueryParams{
- input_date_range: unquote(input_date_range),
- include: @default_include
- }
-
- assert serialize(params) == "period=#{Atom.to_string(unquote(input_date_range))}"
- end
- end
-
- for i <- [7, 28, 30, 91] do
- test "serializes {:last_n_days, #{i}} input_date_range" do
- params = %ParsedQueryParams{
- input_date_range: {:last_n_days, unquote(i)},
- include: @default_include
- }
-
- assert serialize(params) == "period=#{unquote(i)}d"
- end
- end
-
- for i <- [6, 12] do
- test "serializes {:last_n_months, #{i}} input_date_range" do
- params = %ParsedQueryParams{
- input_date_range: {:last_n_months, unquote(i)},
- include: @default_include
- }
-
- assert serialize(params) == "period=#{unquote(i)}mo"
- end
- end
-
- test "serlializes custom input_date_range" do
- params = %ParsedQueryParams{
- input_date_range: {:date_range, ~D[2021-01-01], ~D[2021-03-05]},
- include: @default_include
- }
-
- assert serialize(params) == "from=2021-01-01&period=custom&to=2021-03-05"
- end
- end
-
- describe "relative_date -> date" do
- test "serializes a date struct into iso8601" do
- params = %ParsedQueryParams{relative_date: ~D[2021-05-05], include: @default_include}
- assert serialize(params) == "date=2021-05-05"
- end
- end
-
- describe "include.imports -> with_imported" do
- test "false -> false" do
- params = %ParsedQueryParams{include: %{@default_include | imports: false}}
- assert serialize(params) == "with_imported=false"
- end
- end
-
- describe "include.compare -> comparison" do
- for mode <- [:previous_period, :year_over_year] do
- test "serializes #{mode} mode" do
- params = %ParsedQueryParams{include: %{@default_include | compare: unquote(mode)}}
- assert serialize(params) == "comparison=#{unquote(mode)}"
- end
- end
-
- test "serializes custom comparison range" do
- params = %ParsedQueryParams{
- include: %{@default_include | compare: {:date_range, ~D[2021-01-01], ~D[2021-04-30]}}
- }
-
- assert serialize(params) ==
- "compare_from=2021-01-01&compare_to=2021-04-30&comparison=custom"
- end
- end
-
- describe "include.compare_match_day_of_week -> match_day_of_week" do
- test "false -> false" do
- params = %ParsedQueryParams{include: %{@default_include | compare_match_day_of_week: false}}
- assert serialize(params) == "match_day_of_week=false"
- end
- end
-
- describe "filters" do
- test "serializes multiple is filters" do
- serialized =
- serialize(%ParsedQueryParams{
- filters: [
- [:is, "visit:exit_page", ["/:dashboard"]],
- [:is, "visit:source", ["Bing"]],
- [:is, "event:props:theme", ["system"]]
- ],
- include: @default_include
- })
-
- assert serialized == "f=is,exit_page,/:dashboard&f=is,source,Bing&f=is,props:theme,system"
- end
-
- test "serializes filters with integer clauses" do
- serialized =
- serialize(%ParsedQueryParams{
- filters: [
- [:is, "segment", [123, 456, 789]],
- [:is, "visit:city", [2_950_159]]
- ],
- include: @default_include
- })
-
- assert serialized == "f=is,segment,123,456,789&f=is,city,2950159&l=2950159,Berlin"
- end
-
- test "serializes empty filters" do
- serialized = serialize(%ParsedQueryParams{filters: [], include: @default_include}, [])
- assert serialized == ""
- end
- end
-
- describe "labels" do
- test "adds location labels" do
- serialized =
- serialize(%ParsedQueryParams{
- filters: [
- [:is, "visit:country", ["EE"]],
- [:is, "visit:region", ["EE-79"]],
- [:is, "visit:city", [588_335]]
- ],
- include: @default_include
- })
-
- assert serialized ==
- "f=is,country,EE&f=is,region,EE-79&f=is,city,588335&l=EE,Estonia&l=EE-79,Tartumaa&l=588335,Tartu"
- end
-
- test "adds segment label" do
- user = new_user()
- site = new_site(owner: user)
-
- segment =
- insert(:segment,
- type: :personal,
- owner: user,
- site: site,
- name: "personal segment"
- )
-
- serialized =
- serialize(
- %ParsedQueryParams{
- filters: [[:is, "segment", [segment.id]]],
- include: @default_include
- },
- [segment]
- )
-
- assert serialized ==
- "f=is,segment,#{segment.id}&l=#{segment.id},#{segment.name}"
- end
-
- test "skips location labels when not found" do
- serialized =
- serialize(%ParsedQueryParams{
- filters: [
- [:is, "visit:country", ["XX"]],
- [:is, "visit:region", ["XX-00"]],
- [:is, "visit:city", [999_999_999]]
- ],
- include: @default_include
- })
-
- assert serialized == "f=is,country,XX&f=is,region,XX-00&f=is,city,999999999"
- end
-
- test "skips segment label when not found" do
- serialized =
- serialize(%ParsedQueryParams{
- filters: [[:is, "segment", [1]]],
- include: @default_include
- })
-
- assert serialized == "f=is,segment,1"
- end
- end
-end
diff --git a/test/plausible/stats/dashboard/utils_test.exs b/test/plausible/stats/dashboard/utils_test.exs
deleted file mode 100644
index a21f5a5270..0000000000
--- a/test/plausible/stats/dashboard/utils_test.exs
+++ /dev/null
@@ -1,40 +0,0 @@
-defmodule Plausible.Stats.Dashboard.UtilsTest do
- use Plausible.DataCase
- import Plausible.Stats.Dashboard.Utils
-
- describe "page_external_link_fn_for/1" do
- @tag :ee_only
- test "returns nil for a consolidated site" do
- site = build(:site, consolidated: true)
- assert is_nil(page_external_link_fn_for(site))
- end
-
- test "returns a function returning a valid link for valid site" do
- site = build(:site, domain: "abc.com")
- fun = page_external_link_fn_for(site)
- assert fun.(%{dimensions: ["/some-page"]}) == "https://abc.com/some-page"
- end
-
- test "returns a function returning a valid link for site with subdomain" do
- site = build(:site, domain: "foo.abc.com")
- fun = page_external_link_fn_for(site)
- assert fun.(%{dimensions: ["/some-page"]}) == "https://foo.abc.com/some-page"
- end
-
- test "subfolder in site domain is stripped" do
- site = build(:site, domain: "abc.com/subfolder")
- fun = page_external_link_fn_for(site)
-
- assert fun.(%{dimensions: ["/subfolder/some-page"]}) ==
- "https://abc.com/subfolder/some-page"
-
- assert fun.(%{dimensions: ["/some-page"]}) == "https://abc.com/some-page"
- end
-
- test "handles internationalized domain names" do
- site = build(:site, domain: "é-1.com")
- fun = page_external_link_fn_for(site)
- assert fun.(%{dimensions: ["/some-page"]}) == "https://xn---1-9ia.com/some-page"
- end
- end
-end
diff --git a/test/plausible_web/live/components/dashboard/report_list_test.exs b/test/plausible_web/live/components/dashboard/report_list_test.exs
deleted file mode 100644
index 84e5e381d1..0000000000
--- a/test/plausible_web/live/components/dashboard/report_list_test.exs
+++ /dev/null
@@ -1,52 +0,0 @@
-defmodule PlausibleWeb.Components.Dashboard.ReportListTest do
- use PlausibleWeb.ConnCase, async: true
- import Phoenix.LiveViewTest, only: [render_component: 2]
-
- alias PlausibleWeb.Components.Dashboard.ReportList
- alias Plausible.Stats.{ParsedQueryParams, QueryResult}
- import Plausible.DashboardTestUtils
-
- @report_list_selector ~s|[data-test-id="pages-report-list"]|
- @bar_indicator_selector ~s|[data-test-id="bar-indicator"]|
-
- setup do
- assigns = [
- site: build(:site),
- data_test_id: "pages-report-list",
- key_label: "Page",
- dimension: "event:page",
- params: %ParsedQueryParams{},
- external_link_fn: fn _ -> "" end
- ]
-
- {:ok, %{assigns: assigns}}
- end
-
- test "item bar width depends on visitors metric", %{assigns: assigns} do
- query_result =
- %QueryResult{
- results: [
- %{metrics: [100, 60.0], dimensions: ["/a"]},
- %{metrics: [70, 40.0], dimensions: ["/b"]},
- %{metrics: [30, 20.0], dimensions: ["/c"]}
- ],
- meta: Jason.OrderedObject.new(metric_labels: ["Conversions", "CR"]),
- query: Jason.OrderedObject.new(metrics: [:visitors, :conversion_rate])
- }
-
- assigns = Keyword.put(assigns, :query_result, query_result)
-
- html = render_component(&ReportList.report/1, assigns)
-
- report_list = find(html, @report_list_selector)
-
- [{1, "100.0%"}, {2, "70.0%"}, {3, "30.0%"}]
- |> Enum.each(fn {item, expected_width} ->
- bar =
- get_in_report_list(report_list, item, 0, text?: false)
- |> find(@bar_indicator_selector)
-
- assert text_of_attr(bar, "style") =~ "width: #{expected_width}"
- end)
- end
-end
diff --git a/test/plausible_web/live/dashboard/dashboard_test.exs b/test/plausible_web/live/dashboard/dashboard_test.exs
deleted file mode 100644
index 4dfadec1a1..0000000000
--- a/test/plausible_web/live/dashboard/dashboard_test.exs
+++ /dev/null
@@ -1,38 +0,0 @@
-defmodule PlausibleWeb.Live.DashboardTest do
- use PlausibleWeb.ConnCase, async: false
-
- import Phoenix.LiveViewTest
-
- setup [:create_user, :log_in, :create_site]
-
- setup %{site: site} do
- populate_stats(site, [build(:pageview)])
-
- :ok
- end
-
- describe "GET /:domain" do
- test "renders live dashboard container", %{conn: conn, site: site} do
- conn = get(conn, "/#{site.domain}")
- html = html_response(conn, 200)
-
- assert element_exists?(html, "#live-dashboard-container")
- assert element_exists?(html, "#pages-breakdown-live-container")
- end
- end
-
- describe "Live.Dashboard" do
- test "it works", %{conn: conn, site: site} do
- {lv, _html} = get_liveview(conn, site)
- assert has_element?(lv, "#pages-breakdown-live-container")
- assert has_element?(lv, "#breakdown-tile-pages")
- assert has_element?(lv, "#breakdown-tile-pages-tabs")
- end
- end
-
- defp get_liveview(conn, site) do
- conn = assign(conn, :live_module, PlausibleWeb.Live.Dashboard)
- {:ok, lv, html} = live(conn, "/#{site.domain}")
- {lv, html}
- end
-end
diff --git a/test/plausible_web/live/dashboard/pages_test.exs b/test/plausible_web/live/dashboard/pages_test.exs
deleted file mode 100644
index 09ba906001..0000000000
--- a/test/plausible_web/live/dashboard/pages_test.exs
+++ /dev/null
@@ -1,289 +0,0 @@
-defmodule PlausibleWeb.Live.Dashboard.PagesTest do
- use PlausibleWeb.ConnCase, async: false
-
- import Phoenix.LiveViewTest
- import Plausible.DashboardTestUtils
-
- setup [:create_user, :log_in, :create_site]
-
- @top_pages_report_list ~s|[data-test-id="pages-report-list"]|
- @entry_pages_report_list ~s|[data-test-id="entry-pages-report-list"]|
- @exit_pages_report_list ~s|[data-test-id="exit-pages-report-list"]|
- @unsupported_filters_warning ~s|#breakdown-tile-pages [data-test-id="unsupported-filters-warning"]|
-
- describe "Top Pages" do
- test "eventually renders and orders items by visitor counts", %{conn: conn, site: site} do
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/three"),
- build(:pageview, pathname: "/three"),
- build(:pageview, pathname: "/three")
- ])
-
- assert report_list = get_liveview(conn, site) |> wait_for_element(@top_pages_report_list)
-
- assert report_list_as_table(report_list, 4, 2) == [
- ["Page", "Visitors"],
- ["/three", "3"],
- ["/two", "2"],
- ["/one", "1"]
- ]
- end
-
- test "renders current visitors", %{conn: conn, site: site} do
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/two")
- ])
-
- assert report_list =
- get_liveview(conn, site, "period=realtime")
- |> wait_for_element(@top_pages_report_list)
-
- assert report_list_as_table(report_list, 3, 2) == [
- ["Page", "Current visitors"],
- ["/two", "2"],
- ["/one", "1"]
- ]
- end
-
- test "renders conversions with conversion rate", %{conn: conn, site: site} do
- insert(:goal, site: site, event_name: "Signup")
-
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:event, name: "Signup", pathname: "/two"),
- build(:pageview, pathname: "/two")
- ])
-
- assert report_list =
- get_liveview(conn, site, "period=day&f=is,goal,Signup")
- |> wait_for_element(@top_pages_report_list)
-
- assert report_list_as_table(report_list, 2, 3) == [
- ["Page", "Conversions", "CR"],
- ["/two", "1", "50.00%"]
- ]
-
- refute get_in_report_list(report_list, 2, 0)
- end
- end
-
- describe "Entry Pages" do
- test "eventually renders and orders items by visitor counts", %{conn: conn, site: site} do
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/three"),
- build(:pageview, pathname: "/three"),
- build(:pageview, pathname: "/three")
- ])
-
- assert report_list =
- get_liveview(conn, site)
- |> change_tab("entry-pages")
- |> wait_for_element(@entry_pages_report_list)
-
- assert report_list_as_table(report_list, 4, 2) == [
- ["Entry page", "Unique entrances"],
- ["/three", "3"],
- ["/two", "2"],
- ["/one", "1"]
- ]
- end
-
- test "renders current visitors", %{conn: conn, site: site} do
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/two")
- ])
-
- assert report_list =
- get_liveview(conn, site, "period=realtime")
- |> change_tab("entry-pages")
- |> wait_for_element(@entry_pages_report_list)
-
- assert report_list_as_table(report_list, 3, 2) == [
- ["Entry page", "Current visitors"],
- ["/two", "2"],
- ["/one", "1"]
- ]
- end
-
- test "renders conversions with conversion rate", %{conn: conn, site: site} do
- insert(:goal, site: site, event_name: "Signup")
-
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/two"),
- build(:pageview, user_id: 1, pathname: "/two"),
- build(:event, user_id: 1, name: "Signup", pathname: "/two")
- ])
-
- assert report_list =
- get_liveview(conn, site, "period=day&f=is,goal,Signup")
- |> change_tab("entry-pages")
- |> wait_for_element(@entry_pages_report_list)
-
- assert report_list_as_table(report_list, 2, 3) == [
- ["Entry page", "Conversions", "CR"],
- ["/two", "1", "33.33%"]
- ]
-
- refute get_in_report_list(report_list, 2, 0)
- end
- end
-
- describe "Exit Pages" do
- test "eventually renders and orders items by visitor counts", %{conn: conn, site: site} do
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/three"),
- build(:pageview, pathname: "/three"),
- build(:pageview, pathname: "/three")
- ])
-
- assert report_list =
- get_liveview(conn, site)
- |> change_tab("exit-pages")
- |> wait_for_element(@exit_pages_report_list)
-
- assert report_list_as_table(report_list, 4, 2) == [
- ["Exit page", "Unique exits"],
- ["/three", "3"],
- ["/two", "2"],
- ["/one", "1"]
- ]
- end
-
- test "renders current visitors", %{conn: conn, site: site} do
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:pageview, pathname: "/two"),
- build(:pageview, pathname: "/two")
- ])
-
- assert report_list =
- get_liveview(conn, site, "period=realtime")
- |> change_tab("exit-pages")
- |> wait_for_element(@exit_pages_report_list)
-
- assert report_list_as_table(report_list, 3, 2) == [
- ["Exit page", "Current visitors"],
- ["/two", "2"],
- ["/one", "1"]
- ]
- end
-
- test "renders conversions with conversion rate", %{conn: conn, site: site} do
- insert(:goal, site: site, event_name: "Signup")
-
- populate_stats(site, [
- build(:pageview, pathname: "/one"),
- build(:event, user_id: 1, name: "Signup", pathname: "/two"),
- build(:pageview, user_id: 1, pathname: "/two"),
- build(:pageview, pathname: "/two")
- ])
-
- assert report_list =
- get_liveview(conn, site, "period=day&f=is,goal,Signup")
- |> change_tab("exit-pages")
- |> wait_for_element(@exit_pages_report_list)
-
- assert report_list_as_table(report_list, 2, 3) == [
- ["Exit page", "Conversions", "CR"],
- ["/two", "1", "50.00%"]
- ]
-
- refute get_in_report_list(report_list, 2, 0)
- end
- end
-
- describe "unsupported filters warning" do
- setup %{site: site} do
- site_import = insert(:site_import, site: site)
-
- populate_stats(site, site_import.id, [
- build(:pageview, timestamp: ~N[2021-01-02 00:00:00]),
- build(:imported_visitors, visitors: 1, date: ~D[2021-01-01]),
- build(:imported_pages, page: "/", visitors: 1, date: ~D[2021-01-01])
- ])
-
- :ok
- end
-
- test "shows up when mixing dimensions", %{conn: conn, site: site} do
- tooltip_element =
- get_liveview(conn, site, "period=all&f=is,browser,Chrome")
- |> wait_for_element(@unsupported_filters_warning)
-
- assert text(tooltip_element) =~ "Imported data is excluded due to the applied filters"
- end
-
- test "does not show up when mixing dimensions but imports not requested", %{
- conn: conn,
- site: site
- } do
- lv = get_liveview(conn, site, "period=all&f=is,browser,Chrome&with_imported=false")
- _report_list = wait_for_element(lv, @top_pages_report_list)
- html = render(lv)
-
- refute element_exists?(html, @unsupported_filters_warning)
- end
-
- test "does not show up when imports are included in the data", %{conn: conn, site: site} do
- lv = get_liveview(conn, site, "period=all")
- _report_list = wait_for_element(lv, @top_pages_report_list)
- html = render(lv)
-
- refute element_exists?(html, @unsupported_filters_warning)
- end
-
- test "does not show up when imports don't exist", %{conn: conn, user: user} do
- site_without_imports = new_site(owner: user, stats_start_date: ~D[2021-01-01])
-
- lv = get_liveview(conn, site_without_imports, "period=all")
- _report_list = wait_for_element(lv, @top_pages_report_list)
- html = render(lv)
-
- refute element_exists?(html, @unsupported_filters_warning)
- end
-
- test "does not show up when imports exist but out of range", %{conn: conn, site: site} do
- lv = get_liveview(conn, site, "period=day")
- _report_list = wait_for_element(lv, @top_pages_report_list)
- html = render(lv)
-
- refute element_exists?(html, @unsupported_filters_warning)
- end
- end
-
- defp wait_for_element(lv, selector) do
- eventually(fn ->
- html = render(lv)
- {element_exists?(html, selector), find(html, selector)}
- end)
- end
-
- defp get_liveview(conn, site, search_params \\ "period=day") do
- conn = assign(conn, :live_module, PlausibleWeb.Live.Dashboard)
- {:ok, lv, _html} = live(conn, "/#{site.domain}?#{search_params}")
- lv
- end
-
- defp change_tab(lv, tab) do
- lv
- |> element("#breakdown-tile-pages-tabs")
- |> render_hook("set-tab", %{"tab" => tab})
-
- lv
- end
-end
diff --git a/test/support/dashboard_test_utils.ex b/test/support/dashboard_test_utils.ex
deleted file mode 100644
index e1f83a1060..0000000000
--- a/test/support/dashboard_test_utils.ex
+++ /dev/null
@@ -1,33 +0,0 @@
-defmodule Plausible.DashboardTestUtils do
- @moduledoc false
-
- import Plausible.Test.Support.HTML
-
- @doc """
- Takes a LazyHTML rendered ReportList component argument with the number of
- rows and columns it's supposed to have, and returns a table-like, 2D list
- with all its data (including headers as the first row).
- """
- def report_list_as_table(%LazyHTML{} = report_list, rows, columns) do
- for row_index <- 0..(rows - 1) do
- for column_index <- 0..(columns - 1) do
- get_in_report_list(report_list, row_index, column_index)
- end
- end
- end
-
- def get_in_report_list(%LazyHTML{} = report_list, row_index, column_index, opts \\ []) do
- selector = ~s|[data-test-id="report-list-#{row_index}-#{column_index}"]|
-
- cond do
- not element_exists?(report_list, selector) ->
- nil
-
- Keyword.get(opts, :text?, true) ->
- text_of_element(report_list, selector)
-
- true ->
- find(report_list, selector)
- end
- end
-end
diff --git a/test/test_helper.exs b/test/test_helper.exs
index 9dbbed1018..e11ea3df95 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -9,8 +9,6 @@ Mox.defmock(Plausible.DnsLookup.Mock,
for: Plausible.DnsLookupInterface
)
-FunWithFlags.enable(:live_dashboard)
-
Application.ensure_all_started(:double)
Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, :manual)