@@ -16,7 +16,9 @@ export default class lightningFlowScannerApp extends LightningElement {
1616 @track rules = [ ] ;
1717 @track rulesConfig = null ;
1818 @track isLoading = false ;
19- @track currentFlowIndex = 0 ; // Track the index of the selected flow
19+ @track currentFlowIndex = 0 ;
20+ @track nextRecordsUrl ;
21+ @track hasMoreRecords = false ;
2022 conn ;
2123 scriptLoaded = false ;
2224
@@ -52,7 +54,6 @@ export default class lightningFlowScannerApp extends LightningElement {
5254 ] ) ;
5355 this . scriptLoaded = true ;
5456
55- // Fetch rules for Configuration tab, default all to active
5657 this . rules = lightningflowscanner . getRules ( ) . map ( ( rule , index ) => ( {
5758 id : `rule-${ index } ` ,
5859 name : rule . name ,
@@ -62,7 +63,6 @@ export default class lightningFlowScannerApp extends LightningElement {
6263 isActive : true
6364 } ) ) ;
6465
65- // Initialize rulesConfig with all rules
6666 this . rulesConfig = {
6767 rules : this . rules . reduce ( ( acc , rule ) => {
6868 acc [ rule . name ] = { severity : rule . severity } ;
@@ -78,9 +78,27 @@ export default class lightningFlowScannerApp extends LightningElement {
7878 maxRequest : '10000'
7979 } ) ;
8080
81- const res = await this . conn . tooling . query ( `SELECT Id, DeveloperName, ActiveVersionId, LatestVersionId, ActiveVersion.Status, ActiveVersion.MasterLabel, ActiveVersion.ProcessType, LatestVersion.Status, LatestVersion.MasterLabel, LatestVersion.ProcessType FROM FlowDefinition` ) ;
81+ await this . fetchFlows ( ) ;
82+ } catch ( error ) {
83+ this . err = error . message ;
84+ console . error ( 'Error in connectedCallback:' , error ) ;
85+ }
86+ }
87+
88+ async fetchFlows ( searchTerm = '' ) {
89+ try {
90+ this . isLoading = true ;
91+ let query = `SELECT Id, DeveloperName, ActiveVersionId, LatestVersionId, ActiveVersion.Status, ActiveVersion.MasterLabel, ActiveVersion.ProcessType, LatestVersion.Status, LatestVersion.MasterLabel, LatestVersion.ProcessType FROM FlowDefinition` ;
92+
93+ if ( searchTerm ) {
94+ const escapedSearchTerm = searchTerm . replace ( / ' / g, "\\'" ) ;
95+ query += ` WHERE DeveloperName LIKE '%${ escapedSearchTerm } %' OR MasterLabel LIKE '%${ escapedSearchTerm } %'` ;
96+ }
97+ query += ' LIMIT 50' ;
98+
99+ const res = await this . conn . tooling . query ( query ) ;
82100 if ( res && res . records ) {
83- this . records = res . records . map ( record => ( {
101+ const newRecords = res . records . map ( record => ( {
84102 id : record . Id ,
85103 developerName : record . DeveloperName ,
86104 developerNameUrl : `/${ record . Id } ` ,
@@ -90,18 +108,59 @@ export default class lightningFlowScannerApp extends LightningElement {
90108 versionId : record . ActiveVersionId ? record . ActiveVersionId : record . LatestVersionId
91109 } ) ) ;
92110
93- if ( this . records . length > 0 ) {
111+ this . records = searchTerm ? newRecords : [ ...this . records , ...newRecords ] ;
112+ this . nextRecordsUrl = res . nextRecordsUrl ;
113+ this . hasMoreRecords = ! ! res . nextRecordsUrl ;
114+
115+ if ( this . records . length > 0 && ! searchTerm ) {
94116 this . selectedFlowRecord = this . records [ 0 ] ;
95- this . currentFlowIndex = 0 ; // Set initial index
117+ this . currentFlowIndex = 0 ;
96118 await this . loadFlowMetadata ( this . selectedFlowRecord ) ;
97119 }
98120 }
99121 } catch ( error ) {
100122 this . err = error . message ;
101- console . error ( 'Error in connectedCallback:' , error ) ;
123+ console . error ( 'Error in fetchFlows:' , error ) ;
124+ } finally {
125+ this . isLoading = false ;
102126 }
103127 }
104128
129+ async loadMoreFlows ( ) {
130+ if ( ! this . nextRecordsUrl || ! this . hasMoreRecords ) return ;
131+ try {
132+ this . isLoading = true ;
133+ const res = await this . conn . tooling . queryMore ( this . nextRecordsUrl ) ;
134+ if ( res && res . records ) {
135+ const newRecords = res . records . map ( record => ( {
136+ id : record . Id ,
137+ developerName : record . DeveloperName ,
138+ developerNameUrl : `/${ record . Id } ` ,
139+ isActive : ! ! record . ActiveVersionId ,
140+ masterLabel : record . ActiveVersionId ? record . ActiveVersion . MasterLabel : record . LatestVersion . MasterLabel ,
141+ processType : record . ActiveVersionId ? record . ActiveVersion . ProcessType : record . LatestVersion . ProcessType ,
142+ versionId : record . ActiveVersionId ? record . ActiveVersionId : record . LatestVersionId
143+ } ) ) ;
144+ this . records = [ ...this . records , ...newRecords ] ;
145+ this . nextRecordsUrl = res . nextRecordsUrl ;
146+ this . hasMoreRecords = ! ! res . nextRecordsUrl ;
147+ }
148+ } catch ( error ) {
149+ this . err = error . message ;
150+ console . error ( 'Error in loadMoreFlows:' , error ) ;
151+ } finally {
152+ this . isLoading = false ;
153+ }
154+ }
155+
156+ async handleSearch ( event ) {
157+ const searchTerm = event . detail . searchTerm ;
158+ this . records = [ ] ;
159+ this . nextRecordsUrl = null ;
160+ this . hasMoreRecords = false ;
161+ await this . fetchFlows ( searchTerm ) ;
162+ }
163+
105164 async loadFlowMetadata ( record ) {
106165 try {
107166 this . isLoading = true ;
@@ -186,7 +245,7 @@ export default class lightningFlowScannerApp extends LightningElement {
186245 if ( record ) {
187246 this . isLoading = true ;
188247 this . selectedFlowRecord = record ;
189- this . currentFlowIndex = this . records . findIndex ( rec => rec . id === flowId ) ; // Update index
248+ this . currentFlowIndex = this . records . findIndex ( rec => rec . id === flowId ) ;
190249 try {
191250 await this . loadFlowMetadata ( record ) ;
192251 this . activeTab = 2 ;
0 commit comments