fix(thumbnails): render dataset card maps instead of collapsing them - #5
Open
a5dur wants to merge 1 commit into
Open
fix(thumbnails): render dataset card maps instead of collapsing them#5a5dur wants to merge 1 commit into
a5dur wants to merge 1 commit into
Conversation
The map thumbnails on /dataset never appeared. Two independent causes,
both confirmed against the sandbox deployment.
1. Every container was zero width. snippets/package_item.html places
.dataset-item-map next to the dataset content in a flex row. The
element is empty at layout time -- Leaflet fills it with absolutely
positioned panes -- so its min-content width is 0 and the default
flex-shrink lets the sibling collapse it entirely. Leaflet built the
maps (the containers had _leaflet_id set and two child nodes) at
125px tall and 0px wide, so nothing was ever visible. Pinned the
track size with `flex: 0 0 125px` and added an invalidateSize() call,
since Leaflet caches the zero size it measured at init.
2. One dataset blanked all of them. createMapImage() awaited every card
in a single unguarded sequence, so the first throw abandoned the
rest. gztr_spatial_full_with_geometry returns features with a null
geometry when it cannot resolve one, L.geoJSON then yields an empty
layer, and fitBounds raises "Bounds are not valid." Each card now
builds inside its own try/catch, an invalid bounds falls back to the
configured default view rather than throwing, and the action returns
None explicitly on failure instead of falling off the end.
The unresolvable feature came from a spatial_full shape the action did
not recognise. Three shapes exist in the wild: the current one, with
`collection` and `id` at the top level; an older one nesting the whole
config.json entry under properties.collection, keyed by `location`
("nm_counties.geojson" -> "nm_counties"); and the oldest, a bare GeoJSON
Feature with inline geometry and no collection reference at all. The
lookup is now factored into _resolve_feature_ref, which handles all
three, refuses collections that are not installed rather than letting
stac_item_show 500 on them, and casts the id to a string because
stac_item_show compares it as a quoted SQL literal -- an int id silently
matches no rows.
Also dropped the two console.log calls that dumped full geometry
payloads to the browser console on every page load.
tests/test_resolve_feature_ref.py covers all three shapes plus the drawn
feature and unknown collection cases; it imports the function without
loading CKAN so it runs standalone.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Map thumbnails on
/datasetnever appeared. Two independent causes, both confirmed against the live sandbox deployment.1. Every container was zero width
Browser diagnostic on
/dataset:alreadyInitialised: truewith two child nodes means Leaflet did build the map. It was 125px tall and 0px wide.snippets/package_item.htmlputs.dataset-item-mapnext to the dataset content in a flex row. The element is empty at layout time β Leaflet fills it with absolutely positioned panes β so itsmin-contentwidth is 0 and the defaultflex-shrinklets the sibling collapse it entirely.Plus an
invalidateSize()after render, because Leaflet caches the zero size it measured at init and won't recover on its own.Verified live in the console β setting
flex: 0 0 125pxand dispatchingresizemade the tiles appear.2. One dataset blanked all of them
createMapImage()awaited every card in a single unguarded sequence, so the first throw abandoned the rest.gztr_spatial_full_with_geometryreturns features with a null geometry when it can't resolve one;L.geoJSONthen yields an empty layer andfitBoundsraises.Each card now builds in its own
try/catch, invalid bounds fall back to the configured default view, and the action returnsNoneexplicitly on failure instead of falling off the end.Why that feature was unresolvable
Three
spatial_fullshapes exist in the wild:collectionidproperties.collection, keyed bylocationThe action only understood the first. The offending dataset had the second:
{ "id": 31, "properties": { "OBJECTID": 31, "NAMELSAD": "Bernalillo County", "collection": { "properties": { "location": "nm_counties.geojson", ... } } } }feature.get("collection")returnedNone, so the STAC lookup was skipped and the feature came back geometry-less.Now factored into
_resolve_feature_ref, which:"nm_counties.geojson"βnm_counties)stac_item_show500 on themstac_item_showcompares it as a quoted SQL literal (WHERE item.id = '31'), so an int id silently matches zero rowsVerification
ckanext/gztr/tests/test_resolve_feature_ref.pyβ 5 cases covering all three shapes plus drawn-features and unknown-collection. Imports the function without loading CKAN, so it runs standalone:Against the 5 real production payloads β the four with inline geometry need no lookup, and the one that was throwing now resolves:
nm_counties/31matches itsNAMELSAD: "Bernalillo County".Also
Dropped two
console.logcalls that dumped full geometry payloads to the browser console on every page load.Not in this PR
before_dataset_indexinplugin.pyhas the same legacy-shape problem β it doesfeature["collection"](subscript, not.get()) and raisesKeyErroron the oldest shape, which makessearch-index rebuildsilently drop those datasets out of bbox search. Same root cause, but a separate symptom; happy to fold it in here or do it separately.π€ Generated with Claude Code