mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Remove allowed props list from dashboard data attribute (#3230)
This commit removes the allowed props list from the data attribute passed to React. The list was used for checking whether props configured or not. This commit adds a new `hasProps` attribute, and removes the list.
This commit is contained in:
parent
373b8e8201
commit
1fedaf18c3
@ -19,8 +19,8 @@ if (container) {
|
||||
conversionsEnabled: container.dataset.conversionsEnabled === 'true',
|
||||
funnelsEnabled: container.dataset.funnelsEnabled === 'true',
|
||||
propsEnabled: container.dataset.propsEnabled === 'true',
|
||||
hasProps: container.dataset.hasProps === 'true',
|
||||
funnels: JSON.parse(container.dataset.funnels),
|
||||
allowedEventProps: JSON.parse(container.dataset.allowedEventProps),
|
||||
statsBegin: container.dataset.statsBegin,
|
||||
nativeStatsBegin: container.dataset.nativeStatsBegin,
|
||||
embedded: container.dataset.embedded,
|
||||
|
@ -166,8 +166,8 @@ export default function Behaviours(props) {
|
||||
}
|
||||
|
||||
function renderProps() {
|
||||
if (site.allowedEventProps && site.allowedEventProps.length > 0) {
|
||||
return <Properties site={site} query={query} allowedEventProps={site.allowedEventProps}/>
|
||||
if (site.hasProps) {
|
||||
return <Properties site={site} query={props.query} />
|
||||
} else if (adminAccess) {
|
||||
return (
|
||||
<FeatureSetupNotice
|
||||
|
@ -119,4 +119,11 @@ defmodule Plausible.Props do
|
||||
defp valid?(key) do
|
||||
String.length(key) in 1..@max_prop_key_length
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns whether the site has configured custom props or not.
|
||||
"""
|
||||
def configured?(%Plausible.Site{allowed_event_props: allowed_event_props}) do
|
||||
is_list(allowed_event_props) && length(allowed_event_props) > 0
|
||||
end
|
||||
end
|
||||
|
@ -65,7 +65,7 @@ defmodule PlausibleWeb.StatsController do
|
||||
site: site,
|
||||
has_goals: Plausible.Sites.has_goals?(site),
|
||||
funnels: Plausible.Funnels.list(site),
|
||||
allowed_event_props: site.allowed_event_props,
|
||||
has_props: Plausible.Props.configured?(site),
|
||||
stats_start_date: stats_start_date,
|
||||
native_stats_start_date: NaiveDateTime.to_date(site.native_stats_start_at),
|
||||
title: title(conn, site),
|
||||
@ -309,7 +309,7 @@ defmodule PlausibleWeb.StatsController do
|
||||
site: shared_link.site,
|
||||
has_goals: Sites.has_goals?(shared_link.site),
|
||||
funnels: Plausible.Funnels.list(shared_link.site),
|
||||
allowed_event_props: shared_link.site.allowed_event_props,
|
||||
has_props: Plausible.Props.configured?(shared_link.site),
|
||||
stats_start_date: shared_link.site.stats_start_date,
|
||||
native_stats_start_date: NaiveDateTime.to_date(shared_link.site.native_stats_start_at),
|
||||
title: title(conn, shared_link.site),
|
||||
|
@ -22,7 +22,7 @@
|
||||
data-funnels-enabled="<%= @site.funnels_enabled %>"
|
||||
data-props-enabled="<%= @site.props_enabled %>"
|
||||
data-funnels="<%= Jason.encode!(@funnels) %>"
|
||||
data-allowed-event-props="<%= Jason.encode!(@allowed_event_props) %>"
|
||||
data-has-props="<%= @has_props %>"
|
||||
data-logged-in="<%= !!@conn.assigns[:current_user] %>"
|
||||
data-stats-begin="<%= @stats_start_date %>"
|
||||
data-native-stats-begin="<%= @native_stats_start_date %>"
|
||||
|
@ -241,4 +241,15 @@ defmodule Plausible.PropsTest do
|
||||
assert ["first_time_customer", "logged_in", "with_error"] ==
|
||||
site |> Plausible.Props.suggest_keys_to_allow() |> Enum.sort()
|
||||
end
|
||||
|
||||
test "configured?/1 returns whether the site has allow at least one prop" do
|
||||
site = insert(:site)
|
||||
refute Plausible.Props.configured?(site)
|
||||
|
||||
{:ok, site} = Plausible.Props.allow(site, "hello-world")
|
||||
assert Plausible.Props.configured?(site)
|
||||
|
||||
{:ok, site} = Plausible.Props.disallow(site, "hello-world")
|
||||
refute Plausible.Props.configured?(site)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user