diff --git a/packages/core/src/components/ErrorBoundaryFallback/ErrorBoundaryFallback.tsx b/packages/core/src/components/ErrorBoundaryFallback/ErrorBoundaryFallback.tsx index 0fe7d11c1f..8be43995f1 100644 --- a/packages/core/src/components/ErrorBoundaryFallback/ErrorBoundaryFallback.tsx +++ b/packages/core/src/components/ErrorBoundaryFallback/ErrorBoundaryFallback.tsx @@ -14,11 +14,9 @@ * limitations under the License. */ -// TODO align this design with the backend errors - import React from 'react'; import { AppComponents } from '../..'; -import { ResponseErrorPanel } from '../ResponseErrorPanel'; +import { ErrorPanel } from '../ErrorPanel'; import { Button } from '@material-ui/core'; export const ErrorBoundaryFallback: AppComponents['ErrorBoundaryFallback'] = ({ @@ -27,15 +25,14 @@ export const ErrorBoundaryFallback: AppComponents['ErrorBoundaryFallback'] = ({ plugin, }) => { return ( - - Retry - - } - /> + > + + ); }; diff --git a/packages/core/src/components/ErrorPanel/ErrorPanel.tsx b/packages/core/src/components/ErrorPanel/ErrorPanel.tsx new file mode 100644 index 0000000000..1f7d2a4be7 --- /dev/null +++ b/packages/core/src/components/ErrorPanel/ErrorPanel.tsx @@ -0,0 +1,114 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { List, ListItem, ListItemText, makeStyles } from '@material-ui/core'; +import React, { PropsWithChildren } from 'react'; +import { CopyTextButton } from '../CopyTextButton'; +import { WarningPanel } from '../WarningPanel'; + +const useStyles = makeStyles(theme => ({ + text: { + fontFamily: 'monospace', + whiteSpace: 'pre', + overflowX: 'auto', + marginRight: theme.spacing(2), + }, + divider: { + margin: theme.spacing(2), + }, +})); + +type ErrorListProps = { + error: string; + message: string; + request?: string; + stack?: string; + json?: string; +}; + +const ErrorList = ({ + error, + message, + stack, + children, +}: PropsWithChildren) => { + const classes = useStyles(); + + return ( + + + + + + + + + + + + {stack && ( + + + + + )} + + {children} + + ); +}; + +export type ErrorPanelProps = { + error: Error; + defaultExpanded?: boolean; + title?: string; +}; + +/** + * Renders a warning panel as the effect of an error. + */ +export const ErrorPanel = ({ + title, + error, + defaultExpanded, + children, +}: PropsWithChildren) => { + return ( + + + + ); +}; diff --git a/packages/core/src/components/ErrorPanel/index.ts b/packages/core/src/components/ErrorPanel/index.ts new file mode 100644 index 0000000000..7103266eab --- /dev/null +++ b/packages/core/src/components/ErrorPanel/index.ts @@ -0,0 +1,18 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { ErrorPanel } from './ErrorPanel'; +export type { ErrorPanelProps } from './ErrorPanel'; diff --git a/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx b/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx index 42adf1980c..33da6261ec 100644 --- a/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx +++ b/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx @@ -15,17 +15,11 @@ */ import { ResponseError } from '@backstage/errors'; -import { - Divider, - List, - ListItem, - ListItemText, - makeStyles, -} from '@material-ui/core'; +import { Divider, ListItem, ListItemText, makeStyles } from '@material-ui/core'; import React from 'react'; import { CodeSnippet } from '../CodeSnippet'; import { CopyTextButton } from '../CopyTextButton'; -import { WarningPanel } from '../WarningPanel'; +import { ErrorPanel, ErrorPanelProps } from '../ErrorPanel'; const useStyles = makeStyles(theme => ({ text: { @@ -39,107 +33,25 @@ const useStyles = makeStyles(theme => ({ }, })); -type ResponseErrorListProps = { - error: string; - message: string; - request?: string; - stack?: string; - json?: string; - actions?: React.ReactNode; -}; - -const ResponseErrorList = ({ - error, - request, - message, - stack, - json, - actions, -}: ResponseErrorListProps) => { - const classes = useStyles(); - - return ( - - - - - - - - - - {request && ( - - - - - )} - {stack && ( - - - - - )} - {json && ( - <> - - - } - /> - - - - )} - {actions && ( - <> - - {actions} - - )} - - ); -}; - -type Props = { - error: Error; - defaultExpanded?: boolean; - title?: string; - actions?: React.ReactNode; -}; - /** - * Renders details about a failed server request. + * Renders a warning panel as the effect of a failed server request. * * Has special treatment for ResponseError errors, to display rich * server-provided information about what happened. */ -export const ResponseErrorDetails = ({ error, actions }: Props) => { +export const ResponseErrorPanel = ({ + title, + error, + defaultExpanded, +}: ErrorPanelProps) => { + const classes = useStyles(); + if (error.name !== 'ResponseError') { return ( - ); } @@ -154,34 +66,32 @@ export const ResponseErrorDetails = ({ error, actions }: Props) => { const jsonString = JSON.stringify(data, undefined, 2); return ( - - ); -}; - -/** - * Renders a warning panel as the effect of a failed server request. - * - * Has special treatment for ResponseError errors, to display rich - * server-provided information about what happened. - */ -export const ResponseErrorPanel = ({ - title, - error, - defaultExpanded, - actions, -}: Props) => { - return ( - - - + {requestString && ( + + + + + )} + <> + + + } + /> + + + + ); }; diff --git a/packages/core/src/components/ResponseErrorPanel/index.ts b/packages/core/src/components/ResponseErrorPanel/index.ts index ac62553fd5..1fc6221a44 100644 --- a/packages/core/src/components/ResponseErrorPanel/index.ts +++ b/packages/core/src/components/ResponseErrorPanel/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { ResponseErrorDetails, ResponseErrorPanel } from './ResponseErrorPanel'; +export { ResponseErrorPanel } from './ResponseErrorPanel';