Skip to content

Commit

Permalink
Fix prop-type warnings in the frontend.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniessink committed Jun 24, 2024
1 parent c91f202 commit bbc0643
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 68 deletions.
1 change: 1 addition & 0 deletions components/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.2.0",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-simple-import-sort": "^12.1.0",
"globals": "^15.5.0",
"prettier": "^3.3.2",
Expand Down
7 changes: 3 additions & 4 deletions components/frontend/src/dashboard/CardDashboard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { array, arrayOf, bool, func } from "prop-types"
import { array, arrayOf, bool, element, func } from "prop-types"
import { useEffect, useState } from "react"
import RGL, { WidthProvider } from "react-grid-layout"

import { accessGranted, EDIT_REPORT_PERMISSION, Permissions } from "../context/Permissions"
import { Card } from "../semantic_ui_react_wrappers"

const ReactGridLayout = WidthProvider(RGL)

Expand All @@ -23,7 +22,7 @@ function cardDivs(cards, dragging, isDragging) {
))
}
cardDivs.propTypes = {
cards: arrayOf(Card),
cards: arrayOf(element),
dragging: bool,
isDragging: func,
}
Expand Down Expand Up @@ -106,7 +105,7 @@ export function CardDashboard({ cards, initialLayout, saveLayout }) {
)
}
CardDashboard.propTypes = {
cards: arrayOf(Card),
cards: arrayOf(element),
initialLayout: array,
saveLayout: func,
}
78 changes: 38 additions & 40 deletions components/frontend/src/dashboard/CardDashboard.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fireEvent, render, screen } from "@testing-library/react"

import { DarkMode } from "../context/DarkMode"
import { EDIT_REPORT_PERMISSION, Permissions } from "../context/Permissions"
import { CardDashboard } from "./CardDashboard"
import { MetricSummaryCard } from "./MetricSummaryCard"
Expand All @@ -9,56 +10,53 @@ beforeEach(() => mockGetAnimations())

afterEach(() => jest.restoreAllMocks())

it("returns null without cards", () => {
const { container } = render(
<div id="dashboard">
<CardDashboard cards={[]} />
</div>,
function renderCardDashboard({ cards = [], initialLayout = [], saveLayout = jest.fn } = {}) {
return render(
<DarkMode.Provider value={false}>
<Permissions.Provider value={[EDIT_REPORT_PERMISSION]}>
<div id="dashboard">
<CardDashboard cards={cards} initialLayout={initialLayout} saveLayout={saveLayout} />
</div>
</Permissions.Provider>
</DarkMode.Provider>,
)
}

it("returns null without cards", () => {
const { container } = renderCardDashboard()
expect(container.children[0].children.length).toBe(0)
})

it("adds the card to the dashboard", () => {
const { container } = render(
<div id="dashboard">
<CardDashboard
cards={[
<MetricSummaryCard
key="card"
header="Card"
summary={{
date: { blue: 0, red: 1, green: 2, yellow: 1, white: 0, grey: 0 },
}}
/>,
]}
initialLayout={[]}
/>
</div>,
)
const { container } = renderCardDashboard({
cards: [
<MetricSummaryCard
header="Card"
key="card"
summary={{
date: { blue: 0, red: 1, green: 2, yellow: 1, white: 0, grey: 0 },
}}
/>,
],
})
expect(container.children.length).toBe(1)
})

it("does not save the layout after click", async () => {
const mockCallback = jest.fn()
render(
<div id="dashboard">
<Permissions.Provider value={[EDIT_REPORT_PERMISSION]}>
<CardDashboard
cards={[
<MetricSummaryCard
key="card"
header="Card"
summary={{
date: { blue: 0, red: 1, green: 2, yellow: 1, white: 0, grey: 0 },
}}
/>,
]}
initialLayout={[{ h: 6, w: 4, x: 0, y: 0 }]}
saveLayout={mockCallback}
/>
</Permissions.Provider>
</div>,
)
renderCardDashboard({
cards: [
<MetricSummaryCard
header="Card"
key="card"
summary={{
date: { blue: 0, red: 1, green: 2, yellow: 1, white: 0, grey: 0 },
}}
/>,
],
initialLayout: [{ h: 6, w: 4, x: 0, y: 0 }],
saveLayout: mockCallback,
})
fireEvent.click(screen.getByText("Card"))
expect(mockCallback).not.toHaveBeenCalled()
})
4 changes: 2 additions & 2 deletions components/frontend/src/dashboard/MetricSummaryCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ function ariaChartLabel(summary) {

export function MetricSummaryCard({ header, onClick, selected, summary, maxY }) {
const [boundingBox, ref] = useBoundingBox()
const animate = { duration: 0, onLoad: { duration: 0 } }
const colors = STATUSES.map((status) => STATUS_COLORS_RGB[status])
const labelColor = useContext(DarkMode) ? "darkgrey" : "rgba(120, 120, 120)"
const flyoutBgColor = useContext(DarkMode) ? "rgba(60, 65, 70)" : "white"
const animate = { duration: 0, onLoad: { duration: 0 } }
const colors = STATUSES.map((status) => STATUS_COLORS_RGB[status])
const style = {
labels: { fontFamily: "Arial", fontSize: 12, fill: labelColor },
}
Expand Down
2 changes: 1 addition & 1 deletion components/frontend/src/measurement/TrendSparkline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it("renders an empty sparkline if there are no measurements", () => {

it("renders an empty sparkline if there are no measurements in dark mode", () => {
render(
<DarkMode.Provider value="true">
<DarkMode.Provider value={true}>
<TrendSparkline measurements={[]} />
</DarkMode.Provider>,
)
Expand Down
6 changes: 5 additions & 1 deletion components/frontend/src/metric/MetricDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ export function MetricDetails({
panes.push({
menuItem: (
<Menu.Item key="trend_graph">
<Icon name="linegraph" />
<Icon
className="linegraph"
/* Using name="linegraph" results in "Invalid prop `name` of value `linegraph` supplied to `Icon`."
Using name="line graph" does not show the icon. Using className works around this. */
/>
<FocusableTab>{"Trend graph"}</FocusableTab>
</Menu.Item>
),
Expand Down
4 changes: 3 additions & 1 deletion components/frontend/src/metric/MetricDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ it("removes the existing hashtag from the URL to share", async () => {
clipboard: { writeText: jest.fn().mockImplementation(() => Promise.resolve()) },
})
await renderMetricDetails()
fireEvent.click(screen.getByText(/Share/))
await act(async () => {
fireEvent.click(screen.getByText(/Share/))
})
expect(navigator.clipboard.writeText).toHaveBeenCalledWith("http://localhost/#metric_uuid")
})

Expand Down
4 changes: 2 additions & 2 deletions components/frontend/src/report/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ExportCard } from "../dashboard/ExportCard"
import {
datePropType,
datesPropType,
measurementPropType,
measurementsPropType,
optionalDatePropType,
reportPropType,
reportsPropType,
Expand Down Expand Up @@ -97,7 +97,7 @@ Report.propTypes = {
dates: datesPropType,
handleSort: func,
lastUpdate: datePropType,
measurements: measurementPropType,
measurements: measurementsPropType,
openReportsOverview: func,
reload: func,
report: reportPropType,
Expand Down
4 changes: 2 additions & 2 deletions components/frontend/src/report/ReportDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LegendCard } from "../dashboard/LegendCard"
import { MetricsRequiringActionCard } from "../dashboard/MetricsRequiringActionCard"
import { MetricSummaryCard } from "../dashboard/MetricSummaryCard"
import { STATUS_COLORS } from "../metric/status"
import { datesPropType, measurementPropType, reportPropType, settingsPropType } from "../sharedPropTypes"
import { datesPropType, measurementsPropType, reportPropType, settingsPropType } from "../sharedPropTypes"
import { getMetricTags, getReportTags, getSubjectName, nrMetricsInReport, visibleMetrics } from "../utils"
import { Tag } from "../widgets/Tag"
import { metricStatusOnDate } from "./report_utils"
Expand Down Expand Up @@ -120,7 +120,7 @@ export function ReportDashboard({ dates, measurements, onClick, onClickTag, relo
}
ReportDashboard.propTypes = {
dates: datesPropType,
measurements: measurementPropType,
measurements: measurementsPropType,
onClick: func,
onClickTag: func,
reload: func,
Expand Down
4 changes: 2 additions & 2 deletions components/frontend/src/report/ReportsOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Segment } from "../semantic_ui_react_wrappers"
import {
datePropType,
datesPropType,
measurementPropType,
measurementsPropType,
optionalDatePropType,
reportsOverviewPropType,
reportsPropType,
Expand Down Expand Up @@ -112,7 +112,7 @@ ReportsOverview.propTypes = {
dates: datesPropType,
handleSort: func,
lastUpdate: datePropType,
measurements: measurementPropType,
measurements: measurementsPropType,
reports: reportsPropType,
openReport: func,
reload: func,
Expand Down
4 changes: 2 additions & 2 deletions components/frontend/src/report/ReportsOverviewDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LegendCard } from "../dashboard/LegendCard"
import { MetricsRequiringActionCard } from "../dashboard/MetricsRequiringActionCard"
import { MetricSummaryCard } from "../dashboard/MetricSummaryCard"
import { STATUS_COLORS } from "../metric/status"
import { datesPropType, measurementPropType, reportsPropType, settingsPropType } from "../sharedPropTypes"
import { datesPropType, measurementsPropType, reportsPropType, settingsPropType } from "../sharedPropTypes"
import { getMetricTags, getReportsTags, nrMetricsInReport, sum, visibleMetrics } from "../utils"
import { Tag } from "../widgets/Tag"
import { metricStatusOnDate } from "./report_utils"
Expand Down Expand Up @@ -141,7 +141,7 @@ export function ReportsOverviewDashboard({
ReportsOverviewDashboard.propTypes = {
dates: datesPropType,
layout: array,
measurements: measurementPropType,
measurements: measurementsPropType,
onClickTag: func,
openReport: func,
reload: func,
Expand Down
9 changes: 4 additions & 5 deletions components/frontend/src/semantic_ui_react_wrappers/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export function Card(props) {
return <SemanticUICard {...addInvertedClassNameWhenInDarkMode(props, useContext(DarkMode))} />
}

function Header(props) {
return <SemanticUICard.Header {...addInvertedClassNameWhenInDarkMode(props, useContext(DarkMode))} />
}

Card.Content = SemanticUICard.Content
Card.Header = Header
Card.Description = SemanticUICard.Description
Card.Group = SemanticUICard.Group
Card.Header = SemanticUICard.Header
Card.Meta = SemanticUICard.Meta
2 changes: 1 addition & 1 deletion components/frontend/src/sharedPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const entityPropType = shape({
key: string,
})

const entityAttributePropType = shape({
export const entityAttributePropType = shape({
key: string,
})

Expand Down
6 changes: 2 additions & 4 deletions components/frontend/src/source/SourceEntityAttribute.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { string } from "prop-types"

import { StatusIcon } from "../measurement/StatusIcon"
import { entityPropType } from "../sharedPropTypes"
import { entityAttributePropType, entityPropType } from "../sharedPropTypes"
import { formatMetricValue } from "../utils"
import { HyperLink } from "../widgets/HyperLink"
import { TimeAgoWithDate } from "../widgets/TimeAgoWithDate"
Expand Down Expand Up @@ -45,5 +43,5 @@ export function SourceEntityAttribute({ entity, entityAttribute }) {
}
SourceEntityAttribute.propTypes = {
entity: entityPropType,
entityAttribute: string,
entityAttribute: entityAttributePropType,
}
1 change: 0 additions & 1 deletion components/frontend/src/widgets/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ test("PermLinkButton copies URL to clipboard", async () => {
clipboard: { writeText: jest.fn().mockImplementation(() => Promise.resolve()) },
})
render(<PermLinkButton itemType="metric" url="https://example.org" />)
screen.debug()
await act(async () => {
fireEvent.click(screen.getByText(/Share/))
})
Expand Down

0 comments on commit bbc0643

Please sign in to comment.