@@ -7,6 +7,7 @@ import { QueryType } from '@/pages/Stream/providers/FilterProvider';
77import { FilterQueryBuilder } from '@/utils/queryBuilder' ;
88import { formatQuery } from 'react-querybuilder' ;
99import { Correlation } from '@/@types/parseable/api/correlation' ;
10+ import { isJqSearch , ViewMode } from '@/pages/Stream/providers/LogsProvider' ;
1011
1112export const CORRELATION_LOAD_LIMIT = 1000 ;
1213
@@ -49,6 +50,7 @@ type CorrelationStore = {
4950 activeCorrelation : Correlation | null ;
5051 isSavedCorrelationsModalOpen : boolean ;
5152 isSaveCorrelationModalOpen : boolean ;
53+ viewMode : ViewMode ;
5254 tableOpts : {
5355 disabledColumns : string [ ] ;
5456 wrapDisabledColumns : string [ ] ;
@@ -73,7 +75,7 @@ type CorrelationStore = {
7375} ;
7476
7577type CorrelationStoreReducers = {
76- setStreamData : ( store : CorrelationStore , currentStream : string , data : Log [ ] ) => ReducerOutput ;
78+ setStreamData : ( store : CorrelationStore , currentStream : string , data : Log [ ] , jqFilteredData ?: Log [ ] ) => ReducerOutput ;
7779 deleteStreamData : ( store : CorrelationStore , currentStream : string ) => ReducerOutput ;
7880 setSelectedFields : ( store : CorrelationStore , field : string , streamName : string , clearAll ?: boolean ) => ReducerOutput ;
7981 deleteSelectedField : ( store : CorrelationStore , field : string , streamName : string ) => ReducerOutput ;
@@ -94,6 +96,10 @@ type CorrelationStoreReducers = {
9496 setTotalCount : ( store : CorrelationStore , count : number ) => ReducerOutput ;
9597 setTargetPage : ( store : CorrelationStore , target : number | undefined ) => ReducerOutput ;
9698 setPerPage : ( store : CorrelationStore , perPage : number ) => ReducerOutput ;
99+ onToggleView : ( store : CorrelationStore , viewMode : 'json' | 'table' ) => ReducerOutput ;
100+ // applyJqSearch: (store: CorrelationStore, jqFilteredData: any[]) => ReducerOutput;
101+ // applyInstantSearch: (store: CorrelationStore) => ReducerOutput;
102+ setInstantSearchValue : ( store : CorrelationStore , value : string ) => ReducerOutput ;
97103} ;
98104
99105const initialState : CorrelationStore = {
@@ -109,6 +115,7 @@ const initialState: CorrelationStore = {
109115 activeCorrelation : null ,
110116 isSavedCorrelationsModalOpen : false ,
111117 isSaveCorrelationModalOpen : false ,
118+ viewMode : 'json' ,
112119 tableOpts : {
113120 disabledColumns : [ ] ,
114121 wrapDisabledColumns : [ ] ,
@@ -252,8 +259,79 @@ const generatePaginatedPageData = (
252259 . filter ( Boolean ) ;
253260} ;
254261
262+ const setInstantSearchValue = ( store : CorrelationStore , value : string ) => {
263+ return { tableOpts : { ...store . tableOpts , instantSearchValue : value } } ;
264+ } ;
265+
266+ const searchAndSortData = ( opts : { searchValue : string } , data : Log [ ] ) => {
267+ const { searchValue } = opts ;
268+ const filteredData = _ . isEmpty ( searchValue )
269+ ? data
270+ : ( _ . reduce (
271+ data ,
272+ ( acc : Log [ ] , d : Log ) => {
273+ const allValues = _ . chain ( d )
274+ . entries ( )
275+ . map ( ( [ key , value ] ) => [ key , _ . toString ( value ) ] )
276+ . value ( ) ;
277+
278+ const doesMatch = _ . some (
279+ allValues ,
280+ ( [ key , value ] ) => key . includes ( searchValue ) || value . includes ( searchValue ) ,
281+ ) ;
282+
283+ return doesMatch ? [ ...acc , d ] : acc ;
284+ } ,
285+ [ ] ,
286+ ) as Log [ ] ) ;
287+ const sortedData = _ . orderBy ( filteredData , [ defaultSortKey ] , [ defaultSortOrder ] ) ;
288+ return sortedData ;
289+ } ;
290+
255291// Reducer Functions
256292
293+ // const applyJqSearch = (store: CorrelationStore, jqFilteredData: any[]) => {
294+ // const { data, tableOpts } = store;
295+ // const currentPage = 1;
296+ // const newPageSlice = getPageSlice(currentPage, tableOpts.perPage, jqFilteredData);
297+
298+ // return {
299+ // data: {
300+ // ...data,
301+ // filteredData: jqFilteredData,
302+ // },
303+ // tableOpts: {
304+ // ...tableOpts,
305+ // filters: {},
306+ // pageData: newPageSlice,
307+ // currentPage,
308+ // totalPages: getTotalPages(jqFilteredData, tableOpts.perPage),
309+ // },
310+ // };
311+ // };
312+
313+ // const applyInstantSearch = (store: CorrelationStore) => {
314+ // const { data, tableOpts } = store;
315+ // const { instantSearchValue: searchValue } = tableOpts;
316+ // const filteredData = searchAndSortData({ searchValue }, data.rawData);
317+ // const currentPage = 1;
318+ // const newPageSlice = getPageSlice(currentPage, tableOpts.perPage, filteredData);
319+
320+ // return {
321+ // data: {
322+ // ...data,
323+ // filteredData,
324+ // },
325+ // tableOpts: {
326+ // ...tableOpts,
327+ // filters: {},
328+ // pageData: newPageSlice,
329+ // currentPage,
330+ // totalPages: getTotalPages(filteredData, tableOpts.perPage),
331+ // },
332+ // };
333+ // };
334+
257335const cleanCorrelationStore = ( store : CorrelationStore ) => {
258336 return {
259337 ...store ,
@@ -439,15 +517,27 @@ const deleteSelectedField = (store: CorrelationStore, field: string, streamName:
439517 } ;
440518} ;
441519
442- const setStreamData = ( store : CorrelationStore , currentStream : string , data : Log [ ] ) : ReducerOutput => {
520+ const setStreamData = (
521+ store : CorrelationStore ,
522+ currentStream : string ,
523+ data : Log [ ] ,
524+ jqFilteredData ?: Log [ ] ,
525+ ) : ReducerOutput => {
443526 if ( ! currentStream ) return { fields : store . fields } ;
527+ const { tableOpts, viewMode } = store ;
528+ const isJsonView = viewMode === 'json' ;
444529 // Update streamData
445530 const updatedStreamData = {
446531 ...store . streamData ,
447532 [ currentStream ] : { logData : data } ,
448533 } ;
449534 // Recompute filtered and sliced data for the table
450- const filteredData = filterAndSortData ( store . tableOpts , updatedStreamData [ currentStream ] ?. logData || [ ] ) ;
535+ const filteredData =
536+ isJsonView && ! _ . isEmpty ( tableOpts . instantSearchValue )
537+ ? isJqSearch ( tableOpts . instantSearchValue )
538+ ? jqFilteredData || [ ]
539+ : searchAndSortData ( { searchValue : tableOpts . instantSearchValue } , data )
540+ : filterAndSortData ( tableOpts , data ) ;
451541 const currentPage = 1 ;
452542
453543 if ( store . isCorrelatedData ) {
@@ -478,6 +568,29 @@ const setStreamData = (store: CorrelationStore, currentStream: string, data: Log
478568 } ;
479569} ;
480570
571+ const onToggleView = ( store : CorrelationStore , viewMode : 'json' | 'table' ) => {
572+ const { tableOpts } = store ;
573+ // const filteredData = filterAndSortData(
574+ // { sortOrder: defaultSortOrder, sortKey: defaultSortKey, filters: {} },
575+ // streamData,
576+ // );
577+ // const currentPage = tableOpts.currentPage;
578+ // const newPageSlice = getPageSlice(currentPage, tableOpts.perPage, filteredData);
579+
580+ return {
581+ ...store ,
582+ tableOpts : {
583+ ...tableOpts ,
584+ filters : { } ,
585+ // pageData: newPageSlice,
586+ instantSearchValue : '' ,
587+ // currentPage,
588+ // totalPages: getTotalPages(filteredData, tableOpts.perPage),
589+ } ,
590+ viewMode,
591+ } ;
592+ } ;
593+
481594const setCorrelationCondition = ( store : CorrelationStore , correlationCondition : string ) => {
482595 return {
483596 ...store ,
@@ -634,6 +747,10 @@ const correlationStoreReducers: CorrelationStoreReducers = {
634747 setTotalCount,
635748 setTargetPage,
636749 setPerPage,
750+ onToggleView,
751+ // applyJqSearch,
752+ // applyInstantSearch,
753+ setInstantSearchValue,
637754} ;
638755
639756export { CorrelationProvider , useCorrelationStore , correlationStoreReducers } ;
0 commit comments