-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dashboard card showing metrics requiring action.
Show a card in the dashboard with the number of metrics that require action (red, yellow, and white metrics). The card can be hidden via the Settings panel. Clicking the card or setting "Visible metrics" to "Metrics requiring actions" in the Settings panel hides metrics that do not require action. Closes #8938.
- Loading branch information
Showing
20 changed files
with
281 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.ui.card.filter_card .table { | ||
margin-top: 0.1em; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
table-layout: fixed; | ||
} | ||
|
||
.ui.card.filter_card .header { | ||
margin-bottom: 0.3em; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
} | ||
|
||
.ui.card.filter_card .header.blue { | ||
color: #2185d0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import "./FilterCard.css" | ||
|
||
import { bool, func, string } from "prop-types" | ||
|
||
import { Card, Header, Table } from "../semantic_ui_react_wrappers" | ||
import { childrenPropType } from "../sharedPropTypes" | ||
|
||
export function FilterCard({ children, onClick, selected, title }) { | ||
const color = selected ? "blue" : null | ||
return ( | ||
<Card className="filter_card" color={color} onClick={onClick} onKeyPress={onClick} tabIndex="0"> | ||
<Card.Content> | ||
<Header as="h3" color={color} textAlign="center"> | ||
{title} | ||
</Header> | ||
<Table basic="very" compact="very" size="small"> | ||
<Table.Body>{children}</Table.Body> | ||
</Table> | ||
</Card.Content> | ||
</Card> | ||
) | ||
} | ||
FilterCard.propTypes = { | ||
children: childrenPropType, | ||
onClick: func, | ||
selected: bool, | ||
title: string, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
components/frontend/src/dashboard/MetricsRequiringActionCard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { bool, func } from "prop-types" | ||
|
||
import { Label, Table } from "../semantic_ui_react_wrappers" | ||
import { reportsPropType } from "../sharedPropTypes" | ||
import { getMetricStatus, STATUS_COLORS, STATUS_NAME, STATUSES_REQUIRING_ACTION, sum } from "../utils" | ||
import { FilterCard } from "./FilterCard" | ||
|
||
function metricStatuses(reports) { | ||
const statuses = {} | ||
STATUSES_REQUIRING_ACTION.forEach((status) => { | ||
statuses[status] = 0 | ||
}) | ||
reports.forEach((report) => { | ||
Object.values(report.subjects).forEach((subject) => { | ||
Object.values(subject.metrics).forEach((metric) => { | ||
const status = getMetricStatus(metric) | ||
if (STATUSES_REQUIRING_ACTION.includes(status)) { | ||
statuses[status] += 1 | ||
} | ||
}) | ||
}) | ||
}) | ||
return statuses | ||
} | ||
metricStatuses.propTypes = { | ||
reports: reportsPropType, | ||
} | ||
|
||
function tableRows(reports) { | ||
const statuses = metricStatuses(reports) | ||
const rows = Object.keys(statuses).map((status) => ( | ||
<Table.Row key={status}> | ||
<Table.Cell>{STATUS_NAME[status]}</Table.Cell> | ||
<Table.Cell textAlign="right"> | ||
<Label size="small" color={STATUS_COLORS[status] === "white" ? null : STATUS_COLORS[status]}> | ||
{statuses[status]} | ||
</Label> | ||
</Table.Cell> | ||
</Table.Row> | ||
)) | ||
rows.push( | ||
<Table.Row key="total"> | ||
<Table.Cell> | ||
<b>Total</b> | ||
</Table.Cell> | ||
<Table.Cell textAlign="right"> | ||
<Label size="small" color="black"> | ||
{sum(Object.values(statuses))} | ||
</Label> | ||
</Table.Cell> | ||
</Table.Row>, | ||
) | ||
return rows | ||
} | ||
tableRows.propTypes = { | ||
reports: reportsPropType, | ||
} | ||
|
||
export function MetricsRequiringActionCard({ onClick, reports, selected }) { | ||
return ( | ||
<FilterCard onClick={onClick} selected={selected} title="Action required"> | ||
{tableRows(reports)} | ||
</FilterCard> | ||
) | ||
} | ||
MetricsRequiringActionCard.propTypes = { | ||
onClick: func, | ||
reports: reportsPropType, | ||
selected: bool, | ||
} |
47 changes: 47 additions & 0 deletions
47
components/frontend/src/dashboard/MetricsRequiringActionCard.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { render, screen } from "@testing-library/react" | ||
|
||
import { MetricsRequiringActionCard } from "./MetricsRequiringActionCard" | ||
|
||
const report = { | ||
subjects: { | ||
subject_uuid: { | ||
metrics: { | ||
metric_uuid: { | ||
status: "target_not_met", | ||
}, | ||
another_metric_uuid: { | ||
status: "near_target_met", | ||
}, | ||
}, | ||
}, | ||
another_subject_uuid: { | ||
metrics: { | ||
yet_another_metric_uuid: { | ||
status: "near_target_met", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
function renderMetricsRequiringActionCard({ selected = false } = {}) { | ||
render(<MetricsRequiringActionCard reports={[report]} selected={selected} />) | ||
} | ||
|
||
it("shows the correct title", () => { | ||
renderMetricsRequiringActionCard() | ||
expect(screen.getByText(/Action required/)).toBeInTheDocument() | ||
}) | ||
|
||
it("shows the title in blue when selected", () => { | ||
renderMetricsRequiringActionCard({ selected: true }) | ||
expect(screen.getByText(/Action required/)).toHaveClass("blue") | ||
}) | ||
|
||
it("shows the number of metrics", () => { | ||
renderMetricsRequiringActionCard() | ||
expect(screen.getByRole("row", { name: "Unknown 0" })).toBeInTheDocument() | ||
expect(screen.getByRole("row", { name: "Target not met 1" })).toBeInTheDocument() | ||
expect(screen.getByRole("row", { name: "Near target met 2" })).toBeInTheDocument() | ||
expect(screen.getByRole("row", { name: "Total 3" })).toBeInTheDocument() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.