michael-s-molina opened a new pull request, #37642:
URL: https://github.com/apache/superset/pull/37642

   ## Summary
   
   This PR extends the SQL Lab API with new capabilities for tab management, 
query execution, and editor manipulation.
   
   ## New APIs
   
   ### Editor Access (now available via `Tab.getEditor()`)
   - **`Tab.getEditor()`** - Async method to get the editor handle
   - **`Editor.getValue()`** - Get the current SQL content
   - **`Editor.setValue(sql)`** - Replace the editor content
   - **`Editor.insertText(text)`** - Insert text at cursor position
   - **`Editor.focus()`** - Focus the editor
   - **`Editor.getCursorPosition()`** - Get current cursor position
   - **`Editor.getSelections()`** - Get current selections
   - **`Editor.setAnnotations(annotations)`** - Set error/warning markers
   - **`Editor.registerCompletionProvider(provider)`** - Register custom 
autocomplete
   
   ### Tab Management
   - **`createTab(options?)`** - Create a new query editor tab with optional 
SQL, title, database, catalog, and schema
   - **`closeTab(tabId)`** - Close a specific tab
   - **`setActiveTab(tabId)`** - Switch to a specific tab
   - **`onDidCreateTab`** - Event fired when a new tab is created
   
   ### Query Execution
   - **`runQuery()`** - Execute the SQL query in the current tab
   - **`stopQuery(queryId)`** - Stop a running query
   
   ### Tab Context
   - **`setDatabase(databaseId)`** - Set the database for the current tab
   - **`setCatalog(catalog)`** - Set the catalog for the current tab
   - **`setSchema(schema)`** - Set the schema for the current tab
   - **`Tab.databaseId`**, **`Tab.catalog`**, **`Tab.schema`** - Direct access 
to tab context
   
   ## API Changes
   
   ### Tab Interface
   ```typescript
   // Before
   interface Tab {
     id: string;
     title: string;
     editor: Editor;  // sync property with content, databaseId, catalog, schema
     panels: Panel[];
   }
   
   // After
   interface Tab {
     id: string;
     title: string;
     databaseId: number;
     catalog: string | null;
     schema: string | null;
     getEditor(): Promise<Editor>;  // async method returning EditorHandle
     panels: Panel[];
   }
   ```
   
   ### Editor Interface
   ```typescript
   // Before
   interface Editor {
     content: string;
     databaseId: number;
     catalog: string | null;
     schema: string;
     table: string | null;
   }
   
   // After - extends EditorHandle with full editor manipulation
   interface Editor extends EditorHandle {
     // Inherited: getValue(), setValue(), insertText(), focus(),
     // getCursorPosition(), getSelections(), setAnnotations(), etc.
   }
   ```
   
   ### Migration Example
   ```typescript
   // Before
   const tab = sqlLab.getCurrentTab();
   const sql = tab.editor.content;
   const dbId = tab.editor.databaseId;
   
   // After
   const tab = sqlLab.getCurrentTab();
   const editor = await tab.getEditor();
   const sql = editor.getValue();
   const dbId = tab.databaseId;
   ```
   
   ## Documentation
   
   Improved JSDoc documentation for the Editor API in 
`packages/superset-core/src/api/editors.ts`:
   
   - **EditorHandle** - Comprehensive documentation for all methods including 
behavior details, edge cases, and parameter descriptions
   - **Position, Range, Selection** - Added examples and clarified zero-based 
indexing
   - **EditorAnnotation** - Added example and severity color explanations
   - **EditorHotkey** - Documented key combination format with example
   - **CompletionProvider** - Added example showing async table completion
   - **executeCommand()** - Noted that command names are editor-specific (Ace 
vs Monaco)
   
   ## Test Plan
   
   - Create new tabs via `createTab()` with various options
   - Verify default tab naming "Untitled Query N"
   - Close and switch tabs via API
   - Execute and stop queries via API
   - Change database/catalog/schema via API
   - Access editor via `getEditor()` and manipulate content
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to