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:
Vini Brasil 2023-08-05 10:35:31 -03:00 committed by GitHub
parent 373b8e8201
commit 1fedaf18c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 6 deletions

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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),

View File

@ -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 %>"

View File

@ -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