import { getHeaderSearchContent , getRequestSearchContent , getResponseSearchContent , } from "../helpers/getSearchContent" ; import { NetworkRequest } from "../hooks/useNetworkMonitor" ; export interface ISearchResult { matches : { request : boolean ; response : boolean ; headers : boolean ; } ; networkRequest : NetworkRequest ; } const getMatchedHeaders = ( searchQuery , networkRequests ) : boolean => { return getHeaderSearchContent ( networkRequests ) . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ; } ; const getMatchedRequest = ( searchQuery , networkRequests ) : boolean => { return getRequestSearchContent ( networkRequests ) . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ; } ; const getMatchedResponse = ( searchQuery , networkRequests ) : boolean => { return getResponseSearchContent ( networkRequests ) . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ; } ; export const getSearchResults = ( searchQuery , networkRequests ) : ISearchResult [ ] => { if ( ! searchQuery ) { return [ ] ; } const lowercaseSearchQuery = searchQuery . toLocaleLowerCase ( ) ; return networkRequests . map ( ( networkRequest ) => { const matches = { request : getMatchedRequest ( lowercaseSearchQuery , networkRequest ) , response : getMatchedResponse ( lowercaseSearchQuery , networkRequest ) , headers : getMatchedHeaders ( lowercaseSearchQuery , networkRequest ) , } ; return { networkRequest , matches , } ; } ) . filter ( ( searchResult ) => { return Object . values ( searchResult . matches ) . some ( Boolean ) ; } ) ; } ;