-
Notifications
You must be signed in to change notification settings - Fork 14
delete button #112
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
delete button #112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,16 @@ def feed_page(): | |
| # Create chat feed | ||
| chat_feed = pn.Column(sizing_mode="stretch_both") | ||
|
|
||
| def on_delete(snippet_id): | ||
| """Handle deletion of a visualization.""" | ||
| # Delete from database | ||
| get_db().delete_snippet(snippet_id) | ||
| # Remove from cache | ||
| if snippet_id in pn.state.cache["views"]: | ||
| del pn.state.cache["views"][snippet_id] | ||
| # Refresh feed | ||
| update_chat() | ||
|
Comment on lines
+25
to
+33
|
||
|
|
||
| def get_view(req): | ||
| """Create view for a single visualization in the feed.""" | ||
| if req.id in pn.state.cache["views"]: | ||
|
|
@@ -35,7 +45,7 @@ def get_view(req): | |
| title = f"""\ | ||
| **{req.name or req.id}** ({created_at})\n\n{req.description}\n | ||
| """ | ||
| iframe = f"""<div style="resize: vertical; overflow: hidden; height: calc(75vh - 200px); width: 100%; max-width: 100%; border: 1px solid gray;"> | ||
| iframe = f"""<div style="resize: vertical; overflow: hidden; height: calc(75vh - 300px); width: 100%; max-width: 100%; border: 1px solid gray;"> | ||
| <iframe src="{url}" style="height: 100%; width: 100%; border: none;" frameborder="0"></iframe> | ||
| </div>""" | ||
| # Create copy button with JavaScript callback | ||
|
|
@@ -66,9 +76,31 @@ def get_view(req): | |
| """, | ||
| ) | ||
|
|
||
| delete_button = pn.widgets.Button( | ||
| name="🗑️ Delete", | ||
| button_type="danger", | ||
| width=120, | ||
| description="Delete this visualization", | ||
| ) | ||
| delete_button.on_click(lambda event: on_delete(req.id)) | ||
|
|
||
| with pn.config.set(sizing_mode="stretch_width"): | ||
| message = pn.Column( | ||
| pn.pane.Markdown(title), pn.pane.Markdown(iframe), pn.Row(pn.HSpacer(), open_button, copy_button, margin=(0, 10, 0, 10), align="end") | ||
| pn.pane.Markdown( | ||
| title, | ||
| margin=(10, 10, 0, 10), | ||
| ), | ||
| pn.Tabs( | ||
| pn.pane.Markdown(iframe, name="View"), | ||
| pn.widgets.CodeEditor( | ||
| value=req.app, | ||
| name="Code", | ||
| language="python", | ||
| theme="github_dark", | ||
| ), | ||
| margin=(0, 10, 10, 10), | ||
| ), | ||
| pn.Row(pn.HSpacer(), open_button, copy_button, delete_button, margin=(0, 10, 0, 10), align="end"), | ||
| ) | ||
|
|
||
| pn.state.cache["views"][req.id] = message | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The on_delete function does not handle potential errors from the database deletion operation. If get_db().delete_snippet() fails or raises an exception, the cache could be left in an inconsistent state (the cache entry might be deleted while the database record remains). Consider wrapping the deletion logic in a try-except block and only clearing the cache if the database deletion succeeds. The delete_snippet method returns a bool indicating success, which should be checked before modifying the cache.