Skip to content

Commit ac22041

Browse files
committed
show queryResults in search tab panel
1 parent dcada93 commit ac22041

File tree

1 file changed

+22
-38
lines changed
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel

1 file changed

+22
-38
lines changed

src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx

+22-38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import {useState} from "react";
1+
import {
2+
useContext,
3+
useRef,
4+
useState,
5+
} from "react";
26

37
import {
48
AccordionGroup,
@@ -10,11 +14,11 @@ import {
1014
import UnfoldLessIcon from "@mui/icons-material/UnfoldLess";
1115
import UnfoldMoreIcon from "@mui/icons-material/UnfoldMore";
1216

17+
import {StateContext} from "../../../../../contexts/StateContextProvider";
1318
import {
1419
TAB_DISPLAY_NAMES,
1520
TAB_NAME,
1621
} from "../../../../../typings/tab";
17-
import {QueryResults} from "../../../../../typings/worker";
1822
import CustomTabPanel from "../CustomTabPanel";
1923
import TitleButton from "../TitleButton";
2024
import ResultsGroup from "./ResultsGroup";
@@ -25,37 +29,6 @@ enum SEARCH_OPTION {
2529
IS_REGEX = "isRegex"
2630
}
2731

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-
5932
/**
6033
* Displays a panel for submitting search queries and viewing query results.
6134
*
@@ -64,24 +37,34 @@ const SAMPLE_RESULTS: QueryResults = new Map([
6437
const SearchTabPanel = () => {
6538
const [isAllExpanded, setIsAllExpanded] = useState<boolean>(true);
6639
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+
};
6750

6851
return (
6952
<CustomTabPanel
7053
tabName={TAB_NAME.SEARCH}
7154
title={TAB_DISPLAY_NAMES[TAB_NAME.SEARCH]}
72-
titleButtons={<>
55+
titleButtons={
7356
<TitleButton onClick={() => { setIsAllExpanded((v) => !v); }}>
7457
{isAllExpanded ?
7558
<UnfoldLessIcon/> :
7659
<UnfoldMoreIcon/>}
7760
</TitleButton>
78-
</>}
61+
}
7962
>
8063
<Textarea
8164
maxRows={7}
8265
placeholder={"Search"}
8366
size={"sm"}
84-
slotProps={{endDecorator: {sx: {marginBlockStart: 0, display: "block"}}}}
67+
slotProps={{textarea: {ref: searchTextRef}, endDecorator: {sx: {marginBlockStart: 0, display: "block"}}}}
8568
sx={{flexDirection: "row"}}
8669
endDecorator={
8770
<>
@@ -109,14 +92,15 @@ const SearchTabPanel = () => {
10992
</IconButton>
11093
</ToggleButtonGroup>
11194
</>
112-
}/>
95+
}
96+
onKeyDown={handleSearch}/>
11397
<AccordionGroup
11498
disableDivider={true}
11599
size={"sm"}
116100
>
117101
<ResultsGroup
118102
isAllExpanded={isAllExpanded}
119-
queryResults={SAMPLE_RESULTS}/>
103+
queryResults={queryResults}/>
120104
</AccordionGroup>
121105
</CustomTabPanel>
122106
);

0 commit comments

Comments
 (0)