@@ -6,11 +6,9 @@ import React, {
66import {
77 AccordionGroup ,
88 Box ,
9- IconButton ,
109 LinearProgress ,
10+ Stack ,
1111 Textarea ,
12- ToggleButtonGroup ,
13- Tooltip ,
1412} from "@mui/joy" ;
1513
1614import UnfoldLessIcon from "@mui/icons-material/UnfoldLess" ;
@@ -30,33 +28,11 @@ import {isDisabled} from "../../../../../utils/states";
3028import CustomTabPanel from "../CustomTabPanel" ;
3129import PanelTitleButton from "../PanelTitleButton" ;
3230import ResultsGroup from "./ResultsGroup" ;
31+ import ToggleIconButton from "./ToggleIconButton" ;
3332
3433import "./index.css" ;
3534
3635
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-
6036/**
6137 * Displays a panel for submitting queries and viewing query results.
6238 *
@@ -65,17 +41,18 @@ const getIsRegex =
6541const SearchTabPanel = ( ) => {
6642 const { queryProgress, queryResults, startQuery, uiState} = useContext ( StateContext ) ;
6743 const [ isAllExpanded , setIsAllExpanded ] = useState < boolean > ( true ) ;
68- const [ queryOptions , setQueryOptions ] = useState < QUERY_OPTION [ ] > ( [ ] ) ;
6944 const [ queryString , setQueryString ] = useState < string > ( "" ) ;
45+ const [ isCaseSensitive , setIsCaseSensitive ] = useState < boolean > ( false ) ;
46+ const [ isRegex , setIsRegex ] = useState < boolean > ( false ) ;
7047
7148 const handleCollapseAllButtonClick = ( ) => {
7249 setIsAllExpanded ( ( v ) => ! v ) ;
7350 } ;
7451
7552 const handleQuerySubmit = ( newArgs : Partial < QueryArgs > ) => {
7653 startQuery ( {
77- isCaseSensitive : getIsCaseSensitive ( queryOptions ) ,
78- isRegex : getIsRegex ( queryOptions ) ,
54+ isCaseSensitive : isCaseSensitive ,
55+ isRegex : isRegex ,
7956 queryString : queryString ,
8057 ...newArgs ,
8158 } ) ;
@@ -86,15 +63,14 @@ const SearchTabPanel = () => {
8663 handleQuerySubmit ( { queryString : ev . target . value } ) ;
8764 } ;
8865
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 ) ;
9874 } ;
9975
10076 const isQueryInputBoxDisabled = isDisabled ( uiState , UI_ELEMENT . QUERY_INPUT_BOX ) ;
@@ -124,36 +100,34 @@ const SearchTabPanel = () => {
124100 placeholder = { "Search" }
125101 size = { "sm" }
126102 endDecorator = {
127- < ToggleButtonGroup
128- disabled = { isQueryInputBoxDisabled }
129- size = { "sm" }
103+ < Stack
104+ direction = { "row" }
130105 spacing = { 0.25 }
131- value = { queryOptions }
132- variant = { "plain" }
133- onChange = { handleQueryOptionsChange }
134106 >
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 >
157131 }
158132 slotProps = { {
159133 textarea : {
0 commit comments