@@ -51,8 +51,6 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
5151 guid : "text" ,
5252 byte : "number" ,
5353 short : "number" ,
54- int : "number" ,
55- long : "number" ,
5654 real : "number" ,
5755 float : "number" ,
5856 char : "text" ,
@@ -199,7 +197,9 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
199197 ( ) => ( { } ) ,
200198 ) ;
201199
202- columns . forEach ( ( column ) => {
200+ const columnsArray = Array . isArray ( columns ) ? columns : [ columns ] ;
201+
202+ columnsArray . forEach ( ( column ) => {
203203 const { name, values } = column ;
204204 values . forEach ( ( value , index ) => {
205205 rowData [ index ] [ name ] = decodeQUTF ( value ) ;
@@ -212,7 +212,9 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
212212 updatedExtractColumnDefs ( results : StructuredTextResults ) {
213213 const { columns } = results ;
214214
215- const columnDefs = columns . map ( ( column ) => {
215+ const columnsArray = Array . isArray ( columns ) ? columns : [ columns ] ;
216+
217+ const columnDefs = columnsArray . map ( ( column ) => {
216218 const sanitizedKey = this . sanitizeString ( column . name ) ;
217219 const cellDataType = this . kdbToAgGridCellType ( column . type ) ;
218220 const headerName = column . type
@@ -303,24 +305,8 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
303305 }
304306
305307 const gridOptions : GridOptions = {
306- defaultColDef : {
307- sortable : true ,
308- resizable : true ,
309- filter : true ,
310- flex : 1 ,
311- minWidth : 100 ,
312- } ,
313308 rowData : rowData ,
314309 columnDefs : columnDefs ,
315- domLayout : "autoHeight" ,
316- pagination : true ,
317- paginationPageSize : 100 ,
318- enableCellTextSelection : true ,
319- ensureDomOrder : true ,
320- suppressContextMenu : true ,
321- suppressDragLeaveHidesColumns : true ,
322- tooltipShowDelay : 200 ,
323- loading : true ,
324310 } ;
325311
326312 return gridOptions ;
@@ -362,17 +348,16 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
362348 this . _results = queryResult ;
363349 let result = "" ;
364350 let gridOptions = undefined ;
351+
365352 if ( ! this . _view ) {
366353 kdbOutputLog ( "[Results Tab] No view to update" , "ERROR" ) ;
367354 return ;
368355 }
356+
357+ this . _view . webview . postMessage ( { command : "loading" } ) ;
358+
369359 if ( typeof queryResult === "string" || typeof queryResult === "number" ) {
370- result =
371- queryResult !== ""
372- ? `<p class="results-txt">${ queryResult
373- . toString ( )
374- . replace ( / \n / g, "<br/>" ) } </p>`
375- : "<p>No results to show</p>" ;
360+ result = this . formatResult ( queryResult ) ;
376361 } else if ( queryResult ) {
377362 gridOptions = this . convertToGrid (
378363 queryResult ,
@@ -381,16 +366,33 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
381366 this . isPython ,
382367 ) ;
383368 }
384- if ( gridOptions ) {
385- this . _view . webview . postMessage ( {
386- command : "setGridOptions" ,
387- gridOptions : gridOptions ,
388- } ) ;
389- } else {
390- this . _view . webview . postMessage ( {
391- command : "setResultsContent" ,
392- results : result ,
393- } ) ;
369+
370+ this . postMessageToWebview ( gridOptions , result ) ;
371+ }
372+
373+ private formatResult ( queryResult : string | number ) : string {
374+ return queryResult !== ""
375+ ? `<p class="results-txt">${ queryResult . toString ( ) . replace ( / \n / g, "<br/>" ) } </p>`
376+ : "<p>No results to show</p>" ;
377+ }
378+
379+ private postMessageToWebview (
380+ gridOptions : GridOptions | undefined ,
381+ result : string ,
382+ ) {
383+ if ( this . _view ) {
384+ if ( gridOptions ) {
385+ this . _view . webview . postMessage ( {
386+ command : "setGridDatasource" ,
387+ results : gridOptions . rowData ,
388+ columnDefs : gridOptions . columnDefs ,
389+ } ) ;
390+ } else {
391+ this . _view . webview . postMessage ( {
392+ command : "setResultsContent" ,
393+ results : result ,
394+ } ) ;
395+ }
394396 }
395397 }
396398
@@ -420,16 +422,33 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
420422 "ag-grid-community.min.js" ,
421423 ) } "></script>
422424 </head>
423- <body>
425+ <body>
424426 <div id="results" class="results-view-container">
425427 <div class="content-wrapper"></div>
426- </div>
428+ </div>
429+ <div id="overlay" class="overlay">
430+ <div class="loading-box">
431+ <div class="spinner"></div>
432+ <div class="loading-text">Loading data...</div>
433+ </div>
434+ </div>
427435 <script type="module" nonce="${ nonce } " src="${ webviewUri } "></script>
428436 <div id="grid" style="height: 100%; width:100%;" class="${ agGridTheme } "></div>
429- <script nonce="${ nonce } " >
437+ <script nonce="${ nonce } " >
430438 const vscode = acquireVsCodeApi();
439+ const gridDiv = document.getElementById('grid');
440+ const resultsDiv = document.querySelector('#results .content-wrapper');
441+ const overlay = document.getElementById('overlay');
431442 let gridApi;
432443
444+ function showOverlay() {
445+ overlay.style.display = 'flex';
446+ }
447+
448+ function hideOverlay() {
449+ overlay.style.display = 'none';
450+ }
451+
433452 function saveColumnWidths() {
434453 if (!gridApi) {return null};
435454 return gridApi.getColumnState();
@@ -442,30 +461,78 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
442461
443462 window.addEventListener('message', event => {
444463 const message = event.data;
445- console.log(event)
446- if (message.command === 'setGridOptions') {
464+ showOverlay();
465+
466+ const handleSetGridDatasource = () => {
447467 const columnWidths = saveColumnWidths();
448- const gridOptions = message.gridOptions;
449- const gridDiv = document.getElementById('grid');
450- const resultsDiv = document.querySelector('#results .content-wrapper');
451- resultsDiv.innerHTML = '';
452- gridDiv.innerHTML = '';
453- const rowData = gridOptions.rowData;
454- gridOptions.rowData = [];
468+ const gridOptions = {
469+ defaultColDef: {
470+ sortable: true,
471+ resizable: true,
472+ filter: true,
473+ flex: 1,
474+ minWidth: 100,
475+ },
476+ columnDefs: message.columnDefs,
477+ domLayout: "autoHeight",
478+ pagination: true,
479+ enableCellTextSelection: true,
480+ ensureDomOrder: true,
481+ suppressContextMenu: true,
482+ suppressDragLeaveHidesColumns: true,
483+ tooltipShowDelay: 200,
484+ rowBuffer: 0,
485+ rowModelType: "infinite",
486+ cacheBlockSize: 100,
487+ cacheOverflowSize: 2,
488+ maxConcurrentDatasourceRequests: 1,
489+ infiniteInitialRowCount: 10000,
490+ maxBlocksInCache: 10,
491+ datasource: {
492+ rowCount: undefined,
493+ getRows: function(params) {
494+ showOverlay();
495+ const results = message.results;
496+ setTimeout(() => {
497+ const lastRow = results.length;
498+ const rowsThisPage = results.slice(params.startRow, params.endRow);
499+ params.successCallback(rowsThisPage, lastRow);
500+ hideOverlay();
501+ }, 500);
502+ }
503+ }
504+ };
505+ resultsDiv.innerHTML = '';
506+ gridDiv.innerHTML = '';
455507 gridApi = agGrid.createGrid(gridDiv, gridOptions);
456508 restoreColumnWidths(columnWidths);
457- setTimeout(() => {
458- gridApi.setGridOption("rowData", rowData);
459- gridApi.setGridOption("loading", false);
460- }, 500);
461509 document.getElementById("results").scrollIntoView();
462- } else if (message.command === 'setResultsContent') {
510+ };
511+
512+ const handleSetResultsContent = () => {
463513 const resultsContent = message.results;
464- const resultsDiv = document.querySelector('#results .content-wrapper');
465- const gridDiv = document.getElementById('grid');
466- gridDiv.innerHTML = '';
467- resultsDiv.innerHTML = '';
514+ gridDiv.innerHTML = '';
515+ resultsDiv.innerHTML = '';
468516 resultsDiv.innerHTML = resultsContent;
517+ hideOverlay();
518+ };
519+
520+ const handleLoading = () => {
521+ gridDiv.innerHTML = '';
522+ resultsDiv.innerHTML = '';
523+ };
524+
525+ switch (message.command) {
526+ case 'setGridDatasource':
527+ handleSetGridDatasource();
528+ break;
529+ case 'setResultsContent':
530+ handleSetResultsContent();
531+ break;
532+ default:
533+ case 'loading':
534+ handleLoading();
535+ break;
469536 }
470537 });
471538 document.addEventListener('contextmenu', (e) => {
0 commit comments