forked from y-scope/yscope-log-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResultsGroup.tsx
114 lines (101 loc) · 3.05 KB
/
ResultsGroup.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {
memo,
useEffect,
useState,
} from "react";
import {
Accordion,
AccordionDetails,
AccordionSummary,
Box,
Chip,
List,
Stack,
Typography,
} from "@mui/joy";
import DescriptionOutlinedIcon from "@mui/icons-material/DescriptionOutlined";
import {QueryResultsType} from "../../../../../typings/worker";
import Result from "./Result";
import "./ResultsGroup.css";
interface ResultsGroupProps {
isAllExpanded: boolean,
pageNum: number,
results: QueryResultsType[],
}
/**
* Renders a group of results, where each group represents a list of results from a single page.
*
* @param props
* @param props.isAllExpanded
* @param props.pageNum
* @param props.results
* @return
*/
const ResultsGroup = memo(({
isAllExpanded,
pageNum,
results,
}: ResultsGroupProps) => {
const [isExpanded, setIsExpanded] = useState<boolean>(isAllExpanded);
const handleAccordionChange = (
_: React.SyntheticEvent,
newValue: boolean
) => {
setIsExpanded(newValue);
};
// On `isAllExpanded` update, sync current results group's expand status.
useEffect(() => {
setIsExpanded(isAllExpanded);
}, [isAllExpanded]);
return (
<Accordion
expanded={isExpanded}
onChange={handleAccordionChange}
>
<AccordionSummary
slotProps={{
button: {className: "results-group-summary-button"},
}}
>
<Box className={"results-group-summary-container"}>
<Stack
className={"results-group-summary-text-container"}
direction={"row"}
>
<DescriptionOutlinedIcon fontSize={"inherit"}/>
<Typography
fontFamily={"Inter"}
level={"title-sm"}
>
{"Page "}
{pageNum}
</Typography>
</Stack>
<Chip
className={"results-group-summary-count"}
size={"sm"}
variant={"solid"}
>
{results.length}
</Chip>
</Box>
</AccordionSummary>
<AccordionDetails
className={"results-group-details"}
slotProps={{content: {className: "results-group-details-content"}}}
>
<List size={"sm"}>
{results.map((r, index) => (
<Result
key={index}
logEventNum={r.logEventNum}
matchRange={r.matchRange}
message={r.message}/>
))}
</List>
</AccordionDetails>
</Accordion>
);
});
ResultsGroup.displayName = "ResultsGroup";
export default ResultsGroup;