Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view_actions() hook, to avoid showing table actions on view pages that don't work #2297

Closed
simonw opened this issue Mar 7, 2024 · 6 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented Mar 7, 2024

Spotted this on Datasette Cloud:

CleanShot 2024-03-07 at 09 38 49@2x

All those plugins forgot to check if the table was actually a view, and break if you attempt to use them!

Need something in Datasette Core to help plugins not make that mistake.

@simonw simonw added the plugins label Mar 7, 2024
@simonw
Copy link
Owner Author

simonw commented Mar 7, 2024

Some options to add to Datasette:

  • await db.is_view(name) - to save you from needing to do if name in await db.view_names()
  • Option: don't show table actions on the view page at all - this would at least prevent the default mistake, it's probably the best way to do it
  • Could pass an is_view=True parameter to the plugin hook?

@simonw
Copy link
Owner Author

simonw commented Mar 12, 2024

Or... I could add a view_actions() hook that is separate from table_actions().

I think this may be the best solution. It will very slightly break any existing plugins that expect to work on the views at the moment, but that's a good change to ship prior to 1.0 - plus I can't think of anything that will really get hurt by this. Best I can think of is that datasette-graphql won't show up on SQL views as a suggested API explorer option, which is harmless since you can still get to the GraphiQL interface and build view queries from there.

@simonw simonw changed the title Mechanisms to help avoid table actions on view pages that don't work view_actions() hook, to avoid showing table actions on view pages that don't work Mar 12, 2024
@simonw simonw closed this as completed in 909c85c Mar 12, 2024
@simonw
Copy link
Owner Author

simonw commented Mar 12, 2024

@simonw
Copy link
Owner Author

simonw commented Mar 12, 2024

This is wrong:

https://latest.datasette.io/fixtures/simple_view

CleanShot 2024-03-12 at 14 29 55@2x

Should say "View actions", not "Table actions".

@simonw simonw reopened this Mar 12, 2024
@simonw
Copy link
Owner Author

simonw commented Mar 12, 2024

... which is weird, because in the tests it seems to have the correct label.

@simonw
Copy link
Owner Author

simonw commented Mar 12, 2024

... no, it's working. I hit the demo page before the demo had finished deploying.

Now https://latest.datasette.io/fixtures/simple_view looks like this:

CleanShot 2024-03-12 at 14 33 30@2x

@simonw simonw closed this as completed Mar 12, 2024
This was referenced Mar 12, 2024
simonw added a commit that referenced this issue Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant