Skip to content

Commit b45097a

Browse files
committed
fix: find to work in grouped rows
1 parent 7eeeb8a commit b45097a

4 files changed

Lines changed: 68 additions & 51 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: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ export class DMLView extends LitElement {
272272
});
273273
}
274274
}
275-
const dmlText = this.sortByFrequency(dmlData || [], 'dml');
276275

277276
this.dmlTable = new Tabulator(dmlTableContainer, {
278277
height: '100%',
@@ -298,8 +297,6 @@ export class DMLView extends LitElement {
298297
groupSort: true,
299298
groupClosedShowCalcs: true,
300299
groupStartOpen: false,
301-
groupValues: [dmlText],
302-
groupBy: ['dml'],
303300
groupToggleElement: false,
304301
selectableRowsCheck: function (row: RowComponent) {
305302
return !row.getData().isDetail;
@@ -381,7 +378,6 @@ export class DMLView extends LitElement {
381378
if (data.isDetail && data.timestamp) {
382379
const detailContainer = this.createDetailPanel(data.timestamp);
383380
row.getElement().replaceChildren(detailContainer);
384-
row.normalizeHeight();
385381
}
386382

387383
requestAnimationFrame(() => {
@@ -424,22 +420,39 @@ export class DMLView extends LitElement {
424420
row.getCell('dml').getElement().style.height = origRowHeight + 'px';
425421
});
426422

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

438430
this.dmlTable.on('renderComplete', () => {
439431
const holder = this._getTableHolder();
440432
const table = this._getTable();
441433
holder.style.minHeight = Math.min(holder.clientHeight, table.clientHeight) + 'px';
442434
});
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+
});
443456
}
444457

445458
_resetFindWidget() {
@@ -457,6 +470,12 @@ export class DMLView extends LitElement {
457470
this.dmlTable.clearFindHighlights(Object.values(this.findMap));
458471
this.findMap = {};
459472
this.totalMatches = 0;
473+
474+
document.dispatchEvent(
475+
new CustomEvent('db-find-results', {
476+
detail: { totalMatches: this.totalMatches, type: 'dml' },
477+
}),
478+
);
460479
}
461480

462481
_getTable() {
@@ -477,17 +496,6 @@ export class DMLView extends LitElement {
477496
return detailContainer;
478497
}
479498

480-
sortByFrequency(dataArray: DMLRow[], field: keyof DMLRow) {
481-
const map = new Map<unknown, number>();
482-
dataArray.forEach((row) => {
483-
const val = row[field];
484-
map.set(val, (map.get(val) || 0) + 1);
485-
});
486-
const newMap = new Map([...map.entries()].sort((a, b) => b[1] - a[1]));
487-
488-
return [...newMap.keys()];
489-
}
490-
491499
downlodEncoder(defaultFileName: string) {
492500
return function (fileContents: string, mimeType: string) {
493501
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: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ export class SOQLView extends LitElement {
313313
}
314314
}
315315

316-
const soqlText = this.sortByFrequency(soqlData || [], 'soql');
317-
318316
this.soqlTable = new Tabulator(soqlTableContainer, {
319317
height: '100%',
320318
rowKeyboardNavigation: true,
@@ -339,8 +337,6 @@ export class SOQLView extends LitElement {
339337
groupSort: true,
340338
groupClosedShowCalcs: true,
341339
groupStartOpen: false,
342-
groupBy: 'soql',
343-
groupValues: [soqlText],
344340
groupToggleElement: false,
345341
selectableRows: 'highlight',
346342
selectableRowsCheck: function (row: RowComponent) {
@@ -507,9 +503,7 @@ export class SOQLView extends LitElement {
507503
const data = row.getData();
508504
if (data.isDetail && data.timestamp) {
509505
const detailContainer = this.createSOQLDetailPanel(data.timestamp, timestampToSOQl);
510-
511506
row.getElement().replaceChildren(detailContainer);
512-
row.normalizeHeight();
513507
}
514508

515509
requestAnimationFrame(() => {
@@ -552,15 +546,32 @@ export class SOQLView extends LitElement {
552546
row.getCell('soql').getElement().style.height = origRowHeight + 'px';
553547
});
554548

555-
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', () => {
556557
if (!this.blockClearHighlights && this.totalMatches > 0) {
557558
this._resetFindWidget();
558559
this._clearSearchHighlights();
559560
}
561+
});
560562

561-
const holder = this._getTableHolder();
562-
holder.style.minHeight = holder.clientHeight + 'px';
563-
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+
}
564575
});
565576

566577
this.soqlTable.on('renderComplete', () => {
@@ -585,6 +596,12 @@ export class SOQLView extends LitElement {
585596
this.soqlTable.clearFindHighlights(Object.values(this.findMap));
586597
this.findMap = {};
587598
this.totalMatches = 0;
599+
600+
document.dispatchEvent(
601+
new CustomEvent('db-find-results', {
602+
detail: { totalMatches: this.totalMatches, type: 'dml' },
603+
}),
604+
);
588605
}
589606

590607
_getTable() {
@@ -613,17 +630,6 @@ export class SOQLView extends LitElement {
613630
return detailContainer;
614631
}
615632

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

0 commit comments

Comments
 (0)