Skip to content

Commit e2e84d4

Browse files
Merge pull request certinia#622 from lukecotter/fix-search-too-many-calls
fix: stop search from occurring multiple times
2 parents af5cb29 + c19ffed commit e2e84d4

5 files changed

Lines changed: 84 additions & 56 deletions

File tree

log-viewer/modules/components/analysis-view/AnalysisView.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class AnalysisView extends LitElement {
110110
options: { matchCase: false },
111111
};
112112
totalMatches = 0;
113-
blockClearHighlights = false;
113+
blockClearHighlights = true;
114114

115115
constructor() {
116116
super();
@@ -239,8 +239,7 @@ export class AnalysisView extends LitElement {
239239
}
240240
}
241241

242-
const hasHighlights = Object.keys(this.findMap).length !== 0;
243-
if (!hasHighlights) {
242+
if (this.totalMatches <= 0) {
244243
return;
245244
}
246245
this.blockClearHighlights = true;
@@ -420,7 +419,7 @@ export class AnalysisView extends LitElement {
420419
});
421420

422421
this.analysisTable.on('renderStarted', () => {
423-
if (!this.blockClearHighlights) {
422+
if (!this.blockClearHighlights && this.totalMatches > 0) {
424423
this._resetFindWidget();
425424
this._clearSearchHighlights();
426425
}
@@ -432,11 +431,12 @@ export class AnalysisView extends LitElement {
432431
}
433432

434433
_clearSearchHighlights() {
435-
this._find(
436-
new CustomEvent('lv-find-close', {
437-
detail: { text: '', count: 0, options: { matchCase: false } },
438-
}),
439-
);
434+
this.findArgs.text = '';
435+
this.findArgs.count = 0;
436+
//@ts-expect-error This is a custom function added in by Find custom module
437+
this.analysisTable.clearFindHighlights(Object.values(this.findMap));
438+
this.findMap = {};
439+
this.totalMatches = 0;
440440
}
441441
}
442442
export class Metric {

log-viewer/modules/components/calltree-view/CalltreeView.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class CalltreeView extends LitElement {
5757
findMap: { [key: number]: RowComponent } = {};
5858
totalMatches = 0;
5959

60-
blockClearHighlights = false;
60+
blockClearHighlights = true;
6161
searchString = '';
6262
findArgs: { text: string; count: number; options: { matchCase: boolean } } = {
6363
text: '',
@@ -361,6 +361,7 @@ export class CalltreeView extends LitElement {
361361
if (clearHighlights) {
362362
newFindArgs.text = '';
363363
}
364+
364365
if (newSearch || clearHighlights) {
365366
this.blockClearHighlights = true;
366367
//@ts-expect-error This is a custom function added in by Find custom module
@@ -377,8 +378,7 @@ export class CalltreeView extends LitElement {
377378
}
378379

379380
// Highlight the current row and reset the previous or next depending on whether we are stepping forward or back.
380-
const hasHighlights = Object.keys(this.findMap).length !== 0;
381-
if (!hasHighlights) {
381+
if (this.totalMatches <= 0) {
382382
return;
383383
}
384384
this.blockClearHighlights = true;
@@ -793,7 +793,7 @@ export class CalltreeView extends LitElement {
793793
});
794794

795795
this.calltreeTable.on('renderStarted', () => {
796-
if (!this.blockClearHighlights) {
796+
if (!this.blockClearHighlights && this.totalMatches > 0) {
797797
this._resetFindWidget();
798798
this._clearSearchHighlights();
799799
}
@@ -810,11 +810,12 @@ export class CalltreeView extends LitElement {
810810
}
811811

812812
private _clearSearchHighlights() {
813-
this._find(
814-
new CustomEvent('lv-find-close', {
815-
detail: { text: '', count: 0, options: { matchCase: false } },
816-
}),
817-
);
813+
this.findArgs.text = '';
814+
this.findArgs.count = 0;
815+
//@ts-expect-error This is a custom function added in by Find custom module
816+
this.calltreeTable.clearFindHighlights(Object.values(this.findMap));
817+
this.findMap = {};
818+
this.totalMatches = 0;
818819
}
819820

820821
private _expandCollapseAll(rows: RowComponent[], expand: boolean = true) {

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class Find extends Module {
1616
super(table);
1717
// @ts-expect-error registerTableFunction() needs adding to tabulator types
1818
this.registerTableFunction('find', this._find.bind(this));
19+
// @ts-expect-error registerTableFunction() needs adding to tabulator types
20+
this.registerTableFunction('clearFindHighlights', this._clearFindHighlights.bind(this));
1921
}
2022

2123
initialize() {}
@@ -100,6 +102,16 @@ export class Find extends Module {
100102
return result;
101103
}
102104

105+
_clearFindHighlights(rows: RowComponent[]) {
106+
this.table.blockRedraw();
107+
for (const row of rows) {
108+
const data = row.getData();
109+
data.highlightIndexes = [];
110+
row.reformat();
111+
}
112+
this.table.restoreRedraw();
113+
}
114+
103115
_countMatches(elem: Node, findArgs: FindArgs, regex: RegExp) {
104116
let count = 0;
105117

@@ -201,25 +213,19 @@ export class Find extends Module {
201213

202214
export function formatter(row: RowComponent, findArgs: FindArgs) {
203215
const { text, count } = findArgs;
204-
if (!text || !count || !row.getData()) {
216+
if (!text || !count || !row.getData() || !row.getData().highlightIndexes?.length) {
205217
return;
206218
}
207-
requestAnimationFrame(() => {
208-
const data = row.getData();
209-
const highlights = {
210-
indexes: data.highlightIndexes,
211-
currentMatch: 0,
212-
};
213219

214-
row.getCells().forEach((cell) => {
215-
const cellElem = cell.getElement();
216-
_highlightText(cellElem, findArgs, highlights);
217-
});
220+
const data = row.getData();
221+
const highlights = {
222+
indexes: data.highlightIndexes,
223+
currentMatch: 0,
224+
};
218225

219-
//@ts-expect-error This is private to tabulator, but we have no other choice atm.
220-
if (row._getSelf().type === 'row') {
221-
row.normalizeHeight();
222-
}
226+
row.getCells().forEach((cell) => {
227+
const cellElem = cell.getElement();
228+
_highlightText(cellElem, findArgs, highlights);
223229
});
224230
}
225231

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class DMLView extends LitElement {
6262
};
6363
findMap: { [key: number]: RowComponent } = {};
6464
totalMatches = 0;
65-
blockClearHighlights = false;
65+
blockClearHighlights = true;
6666

6767
constructor() {
6868
super();
@@ -196,6 +196,7 @@ export class DMLView extends LitElement {
196196
});
197197
}
198198

199+
// todo: fix search on grouped data
199200
_highlightMatches(highlightIndex: number) {
200201
if (!this.dmlTable?.element?.clientHeight) {
201202
return;
@@ -304,7 +305,7 @@ export class DMLView extends LitElement {
304305
selectableRows: 'highlight',
305306
dataTree: true,
306307
dataTreeBranchElement: false,
307-
dataTreeStartExpanded: true,
308+
dataTreeStartExpanded: false,
308309
columnDefaults: {
309310
title: 'default',
310311
resizable: true,
@@ -381,7 +382,9 @@ export class DMLView extends LitElement {
381382
row.normalizeHeight();
382383
}
383384

384-
formatter(row, this.findArgs);
385+
requestAnimationFrame(() => {
386+
formatter(row, this.findArgs);
387+
});
385388
},
386389
});
387390

@@ -391,9 +394,16 @@ export class DMLView extends LitElement {
391394
return;
392395
}
393396

394-
this.dmlTable?.blockRedraw();
395397
group.toggle();
396-
this.dmlTable?.restoreRedraw();
398+
if (this.dmlTable && group.isVisible()) {
399+
this.dmlTable.blockRedraw();
400+
for (const row of group.getRows()) {
401+
if (row.getTreeChildren() && !row.isTreeExpanded()) {
402+
row.treeExpand();
403+
}
404+
}
405+
this.dmlTable.restoreRedraw();
406+
}
397407
});
398408

399409
this.dmlTable.on('rowClick', function (e, row) {
@@ -413,7 +423,7 @@ export class DMLView extends LitElement {
413423
});
414424

415425
this.dmlTable.on('renderStarted', () => {
416-
if (!this.blockClearHighlights) {
426+
if (!this.blockClearHighlights && this.totalMatches > 0) {
417427
this._resetFindWidget();
418428
this._clearSearchHighlights();
419429
}
@@ -439,11 +449,12 @@ export class DMLView extends LitElement {
439449
}
440450

441451
private _clearSearchHighlights() {
442-
this._find(
443-
new CustomEvent('lv-find-close', {
444-
detail: { text: '', count: 0, options: { matchCase: false } },
445-
}),
446-
);
452+
this.findArgs.text = '';
453+
this.findArgs.count = 0;
454+
//@ts-expect-error This is a custom function added in by Find custom module
455+
this.dmlTable.clearFindHighlights(Object.values(this.findMap));
456+
this.findMap = {};
457+
this.totalMatches = 0;
447458
}
448459

449460
_getTable() {

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class SOQLView extends LitElement {
7373
};
7474
findMap: { [key: number]: RowComponent } = {};
7575
totalMatches = 0;
76-
blockClearHighlights = false;
76+
blockClearHighlights = true;
7777

7878
get _soqlTableWrapper(): HTMLDivElement | null {
7979
return this.renderRoot?.querySelector('#db-soql-table') ?? null;
@@ -346,7 +346,7 @@ export class SOQLView extends LitElement {
346346
},
347347
dataTree: true,
348348
dataTreeBranchElement: false,
349-
dataTreeStartExpanded: true,
349+
dataTreeStartExpanded: false,
350350
columnDefaults: {
351351
title: 'default',
352352
resizable: true,
@@ -510,7 +510,9 @@ export class SOQLView extends LitElement {
510510
row.normalizeHeight();
511511
}
512512

513-
formatter(row, this.findArgs);
513+
requestAnimationFrame(() => {
514+
formatter(row, this.findArgs);
515+
});
514516
},
515517
});
516518

@@ -519,10 +521,17 @@ export class SOQLView extends LitElement {
519521
if (type === 'Range') {
520522
return;
521523
}
522-
523-
this.soqlTable?.blockRedraw();
524524
group.toggle();
525-
this.soqlTable?.restoreRedraw();
525+
526+
if (this.soqlTable && group.isVisible()) {
527+
this.soqlTable.blockRedraw();
528+
for (const row of group.getRows()) {
529+
if (row.getTreeChildren() && !row.isTreeExpanded()) {
530+
row.treeExpand();
531+
}
532+
}
533+
this.soqlTable.restoreRedraw();
534+
}
526535
});
527536

528537
this.soqlTable.on('rowClick', function (e, row) {
@@ -542,7 +551,7 @@ export class SOQLView extends LitElement {
542551
});
543552

544553
this.soqlTable.on('renderStarted', () => {
545-
if (!this.blockClearHighlights) {
554+
if (!this.blockClearHighlights && this.totalMatches > 0) {
546555
this._resetFindWidget();
547556
this._clearSearchHighlights();
548557
}
@@ -568,11 +577,12 @@ export class SOQLView extends LitElement {
568577
}
569578

570579
_clearSearchHighlights() {
571-
this._find(
572-
new CustomEvent('lv-find-close', {
573-
detail: { text: '', count: 0, options: { matchCase: false } },
574-
}),
575-
);
580+
this.findArgs.text = '';
581+
this.findArgs.count = 0;
582+
//@ts-expect-error This is a custom function added in by Find custom module
583+
this.soqlTable.clearFindHighlights(Object.values(this.findMap));
584+
this.findMap = {};
585+
this.totalMatches = 0;
576586
}
577587

578588
_getTable() {

0 commit comments

Comments
 (0)