badges: refactoring after review from @freben.
Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se>
This commit is contained in:
committed by
Fredrik Adelöw
parent
97836e51f1
commit
c46ab4afba
@@ -16,6 +16,7 @@
|
||||
|
||||
import { generatePath } from 'react-router';
|
||||
import { DiscoveryApi } from '@backstage/core';
|
||||
import { ResponseError } from '@backstage/errors';
|
||||
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
|
||||
import { entityRoute } from '@backstage/plugin-catalog-react';
|
||||
import { BadgesApi, BadgeSpec } from './types';
|
||||
@@ -29,11 +30,13 @@ export class BadgesClient implements BadgesApi {
|
||||
|
||||
public async getEntityBadgeSpecs(entity: Entity): Promise<BadgeSpec[]> {
|
||||
const entityBadgeSpecsUrl = await this.getEntityBadgeSpecsUrl(entity);
|
||||
const specs = (await (
|
||||
await fetch(entityBadgeSpecsUrl)
|
||||
).json()) as BadgeSpec[];
|
||||
const response = await fetch(entityBadgeSpecsUrl);
|
||||
|
||||
return specs;
|
||||
if (!response.ok) {
|
||||
throw await ResponseError.fromResponse(response);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
private async getEntityBadgeSpecsUrl(entity: Entity): Promise<string> {
|
||||
|
||||
@@ -15,7 +15,12 @@
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { CodeSnippet, Progress, useApi } from '@backstage/core';
|
||||
import {
|
||||
CodeSnippet,
|
||||
Progress,
|
||||
ResponseErrorPanel,
|
||||
useApi,
|
||||
} from '@backstage/core';
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
@@ -28,7 +33,6 @@ import {
|
||||
useTheme,
|
||||
} from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import Alert from '@material-ui/lab/Alert';
|
||||
import React from 'react';
|
||||
import { useAsync } from 'react-use';
|
||||
import { badgesApiRef } from '../api';
|
||||
@@ -80,17 +84,11 @@ export const EntityBadgesDialog = ({ open, onClose, entity }: Props) => {
|
||||
|
||||
return (
|
||||
<Dialog fullScreen={fullScreen} open={open} onClose={onClose}>
|
||||
<DialogTitle id="badges-dialog-title">Entity Badges</DialogTitle>
|
||||
<DialogTitle>Entity Badges</DialogTitle>
|
||||
|
||||
<DialogContent>
|
||||
{loading ? <Progress /> : null}
|
||||
|
||||
{error ? (
|
||||
<Alert severity="error" style={{ wordBreak: 'break-word' }}>
|
||||
{error.toString()}
|
||||
</Alert>
|
||||
) : null}
|
||||
|
||||
{loading && <Progress />}
|
||||
{error && <ResponseErrorPanel error={error} />}
|
||||
{content}
|
||||
</DialogContent>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user