* fix(app): disable the values downloads while there is nothing to download (GH-…2065)
selected no longer sends `station=` empty and saves the 422 as the file. It
returns before asking, though, and the download menu went on offering CSV,
JSON and GeoJSON as if they worked: choosing one did nothing, with no file
and no message. A values download asks the backend again for the current
selection, so this happens whenever the selection is cleared, even with a
table still on screen.
The three items are now disabled while canFetchData is false, as the
button is while values load. The chart-image items export the chart on
screen and are left as they are. downloadMenuItems is exposed beside
canFetchData, for the new component test that mounts DataViewer and reads
the items with no station and with one; the first fails before this change.
The review's other point, that canFetchData lets a latitude cleared to null
through, cannot occur: numberFromBox answers undefined for a cleared box.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): describe the download case that can happen, and test it (GH-2065)
The previous commit, #2065 and the changelog said the values downloads are
disabled while no station or point is selected. That state has no download
menu: explorer.vue mounts DataViewer only while hasLocationSelection holds,
so clearing the station removes the viewer, table and menu with it. The case
the change covers is a station or point chosen with every parameter
deselected, which the parameter selection allows. The GH-2056 entry made the
same claim about the guard in downloadValues; both entries now name the case.
The component test mounted DataViewer with no station, a state the explorer
never renders, and cast the whole selection to hide the fixture's gaps. It
now mounts the two states the explorer shows -- a station, a point -- each
with no parameter and with one, typed as StationSelectionState with only the
station object cast. With the items' `disabled` removed, all four fail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): download what the table shows, not a fresh answer for the selection (GH-2065)
A values download asked the backend again, for whatever was selected when
the menu was used, and saved the answer. The table shows what the last
fetch returned, so the two parted whenever the selection changed after it:
another station, other parameters, or other units, as the download also left
out humanize, convert_units and unit_targets, which the fetch sends. With no
parameter it did nothing. Two review rounds found a gate to add for each way
they part -- no parameter, a missing date range -- and each gate left rows on
screen that could not be saved.
CSV and JSON are now written from the rows the table shows, after the query
panel and the sorting, in its columns, by valuesToCsv and valuesToJson
(utils/values-export.ts). JSON is `{ "values": [...] }`, as the REST API
answers. The CSV quotes a field holding a comma or a quote: taken_station_ids
holds several ids and spilled into the columns after it, in the copy buttons
too, which now share the writer.
GeoJSON needs the station positions and metadata the backend adds, so it is
still asked for, but with the request that filled the table: fetchData keeps
the endpoint and query it sent once they answer, and clearData forgets them.
That also replaces some seventy lines that rebuilt the query by hand.
The menu offers CSV and JSON while the table shows rows, and GeoJSON while it
also shows what that request answered, not while the query panel has
rewritten it. downloadMenuItems is no longer exposed: the tests open the real
menu, as a keyboard does, and read what it offers. fetchData now resolves
when the answer is in, which the tests await.
Tests: the export writers, including the quoting; the menu before and after
a fetch; a CSV download saving the table's row without a request; and a
GeoJSON download asking for the fetched station after the selection moved to
another, with the fetch's settings. All four component tests fail against
the previous download code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): the review's findings on downloading what the table shows (GH-2065)
CSV and JSON kept only the columns the table shows, a fixed set. A wide
shape, which the Explorer offers, puts each parameter in a column of its
own and has no `value`: the download wrote empty columns and no measurement,
where main's saved the backend's whole answer. A query panel's own columns
(`avg_value`) went the same way. exportColumns now keeps the shown columns
first, then every other column the rows carry.
Two fetches overlapping could leave the request of the one started first
as the one GeoJSON asks for again, when it finished last; fetchData counts
the fetches it starts and only the latest records its request.
The GeoJSON request is made with $fetch, as the table's own is, so the query
reads the same, and a failure of any kind -- a refusal, no answer at all --
is told in the error toast; a network failure went unhandled. Asked for as
text, a refusal's body comes as text too, and is read as JSON before it is
described, so the toast names the parameter and the problem.
The JSON is compact, as the REST API answers by default. The file is named
after the request that filled the table only. The tests wait for the menu's
items rather than a fixed 20 ms.
New tests: a wide-shaped table's measurement in the CSV; the later of two
overlapping fetches kept; a refused GeoJSON request told and nothing saved.
With the column set back to the shown columns, and with the fetch count
ignored, the wide and the overlap test each fail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): fetch the table's values with the request downloads use (GH-2065)
The table's values were fetched with useFetch bound to the live selection,
and the request behind the table was kept as a copy beside it, which the
previous commit held in step with a count of fetches. It still parted: the
fetch reads its error from the entry of the current key, so a selection
changed mid-fetch recorded a request that never reached the table, or a
failed one as a success; and Clear during a fetch let the answer come back
and fill the cleared table.
useFetch now reads its endpoint and query from fetchedRequest, which only
Fetch sets and Clear empties. The table, its error and a GeoJSON download
answer to one request by construction; the count and the check after the
await are gone. GeoJSON is also not offered while that request failed.
The export's columns follow the table: the columns it shows, in its order,
then any the rows carry that it has no column for (a wide shape's
parameters, a query panel's aggregates). A column hidden in the picker stays
out; it did not, and the order was the picker's. The copy buttons use the
same columns, where they dropped a wide table's measurements.
A query panel's COUNT(*) comes back from DuckDB as a BigInt, which
JSON.stringify refuses: the JSON download threw inside the menu, saving
nothing and saying nothing. valuesToJson writes a BigInt as a number.
describeFetchError (utils/api-error.ts) tells a failed request, reading a
body that came as text, for both the fetch's toast and the GeoJSON
download's, which each had their own copy. The columns are worked out only
for CSV and JSON. The changelog entry says what changed, not how.
Tests: Clear during a fetch leaves the table empty and nothing offered; a
selection moved during a fetch leaves the table and GeoJSON on the fetched
station -- both fail against the previous component. Unit tests for the
column rule (hidden, wide, query panel), the BigInt, and describeFetchError.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): export every column the rows carry, whatever the picker shows (GH-2065)
The export followed the column picker, whose defaults hide `resolution` and
`dataset`: a JSON download lacked fields the REST API's answer always had.
The picker also follows the mode selected now, not the one the rows were
fetched in, so switching mode after a fetch reset it and dropped
`taken_station_ids` from an interpolated download, with no way to add it
back. Downloads and copies now write every column the rows carry, the
table's known columns in its order first; the picker changes the view only.
The CSV header went unescaped while every field was quoted where needed: a
query panel's unaliased `round(avg("value"), 2)` split into three columns.
It is written through csvField too.
The copy buttons are disabled on an empty table, where they copied nothing
and reported it copied, as the download items already are. Each mode's
endpoint and file name are one table, ENDPOINTS, which fetchData records
with the request; DOWNLOAD_FILENAMES and apiEndpoint go. The GeoJSON item's
`Boolean(valuesError.value)` is gone: an error resets the rows to none, which
disables it already.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): the review's findings on keyed fetches, copies and GeoJSON (GH-2065)
The table's values were kept apart from an overtaken fetch only because
useFetch keys an entry by a hash of its request by default, and Nuxt drops
the old entry's request when the key moves. The comment on clearData said
the fetch still answered its request; it is aborted. Anything that kept an
entry past its key -- a cache, an explicit key -- would have let an answer
overtaken by Clear or a newer Fetch be written back, and two Fetches of one
request shared an entry. The fetch now has a key of its own, which Fetch
and Clear both move on, so each fetch answers into an entry the table
leaves as soon as it is overtaken.
The copy buttons follow the column picker again: a copy is of what the
table shows. A download still writes every column the rows carry.
A GeoJSON download is not offered again while one is under way; a second
choice sent a second request and saved a second file.
exportColumns reads the columns from the first row, as the rows of one
answer or one query share them, rather than every key of every row on each
download. The fallback file name and the GeoJSON guard fold into one check
of the request at the top of the download.
The GH-2056 changelog entry said any download the backend refuses shows the
toast; CSV and JSON no longer ask the backend, so it names GeoJSON.
Tests: a copy writes the picker's default columns; GeoJSON is not offered
while one is downloading. Each fails with its change taken out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): save no GeoJSON the table has moved on from, and name a failure by its status (GH-2065)
A GeoJSON download kept the request it was started with. Clear, or a new
Fetch, while it was being asked for still saved the old request's file and
reported it downloaded, for a table that no longer held it. The download now
notes the fetch generation it started in and saves nothing if Fetch or Clear
has moved it on by the time the answer comes.
describeFetchError fell back to the error's message where the answer had no
`detail`, and ofetch's message spells out the whole request -- a plain-text
500 showed `[GET] "/api/interpolate?provider=...&latitude=...": 500 ...` in
the toast. It now gives the status and its text, and the message only where
there was no answer at all. The table's own error toast uses it too.
fetchData's branch for an empty selection repeated clearData, less the page
reset; it calls clearData. The visible columns are one computed that both
the table and the copy buttons read, where the table filtered them twice.
The GeoJSON item's `!fetchedRequest.value` went: every path that empties the
request empties the rows, which disables it already.
dataviewer-logic.test.ts tested a CSV writer of its own, the unquoted one
this PR replaced, whatever the shipped one did; values-export.test.ts covers
the real one, and the copy is gone.
Tests: a GeoJSON download overtaken by Clear saves nothing, which fails with
the generation check taken out; the status stands in for a detail-less body.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): the review's findings on failures and overtaken GeoJSON downloads (GH-2065)
describeFetchError told a status in place of a missing `detail`, and
useFetch wraps every failure with h3's createError, whose status is 500
unless an answer said otherwise: a request that never reached the backend
was reported as "500". The status is told only with the text an answer
gives it; otherwise the error's message, without the `[GET] "/api/...":`
ofetch puts first. The tests of that path build the error with createError,
as useFetch does, where the unit tests had a plain object that passed
whatever the wrapping did.
A GeoJSON download ran to its end whatever happened meanwhile: a query panel
run while it loaded left it saving the untransformed rows' file, and Clear
or a new Fetch left the backend working on an answer that was then dropped.
fetchGeojson aborts it as soon as the table moves on -- a Fetch, a Clear,
the query panel -- and saves nothing from an aborted request, however late
the answer comes. It asks once: $fetch retries a failed GET by default,
which sent an expensive request twice and delayed the toast.
The copy buttons read one computed of the visible keys; the CSV and JSON
branches work out the export's columns once. A comment says why watch:false
must stay: a key that moves on, as Clear's does, would otherwise send an
empty request.
The component tests unmount what they mounted and restore the clipboard
after each test, where they left both to the next.
Tests: a request nothing answered is not a 500, and an answer without a
detail is told by its status, both with createError; a failed GeoJSON
request is asked for once, which fails with the retry left at ofetch's
default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): one fetch key, and the review's other findings (GH-2065)
The query panel's plain values moved to their own PR (GH-2068), which this
one builds on: downloads write query-panel rows, and valuesToJson no longer
carries the BigInt replacer that ran over every value of every table.
The table's values had a key per Fetch and per Clear, and every one left an
entry in the app's data for the rest of the session. They have one key now:
a newer Fetch cancels one under way (useFetch's `dedupe: 'cancel'`), and
Clear aborts it and empties the table (`clear`), so an answer they overtook
still never reaches the table. With Clear emptying the table by hand
instead, the test of a Clear during a fetch fails.
A GeoJSON download under way is aborted when the viewer is unmounted as
well, where leaving the page let it save a file on another. Its state is
one shallowRef, the controller, from which "downloading" is derived. The
object URL is revoked some seconds after the click, as some browsers start
a large download after the click returns.
exportColumns takes every row's columns, not the first row's: a row set
need not give each row every column. valuesToJson writes rows that hold
exactly the export's columns as they are, rather than copying a large table
first.
The rebase onto GH-2068 left the changelog's [Unreleased] entries tangled
where earlier commits rewrote the GH-2056 entry; they are set right here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): abort a GeoJSON download as the table changes, and the review's other findings (GH-2065)
A watcher aborted the GeoJSON download on Fetch, Clear or the query panel,
and a watcher runs only once they have returned: an answer that arrived in
between was saved for a table already replaced. abortGeojson is called
directly by fetchData, clearData and handleDataTransformed, and on unmount.
The fetch generation it watched is gone with it.
valuesToJson wrote the rows as they are when the first row held every
column, so a later row lacking one wrote no key where the copy path writes
null. It now writes them as they are only when every row holds every
column, counted without building a key list per row.
describeFetchError told a status only with its text, and an HTTP/2 answer
has none: a 502 without a detail fell to ofetch's message, stripped to
"502 ". The code is told alone where an answer came with a body but no
status text; a request nothing answered, which has neither, is still told by
its message.
`dedupe: 'cancel'` is useFetch's default and goes; the comment says so. A
duplicated comment line is gone.
Tests: an HTTP/2 answer is told as "502"; a row lacking a column writes it
as null.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): the review's findings on #2066's own diff (GH-2065)
fetchGeojson cleared the controller in its `finally` whatever it held: an
aborted download finishing after a newer one had started cleared the newer
one's, which then could not be aborted and was offered again while it ran.
It clears only its own.
handleDataTransformed aborted the GeoJSON download on every emit from the
query panel, and an aborted download says nothing: leaving query mode,
which hands back the table's own rows, or a query that found none, dropped
a download for a table that had not changed. It aborts only when a query's
own rows replace the table's.
valuesToJson wrote rows as they are when each held as many keys as there
were columns, without checking they were those columns: [{a, b}] asked for
[b, c] wrote a and no c. It checks the columns themselves, and that none is
undefined, which JSON would leave out rather than write as null.
describeFetchError gave an empty text for an error whose message is empty,
as h3 makes one given nothing; it falls through to the error itself.
The test's clipboard restore did nothing: the clipboard is a getter on
Navigator's prototype, so there was no own property to put back, and the
fake one stayed for every later test. It is removed.
The rebase onto GH-2068's review fixes left the changelog's [Unreleased]
section as that branch had it; it is set right, and the GH-2065 entry says
what a user will notice: downloads are offered once Fetch has filled the
table, and GeoJSON not while the query panel has rewritten it.
Tests: leaving query mode keeps a GeoJSON download under way and a query's
own rows abort it; valuesToJson writes the columns asked for and an
undefined value as null; an empty-message error gives a text. The first and
the second each fail with the change taken out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): tell a cancelled download, one JSON field order, and the review's other findings (GH-2065)
A GeoJSON download aborted because Fetch, Clear or a query changed the
table was dropped without a word: the user saw it start and got nothing.
The abort carries its reason; where the table changed, a warning says
"Download cancelled: the table changed" (dataViewer.downloadCancelled, in
every locale, the format left out of it). An abort on unmount says nothing,
there being no one to tell.
valuesToJson wrote rows that held every column as they were, in each row's
own key order, and the others by the columns: the same table's JSON and
CSV disagreed on field order, and the JSON's order changed with whether the
rows were uniform. Every row is written by the columns now, and the second
scan over all rows that decided which way is gone with it.
describeFetchError took an answer to have come when it had a body or a
status text. h3's createError, which wraps useFetch's errors, copies no
empty body, and HTTP/2 sends no status text, so an empty 502 fell through to
"502 " with a trailing space. An answer is known by its response, which
ofetch's error carries, and useFetch's wrapping of it as its cause; checked
against both in the Nuxt test environment, with a 502 of empty body and a
request to a closed port.
The component tests wait for what they depend on -- the request reaching
the endpoint, the menu closing, the answer, the cancelled notice -- where
they slept a fixed 20, 50, 150 or 250 ms.
Rebased onto GH-2068's switch to DuckDB's casts; the changelog's
[Unreleased] section is set right after the rebase.
Tests: an empty HTTP/2 answer is told as "502", built with createError as
useFetch builds it; a GeoJSON download cancelled by Clear or a query is
told as cancelled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(app): the review's two findings on #2066's own diff (GH-2065)
The comment describing abortGeojson sat above TABLE_CHANGED, with the
constant's own comment between them; each is above what it describes now.
tests/unit/api-error.test.ts repeated, with hand-built objects, the cases
tests/nuxt/utils/api-error.test.ts tests with errors built by h3's
createError as useFetch builds them: a status with and without its text,
and a request nothing answered. The hand-built ones could go on passing
after they stopped matching what useFetch holds; they are gone, and the
unit tests keep the reading of a body's detail.
Rebased onto GH-2068's review fixes; the changelog's [Unreleased] section
is set right after the rebase.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): write a query panel's BigInt, and keep the table's request until the next answers (GH-2065)
GH-2068's PR, on which this one was stacked, is closed unmerged, and this
branch is rebased onto main without it. What these downloads needed from
it is here instead: a query panel's COUNT(*) comes from DuckDB as a BigInt,
which JSON.stringify refuses, so valuesToJson writes a BigInt as a number,
or as its digits past 2^53.
fetchData made the request it sent the table's at once, before it answered:
the table still showed the last answer, but the file name and a GeoJSON
download already followed the new request. The request sent now lives
apart, as sentRequest, which the table's values are fetched with; it
becomes fetchedRequest only once it has answered, and only if no newer
Fetch or Clear has sent another since. Both are shallowRefs, so the one
sent compares as itself rather than as Vue's proxy of it.
fetchGeojson starts none while one is under way: a second chosen before the
menu updated overwrote the first one's controller, which Fetch and Clear
then could not abort. handleDataTransformed's comment said a query that
found nothing leaves the table as it is; it falls back to the fetched rows,
and no GeoJSON download runs while a query's rows are shown.
Tests: a query's BigInt written as a number and as digits; a GeoJSON
download made while a newer Fetch is under way asks for the table shown,
which fails with the request made the table's at once.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): abort a GeoJSON download from one watcher, and the review's other findings (GH-2065)
The previous commit kept the table on the last answer until a newer Fetch
answered, but a GeoJSON download was aborted only as Fetch was pressed: one
chosen after that, while the newer Fetch was loading, went on when its
answer replaced the table, and was saved for a table no longer shown. The
hand-placed calls in fetchData, clearData and handleDataTransformed are one
watcher on displayData now, with `flush: 'sync'` so it runs as the change
happens rather than after it, which is why a watcher had been avoided. Any
change to what the table shows aborts the download; leaving query mode,
which shows the same rows, aborts nothing. With the watcher taken out, the
new test and those for Clear and a query each fail.
CSV and JSON bailed out without a word where no request was recorded,
though the menu offered them for the rows on screen; they take only the
file's name from the request, and fall back to a default one.
describeFetchError left ofetch's own `<no response>` token in the text the
toast shows for a request nothing answered; it is left out with the request
before it: "Failed to fetch".
A query panel's struct or list was written to the CSV as `[object Object]`,
where the JSON kept it; the CSV writes its JSON text, as the JSON does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): write taken_station_ids to the CSV with commas, as the REST API's CSV does (GH-2065)
The previous commit wrote any non-primitive CSV field as its JSON text, for
a query panel's struct. But the REST API answers an interpolation's
taken_station_ids as a list, and the table holds it so: the CSV download
wrote `["00011","00012"]`, where the backend's CSV writes `00011,00012`
(_join_list_columns in io/export.py). The test had used a comma-joined
string, which is not the shape the table holds.
A list of plain values is joined with commas, as the backend joins a list
column; only a value nested deeper, a struct, is written as its JSON text.
The test uses the list the REST API answers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): check the table once more before saving a GeoJSON, and the copy-page gate (GH-2065)
fetchGeojson checks its abort before handing back the answer, and
downloadValues saves it after one more await: a table change settling in
that same tick found no controller left to abort, and the GeoJSON of the
table just replaced was saved and reported downloaded. downloadValues
looks at the table once more, that its request is still the one asked
with and no query rewrote it, and says the download was cancelled if not.
Copy page was enabled while the table held rows, but copies the current
page: after a query shrank the rows while a later page was shown, it wrote
nothing to the clipboard and reported it copied. It is enabled while the
page holds rows.
downloadValues' comment still said the shown columns come first; every
column the rows carry is written, the table's own in its order first.
Neither the same-tick settle nor a page left past the end is set up by the
component tests; both are guarded by a check read straight off the state.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): hold the ordering tests' answers on gates, and offer GeoJSON only with a request (GH-2065)
The component tests ordered two answers by delays (50 to 300 ms), which a
slow runner can outlast. Each held answer now waits on a gate the test
opens at the point where the order matters.
With the displayData watcher removed, every test still passed: the check
after the answer caught each case, so none showed the request being
aborted. The three abort tests now read the reason AbortController.abort
was called with, and fail without the watcher.
The test "keeps the request of the fetch started last, whichever finishes
last" described a race useFetch does not run: its dedupe cancels the
first fetch. Renamed, and it checks the table shows the second.
The watcher's comment said leaving query mode aborts nothing; where the
query's own rows were showing, leaving swaps the table back and aborts.
GeoJSON is offered only once a Fetch's request is recorded, not merely
when rows are showing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): save a GeoJSON as its abort is looked at, and no CSV of an emptied table (GH-2065)
Whether the table had moved on was decided twice: by the abort reason in
fetchGeojson, and by a second look at fetchedRequest and the query panel
in downloadValues, each with its own cancelled toast. The second look
covered the tick between fetchGeojson returning and the file being saved.
downloadGeojson now saves in the same tick it finds the download not
aborted, so the abort alone decides and one toast says so. Every change
to what the table shows aborts at once (the displayData watcher), the
query panel's included: isDataTransformed changes only with displayData.
CSV and JSON lost their guard when the download stopped asking the
backend: chosen after Clear, before the menu updates, they saved an
empty file with a success toast. They now save nothing where the table
is empty.
The CSV test's spy on fetch could not fail through $fetch, which holds
the fetch it was built with; it now counts requests at the endpoint.
Toasts are the app's, not a viewer's, so one left over from a test was
shown, and could be found, in the next. They are cleared after each.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(app): ask for no GeoJSON of a table the query panel rewrote before the menu updated (GH-2065)
The menu stops offering GeoJSON once the query panel has rewritten the
table, but a choice made before it re-renders still reached
downloadGeojson. The displayData watcher had already run, so nothing
aborted it, and the fetched request's GeoJSON was saved while the table
showed the query's rows. downloadValues now checks, as it does for an
emptied table, before asking.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>