cldellow / datasette-ui-extras

Add editing UI and other power-user features to Datasette.
Apache License 2.0
12 stars 1 forks source link

redirect user to new page on save #74

Closed cldellow closed 1 year ago

cldellow commented 1 year ago

We'd like to send the user to a new page when they update (and eventually insert) a row.

What page should they go to?

1) The same page, just reload it so they know their change was committed, and we reset dirty indicators.

2) A user-definable static page: e.g. on a form, you might want to thank the user and tell them next steps

3) A user-definable dynamic page: e.g. in turker mode, you might want to redirect to the "next" row that needs editing, for some value of next.

Maybe: add a redirect_after_save(datasette, database, table, action, pk) hook.

It if returns none, we'll send you to the current page.

Otherwise, we'll send you to the the return value of the hook. We could make the common cases configurable via metadata.json, too, but let's not do that to start.

cldellow commented 1 year ago

New hook is documented at https://dux.cldellow.com/docs/hooks#redirect-after-save:

def redirect_after_save(
  datasette, # An instance of the Datasette class.
  database,  # The database name, e.g. "cooking"
  table,     # The table name, e.g. "posts"
  action,    # "insert-row", "update-row" or "delete-row"
  pk         # The key of the modified row, eg `1` or `compound,key`
)