Pass interval param to CSV export (#2469)

This commit adds the interval param to the CSV export client-side
request.
This commit is contained in:
Vini Brasil 2022-11-25 05:53:22 -03:00 committed by GitHub
parent 32a38fac7a
commit ffbfb14714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -233,7 +233,9 @@ class LineGraph extends React.Component {
</div>
)
} else {
const endpoint = `/${encodeURIComponent(this.props.site.domain)}/export${api.serializeQuery(this.props.query)}`
const interval = this.props.graphData?.interval || this.state.interval
const queryParams = api.serializeQuery(this.props.query, [{ interval }])
const endpoint = `/${encodeURIComponent(this.props.site.domain)}/export${queryParams}`
return (
<a className="w-4 h-4 mx-2" href={endpoint} download onClick={this.downloadSpinner.bind(this)}>

View File

@ -102,6 +102,32 @@ defmodule PlausibleWeb.StatsControllerTest do
conn = get(conn, "/" <> site.domain <> "/export?date=2021-10-20")
assert_zip(conn, "30d")
end
test "exports data grouped by interval", %{conn: conn, site: site} do
populate_exported_stats(site)
conn = get(conn, "/" <> site.domain <> "/export?date=2021-10-20&period=30d&interval=week")
assert response = response(conn, 200)
{:ok, zip} = :zip.unzip(response, [:memory])
{_filename, visitors} =
Enum.find(zip, fn {filename, _data} -> filename == 'visitors.csv' end)
parsed_csv =
visitors
|> String.split("\r\n")
|> Enum.map(&String.split(&1, ","))
assert parsed_csv == [
["date", "visitors", "pageviews", "bounce_rate", "visit_duration"],
["2021-09-20", "1", "1", "100", "0"],
["2021-09-27", "0", "0", "", ""],
["2021-10-04", "0", "0", "", ""],
["2021-10-11", "0", "0", "", ""],
["2021-10-18", "3", "3", "67", "20"],
[""]
]
end
end
describe "GET /:website/export - via shared link" do