return city codes as integers in suggestions (#4589)

This commit is contained in:
RobertJoonas 2024-09-17 15:37:13 +03:00 committed by GitHub
parent f645a9ba1d
commit 45c0d538da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 12 deletions

View File

@ -119,7 +119,7 @@ defmodule Plausible.Stats.FilterSuggestions do
city = Location.get_city(c) city = Location.get_city(c)
%{ %{
value: Integer.to_string(c), value: c,
label: (city && city.name) || "N/A" label: (city && city.name) || "N/A"
} }
end) end)
@ -145,12 +145,7 @@ defmodule Plausible.Stats.FilterSuggestions do
city && String.contains?(String.downcase(city.name), filter_search) city && String.contains?(String.downcase(city.name), filter_search)
end) end)
|> Enum.slice(0..24) |> Enum.slice(0..24)
|> Enum.map(fn c -> |> Enum.map(fn c -> %{value: c.id, label: c.name} end)
%{
value: Integer.to_string(c.id),
label: c.name
}
end)
end end
def filter_suggestions(site, _query, "goal", filter_search) do def filter_suggestions(site, _query, "goal", filter_search) do

View File

@ -131,7 +131,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
"/api/stats/#{site.domain}/suggestions/city?q=Kär" "/api/stats/#{site.domain}/suggestions/city?q=Kär"
) )
assert json_response(conn, 200) == [%{"value" => "591632", "label" => "Kärdla"}] assert json_response(conn, 200) == [%{"value" => 591_632, "label" => "Kärdla"}]
end end
test "returns suggestions for countries without country in search", %{conn: conn, site: site} do test "returns suggestions for countries without country in search", %{conn: conn, site: site} do
@ -883,8 +883,8 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
) )
assert json_response(conn, 200) == [ assert json_response(conn, 200) == [
%{"value" => "588409", "label" => "Tallinn"}, %{"value" => 588_409, "label" => "Tallinn"},
%{"value" => "591632", "label" => "Kärdla"} %{"value" => 591_632, "label" => "Kärdla"}
] ]
end end
end end
@ -912,7 +912,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
"/api/stats/#{site.domain}/suggestions/city?filters=#{filters}&q=&with_imported=true" "/api/stats/#{site.domain}/suggestions/city?filters=#{filters}&q=&with_imported=true"
) )
assert json_response(conn, 200) == [%{"value" => "591632", "label" => "Kärdla"}] assert json_response(conn, 200) == [%{"value" => 591_632, "label" => "Kärdla"}]
end end
test "queries imported cities when filtering by city", %{ test "queries imported cities when filtering by city", %{
@ -932,7 +932,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
"/api/stats/#{site.domain}/suggestions/city?period=month&date=2019-01-01&filters=#{filters}&q=&with_imported=true" "/api/stats/#{site.domain}/suggestions/city?period=month&date=2019-01-01&filters=#{filters}&q=&with_imported=true"
) )
assert json_response(conn, 200) == [%{"value" => "591632", "label" => "Kärdla"}] assert json_response(conn, 200) == [%{"value" => 591_632, "label" => "Kärdla"}]
end end
test "ignores imported city data when not requested", %{ test "ignores imported city data when not requested", %{