Skip to content

Commit

Permalink
return city codes as integers in suggestions (plausible#4589)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertJoonas authored Sep 17, 2024
1 parent f645a9b commit 45c0d53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 2 additions & 7 deletions lib/plausible/stats/filter_suggestions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ defmodule Plausible.Stats.FilterSuggestions do
city = Location.get_city(c)

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

def filter_suggestions(site, _query, "goal", filter_search) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
"/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

test "returns suggestions for countries without country in search", %{conn: conn, site: site} do
Expand Down Expand Up @@ -883,8 +883,8 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
)

assert json_response(conn, 200) == [
%{"value" => "588409", "label" => "Tallinn"},
%{"value" => "591632", "label" => "Kärdla"}
%{"value" => 588_409, "label" => "Tallinn"},
%{"value" => 591_632, "label" => "Kärdla"}
]
end
end
Expand Down Expand Up @@ -912,7 +912,7 @@ defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
"/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

test "queries imported cities when filtering by city", %{
Expand All @@ -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"
)

assert json_response(conn, 200) == [%{"value" => "591632", "label" => "Kärdla"}]
assert json_response(conn, 200) == [%{"value" => 591_632, "label" => "Kärdla"}]
end

test "ignores imported city data when not requested", %{
Expand Down

0 comments on commit 45c0d53

Please sign in to comment.