-
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
9 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
components/frontend/src/dashboard/MetricsRequiringActionCard.css
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,11 @@ | ||
.ui.card.metrics_requiring_action .table { | ||
margin-top: 0.3em; | ||
} | ||
|
||
.ui.card.metrics_requiring_action .header { | ||
margin-bottom: 0.3em; | ||
} | ||
|
||
.ui.card.metrics_requiring_action .header.blue { | ||
color: #2185d0; | ||
} |
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
import "./MetricsRequiringActionCard.css" | ||
|
||
import { bool, func } from "prop-types" | ||
|
||
import { Card, Header, Label, Table } from "../semantic_ui_react_wrappers" | ||
import { reportPropType } from "../sharedPropTypes" | ||
import { getMetricStatus, STATUS_COLORS, STATUS_NAME, STATUSES_REQUIRING_ACTION, sum } from "../utils" | ||
|
||
function metricStatuses(report) { | ||
const statuses = {} | ||
STATUSES_REQUIRING_ACTION.forEach((status) => {statuses[status] = 0}) | ||
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 | ||
} | ||
|
||
export function MetricsRequiringActionCard({ onClick, report, selected }) { | ||
const statuses = metricStatuses(report) | ||
const tableRows = 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> | ||
)) | ||
tableRows.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> | ||
) | ||
const color = selected ? "blue" : null | ||
return ( | ||
<Card className="metrics_requiring_action" color={color} onClick={onClick} onKeyPress={onClick} tabIndex="0"> | ||
<Card.Content> | ||
<Header as="h3" color={color} textAlign="center"> | ||
{"Action required"} | ||
</Header> | ||
<Table basic="very" compact="very" size="small"> | ||
<Table.Body>{tableRows}</Table.Body> | ||
</Table> | ||
</Card.Content> | ||
</Card> | ||
) | ||
} | ||
MetricsRequiringActionCard.propTypes = { | ||
onClick: func, | ||
report: reportPropType, | ||
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 report={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
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