mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
return city codes as integers in suggestions (#4589)
This commit is contained in:
parent
f645a9ba1d
commit
45c0d538da
@ -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
|
||||||
|
@ -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", %{
|
||||||
|
Loading…
Reference in New Issue
Block a user