feat: editable SQL query editor in $app()#265
Merged
Conversation
Replace the read-only SQL markdown display with a `bslib::input_code_editor()` that lets users edit the SQL directly. The editor submits on blur or Ctrl/Cmd+Enter. - `sync_sql_editor` observer keeps the editor in sync via `update_code_editor()` when the LLM updates SQL, the query is reset, or the active table switches - `on_sql_editor` observer applies user edits to `sql_val()`; treats the default `SELECT * FROM <name>` as NULL to prevent the Reset button from reappearing after a reset (update_code_editor triggers input$sql_editor on the server) - Editor excluded from bookmarking in both R and Python Closes #70
`pre code` no longer exists; SQL is now rendered in `input_code_editor` which uses a `.cm-content` element.
bslib's input_code_editor renders as a <bslib-code-editor> custom element using prism-code-editor (not CodeMirror). The editable value lives in the textarea inside the element; switch from to_contain_text() to to_have_value() accordingly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #70
Summary
Replaces the read-only SQL display in
$app()with an interactivebslib::input_code_editor()(R) and its Python equivalent, allowing users to directly edit and run SQL queries from the UI.Key design decisions:
sync_sql_editorobserver callsupdate_code_editor()on everysql_val()change (LLM update, reset, table switch) to keep the editor current without re-rendering the widget.on_sql_editorcompares incoming SQL toSELECT * FROM <table>and writesNULLon a match, so the Reset button correctly disappears after a reset even thoughupdate_code_editor()triggers the observer.bslib::input_code_editor()/update_code_editor()were already available from the viz feature.sql_editoris excluded from Shiny bookmarking.Both R (
pkg-r/R/QueryChat.R) and Python (pkg-py/src/querychat/_shiny.py) updated in parallel.Verification
querychat_app(penguins)SELECT * FROM penguinsand the Reset button disappears.