@@ -6,11 +6,9 @@ import React, {
6
6
import {
7
7
AccordionGroup ,
8
8
Box ,
9
- IconButton ,
10
9
LinearProgress ,
10
+ Stack ,
11
11
Textarea ,
12
- ToggleButtonGroup ,
13
- Tooltip ,
14
12
} from "@mui/joy" ;
15
13
16
14
import UnfoldLessIcon from "@mui/icons-material/UnfoldLess" ;
@@ -30,33 +28,11 @@ import {isDisabled} from "../../../../../utils/states";
30
28
import CustomTabPanel from "../CustomTabPanel" ;
31
29
import PanelTitleButton from "../PanelTitleButton" ;
32
30
import ResultsGroup from "./ResultsGroup" ;
31
+ import ToggleIconButton from "./ToggleIconButton" ;
33
32
34
33
import "./index.css" ;
35
34
36
35
37
- enum QUERY_OPTION {
38
- IS_CASE_SENSITIVE = "isCaseSensitive" ,
39
- IS_REGEX = "isRegex" ,
40
- }
41
-
42
- /**
43
- * Determines if the query is case-sensitive based on the provided query options.
44
- *
45
- * @param queryOptions
46
- * @return True if the query is case-sensitive.
47
- */
48
- const getIsCaseSensitive =
49
- ( queryOptions : QUERY_OPTION [ ] ) => queryOptions . includes ( QUERY_OPTION . IS_CASE_SENSITIVE ) ;
50
-
51
- /**
52
- * Determines if the query is a regular expression based on the provided query options.
53
- *
54
- * @param queryOptions
55
- * @return True if the query is a regular expression.
56
- */
57
- const getIsRegex =
58
- ( queryOptions : QUERY_OPTION [ ] ) => queryOptions . includes ( QUERY_OPTION . IS_REGEX ) ;
59
-
60
36
/**
61
37
* Displays a panel for submitting queries and viewing query results.
62
38
*
@@ -65,17 +41,18 @@ const getIsRegex =
65
41
const SearchTabPanel = ( ) => {
66
42
const { queryProgress, queryResults, startQuery, uiState} = useContext ( StateContext ) ;
67
43
const [ isAllExpanded , setIsAllExpanded ] = useState < boolean > ( true ) ;
68
- const [ queryOptions , setQueryOptions ] = useState < QUERY_OPTION [ ] > ( [ ] ) ;
69
44
const [ queryString , setQueryString ] = useState < string > ( "" ) ;
45
+ const [ isCaseSensitive , setIsCaseSensitive ] = useState < boolean > ( false ) ;
46
+ const [ isRegex , setIsRegex ] = useState < boolean > ( false ) ;
70
47
71
48
const handleCollapseAllButtonClick = ( ) => {
72
49
setIsAllExpanded ( ( v ) => ! v ) ;
73
50
} ;
74
51
75
52
const handleQuerySubmit = ( newArgs : Partial < QueryArgs > ) => {
76
53
startQuery ( {
77
- isCaseSensitive : getIsCaseSensitive ( queryOptions ) ,
78
- isRegex : getIsRegex ( queryOptions ) ,
54
+ isCaseSensitive : isCaseSensitive ,
55
+ isRegex : isRegex ,
79
56
queryString : queryString ,
80
57
...newArgs ,
81
58
} ) ;
@@ -86,15 +63,14 @@ const SearchTabPanel = () => {
86
63
handleQuerySubmit ( { queryString : ev . target . value } ) ;
87
64
} ;
88
65
89
- const handleQueryOptionsChange = (
90
- _ : React . MouseEvent < HTMLElement > ,
91
- newOptions : QUERY_OPTION [ ]
92
- ) => {
93
- setQueryOptions ( newOptions ) ;
94
- handleQuerySubmit ( {
95
- isCaseSensitive : getIsCaseSensitive ( newOptions ) ,
96
- isRegex : getIsRegex ( newOptions ) ,
97
- } ) ;
66
+ const handleCaseSensitivityButtonClick = ( ) => {
67
+ handleQuerySubmit ( { isCaseSensitive : ! isCaseSensitive } ) ;
68
+ setIsCaseSensitive ( ! isCaseSensitive ) ;
69
+ } ;
70
+
71
+ const handleRegexButtonClick = ( ) => {
72
+ handleQuerySubmit ( { isRegex : ! isRegex } ) ;
73
+ setIsRegex ( ! isRegex ) ;
98
74
} ;
99
75
100
76
const isQueryInputBoxDisabled = isDisabled ( uiState , UI_ELEMENT . QUERY_INPUT_BOX ) ;
@@ -124,36 +100,34 @@ const SearchTabPanel = () => {
124
100
placeholder = { "Search" }
125
101
size = { "sm" }
126
102
endDecorator = {
127
- < ToggleButtonGroup
128
- disabled = { isQueryInputBoxDisabled }
129
- size = { "sm" }
103
+ < Stack
104
+ direction = { "row" }
130
105
spacing = { 0.25 }
131
- value = { queryOptions }
132
- variant = { "plain" }
133
- onChange = { handleQueryOptionsChange }
134
106
>
135
- < Tooltip title = { "Match case" } >
136
- < span >
137
- < IconButton
138
- className = { "query-option-button" }
139
- value = { QUERY_OPTION . IS_CASE_SENSITIVE }
140
- >
141
- Aa
142
- </ IconButton >
143
- </ span >
144
- </ Tooltip >
145
-
146
- < Tooltip title = { "Use regular expression" } >
147
- < span >
148
- < IconButton
149
- className = { "query-option-button" }
150
- value = { QUERY_OPTION . IS_REGEX }
151
- >
152
- .*
153
- </ IconButton >
154
- </ span >
155
- </ Tooltip >
156
- </ ToggleButtonGroup >
107
+ < ToggleIconButton
108
+ className = { "query-option-button" }
109
+ disabled = { isQueryInputBoxDisabled }
110
+ isChecked = { isCaseSensitive }
111
+ size = { "sm" }
112
+ tooltipTitle = { "Match case" }
113
+ variant = { "plain" }
114
+ onClick = { handleCaseSensitivityButtonClick }
115
+ >
116
+ Aa
117
+ </ ToggleIconButton >
118
+
119
+ < ToggleIconButton
120
+ className = { "query-option-button" }
121
+ disabled = { isQueryInputBoxDisabled }
122
+ isChecked = { isRegex }
123
+ size = { "sm" }
124
+ tooltipTitle = { "Use regular expression" }
125
+ variant = { "plain" }
126
+ onClick = { handleRegexButtonClick }
127
+ >
128
+ .*
129
+ </ ToggleIconButton >
130
+ </ Stack >
157
131
}
158
132
slotProps = { {
159
133
textarea : {
0 commit comments