simonw / datasette

An open source multi-tool for exploring and publishing data
https://datasette.io
Apache License 2.0
9.54k stars 689 forks source link

Custom widgets for canned query forms #1090

Open simonw opened 4 years ago

simonw commented 4 years ago

This is an idea that was cut from the first version of writable canned queries:

I really want the option to use a <textarea> for a specific value.

Idea: metadata syntax like this:

{
    "databases": {
       "my-database": {
           "queries": {
               "add_twitter_handle": {
                   "sql": "insert into twitter_handles (username) values (:username)",
                   "write": true,
                   "params": {
                       "username": {
                            "widget": "textarea"
                       }
                   }
               }
           }
       }
    }
}

I can ship with some default widgets and provide a plugin hook for registering extra widgets.

This opens up some really exciting possibilities for things like map widgets that let you draw polygons.

Originally posted by @simonw in https://github.com/simonw/datasette/issues/698#issuecomment-608125928

simonw commented 3 years ago

Related: I built datasette-leaflet-freedraw which turns any canned query field called freedraw or something_freedraw into an interactive map that you can draw on to create a GeoJSON MultiPolygon.

simonw commented 3 years ago

Idea for these: imitate https://django-sql-dashboard.readthedocs.io/en/latest/widgets.html#custom-widgets and drive them with templates.

So a custom widget type of textarea would look for a template called widgets/textarea.html - which means users could define brand new custom widgets just by creating their own template files.

simonw commented 3 years ago

Related feature request: ability to set default values for canned queries: #1258