1
- import { useState } from "react" ;
1
+ import {
2
+ useContext ,
3
+ useRef ,
4
+ useState ,
5
+ } from "react" ;
2
6
3
7
import {
4
8
AccordionGroup ,
@@ -10,11 +14,11 @@ import {
10
14
import UnfoldLessIcon from "@mui/icons-material/UnfoldLess" ;
11
15
import UnfoldMoreIcon from "@mui/icons-material/UnfoldMore" ;
12
16
17
+ import { StateContext } from "../../../../../contexts/StateContextProvider" ;
13
18
import {
14
19
TAB_DISPLAY_NAMES ,
15
20
TAB_NAME ,
16
21
} from "../../../../../typings/tab" ;
17
- import { QueryResults } from "../../../../../typings/worker" ;
18
22
import CustomTabPanel from "../CustomTabPanel" ;
19
23
import TitleButton from "../TitleButton" ;
20
24
import ResultsGroup from "./ResultsGroup" ;
@@ -25,37 +29,6 @@ enum SEARCH_OPTION {
25
29
IS_REGEX = "isRegex"
26
30
}
27
31
28
- /**
29
- *
30
- */
31
- const SAMPLE_RESULTS : QueryResults = new Map ( [
32
- [ 1 ,
33
- [
34
- { logEventNum : 1 ,
35
- message : "hi how are you" ,
36
- matchRange : [ 0 ,
37
- 2 ] as [ number , number ] } ,
38
- ] ] ,
39
- [ 2 ,
40
- [
41
- { logEventNum : 202 ,
42
- message : "i'm a super long message that supposedly overflows in the panel width." ,
43
- matchRange : [ 4 ,
44
- 6 ] as [ number , number ] } ,
45
- ] ] ,
46
- [ 8 ,
47
- [
48
- { logEventNum : 808 ,
49
- message : "hi how are you" ,
50
- matchRange : [ 4 ,
51
- 6 ] as [ number , number ] } ,
52
- { logEventNum : 809 ,
53
- message : "hi how are you" ,
54
- matchRange : [ 4 ,
55
- 6 ] as [ number , number ] } ,
56
- ] ] ,
57
- ] ) ;
58
-
59
32
/**
60
33
* Displays a panel for submitting search queries and viewing query results.
61
34
*
@@ -64,24 +37,34 @@ const SAMPLE_RESULTS: QueryResults = new Map([
64
37
const SearchTabPanel = ( ) => {
65
38
const [ isAllExpanded , setIsAllExpanded ] = useState < boolean > ( true ) ;
66
39
const [ searchOptions , setSearchOptions ] = useState < SEARCH_OPTION [ ] > ( [ ] ) ;
40
+ const searchTextRef = useRef < HTMLTextAreaElement > ( null ) ;
41
+ const { queryResults, startQuery} = useContext ( StateContext ) ;
42
+ const handleSearch = ( event : React . KeyboardEvent < HTMLTextAreaElement > ) => {
43
+ if ( "Enter" === event . key && searchTextRef . current ) {
44
+ event . preventDefault ( ) ;
45
+ const isCaseSensitive = searchOptions . includes ( SEARCH_OPTION . IS_CASE_SENSITIVE ) ;
46
+ const isRegex = searchOptions . includes ( SEARCH_OPTION . IS_REGEX ) ;
47
+ startQuery ( searchTextRef . current . value , isRegex , isCaseSensitive ) ;
48
+ }
49
+ } ;
67
50
68
51
return (
69
52
< CustomTabPanel
70
53
tabName = { TAB_NAME . SEARCH }
71
54
title = { TAB_DISPLAY_NAMES [ TAB_NAME . SEARCH ] }
72
- titleButtons = { < >
55
+ titleButtons = {
73
56
< TitleButton onClick = { ( ) => { setIsAllExpanded ( ( v ) => ! v ) ; } } >
74
57
{ isAllExpanded ?
75
58
< UnfoldLessIcon /> :
76
59
< UnfoldMoreIcon /> }
77
60
</ TitleButton >
78
- </ > }
61
+ }
79
62
>
80
63
< Textarea
81
64
maxRows = { 7 }
82
65
placeholder = { "Search" }
83
66
size = { "sm" }
84
- slotProps = { { endDecorator : { sx : { marginBlockStart : 0 , display : "block" } } } }
67
+ slotProps = { { textarea : { ref : searchTextRef } , endDecorator : { sx : { marginBlockStart : 0 , display : "block" } } } }
85
68
sx = { { flexDirection : "row" } }
86
69
endDecorator = {
87
70
< >
@@ -109,14 +92,15 @@ const SearchTabPanel = () => {
109
92
</ IconButton >
110
93
</ ToggleButtonGroup >
111
94
</ >
112
- } />
95
+ }
96
+ onKeyDown = { handleSearch } />
113
97
< AccordionGroup
114
98
disableDivider = { true }
115
99
size = { "sm" }
116
100
>
117
101
< ResultsGroup
118
102
isAllExpanded = { isAllExpanded }
119
- queryResults = { SAMPLE_RESULTS } />
103
+ queryResults = { queryResults } />
120
104
</ AccordionGroup >
121
105
</ CustomTabPanel >
122
106
) ;
0 commit comments