1- import { Box , Button , Loader , Stack , TextInput , Text } from '@mantine/core' ;
2- import { ReactNode , useCallback , useEffect , useRef , useState } from 'react' ;
3- import classes from '../../Stream/styles/JSONView.module.css' ;
4- import EmptyBox from '@/components/Empty' ;
5- import { useAppStore } from '@/layouts/MainLayout/providers/AppProvider' ;
1+ import { Box , Stack } from '@mantine/core' ;
2+ import { ErrorView , LoadingView } from '@/pages/Stream/Views/Explore/LoadingViews' ;
3+ import { IconCheck , IconCopy , IconDotsVertical } from '@tabler/icons-react' ;
64import {
75 PRIMARY_HEADER_HEIGHT ,
86 STREAM_PRIMARY_TOOLBAR_CONTAINER_HEIGHT ,
97 STREAM_SECONDARY_TOOLBAR_HRIGHT ,
108} from '@/constants/theme' ;
9+ import { ReactNode , useCallback , useEffect , useRef , useState } from 'react' ;
10+ import { formatLogTs , isJqSearch } from '@/pages/Stream/providers/LogsProvider' ;
11+
12+ import EmptyBox from '@/components/Empty' ;
1113import { Log } from '@/@types/parseable/api/query' ;
1214import _ from 'lodash' ;
13- import { IconCheck , IconCopy , IconDotsVertical , IconSearch } from '@tabler/icons-react ' ;
15+ import classes from '../../Stream/styles/JSONView.module.css ' ;
1416import { copyTextToClipboard } from '@/utils' ;
1517import timeRangeUtils from '@/utils/timeRangeUtils' ;
16- import { correlationStoreReducers , useCorrelationStore } from '../providers/CorrelationProvider' ;
17- import { ErrorView , LoadingView } from '@/pages/Stream/Views/Explore/LoadingViews' ;
18- import { formatLogTs , isJqSearch } from '@/pages/Stream/providers/LogsProvider' ;
19- import jqSearch from '@/utils/jqSearch' ;
20- import { useHotkeys } from '@mantine/hooks' ;
18+ import { useAppStore } from '@/layouts/MainLayout/providers/AppProvider' ;
19+ import { useCorrelationStore } from '../providers/CorrelationProvider' ;
2120
2221type ContextMenuState = {
2322 visible : boolean ;
@@ -26,8 +25,6 @@ type ContextMenuState = {
2625 row : Log | null ;
2726} ;
2827
29- const { setInstantSearchValue, applyInstantSearch, applyJqSearch } = correlationStoreReducers ;
30-
3128const Item = ( props : { header : string | null ; value : string ; highlight : boolean } ) => {
3229 return (
3330 < span className = { classes . itemContainer } >
@@ -173,105 +170,6 @@ const JsonRows = (props: { isSearching: boolean; setContextMenu: any }) => {
173170 ) ;
174171} ;
175172
176- const Toolbar = ( {
177- isSearching,
178- setSearching,
179- } : {
180- isSearching : boolean ;
181- setSearching : React . Dispatch < React . SetStateAction < boolean > > ;
182- } ) => {
183- const [ localSearchValue , setLocalSearchValue ] = useState < string > ( '' ) ;
184- const searchInputRef = useRef < HTMLInputElement > ( null ) ;
185-
186- const [ searchValue , setCorrelationData ] = useCorrelationStore ( ( store ) => store . tableOpts . instantSearchValue ) ;
187- const [ pageData ] = useCorrelationStore ( ( store ) => store . tableOpts ) ;
188- const debouncedSearch = useCallback (
189- _ . debounce ( async ( val : string ) => {
190- if ( val . trim ( ) === '' ) {
191- setCorrelationData ( ( store ) => setInstantSearchValue ( store , '' ) ) ;
192- setCorrelationData ( applyInstantSearch ) ;
193- } else {
194- const isJq = isJqSearch ( val ) ;
195- if ( isJq ) {
196- const jqResult = await jqSearch ( pageData , val ) ;
197- setCorrelationData ( ( store ) => applyJqSearch ( store , jqResult ) ) ;
198- } else {
199- setCorrelationData ( applyInstantSearch ) ;
200- }
201- }
202- setSearching ( false ) ;
203- } , 500 ) ,
204- [ pageData ] ,
205- ) ;
206-
207- const handleSearch = useCallback ( ( ) => {
208- if ( localSearchValue . trim ( ) ) {
209- setSearching ( true ) ;
210- setCorrelationData ( ( store ) => setInstantSearchValue ( store , localSearchValue ) ) ;
211- debouncedSearch ( localSearchValue ) ;
212- }
213- } , [ localSearchValue , debouncedSearch , setSearching ] ) ;
214-
215- const handleInputChange = useCallback (
216- ( e : React . ChangeEvent < HTMLInputElement > ) => {
217- const value = e . target . value ;
218- setLocalSearchValue ( value ) ;
219- if ( value . trim ( ) === '' ) {
220- debouncedSearch ( value ) ;
221- }
222- } ,
223- [ debouncedSearch ] ,
224- ) ;
225-
226- useHotkeys ( [ [ 'mod+K' , ( ) => searchInputRef . current ?. focus ( ) ] ] ) ;
227-
228- const handleKeyDown = useCallback (
229- ( e : React . KeyboardEvent < HTMLInputElement > ) => {
230- if ( e . key === 'Enter' && ! isSearching && localSearchValue . trim ( ) ) {
231- handleSearch ( ) ;
232- }
233- } ,
234- [ isSearching , localSearchValue ] ,
235- ) ;
236-
237- if ( _ . isEmpty ( pageData ) ) return null ;
238-
239- const inputStyles = {
240- '--input-left-section-width' : '2rem' ,
241- '--input-right-section-width' : '6rem' ,
242- width : '100%' ,
243- } as React . CSSProperties ;
244-
245- return (
246- < div className = { classes . headerWrapper } >
247- < TextInput
248- leftSection = { isSearching ? < Loader size = "sm" /> : < IconSearch stroke = { 2.5 } size = "0.9rem" /> }
249- placeholder = "Search loaded data with text or jq. For jq input try `jq .[]`"
250- value = { localSearchValue }
251- onChange = { handleInputChange }
252- onKeyDown = { handleKeyDown }
253- ref = { searchInputRef }
254- classNames = { { input : classes . inputField } }
255- style = { inputStyles }
256- rightSection = {
257- searchValue && ! isSearching ? (
258- < Text style = { { fontSize : '0.7rem' , textAlign : 'end' } } lineClamp = { 1 } >
259- Matches
260- </ Text >
261- ) : null
262- }
263- />
264- < Button
265- onClick = { handleSearch }
266- disabled = { ! localSearchValue . trim ( ) || isSearching }
267- style = { { width : '10%' } }
268- leftSection = { < IconSearch stroke = { 2.5 } size = "0.9rem" /> } >
269- Search
270- </ Button >
271- </ div >
272- ) ;
273- } ;
274-
275173const TableContainer = ( props : { children : ReactNode } ) => {
276174 return < Box className = { classes . container } > { props . children } </ Box > ;
277175} ;
@@ -287,7 +185,7 @@ const CorrleationJSONView = (props: { errorMessage: string | null; hasNoData: bo
287185
288186 const contextMenuRef = useRef < HTMLDivElement > ( null ) ;
289187 const { errorMessage, hasNoData, showTable } = props ;
290- const [ isSearching , setSearching ] = useState ( false ) ;
188+ const [ isSearching ] = useState ( false ) ;
291189 const primaryHeaderHeight = ! maximized
292190 ? PRIMARY_HEADER_HEIGHT + STREAM_PRIMARY_TOOLBAR_CONTAINER_HEIGHT + STREAM_SECONDARY_TOOLBAR_HRIGHT
293191 : 0 ;
0 commit comments