|
1 | | -import React from "react"; |
2 | | -import { Table } from "reactstrap"; |
| 1 | +import React, { useState } from "react"; |
| 2 | +import { Table, Button, ButtonGroup } from "reactstrap"; |
3 | 3 | import { ProblemId } from "../../interfaces/Status"; |
4 | 4 | import { isAccepted } from "../../utils"; |
5 | 5 | import { countBy, groupBy } from "../../utils/GroupBy"; |
@@ -47,6 +47,7 @@ export const getUserPointCounts = ( |
47 | 47 | }; |
48 | 48 |
|
49 | 49 | export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => { |
| 50 | + const [grouped, setGrouped] = useState(true); |
50 | 51 | const mergedProblemMap = |
51 | 52 | useMergedProblemMap().data ?? new Map<ProblemId, MergedProblem>(); |
52 | 53 | const userPointCountMap = getUserPointCounts(mergedProblemMap, submissions); |
@@ -87,47 +88,60 @@ export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => { |
87 | 88 | ); |
88 | 89 |
|
89 | 90 | return ( |
90 | | - <Table striped bordered hover responsive> |
91 | | - <thead> |
92 | | - <tr> |
93 | | - <th>Point</th> |
94 | | - {totalCountBy100.map(({ point }) => ( |
95 | | - <th key={point}> |
96 | | - <a |
97 | | - href={window.location.hash} |
98 | | - onClick={(): void => setFilterFunc(point)} |
99 | | - > |
100 | | - {`${point}- `} |
101 | | - </a> |
102 | | - </th> |
103 | | - ))} |
104 | | - </tr> |
105 | | - <tr> |
106 | | - <th>Total</th> |
107 | | - {totalCountBy100.map(({ point, count }) => ( |
108 | | - <th key={point}>{count}</th> |
109 | | - ))} |
110 | | - </tr> |
111 | | - </thead> |
112 | | - <tbody> |
113 | | - {userPointCountMapBy100.map(({ userId, countByPoint }) => ( |
114 | | - <tr key={userId}> |
115 | | - <td>{userId}</td> |
116 | | - {totalCountBy100.map(({ point, count }) => ( |
117 | | - <td |
118 | | - key={point} |
119 | | - className={ |
120 | | - countByPoint.get(point) === count |
121 | | - ? TableColor.Success |
122 | | - : TableColor.None |
123 | | - } |
124 | | - > |
125 | | - {countByPoint.get(point) ?? 0} |
126 | | - </td> |
| 91 | + <> |
| 92 | + <ButtonGroup className="mb-2"> |
| 93 | + <Button onClick={(): void => setGrouped(!grouped)}> |
| 94 | + {grouped ? "Grouped" : "All"} |
| 95 | + </Button> |
| 96 | + </ButtonGroup> |
| 97 | + <Table striped bordered hover responsive> |
| 98 | + <thead> |
| 99 | + <tr> |
| 100 | + <th>Point</th> |
| 101 | + {(grouped ? totalCountBy100 : totalCount).map(({ point }) => ( |
| 102 | + <th key={point}> |
| 103 | + <a |
| 104 | + href={window.location.hash} |
| 105 | + onClick={(): void => setFilterFunc(point)} |
| 106 | + > |
| 107 | + {`${point}- `} |
| 108 | + </a> |
| 109 | + </th> |
127 | 110 | ))} |
128 | 111 | </tr> |
129 | | - ))} |
130 | | - </tbody> |
131 | | - </Table> |
| 112 | + <tr> |
| 113 | + <th>Total</th> |
| 114 | + {(grouped ? totalCountBy100 : totalCount).map( |
| 115 | + ({ point, count }) => ( |
| 116 | + <th key={point}>{count}</th> |
| 117 | + ) |
| 118 | + )} |
| 119 | + </tr> |
| 120 | + </thead> |
| 121 | + <tbody> |
| 122 | + {(grouped ? userPointCountMapBy100 : userPointCountMap).map( |
| 123 | + ({ userId, countByPoint }) => ( |
| 124 | + <tr key={userId}> |
| 125 | + <td>{userId}</td> |
| 126 | + {(grouped ? totalCountBy100 : totalCount).map( |
| 127 | + ({ point, count }) => ( |
| 128 | + <td |
| 129 | + key={point} |
| 130 | + className={ |
| 131 | + countByPoint.get(point) === count |
| 132 | + ? TableColor.Success |
| 133 | + : TableColor.None |
| 134 | + } |
| 135 | + > |
| 136 | + {countByPoint.get(point) ?? 0} |
| 137 | + </td> |
| 138 | + ) |
| 139 | + )} |
| 140 | + </tr> |
| 141 | + ) |
| 142 | + )} |
| 143 | + </tbody> |
| 144 | + </Table> |
| 145 | + </> |
132 | 146 | ); |
133 | 147 | }; |
0 commit comments