datasette
datasette copied to clipboard
Show foreign key label when filtering
For example here:
3 corresponds to "Human Related: Other" - it would be neat to display this in this area of the page somehow.
Maybe like this:
<h3>283 rows
where dcode = 3 <span style="color: #aaa; font-size: 0.9em">(Human Related: Other)</span>
</h3>
I did some horrible things in https://github.com/cldellow/datasette-ui-extras/issues/2 to enable this in my plugin -- example here: https://dux-demo.fly.dev/cooking/posts?_facet=owner_user_id&owner_user_id=67
The implementation relies on two things:
- a
filters_from_requesthook that adds a good human description (unfortunately, without the benefit of the CSS styling you mention) - doing something evil to hijack the
exactandnotoperators in theFiltersclass. We can't leave them as is, or we'll get 2 human descriptions -- the built-in Datasette one and the one from my plugin. We can't remove them, or the filters UI will stop supporting the=and!=operators
This got me thinking: it'd be neat if the list of operators that the filters UI supported wasn't a closed set.
A motivating example: adding a geospatial NEAR operator. Ideally it'd take two arguments - a target point and a radius, so you could express a filter like find me all rows whose lat/lng are within 10km of 43.4516° N, 80.4925° W. (Optionally, the UI could be enhanced if the geonames database was loaded and queried, so a user could say find me all rows whose lat/lng are within 10km of Kitchener, ON, and the city gets translated to a lat/lng for them)