@@ -33,11 +33,6 @@ import { PLAYGROUND_RESULT_SCHEME } from './playgroundResultProvider';
3333import { StatusView } from '../views' ;
3434import type { TelemetryService } from '../telemetry' ;
3535import type { QueryWithCopilotCodeLensProvider } from './queryWithCopilotCodeLensProvider' ;
36- import { createWebviewPanel , getWebviewHtml } from '../utils/webviewHelpers' ;
37- import {
38- PreviewMessageType ,
39- type SortOption ,
40- } from '../views/data-browsing-app/extension-app-message-constants' ;
4136
4237const log = createLogger ( 'editors controller' ) ;
4338
@@ -109,7 +104,6 @@ export default class EditorsController {
109104 _editDocumentCodeLensProvider : EditDocumentCodeLensProvider ;
110105 _collectionDocumentsCodeLensProvider : CollectionDocumentsCodeLensProvider ;
111106 _queryWithCopilotCodeLensProvider : QueryWithCopilotCodeLensProvider ;
112- _activePreviewPanels : vscode . WebviewPanel [ ] = [ ] ;
113107
114108 constructor ( {
115109 context,
@@ -310,139 +304,6 @@ export default class EditorsController {
310304 }
311305 }
312306
313- openCollectionPreview (
314- namespace : string ,
315- documents : Document [ ] ,
316- fetchDocuments ?: ( options ?: {
317- sort ?: SortOption ;
318- limit ?: number ;
319- } ) => Promise < Document [ ] > ,
320- initialTotalCount ?: number ,
321- getTotalCount ?: ( ) => Promise < number > ,
322- ) : boolean {
323- log . info ( 'Open collection preview' , namespace ) ;
324-
325- try {
326- const extensionPath = this . _context . extensionPath ;
327-
328- const panel = createWebviewPanel ( {
329- viewType : 'mongodbPreview' ,
330- title : `Preview: ${ namespace } ` ,
331- extensionPath,
332- } ) ;
333-
334- panel . webview . html = getWebviewHtml ( {
335- extensionPath,
336- webview : panel . webview ,
337- scriptName : 'previewApp.js' ,
338- title : 'Preview' ,
339- } ) ;
340-
341- panel . onDidDispose ( ( ) => this . onPreviewPanelClosed ( panel ) ) ;
342- this . _activePreviewPanels . push ( panel ) ;
343-
344- // Keep track of current documents, sort option, and total count
345- // Fetch limit is fixed - pagination is handled client-side
346- const FETCH_LIMIT = 100 ;
347- let currentDocuments = documents ;
348- let currentSort : SortOption = 'default' ;
349- let totalCount = initialTotalCount ?? documents . length ;
350-
351- // Helper to send current documents to webview
352- const sendDocuments = ( ) : void => {
353- void panel . webview . postMessage ( {
354- command : PreviewMessageType . loadDocuments ,
355- documents : JSON . parse ( EJSON . stringify ( currentDocuments ) ) ,
356- totalCount,
357- } ) ;
358- } ;
359-
360- // Helper to handle errors
361- const handleError = ( operation : string , error : unknown ) : void => {
362- log . error ( `${ operation } failed:` , error ) ;
363- void panel . webview . postMessage ( {
364- command : PreviewMessageType . refreshError ,
365- error : formatError ( error ) . message ,
366- } ) ;
367- } ;
368-
369- // Helper to fetch and update documents
370- const fetchAndUpdateDocuments = async (
371- operation : string ,
372- ) : Promise < void > => {
373- if ( fetchDocuments ) {
374- log . info (
375- `${ operation } with sort:` ,
376- currentSort ,
377- 'limit:' ,
378- FETCH_LIMIT ,
379- ) ;
380- currentDocuments = await fetchDocuments ( {
381- sort : currentSort ,
382- limit : FETCH_LIMIT ,
383- } ) ;
384- log . info ( `${ operation } complete, count:` , currentDocuments . length ) ;
385- }
386- } ;
387-
388- // Send documents to webview
389- panel . webview . onDidReceiveMessage (
390- async ( message : { command : string ; sort ?: SortOption } ) => {
391- log . info ( 'Preview received message:' , message . command ) ;
392-
393- switch ( message . command ) {
394- case PreviewMessageType . getDocuments :
395- sendDocuments ( ) ;
396- break ;
397-
398- case PreviewMessageType . refreshDocuments :
399- try {
400- await fetchAndUpdateDocuments ( 'Refreshing documents' ) ;
401- if ( getTotalCount ) {
402- totalCount = await getTotalCount ( ) ;
403- }
404- sendDocuments ( ) ;
405- } catch ( error ) {
406- handleError ( 'Refresh documents' , error ) ;
407- }
408- break ;
409-
410- case PreviewMessageType . sortDocuments :
411- try {
412- if ( message . sort ) {
413- currentSort = message . sort ;
414- await fetchAndUpdateDocuments ( 'Sorting documents' ) ;
415- }
416- sendDocuments ( ) ;
417- } catch ( error ) {
418- handleError ( 'Sort documents' , error ) ;
419- }
420- break ;
421-
422- default :
423- log . info ( 'Unknown command:' , message . command ) ;
424- break ;
425- }
426- } ,
427- ) ;
428-
429- return true ;
430- } catch ( error ) {
431- void vscode . window . showErrorMessage (
432- `Unable to open preview: ${ formatError ( error ) . message } ` ,
433- ) ;
434-
435- return false ;
436- }
437- }
438-
439- private onPreviewPanelClosed ( panel : vscode . WebviewPanel ) : void {
440- const panelIndex = this . _activePreviewPanels . indexOf ( panel ) ;
441- if ( panelIndex !== - 1 ) {
442- this . _activePreviewPanels . splice ( panelIndex , 1 ) ;
443- }
444- }
445-
446307 onViewMoreCollectionDocuments (
447308 operationId : string ,
448309 connectionId : string ,
0 commit comments