Skip to content

Commit

Permalink
Migrate SUIR components to MUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniessink committed Dec 24, 2024
1 parent 33afc17 commit c41b212
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 210 deletions.
8 changes: 3 additions & 5 deletions components/frontend/src/measurement/SourceStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export function SourceStatus({ metric, measurement_source }) {
const source = metric.sources[measurement_source.source_uuid]
const source_name = getSourceName(source, dataModel)
const configError = !dataModel.metrics[metric.type].sources.includes(source.type)
function source_label(error) {
function source_label() {
return measurement_source.landing_url ? (
<HyperLink error={error} url={measurement_source.landing_url}>
{source_name}
</HyperLink>
<HyperLink url={measurement_source.landing_url}>{source_name}</HyperLink>
) : (
source_name
)
Expand All @@ -43,7 +41,7 @@ export function SourceStatus({ metric, measurement_source }) {
flowing
header={header}
hoverable
trigger={<Label color="red">{source_label(true)}</Label>}
trigger={<Label color="red">{source_label()}</Label>}
/>
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion components/frontend/src/metric/TrendGraph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ it("renders the measurements with missing values for the scale", () => {

it("renders a placeholder while the measurements are loading", () => {
const { container } = renderTrendgraph({ loading: "loading" })
expect(container.firstChild.className).toContain("placeholder")
expect(container.firstChild.className).toContain("MuiSkeleton-rectangular")
expect(screen.queryAllByText(/Time/).length).toBe(0)
})

Expand Down
6 changes: 3 additions & 3 deletions components/frontend/src/metric/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export const STATUS_DESCRIPTION = {
target_not_met: `${STATUS_NAME.target_not_met}: the measurement value does not meet the target value.`,
debt_target_met: (
<>
{`${STATUS_NAME.debt_target_met}: the measurement value does not meet the\ntarget value, but this is accepted as `}
{`${STATUS_NAME.debt_target_met}: the measurement value does not meet the target value, but this is accepted as `}
<HyperLink url="https://en.wikipedia.org/wiki/Technical_debt">technical debt</HyperLink>
{". The measurement\nvalue does meet the technical debt target."}
{". The measurement value does meet the technical debt target."}
</>
),
unknown: `${STATUS_NAME.unknown}: the status could not be determined because no sources have\nbeen configured for the metric yet or the measurement data could not\nbe collected.`,
unknown: `${STATUS_NAME.unknown}: the status could not be determined because no sources have been configured for the metric yet or the measurement data could not be collected.`,
}
export const statusPropType = oneOf(STATUSES)
4 changes: 0 additions & 4 deletions components/frontend/src/semantic_ui_react_wrappers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
export { Breadcrumb } from "./semantic_ui_react_wrappers/Breadcrumb"
export { Card } from "./semantic_ui_react_wrappers/Card"
export { Checkbox } from "./semantic_ui_react_wrappers/Checkbox"
export { Dropdown } from "./semantic_ui_react_wrappers/Dropdown"
export { Feed } from "./semantic_ui_react_wrappers/Feed"
export { Form } from "./semantic_ui_react_wrappers/Form"
export { Header } from "./semantic_ui_react_wrappers/Header"
export { Label } from "./semantic_ui_react_wrappers/Label"
export { Message } from "./semantic_ui_react_wrappers/Message"
export { Modal } from "./semantic_ui_react_wrappers/Modal"
export { Popup } from "./semantic_ui_react_wrappers/Popup"
export { Segment } from "./semantic_ui_react_wrappers/Segment"
export { Tab } from "./semantic_ui_react_wrappers/Tab"
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions components/frontend/src/semantic_ui_react_wrappers/Breadcrumb.js

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions components/frontend/src/semantic_ui_react_wrappers/Feed.css

This file was deleted.

25 changes: 0 additions & 25 deletions components/frontend/src/semantic_ui_react_wrappers/Feed.js

This file was deleted.

15 changes: 0 additions & 15 deletions components/frontend/src/semantic_ui_react_wrappers/Modal.css

This file was deleted.

14 changes: 0 additions & 14 deletions components/frontend/src/semantic_ui_react_wrappers/Modal.js

This file was deleted.

3 changes: 1 addition & 2 deletions components/frontend/src/source/Logo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { string } from "prop-types"
import { Image } from "semantic-ui-react"

export function Logo({ alt, logo }) {
return <Image src={`api/internal/logo/${logo}`} alt={`${alt} logo`} size="mini" spaced="right" />
return <img src={`api/internal/logo/${logo}`} alt={`${alt} logo`} width="32px" height="32px" />
}
Logo.propTypes = {
alt: string,
Expand Down
2 changes: 1 addition & 1 deletion components/frontend/src/source/SourceEntities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ it("renders a message if the measurements failed to load", () => {

it("renders a placeholder while the measurements are loading", () => {
const { container } = renderSourceEntities({ loading: "loading" })
expect(container.firstChild.className).toContain("placeholder")
expect(container.firstChild.className).toContain("MuiSkeleton-rectangular")
expect(screen.queryAllByText("AAA").length).toBe(0)
})

Expand Down
9 changes: 5 additions & 4 deletions components/frontend/src/source/SourceType.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Stack, Typography } from "@mui/material"
import { Chip, Stack, Typography } from "@mui/material"
import { func, string } from "prop-types"
import { useContext } from "react"

import { DataModel } from "../context/DataModel"
import { EDIT_REPORT_PERMISSION } from "../context/Permissions"
import { SingleChoiceInput } from "../fields/SingleChoiceInput"
import { Label } from "../semantic_ui_react_wrappers"
import { dataModelPropType, sourceTypePropType } from "../sharedPropTypes"
import { Logo } from "./Logo"

Expand All @@ -27,10 +26,12 @@ function sourceTypeOption(key, sourceType) {
value: key,
content: (
<Stack direction="row">
<Logo logo={key} alt={sourceType.name} />
<span style={{ paddingRight: "10px" }}>
<Logo logo={key} alt={sourceType.name} />
</span>
<p>
{sourceType.name}
{sourceType.deprecated && <Label color="yellow">Deprecated</Label>}
{sourceType.deprecated && <Chip color="warning" label="Deprecated" sx={{ marginLeft: "8px" }} />}
<Typography variant="body2">{sourceTypeDescription(sourceType)}</Typography>
</p>
</Stack>
Expand Down
5 changes: 3 additions & 2 deletions components/frontend/src/source/SourceTypeHeader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Chip } from "@mui/material"
import { string } from "prop-types"

import { Header, Label } from "../semantic_ui_react_wrappers"
import { Header } from "../semantic_ui_react_wrappers"
import { sourceTypePropType } from "../sharedPropTypes"
import { slugify } from "../utils"
import { ReadTheDocsLink } from "../widgets/ReadTheDocsLink"
Expand All @@ -18,7 +19,7 @@ export function SourceTypeHeader({ metricTypeId, sourceTypeId, sourceType }) {
<Header.Content>
<Logo logo={sourceTypeId} alt={sourceType.name} />
{sourceType.name}
{sourceType.deprecated && <Label color="yellow">Deprecated</Label>}
{sourceType.deprecated && <Chip color="warning" label="Deprecated" sx={{ marginLeft: "8px" }} />}
<Header.Subheader>
{`${sourceTypeDescription(sourceType)} `}
<ReadTheDocsLink url={url} />
Expand Down
23 changes: 9 additions & 14 deletions components/frontend/src/subject/SubjectTableHeader.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { List, ListItem, ListItemIcon, ListItemText } from "@mui/material"
import { bool, func, string } from "prop-types"
import { useContext } from "react"
import { List, Table } from "semantic-ui-react"
import { Table } from "semantic-ui-react"

import { DarkMode } from "../context/DarkMode"
import { StatusIcon } from "../measurement/StatusIcon"
import { STATUS_DESCRIPTION, STATUSES } from "../metric/status"
import { Label } from "../semantic_ui_react_wrappers"
Expand Down Expand Up @@ -49,21 +48,18 @@ const trendHelp = (
</>
)

function statusHelp(darkMode) {
const color = darkMode ? "white" : "black"
function statusHelp() {
return (
<>
<p>The current status of the metric.</p>
<List>
{STATUSES.map((status) => (
<List.Item key={status}>
<List.Icon>
<ListItem key={status} alignItems="flex-start" sx={{ paddingLeft: "8px" }}>
<ListItemIcon sx={{ minWidth: "32px" }}>
<StatusIcon status={status} size="small" />
</List.Icon>
<List.Content verticalAlign="middle" style={{ color: color, whiteSpace: "pre" }}>
{STATUS_DESCRIPTION[status]}
</List.Content>
</List.Item>
</ListItemIcon>
<ListItemText>{STATUS_DESCRIPTION[status]}</ListItemText>
</ListItem>
))}
</List>
<p>Hover over the status to see how long the metric has had the current status.</p>
Expand Down Expand Up @@ -286,7 +282,6 @@ MeasurementHeaderCells.propTypes = {
}

export function SubjectTableHeader({ columnDates, handleSort, settings }) {
const darkMode = useContext(DarkMode)
const sortProps = {
sortColumn: settings.sortColumn,
sortDirection: settings.sortDirection,
Expand All @@ -311,7 +306,7 @@ export function SubjectTableHeader({ columnDates, handleSort, settings }) {
column="status"
label="Status"
textAlign="center"
help={statusHelp(darkMode)}
help={statusHelp()}
{...sortProps}
/>
)}
Expand Down
9 changes: 0 additions & 9 deletions components/frontend/src/widgets/HyperLink.css

This file was deleted.

23 changes: 8 additions & 15 deletions components/frontend/src/widgets/HyperLink.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import "./HyperLink.css"
import { Link } from "@mui/material"
import { string } from "prop-types"

import { bool, string } from "prop-types"
import { useContext } from "react"

import { DarkMode } from "../context/DarkMode"
import { childrenPropType } from "../sharedPropTypes"

export function HyperLink({ url, children, error }) {
let className = useContext(DarkMode) ? "inverted" : ""
if (error) {
className += " error"
}
export function HyperLink({ url, children }) {
return (
<a
className={className}
<Link
color="inherit"
href={url}
onClick={(event) => event.stopPropagation()}
rel="noopener noreferrer"
rel="noreferrer"
target="_blank"
title="Opens new window or tab"
underline="always"
>
{children}
</a>
</Link>
)
}
HyperLink.propTypes = {
url: string,
children: childrenPropType,
error: bool,
}
19 changes: 0 additions & 19 deletions components/frontend/src/widgets/Hyperlink.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
import { fireEvent, render, screen } from "@testing-library/react"

import { DarkMode } from "../context/DarkMode"
import { HyperLink } from "./HyperLink"

it("shows the hyperlink", () => {
render(<HyperLink url="https://url">Link</HyperLink>)
expect(screen.queryAllByText("Link").length).toBe(1)
})

it("is grey in dark mode", () => {
const { container } = render(
<DarkMode.Provider value={true}>
<HyperLink url="https://url">Link</HyperLink>
</DarkMode.Provider>,
)
expect(container.firstChild.className).toEqual(expect.stringContaining("inverted"))
})

it("is can be in error mode", () => {
const { container } = render(
<HyperLink url="https://url" error>
Link
</HyperLink>,
)
expect(container.firstChild.className).toEqual(expect.stringContaining("error"))
})

it("does not propagate a click event", () => {
const eventHandler = jest.fn()
render(
Expand Down
Loading

0 comments on commit c41b212

Please sign in to comment.