badges: fix type issues.
Signed-off-by: Andreas Stenius <git@astekk.se>
This commit is contained in:
committed by
Fredrik Adelöw
parent
45e26d7956
commit
ce4897ff37
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { createDevApp } from '@backstage/dev-utils';
|
||||
import { badgesPlugin } from '../src/plugin';
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import { generatePath } from 'react-router';
|
||||
import { ConfigApi, DiscoveryApi } from '@backstage/core';
|
||||
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
|
||||
import { entityRoute } from '@backstage/plugin-catalog-react';
|
||||
import { BadgesApi, BadgeConfig, BadgeSpec } from './types';
|
||||
import { Badge, BadgesApi, BadgeConfig, BadgeSpec } from './types';
|
||||
|
||||
export class BadgesClient implements BadgesApi {
|
||||
private readonly configApi: ConfigApi;
|
||||
@@ -29,7 +29,7 @@ export class BadgesClient implements BadgesApi {
|
||||
this.discoveryApi = options.discoveryApi;
|
||||
}
|
||||
|
||||
public async getDefinedEntityBadges(entity: Entity): Badge[] {
|
||||
public async getDefinedEntityBadges(entity: Entity): Promise<Badge[]> {
|
||||
const badges = [];
|
||||
const badgesConfig = this.configApi.getOptional('badges') ?? {};
|
||||
const entityBadgeUri = await this.getEntityBadgeUri(entity);
|
||||
@@ -46,7 +46,10 @@ export class BadgesClient implements BadgesApi {
|
||||
return badges;
|
||||
}
|
||||
|
||||
private async getBadgeInfo(entityBadgeUri: string, badgeId: string): Badge {
|
||||
private async getBadgeInfo(
|
||||
entityBadgeUri: string,
|
||||
badgeId: string,
|
||||
): Promise<Badge> {
|
||||
const badgeUrl = `${entityBadgeUri}/${badgeId}`;
|
||||
const spec = (await (
|
||||
await fetch(`${badgeUrl}?format=json`)
|
||||
@@ -60,7 +63,7 @@ export class BadgesClient implements BadgesApi {
|
||||
};
|
||||
}
|
||||
|
||||
private async getEntityBadgeUri(entity: Entity): string {
|
||||
private async getEntityBadgeUri(entity: Entity): Promise<string> {
|
||||
const routeParams = this.getEntityRouteParams(entity);
|
||||
const path = generatePath(entityRoute.path, routeParams);
|
||||
return `${await this.discoveryApi.getBaseUrl('badges')}/entity/${path}`;
|
||||
|
||||
@@ -22,14 +22,21 @@ export const badgesApiRef = createApiRef<BadgesApi>({
|
||||
description: 'Used to make requests to the badges backend',
|
||||
});
|
||||
|
||||
export type BadgeStyle =
|
||||
| 'plastic'
|
||||
| 'flat'
|
||||
| 'flat-square'
|
||||
| 'for-the-badge'
|
||||
| 'social';
|
||||
|
||||
// should probably have this in a "badges-common" package
|
||||
interface BadgeConfig {
|
||||
export interface BadgeConfig {
|
||||
kind?: 'entity';
|
||||
label: string;
|
||||
message: string;
|
||||
color?: string;
|
||||
labelColor?: string;
|
||||
style?: 'plastic' | 'flat' | 'flat-square' | 'for-the-badge' | 'social';
|
||||
style?: BadgeStyle;
|
||||
title?: string;
|
||||
description?: string;
|
||||
link?: string;
|
||||
|
||||
@@ -39,13 +39,13 @@ type Props = {
|
||||
entity: Entity;
|
||||
};
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
const useStyles = makeStyles({
|
||||
codeBlock: {
|
||||
'& code': {
|
||||
whiteSpace: 'pre-wrap',
|
||||
},
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
export const EntityBadgesDialog = ({ open, onClose, entity }: Props) => {
|
||||
const theme = useTheme();
|
||||
@@ -70,7 +70,7 @@ export const EntityBadgesDialog = ({ open, onClose, entity }: Props) => {
|
||||
</DialogContentText>
|
||||
<Typography component="div" className={classes.codeBlock}>
|
||||
Copy the following snippet of markdown code for the badge:
|
||||
<CodeSnippet text={markdown} showCopyCodeButton />
|
||||
<CodeSnippet language="markdown" text={markdown} showCopyCodeButton />
|
||||
</Typography>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user