Skip to content

Commit 9971376

Browse files
committed
fix: find to work in grouped rows
1 parent 7447900 commit 9971376

4 files changed

Lines changed: 74 additions & 53 deletions

File tree

log-viewer/modules/components/calltree-view/module/Find.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,28 @@ export class Find extends Module {
206206
}
207207

208208
export function formatter(row: RowComponent, findArgs: FindArgs) {
209-
const { text, count } = findArgs;
210-
if (!text || !count || !row.getData() || !row.getData().highlightIndexes?.length) {
209+
const { text } = findArgs;
210+
if (!text) {
211211
return;
212212
}
213-
214213
const data = row.getData();
214+
if (!data || !data.highlightIndexes?.length) {
215+
return;
216+
}
217+
215218
const highlights = {
216219
indexes: data.highlightIndexes,
217220
currentMatch: 0,
218221
};
219-
220222
row.getCells().forEach((cell) => {
221223
const cellElem = cell.getElement();
222224
_highlightText(cellElem, findArgs, highlights);
223225
});
226+
227+
//@ts-expect-error This is private to tabulator, but we have no other choice atm.
228+
if (row._getSelf().type === 'row') {
229+
row.normalizeHeight();
230+
}
224231
}
225232

226233
function _highlightText(

log-viewer/modules/components/database-view/DMLView.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ export class DMLView extends LitElement {
159159
this.dmlTable?.download('csv', 'dml.csv', { bom: true, delimiter: ',' });
160160
}
161161

162-
_findEvt = ((event: FindEvt) => this._find(event)) as EventListener;
162+
_findEvt = ((event: FindEvt) => {
163+
this._find(event);
164+
}) as EventListener;
163165

164166
_dmlGroupBy(event: Event) {
165167
const target = event.target as HTMLInputElement;
@@ -270,7 +272,6 @@ export class DMLView extends LitElement {
270272
});
271273
}
272274
}
273-
const dmlText = this.sortByFrequency(dmlData || [], 'dml');
274275

275276
this.dmlTable = new Tabulator(dmlTableContainer, {
276277
height: '100%',
@@ -296,8 +297,6 @@ export class DMLView extends LitElement {
296297
groupSort: true,
297298
groupClosedShowCalcs: true,
298299
groupStartOpen: false,
299-
groupValues: [dmlText],
300-
groupBy: ['dml'],
301300
groupToggleElement: false,
302301
selectableRowsCheck: function (row: RowComponent) {
303302
return !row.getData().isDetail;
@@ -379,7 +378,6 @@ export class DMLView extends LitElement {
379378
if (data.isDetail && data.timestamp) {
380379
const detailContainer = this.createDetailPanel(data.timestamp);
381380
row.getElement().replaceChildren(detailContainer);
382-
row.normalizeHeight();
383381
}
384382

385383
requestAnimationFrame(() => {
@@ -422,22 +420,39 @@ export class DMLView extends LitElement {
422420
row.getCell('dml').getElement().style.height = origRowHeight + 'px';
423421
});
424422

425-
this.dmlTable.on('renderStarted', () => {
426-
if (!this.blockClearHighlights && this.totalMatches > 0) {
427-
this._resetFindWidget();
428-
this._clearSearchHighlights();
429-
}
430-
423+
this.dmlTable.on('tableBuilt', () => {
431424
const holder = this._getTableHolder();
432-
holder.style.minHeight = holder.clientHeight + 'px';
433425
holder.style.overflowAnchor = 'none';
426+
//@ts-expect-error This is a custom function added in the GroupSort custom module
427+
this.dmlTable?.setSortedGroupBy('dml');
434428
});
435429

436430
this.dmlTable.on('renderComplete', () => {
437431
const holder = this._getTableHolder();
438432
const table = this._getTable();
439433
holder.style.minHeight = Math.min(holder.clientHeight, table.clientHeight) + 'px';
440434
});
435+
436+
this.dmlTable.on('dataSorted', () => {
437+
if (!this.blockClearHighlights && this.totalMatches > 0) {
438+
this._resetFindWidget();
439+
this._clearSearchHighlights();
440+
}
441+
});
442+
443+
this.dmlTable.on('dataGrouped', () => {
444+
if (!this.blockClearHighlights && this.totalMatches > 0) {
445+
this._resetFindWidget();
446+
this._clearSearchHighlights();
447+
}
448+
});
449+
450+
this.dmlTable.on('dataFiltering', () => {
451+
if (!this.blockClearHighlights && this.totalMatches > 0) {
452+
this._resetFindWidget();
453+
this._clearSearchHighlights();
454+
}
455+
});
441456
}
442457

443458
_resetFindWidget() {
@@ -455,6 +470,12 @@ export class DMLView extends LitElement {
455470
this.dmlTable.clearFindHighlights(Object.values(this.findMap));
456471
this.findMap = {};
457472
this.totalMatches = 0;
473+
474+
document.dispatchEvent(
475+
new CustomEvent('db-find-results', {
476+
detail: { totalMatches: this.totalMatches, type: 'dml' },
477+
}),
478+
);
458479
}
459480

460481
_getTable() {
@@ -475,17 +496,6 @@ export class DMLView extends LitElement {
475496
return detailContainer;
476497
}
477498

478-
sortByFrequency(dataArray: DMLRow[], field: keyof DMLRow) {
479-
const map = new Map<unknown, number>();
480-
dataArray.forEach((row) => {
481-
const val = row[field];
482-
map.set(val, (map.get(val) || 0) + 1);
483-
});
484-
const newMap = new Map([...map.entries()].sort((a, b) => b[1] - a[1]));
485-
486-
return [...newMap.keys()];
487-
}
488-
489499
downlodEncoder(defaultFileName: string) {
490500
return function (fileContents: string, mimeType: string) {
491501
const vscode = vscodeMessenger.getVsCodeAPI();

log-viewer/modules/components/database-view/DatabaseView.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ export class DatabaseView extends LitElement {
8484
};
8585

8686
_findResults = (e: CustomEvent<{ totalMatches: number; type: 'dml' | 'soql' }>) => {
87-
if (!this.shadowRoot?.host.clientHeight) {
88-
return;
89-
}
90-
9187
if (e.detail.type === 'dml') {
9288
this.dmlMatches = e.detail.totalMatches;
9389
} else if (e.detail.type === 'soql') {

log-viewer/modules/components/database-view/SOQLView.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ export class SOQLView extends LitElement {
191191
this.soqlTable?.download('csv', 'soql.csv', { bom: true, delimiter: ',' });
192192
}
193193

194-
_findEvt = ((event: FindEvt) => this._find(event)) as EventListener;
194+
_findEvt = ((event: FindEvt) => {
195+
this._find(event);
196+
}) as EventListener;
195197

196198
_soqlGroupBy(event: Event) {
197199
if (!this.soqlTable) {
@@ -311,8 +313,6 @@ export class SOQLView extends LitElement {
311313
}
312314
}
313315

314-
const soqlText = this.sortByFrequency(soqlData || [], 'soql');
315-
316316
this.soqlTable = new Tabulator(soqlTableContainer, {
317317
height: '100%',
318318
rowKeyboardNavigation: true,
@@ -337,8 +337,6 @@ export class SOQLView extends LitElement {
337337
groupSort: true,
338338
groupClosedShowCalcs: true,
339339
groupStartOpen: false,
340-
groupBy: 'soql',
341-
groupValues: [soqlText],
342340
groupToggleElement: false,
343341
selectableRows: 'highlight',
344342
selectableRowsCheck: function (row: RowComponent) {
@@ -505,9 +503,7 @@ export class SOQLView extends LitElement {
505503
const data = row.getData();
506504
if (data.isDetail && data.timestamp) {
507505
const detailContainer = this.createSOQLDetailPanel(data.timestamp, timestampToSOQl);
508-
509506
row.getElement().replaceChildren(detailContainer);
510-
row.normalizeHeight();
511507
}
512508

513509
requestAnimationFrame(() => {
@@ -550,15 +546,32 @@ export class SOQLView extends LitElement {
550546
row.getCell('soql').getElement().style.height = origRowHeight + 'px';
551547
});
552548

553-
this.soqlTable.on('renderStarted', () => {
549+
this.soqlTable.on('tableBuilt', () => {
550+
const holder = this._getTableHolder();
551+
holder.style.overflowAnchor = 'none';
552+
//@ts-expect-error This is a custom function added in the GroupSort custom module
553+
this.soqlTable?.setSortedGroupBy('soql');
554+
});
555+
556+
this.soqlTable.on('dataSorted', () => {
554557
if (!this.blockClearHighlights && this.totalMatches > 0) {
555558
this._resetFindWidget();
556559
this._clearSearchHighlights();
557560
}
561+
});
558562

559-
const holder = this._getTableHolder();
560-
holder.style.minHeight = holder.clientHeight + 'px';
561-
holder.style.overflowAnchor = 'none';
563+
this.soqlTable.on('dataGrouped', () => {
564+
if (!this.blockClearHighlights && this.totalMatches > 0) {
565+
this._resetFindWidget();
566+
this._clearSearchHighlights();
567+
}
568+
});
569+
570+
this.soqlTable.on('dataFiltering', () => {
571+
if (!this.blockClearHighlights && this.totalMatches > 0) {
572+
this._resetFindWidget();
573+
this._clearSearchHighlights();
574+
}
562575
});
563576

564577
this.soqlTable.on('renderComplete', () => {
@@ -583,6 +596,12 @@ export class SOQLView extends LitElement {
583596
this.soqlTable.clearFindHighlights(Object.values(this.findMap));
584597
this.findMap = {};
585598
this.totalMatches = 0;
599+
600+
document.dispatchEvent(
601+
new CustomEvent('db-find-results', {
602+
detail: { totalMatches: this.totalMatches, type: 'dml' },
603+
}),
604+
);
586605
}
587606

588607
_getTable() {
@@ -611,17 +630,6 @@ export class SOQLView extends LitElement {
611630
return detailContainer;
612631
}
613632

614-
sortByFrequency(dataArray: GridSOQLData[], field: keyof GridSOQLData) {
615-
const map = new Map<unknown, number>();
616-
dataArray.forEach((row) => {
617-
const val = row[field];
618-
map.set(val, (map.get(val) || 0) + 1);
619-
});
620-
const newMap = new Map([...map.entries()].sort((a, b) => b[1] - a[1]));
621-
622-
return [...newMap.keys()];
623-
}
624-
625633
downlodEncoder(defaultFileName: string) {
626634
return function (fileContents: string, mimeType: string) {
627635
const vscode = vscodeMessenger.getVsCodeAPI();

0 commit comments

Comments
 (0)