Skip to content

Commit 92085ca

Browse files
authored
Add source column to reports table (#959)
1 parent d8ed033 commit 92085ca

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

ui/src/pages/reports/index.tsx

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,21 @@ const getCategoryCounts = (candidate: CandidateQueryResult) => {
3030
return candidate.detections.reduce(
3131
(counts, detection) => {
3232
const category = detection.category;
33-
if (category && category in counts) {
34-
counts[category] += 1;
35-
} else if (category) {
36-
counts[category] = 1;
33+
if (category) {
34+
counts[category] = (counts[category] || 0) + 1;
35+
}
36+
return counts;
37+
},
38+
{} as Record<string, number>,
39+
);
40+
};
41+
42+
const getSourceCounts = (candidate: CandidateQueryResult) => {
43+
return candidate.detections.reduce(
44+
(counts, detection) => {
45+
const source = detection.source;
46+
if (source) {
47+
counts[source] = (counts[source] || 0) + 1;
3748
}
3849
return counts;
3950
},
@@ -102,6 +113,7 @@ const DetectionsPage: NextPageWithLayout = () => {
102113
<TableCell align="right">Detections</TableCell>
103114
<TableCell align="right">Timestamp</TableCell>
104115
<TableCell>Categories</TableCell>
116+
<TableCell>Source</TableCell>
105117
<TableCell>Descriptions</TableCell>
106118

107119
{currentUser?.moderator && <TableCell>Status</TableCell>}
@@ -131,12 +143,34 @@ const DetectionsPage: NextPageWithLayout = () => {
131143
{formatTimestamp(candidate.minTime)}
132144
</TableCell>
133145
<TableCell>
134-
{Object.entries(getCategoryCounts(candidate))
135-
.map(
136-
([category, count]) =>
137-
`${category.toLowerCase()} [${count}]`,
138-
)
139-
.join(", ")}{" "}
146+
{Object.entries(getCategoryCounts(candidate)).map(
147+
([category, count]) => (
148+
<Chip
149+
key={category}
150+
label={`${category.toLowerCase()} ${count}`}
151+
size="small"
152+
sx={{
153+
mb: 0.5,
154+
}}
155+
/>
156+
),
157+
)}
158+
</TableCell>
159+
<TableCell>
160+
{Object.entries(getSourceCounts(candidate)).map(
161+
([source, count]) => (
162+
<Chip
163+
key={source}
164+
label={`${source.toLowerCase()} ${count}`}
165+
size="small"
166+
variant="outlined"
167+
color="primary"
168+
sx={{
169+
mb: 0.5,
170+
}}
171+
/>
172+
),
173+
)}
140174
</TableCell>
141175
<TableCell
142176
title={candidate.minTime.toString()}

0 commit comments

Comments
 (0)