-
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
36 changed files
with
399 additions
and
162 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
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,24 @@ | ||
import { bool, func } from "prop-types" | ||
|
||
import { Card } from "../semantic_ui_react_wrappers" | ||
import { childrenPropType } from "../sharedPropTypes" | ||
|
||
export function FilterCard({ children, onClick, selected }) { | ||
return ( | ||
<Card | ||
className="filter" | ||
color={selected ? "blue" : null} | ||
onClick={onClick} | ||
onKeyPress={onClick} | ||
style={{ height: "100%" }} | ||
tabIndex="0" | ||
> | ||
{children} | ||
</Card> | ||
) | ||
} | ||
FilterCard.propTypes = { | ||
children: childrenPropType, | ||
onClick: func, | ||
selected: bool, | ||
} |
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 .table { | ||
margin-top: 0.1em; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
table-layout: fixed; | ||
} | ||
|
||
.ui.card.filter .header { | ||
margin-bottom: 0.3em; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
} | ||
|
||
.ui.card.filter .header.selected { | ||
color: var(--selection-color); | ||
} |
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 "./FilterCardWithTable.css" | ||
|
||
import { bool, func, string } from "prop-types" | ||
|
||
import { Card, Header, Table } from "../semantic_ui_react_wrappers" | ||
import { childrenPropType } from "../sharedPropTypes" | ||
import { FilterCard } from "./FilterCard" | ||
|
||
export function FilterCardWithTable({ children, onClick, selected, title }) { | ||
return ( | ||
<FilterCard onClick={onClick} selected={selected}> | ||
<Card.Content> | ||
<Header as="h3" className={selected ? "selected" : null} textAlign="center"> | ||
{title} | ||
</Header> | ||
<Table basic="very" compact="very" size="small"> | ||
<Table.Body>{children}</Table.Body> | ||
</Table> | ||
</Card.Content> | ||
</FilterCard> | ||
) | ||
} | ||
FilterCardWithTable.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
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
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
import { bool, func } from "prop-types" | ||
|
||
import { STATUS_COLORS, STATUS_NAME, STATUSES_REQUIRING_ACTION } from "../metric/status" | ||
import { Label, Table } from "../semantic_ui_react_wrappers" | ||
import { reportsPropType } from "../sharedPropTypes" | ||
import { getMetricStatus, sum } from "../utils" | ||
import { FilterCardWithTable } from "./FilterCardWithTable" | ||
|
||
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 ( | ||
<FilterCardWithTable onClick={onClick} selected={selected} title="Action required"> | ||
{tableRows(reports)} | ||
</FilterCardWithTable> | ||
) | ||
} | ||
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 as selected when the card is selected", () => { | ||
renderMetricsRequiringActionCard({ selected: true }) | ||
expect(screen.getByText(/Action required/)).toHaveClass("selected") | ||
}) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
@media print { | ||
#Footer { | ||
div.footer { | ||
display: none; | ||
} | ||
} | ||
|
||
div.footer { | ||
background-color: var(--inverted-menu-background-color) !important; | ||
margin: 5em 0em 0em !important; | ||
padding: 5em 0em 3em !important; | ||
} |
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.