From ac6e65aa1ae4bcb280e5a8d76f8cf00f76430bd4 Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Fri, 27 Nov 2020 14:10:17 +0100 Subject: [PATCH] create MissingTokenError and flatten error --- .../src/components/MissingTokenError.tsx | 35 +++++++++++++++++++ .../src/components/PagerdutyCard.tsx | 28 ++++----------- 2 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 plugins/pagerduty/src/components/MissingTokenError.tsx diff --git a/plugins/pagerduty/src/components/MissingTokenError.tsx b/plugins/pagerduty/src/components/MissingTokenError.tsx new file mode 100644 index 0000000000..c22552b7c6 --- /dev/null +++ b/plugins/pagerduty/src/components/MissingTokenError.tsx @@ -0,0 +1,35 @@ +/* + * Copyright 2020 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 React from 'react'; +import { EmptyState } from '@backstage/core'; +import { Button } from '@material-ui/core'; + +export const MissingTokenError = () => ( + + Read More + + } + /> +); diff --git a/plugins/pagerduty/src/components/PagerdutyCard.tsx b/plugins/pagerduty/src/components/PagerdutyCard.tsx index f24e91a9e0..22a471c031 100644 --- a/plugins/pagerduty/src/components/PagerdutyCard.tsx +++ b/plugins/pagerduty/src/components/PagerdutyCard.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ import React, { useState } from 'react'; -import { useApi, EmptyState } from '@backstage/core'; +import { useApi } from '@backstage/core'; import { Entity } from '@backstage/catalog-model'; import { Button, @@ -31,9 +31,10 @@ import { useAsync } from 'react-use'; import { Alert } from '@material-ui/lab'; import { pagerDutyApiRef, UnauthorizedError } from '../api'; import { IconLinkVertical } from '@backstage/plugin-catalog'; -import PagerDutyIcon from './PagerDutyIcon'; +import { PagerDutyIcon } from './PagerDutyIcon'; import AlarmAddIcon from '@material-ui/icons/AlarmAdd'; import { TriggerDialog } from './TriggerDialog'; +import { MissingTokenError } from './MissingTokenError'; const useStyles = makeStyles(theme => ({ links: { @@ -93,26 +94,11 @@ export const PagerDutyCard = ({ entity }: Props) => { setShowDialog(!showDialog); }; - if (error) { - if (error instanceof UnauthorizedError) { - return ( - - Read More - - } - /> - ); - } + if (error instanceof UnauthorizedError) { + return ; + } + if (error) { return ( Error encountered while fetching information. {error.message}