11<script lang =" ts" >
2- import { TabulatorFull as Tabulator } from " tabulator-tables" ;
3- import { onMount } from " svelte" ;
2+ import { TabulatorFull as Tabulator } from " tabulator-tables" ;
3+ import { onMount } from " svelte" ;
44
5- export let scanResults: any [] = [];
6- let tableComponent: HTMLDivElement ;
7- let table: Tabulator ;
8- let printData: any [] = [];
5+ export let scanResults: any [] = [];
6+ let tableComponent: HTMLDivElement ;
7+ let table: Tabulator ;
8+ let printData: any [] = [];
99
10- const detailButton = () => ` <button style="background:#2765ae;border-radius:10px;">Details</button> ` ;
10+ const detailButton = () =>
11+ ` <button style="background:#2765ae;border-radius:10px;">Details</button> ` ;
1112
12- onMount (() => {
13- printData = scanResults .map (r => {
14- const obj = { ... r };
15- delete obj .flow ;
16- delete obj .ruleResults ;
17- return obj ;
18- });
13+ onMount (() => {
14+ printData = scanResults .map (( r ) => {
15+ const obj = { ... r };
16+ delete obj .flow ;
17+ delete obj .ruleResults ;
18+ return obj ;
19+ });
1920
20- table = new Tabulator (tableComponent , {
21- data: scanResults ,
22- reactiveData: true ,
23- layout: " fitColumns" ,
24- columns: [
25- { title: " # Results" , field: " resultCount" , hozAlign: " center" , bottomCalc: " count" , width: 100 },
26- {
27- title: " Label" , field: " label" , minWidth: 150 , formatter: " link" ,
28- formatterParams : (cell : any ) => ({ label: cell .getValue (), url: " javascript:void(0);" }),
29- cellClick : (_e : any , cell : any ) => {
30- tsvscode .postMessage ({ type: " goToFile" , value: cell .getRow ().getData ().flow });
31- },
32- headerFilter: true ,
33- headerFilterPlaceholder: " " ,
34- },
35- { title: " Flow Type" , field: " type" , minWidth: 120 },
36- {
37- title: " Details" , formatter: detailButton , width: 100 , hozAlign: " center" , print: false ,
38- cellClick : (_e : any , cell : any ) => {
39- tsvscode .postMessage ({ type: " goToDetails" , value: cell .getRow ().getData () });
40- },
41- },
42- ],
43- });
21+ table = new Tabulator (tableComponent , {
22+ data: scanResults ,
23+ reactiveData: true ,
24+ layout: " fitColumns" ,
25+ columns: [
26+ {
27+ title: " # Results" ,
28+ field: " resultCount" ,
29+ hozAlign: " center" ,
30+ bottomCalc: " count" ,
31+ width: 100 ,
32+ },
33+ {
34+ title: " Label" ,
35+ field: " label" ,
36+ minWidth: 150 ,
37+ formatter: " link" ,
38+ formatterParams : (cell : any ) => ({
39+ label: cell .getValue (),
40+ url: " javascript:void(0);" ,
41+ }),
42+ cellClick : (_e : any , cell : any ) => {
43+ tsvscode .postMessage ({
44+ type: " goToFile" ,
45+ value: cell .getRow ().getData ().flow ,
46+ });
47+ },
48+ headerFilter: true ,
49+ headerFilterPlaceholder: " " ,
50+ },
51+ { title: " Flow Type" , field: " type" , minWidth: 120 , headerFilter: true , headerFilterPlaceholder: " " },
52+ {
53+ title: " Details" ,
54+ formatter: detailButton ,
55+ width: 100 ,
56+ hozAlign: " center" ,
57+ print: false ,
58+ cellClick : (_e : any , cell : any ) => {
59+ tsvscode .postMessage ({
60+ type: " goToDetails" ,
61+ value: cell .getRow ().getData (),
62+ });
63+ },
64+ },
65+ ],
4466 });
67+ });
68+
69+ export function download() {
70+ tsvscode .postMessage ({ type: " download" , value: printData });
71+ }
4572
46- export function download() {
47- tsvscode .postMessage ({ type: " download" , value: printData });
73+ function onMessage(e : MessageEvent ) {
74+ const msg = e .data ;
75+ if (msg .type === " applySearchFlowName" ) {
76+ const term = (msg .value ?? " " ).trim ();
77+ if (! term ) {
78+ table ?.clearHeaderFilter ();
79+ return ;
80+ }
81+ table ?.setHeaderFilterValue (" label" , term );
4882 }
4983
50- function onMessage(e : MessageEvent ) {
51- const msg = e .data ;
52- if (msg .type === " applySearchFlowName" ) {
53- const term = (msg .value ?? " " ).trim ();
54- if (! term ) {
55- table ?.clearHeaderFilter ();
56- return ;
57- }
58- table ?.setHeaderFilterValue (" label" , term );
59- }
84+ if (msg .type === " applySearchAttributes" ) {
85+ const term = (msg .value ?? " " ).trim ();
86+
87+ if (term ) {
88+ table ?.setHeaderFilterValue (" resultCount" , term );
89+ table ?.setHeaderFilterValue (" type" , term );
90+ } else {
91+ table ?.clearHeaderFilter (" resultCount" );
92+ table ?.clearHeaderFilter (" type" );
6093 }
94+ return ;
95+ }
96+
97+ // Add new OR filter with unique ID
98+ table ?.addFilter ([
99+ { field: " resultCount" , type: " like" , value: term },
100+ { field: " type" , type: " like" , value: term },
101+ ], " or" , " attributes-or-filter" );
102+ }
103+
61104 </script >
62105
63106<svelte:window on:message ={onMessage } />
64- <div bind:this ={tableComponent } class =" tabulator-table" />
107+ <div bind:this ={tableComponent } class =" tabulator-table" />
0 commit comments