diff --git a/plugins/code-coverage/package.json b/plugins/code-coverage/package.json index e17d894b43..eabd961f4b 100644 --- a/plugins/code-coverage/package.json +++ b/plugins/code-coverage/package.json @@ -22,16 +22,17 @@ "dependencies": { "@backstage/catalog-model": "^0.7.2", "@backstage/config": "^0.1.3", - "@backstage/core": "^0.6.2", + "@backstage/core": "^0.7.5", "@backstage/core-api": "^0.2.12", "@backstage/dev-utils": "^0.1.11", + "@backstage/errors": "^0.1.0", "@backstage/plugin-catalog-react": "^0.1.0", "@backstage/plugin-code-coverage-backend": "^0.1.0", "@backstage/theme": "^0.2.3", "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", "@material-ui/styles": "^4.11.0", - "@material-ui/lab": "4.0.0-alpha.45", + "@material-ui/lab": "4.0.0-alpha.57", "@types/highlightjs": "^10.1.0", "highlight.js": "^10.6.0", "react": "^16.13.1", diff --git a/plugins/code-coverage/src/api.ts b/plugins/code-coverage/src/api.ts index 1443f9de72..1a1bd542ae 100644 --- a/plugins/code-coverage/src/api.ts +++ b/plugins/code-coverage/src/api.ts @@ -21,6 +21,7 @@ import { JsonCodeCoverage, JsonCoverageHistory, } from '@backstage/plugin-code-coverage-backend'; +import { ResponseError } from '@backstage/errors'; export class FetchError extends Error { get name(): string { @@ -66,7 +67,9 @@ export class CodeCoverageRestApi implements CodeCoverageApi { init?: RequestInit, ): Promise { const resp = await fetch(`${this.url}${input}`, init); - if (!resp.ok) throw await FetchError.forResponse(resp); + if (!resp.ok) { + throw await ResponseError.fromResponse(resp); + } if (resp.headers.get('content-type')?.includes('application/json')) { return await resp.json(); } diff --git a/plugins/code-coverage/src/components/CoverageHistoryChart/CoverageHistoryChart.tsx b/plugins/code-coverage/src/components/CoverageHistoryChart/CoverageHistoryChart.tsx index 3e8d9b6387..4f4f442315 100644 --- a/plugins/code-coverage/src/components/CoverageHistoryChart/CoverageHistoryChart.tsx +++ b/plugins/code-coverage/src/components/CoverageHistoryChart/CoverageHistoryChart.tsx @@ -38,7 +38,7 @@ import { useAsync } from 'react-use'; import { useApi } from '@backstage/core-api'; import { useEntity } from '@backstage/plugin-catalog-react'; import { codeCoverageApiRef } from '../../api'; -import { Progress } from '@backstage/core'; +import { Progress, ResponseErrorPanel } from '@backstage/core'; import { Alert } from '@material-ui/lab'; import TrendingDownIcon from '@material-ui/icons/TrendingDown'; import TrendingUpIcon from '@material-ui/icons/TrendingUp'; @@ -88,8 +88,9 @@ export const CoverageHistoryChart = () => { if (loadingHistory) { return ; - } else if (errorHistory) { - return {errorHistory.message}; + } + if (errorHistory) { + return ; } else if (!valueHistory) { return No history found.; } diff --git a/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx b/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx index 72c8b27a12..6844557307 100644 --- a/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx +++ b/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx @@ -23,12 +23,12 @@ import { Progress } from '@backstage/core'; import { Alert } from '@material-ui/lab'; import { makeStyles, Paper } from '@material-ui/core'; import { highlightLines } from './Highlighter'; -import { FileCoverage } from './FileExplorer'; import CoverageRow from './CoverageRow'; +import { FileEntry } from '@backstage/plugin-code-coverage-backend'; type Props = { filename: string; - coverage: FileCoverage; + coverage: FileEntry; }; const useStyles = makeStyles(theme => ({ diff --git a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx index 11baa419f4..da20ba0ed6 100644 --- a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx +++ b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx @@ -16,7 +16,12 @@ import { useApi } from '@backstage/core-api'; import { useEntity } from '@backstage/plugin-catalog-react'; -import { Progress, Table, TableColumn } from '@backstage/core'; +import { + Progress, + ResponseErrorPanel, + Table, + TableColumn, +} from '@backstage/core'; import { Box, Card, @@ -28,15 +33,10 @@ import { import React, { Fragment, useEffect, useState } from 'react'; import { useAsync } from 'react-use'; import { codeCoverageApiRef } from '../../api'; -import { Alert } from '@material-ui/lab'; import DescriptionIcon from '@material-ui/icons/Description'; import { FileContent } from './FileContent'; - -export type FileCoverage = { - filename: string; - branchHits: { [branch: number]: number }; - lineHits: { [line: number]: number }; -}; +import { Alert } from '@material-ui/lab'; +import { FileEntry } from '@backstage/plugin-code-coverage-backend'; type FileStructureObject = Record; @@ -101,7 +101,7 @@ const formatInitialData = (value: any) => { coverage: value.aggregate.line.percentage, missing: value.aggregate.line.missed, tracked: value.aggregate.line.available, - files: value.files.map((fc: FileCoverage) => { + files: value.files.map((fc: FileEntry) => { return { path: '', filename: fc.filename, @@ -145,7 +145,12 @@ export const FileExplorer = () => { if (loading) { return ; } else if (error) { - return {error.message}; + return ; + } + if (!value) { + return ( + No code coverage found for ${entity} + ); } const moveDownIntoPath = (path: string) => { @@ -230,10 +235,14 @@ export const FileExplorer = () => { const pathArray = curPath.split('/'); const lastPathElementIndex = pathArray.length - 1; - const fileCoverage = value.files.find((f: FileCoverage) => + const fileCoverage = value.files.find((f: FileEntry) => f.filename.endsWith(curFile), ); + if (!fileCoverage) { + return null; + } + return ( diff --git a/yarn.lock b/yarn.lock index baf771b351..79f7d85b38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1616,14 +1616,7 @@ core-js-pure "^3.0.0" regenerator-runtime "^0.13.4" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.0", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.4", "@babel/runtime@^7.10.5", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.1", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.4", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.4", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.0", "@babel/runtime@^7.6.3", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": - version "7.13.10" - resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.10.tgz#47d42a57b6095f4468da440388fdbad8bebf0d7d" - integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw== - dependencies: - regenerator-runtime "^0.13.4" - -"@babel/runtime@^7.10.3": +"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.10.0", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.10.3", "@babel/runtime@^7.10.4", "@babel/runtime@^7.10.5", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.1", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.4", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.4", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.0", "@babel/runtime@^7.6.3", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": version "7.13.10" resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.10.tgz#47d42a57b6095f4468da440388fdbad8bebf0d7d" integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw== @@ -1738,49 +1731,6 @@ yaml "^1.9.2" yup "^0.29.3" -"@backstage/core@^0.6.2": - version "0.6.3" - resolved "https://registry.npmjs.org/@backstage/core/-/core-0.6.3.tgz#574ca46ab59e18af07fcf3a248c4428d4dfcc302" - integrity sha512-OSpnvotyCkb6fL02T1Z5TLcogRlOzVIH8YBfNlKeo/Xo/JnlVp1uSpQxCWjAW/lzGK5gp6oh3ezFRjm69mTwSA== - dependencies: - "@backstage/config" "^0.1.3" - "@backstage/core-api" "^0.2.11" - "@backstage/theme" "^0.2.3" - "@material-ui/core" "^4.11.0" - "@material-ui/icons" "^4.9.1" - "@material-ui/lab" "4.0.0-alpha.45" - "@testing-library/react-hooks" "^3.4.2" - "@types/dagre" "^0.7.44" - "@types/prop-types" "^15.7.3" - "@types/react" "^16.9" - "@types/react-sparklines" "^1.7.0" - "@types/react-text-truncate" "^0.14.0" - classnames "^2.2.6" - clsx "^1.1.0" - d3-selection "^2.0.0" - d3-shape "^2.0.0" - d3-zoom "^2.0.0" - dagre "^0.8.5" - immer "^8.0.1" - lodash "^4.17.15" - material-table "^1.69.1" - prop-types "^15.7.2" - qs "^6.9.4" - rc-progress "^3.0.0" - react "^16.12.0" - react-dom "^16.12.0" - react-helmet "6.1.0" - react-hook-form "^6.6.0" - react-markdown "^5.0.2" - react-router "6.0.0-beta.0" - react-router-dom "6.0.0-beta.0" - react-sparklines "^1.7.0" - react-syntax-highlighter "^13.5.1" - react-text-truncate "^0.16.0" - react-use "^15.3.3" - remark-gfm "^1.0.0" - zen-observable "^0.8.15" - "@backstage/plugin-catalog-backend@^0.6.5": version "0.6.7" resolved "https://registry.npmjs.org/@backstage/plugin-catalog-backend/-/plugin-catalog-backend-0.6.7.tgz#97d0ed6db6aeb04e09ed0fee05e76bacf66cc179" @@ -3917,7 +3867,7 @@ react-transition-group "^4.0.0" rifm "^0.7.0" -"@material-ui/styles@^4.10.0", "@material-ui/styles@^4.11.3", "@material-ui/styles@^4.9.6": +"@material-ui/styles@^4.10.0", "@material-ui/styles@^4.11.0", "@material-ui/styles@^4.11.3", "@material-ui/styles@^4.9.6": version "4.11.3" resolved "https://registry.npmjs.org/@material-ui/styles/-/styles-4.11.3.tgz#1b8d97775a4a643b53478c895e3f2a464e8916f2" integrity sha512-HzVzCG+PpgUGMUYEJ2rTEmQYeonGh41BYfILNFb/1ueqma+p1meSdu4RX6NjxYBMhf7k+jgfHFTTz+L1SXL/Zg== @@ -15322,11 +15272,6 @@ immer@8.0.1: resolved "https://registry.npmjs.org/immer/-/immer-8.0.1.tgz#9c73db683e2b3975c424fb0572af5889877ae656" integrity sha512-aqXhGP7//Gui2+UrEtvxZxSquQVXTpZ7KDxfCcKAF3Vysvw0CViVaW9RZ1j1xlIYqaaaipBoqdqeibkc18PNvA== -immer@^8.0.1: - version "8.0.4" - resolved "https://registry.npmjs.org/immer/-/immer-8.0.4.tgz#3a21605a4e2dded852fb2afd208ad50969737b7a" - integrity sha512-jMfL18P+/6P6epANRvRk6q8t+3gGhqsJ9EuJ25AXE+9bNTYtssvzeYbEd0mXRYWCmmXSIbnlpz6vd6iJlmGGGQ== - immer@^9.0.1: version "9.0.1" resolved "https://registry.npmjs.org/immer/-/immer-9.0.1.tgz#1116368e051f9a0fd188c5136b6efb74ed69c57f" @@ -22374,7 +22319,7 @@ react-string-replace@^0.4.1: dependencies: lodash "^4.17.4" -react-syntax-highlighter@^13.5.0, react-syntax-highlighter@^13.5.1: +react-syntax-highlighter@^13.5.0: version "13.5.3" resolved "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-13.5.3.tgz#9712850f883a3e19eb858cf93fad7bb357eea9c6" integrity sha512-crPaF+QGPeHNIblxxCdf2Lg936NAHKhNhuMzRL3F9ct6aYXL3NcZtCL0Rms9+qVo6Y1EQLdXGypBNSbPL/r+qg==