feat(views): add SQL beautify button to view editor#372
Conversation
Add a "Beautify" button to the view editor modal that formats the view definition SQL using sql-formatter, mapping the active driver's dialect (postgres, mysql, mssql, sqlite, oracle) to the matching formatter language. The formatter falls back to the original text on empty input or parse errors so the user's SQL is never lost. Adds the `views.formatSql` i18n key across all 8 locales.
d87a938 to
a9422a4
Compare
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Previous Review Summary (commit a9422a4)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit a9422a4)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (11 files)
Reviewed by kimi-k2.7-code · Input: 48.9K · Output: 6.6K · Cached: 365.8K |
- Read the editor's live value in handleFormat via an onMount editor ref instead of the debounced `definition` state, so edits typed within the 300ms debounce window are no longer discarded by the format. - Add tests for sqlFormat covering each dialect mapping, keyword casing, empty/whitespace passthrough, and the parse-error fallback path.
|
Thanks for the review. Both warnings addressed in bcd169b:
|
|
@danielnuld I really love it! I'd actually extend this to the Query Editor as well. If you're interested, feel free to open a separate PR for that. About It I was also thinking it might make sense to have a single shared component used across the different sections, containing the query textarea, the AI controls (which aren't available in the View Editor yet), and the Beautify action. In the meantime, I'll merge this one. Thanks! |
What
Adds a Beautify button to the view editor modal (create & edit) that pretty-prints the view definition SQL.
Why
When editing a view, the definition returned by the database is often a single dense line (e.g. MySQL stores
SELECT c.id,c.name,...with no whitespace). This makes it hard to read and edit. A one-click formatter improves the editing experience.How
sql-formatter(^15.8.2) as a dependency.src/utils/sqlFormat.tsexposingformatSql(sql, dialect), which maps the active driver's dialect to the matchingsql-formatterlanguage:postgres → postgresql,mysql → mysql,mssql → transactsql,sqlite → sqlite,oracle → plsql, everything else →sql.ViewEditorModalgets aBeautifybutton next to the View Definition label, wired to the active connection'ssql_dialect.views.formatSqli18n key to all 8 locales (en, es, it, fr, de, ja, ru, zh).Testing
pnpm typecheckandpnpm buildpass; ESLint clean on changed files.SELECT … JOIN … WHERE … GROUP BY … HAVING … ORDER BYreformatted with proper indentation and keyword casing.