@@ -50,8 +50,12 @@ interface IOutgoingMessage {
5050 filterObjectsSchema ?: string ;
5151}
5252
53- export const VisualizationController = async ( webview : vscode . Webview , connectionContext : ConnectionContext ) => {
54- await renderWebviewContent ( webview , connectionContext ) ;
53+ export const VisualizationController = async (
54+ webview : vscode . Webview ,
55+ connectionContext : ConnectionContext ,
56+ connectionProfile : azdata . IConnectionProfile
57+ ) => {
58+ await renderWebviewContent ( webview , connectionContext , connectionProfile ) ;
5559} ;
5660
5761
@@ -60,7 +64,11 @@ const postMessage = (webview: azdata.DashboardWebview | vscode.Webview, message:
6064} ;
6165
6266
63- const renderWebviewContent = async ( webview : vscode . Webview , connectionContext : ConnectionContext ) => {
67+ const renderWebviewContent = async (
68+ webview : vscode . Webview ,
69+ connectionContext : ConnectionContext ,
70+ connectionProfile : azdata . IConnectionProfile
71+ ) => {
6472 webview . html = loadWebView ( ) ;
6573 if ( connectionContext . connectionId ) {
6674
@@ -167,6 +175,77 @@ const renderWebviewContent = async (webview: vscode.Webview, connectionContext:
167175 await loadRows ( data . commandSessionId , repository , webview , viewModel ) ;
168176 }
169177 }
178+ case 'openNewQueryEditor' : {
179+ if ( viewModel . selectedObject === undefined ) {
180+ return ;
181+ }
182+
183+ const object = viewModel . selectedObject ;
184+
185+ if (
186+ viewModel . columnsRelativeToObject ?. Name !== object . Name
187+ || viewModel . columnsRelativeToObject ?. Schema !== object . Schema
188+ )
189+ {
190+ return ;
191+ }
192+
193+ let orderByColumns : string [ ] | undefined ;
194+ let sortAscending : boolean [ ] | undefined ;
195+
196+ if ( viewModel . sortRowsByColumnName ) {
197+ orderByColumns = [ viewModel . sortRowsByColumnName ] ;
198+ if ( viewModel . sortRowsByColumnAscending !== undefined ) {
199+ sortAscending = [ viewModel . sortRowsByColumnAscending ] ;
200+ }
201+ else {
202+ sortAscending = [ true ] ;
203+ }
204+ }
205+ else {
206+ const primaryKey = viewModel . columns ?. filter ( c => c . IsPrimaryKey )
207+ . sort ( ( c1 , c2 ) => c1 . KeyOrdinal <= c2 . KeyOrdinal ? - 1 : 1 )
208+ . map ( c => c . Name ) ;
209+ orderByColumns = primaryKey ;
210+ sortAscending = primaryKey ?. map ( p => true ) ;
211+ }
212+
213+ const query = repository . getDbTableRowsQuery ( object , viewModel . columns , viewModel . filter ! , orderByColumns , sortAscending , viewModel . rowsPageIndex , viewModel . rowsPageSize ) ;
214+
215+ try {
216+ const doc = await azdata . queryeditor . openQueryDocument ( {
217+ content : query ,
218+ } ) ;
219+
220+ const connProfile : azdata . connection . ConnectionProfile = {
221+ authenticationType : connectionProfile . authenticationType ,
222+ connectionId : connectionContext . connectionId ,
223+ connectionName : connectionProfile . connectionName ! ,
224+ databaseName : connectionProfile . databaseName ! ,
225+ groupFullName : connectionProfile . groupFullName ! ,
226+ groupId : connectionProfile . groupId ! ,
227+ options : {
228+ ...connectionProfile . options ,
229+ database : connectionProfile . databaseName ! ,
230+ } ,
231+ password : "" ,
232+ providerId : connectionProfile . providerName ,
233+ savePassword : connectionProfile . savePassword ,
234+ saveProfile : connectionProfile . saveProfile ,
235+ serverName : connectionProfile . serverName ! ,
236+ userName : "" ,
237+ } ;
238+
239+ await doc . connect ( connProfile ) ;
240+
241+ } catch ( e ) {
242+ vscode . window . showErrorMessage (
243+ `Error opening new query editor: ${ ( < Error > e ) . message } `
244+ ) ;
245+ }
246+
247+ break ;
248+ }
170249 }
171250 }
172251 } ) ;
0 commit comments