@backstage-community/plugin-badges 0.2.60 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/api/BadgesClient.esm.js +14 -4
- package/dist/api/BadgesClient.esm.js.map +1 -1
- package/dist/api/types.esm.js +8 -1
- package/dist/api/types.esm.js.map +1 -1
- package/dist/components/EntityBadgesDialog.esm.js +38 -9
- package/dist/components/EntityBadgesDialog.esm.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @backstage-community/plugin-badges
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 82bc0cd: UI now supports customizing badge styles.
|
|
8
|
+
|
|
9
|
+
## 0.2.61
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ce804f6: Backstage version bump to v1.30.2
|
|
14
|
+
|
|
3
15
|
## 0.2.60
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -200,5 +200,5 @@ const app = createApp({
|
|
|
200
200
|
|
|
201
201
|
## Links
|
|
202
202
|
|
|
203
|
-
- [Backend part of the plugin](https://github.com/backstage/
|
|
203
|
+
- [Backend part of the plugin](https://github.com/backstage/community-plugins/tree/main/workspaces/badges/plugins/badges-backend)
|
|
204
204
|
- [The Backstage homepage](https://backstage.io)
|
|
@@ -14,7 +14,7 @@ class BadgesClient {
|
|
|
14
14
|
static fromConfig(options) {
|
|
15
15
|
return new BadgesClient(options);
|
|
16
16
|
}
|
|
17
|
-
async getEntityBadgeSpecs(entity) {
|
|
17
|
+
async getEntityBadgeSpecs(entity, badgeOptions) {
|
|
18
18
|
const obfuscate = this.configApi.getOptionalBoolean("app.badges.obfuscate");
|
|
19
19
|
if (obfuscate) {
|
|
20
20
|
const entityUuidUrl = await this.getEntityUuidUrl(entity);
|
|
@@ -30,7 +30,10 @@ class BadgesClient {
|
|
|
30
30
|
}
|
|
31
31
|
return await response2.json();
|
|
32
32
|
}
|
|
33
|
-
const entityBadgeSpecsUrl = await this.getEntityBadgeSpecsUrl(
|
|
33
|
+
const entityBadgeSpecsUrl = await this.getEntityBadgeSpecsUrl(
|
|
34
|
+
entity,
|
|
35
|
+
badgeOptions
|
|
36
|
+
);
|
|
34
37
|
const response = await this.fetchApi.fetch(entityBadgeSpecsUrl);
|
|
35
38
|
if (!response.ok) {
|
|
36
39
|
throw await ResponseError.fromResponse(response);
|
|
@@ -55,11 +58,18 @@ class BadgesClient {
|
|
|
55
58
|
const baseUrl = await this.discoveryApi.getBaseUrl("badges");
|
|
56
59
|
return `${baseUrl}/entity/${entityUuid}/badge-specs`;
|
|
57
60
|
}
|
|
58
|
-
async getEntityBadgeSpecsUrl(entity) {
|
|
61
|
+
async getEntityBadgeSpecsUrl(entity, badgeOptions) {
|
|
59
62
|
const routeParams = this.getEntityRouteParams(entity);
|
|
60
63
|
const path = generatePath(`:namespace/:kind/:name`, routeParams);
|
|
61
64
|
const baseUrl = await this.discoveryApi.getBaseUrl("badges");
|
|
62
|
-
|
|
65
|
+
const queries = [];
|
|
66
|
+
if (badgeOptions.style) {
|
|
67
|
+
queries.push(`style=${badgeOptions.style}`);
|
|
68
|
+
}
|
|
69
|
+
if (badgeOptions.color) {
|
|
70
|
+
queries.push(`color=${badgeOptions.color}`);
|
|
71
|
+
}
|
|
72
|
+
return `${baseUrl}/entity/${path}/badge-specs?${queries.join("&")}`;
|
|
63
73
|
}
|
|
64
74
|
// This function is used to generate the route parameters using the entity kind, namespace and name
|
|
65
75
|
getEntityRouteParams(entity) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BadgesClient.esm.js","sources":["../../src/api/BadgesClient.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { generatePath } from 'react-router-dom';\nimport { ResponseError } from '@backstage/errors';\nimport { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';\nimport { BadgesApi, BadgeSpec } from './types';\nimport { ConfigApi, DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';\n\nexport class BadgesClient implements BadgesApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n private readonly configApi: ConfigApi;\n\n constructor(options: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n configApi: ConfigApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n this.configApi = options.configApi;\n }\n\n static fromConfig(options: {\n fetchApi: FetchApi;\n discoveryApi: DiscoveryApi;\n configApi: ConfigApi;\n }) {\n return new BadgesClient(options);\n }\n\n public async getEntityBadgeSpecs(entity: Entity): Promise<BadgeSpec[]> {\n // Check if obfuscation is enabled in the configuration\n const obfuscate = this.configApi.getOptionalBoolean('app.badges.obfuscate');\n\n if (obfuscate) {\n const entityUuidUrl = await this.getEntityUuidUrl(entity);\n const entityUuid = await this.getEntityUuid(entityUuidUrl).then(data => {\n return data.uuid;\n });\n const entityUuidBadgeSpecsUrl = await this.getEntityUuidBadgeSpecsUrl(\n entityUuid,\n );\n\n const response = await this.fetchApi.fetch(entityUuidBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n // If obfuscation is disabled, get the badge specs directly as the previous implementation\n const entityBadgeSpecsUrl = await this.getEntityBadgeSpecsUrl(entity);\n const response = await this.fetchApi.fetch(entityBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n private async getEntityUuidUrl(entity: Entity): Promise<string> {\n const routeParams = this.getEntityRouteParams(entity);\n const path = generatePath(`:namespace/:kind/:name`, routeParams);\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n const obfuscatedEntityUrl = `${baseUrl}/entity/${path}/obfuscated`;\n\n return obfuscatedEntityUrl;\n }\n\n private async getEntityUuid(entityUuidUrl: string): Promise<any> {\n const responseEntityUuid = await this.fetchApi.fetch(entityUuidUrl);\n\n if (!responseEntityUuid.ok) {\n throw await ResponseError.fromResponse(responseEntityUuid);\n }\n return await responseEntityUuid.json();\n }\n\n private async getEntityUuidBadgeSpecsUrl(entityUuid: {\n uuid: string;\n }): Promise<string> {\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n return `${baseUrl}/entity/${entityUuid}/badge-specs`;\n }\n\n private async getEntityBadgeSpecsUrl(entity: Entity): Promise<string> {\n const routeParams = this.getEntityRouteParams(entity);\n const path = generatePath(`:namespace/:kind/:name`, routeParams);\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n return `${baseUrl}/entity/${path}/badge-specs`;\n }\n\n // This function is used to generate the route parameters using the entity kind, namespace and name\n private getEntityRouteParams(entity: Entity) {\n return {\n kind: entity.kind.toLocaleLowerCase('en-US'),\n namespace:\n entity.metadata.namespace?.toLocaleLowerCase('en-US') ??\n DEFAULT_NAMESPACE,\n name: entity.metadata.name,\n };\n }\n}\n"],"names":["response"],"mappings":";;;;AAsBO,MAAM,YAAkC,CAAA;AAAA,EAC5B,YAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EACA,SAAA,CAAA;AAAA,EAEjB,YAAY,OAIT,EAAA;AACD,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA,CAAA;AAC5B,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA,CAAA;AACxB,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA,CAAA;AAAA,GAC3B;AAAA,EAEA,OAAO,WAAW,OAIf,EAAA;AACD,IAAO,OAAA,IAAI,aAAa,OAAO,CAAA,CAAA;AAAA,GACjC;AAAA,EAEA,MAAa,
|
|
1
|
+
{"version":3,"file":"BadgesClient.esm.js","sources":["../../src/api/BadgesClient.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { generatePath } from 'react-router-dom';\nimport { ResponseError } from '@backstage/errors';\nimport { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';\nimport { BadgesApi, BadgeSpec, BadgeStyleOptions } from './types';\nimport { ConfigApi, DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';\n\nexport class BadgesClient implements BadgesApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n private readonly configApi: ConfigApi;\n\n constructor(options: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n configApi: ConfigApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n this.configApi = options.configApi;\n }\n\n static fromConfig(options: {\n fetchApi: FetchApi;\n discoveryApi: DiscoveryApi;\n configApi: ConfigApi;\n }) {\n return new BadgesClient(options);\n }\n\n public async getEntityBadgeSpecs(\n entity: Entity,\n badgeOptions: BadgeStyleOptions,\n ): Promise<BadgeSpec[]> {\n // Check if obfuscation is enabled in the configuration\n const obfuscate = this.configApi.getOptionalBoolean('app.badges.obfuscate');\n\n if (obfuscate) {\n const entityUuidUrl = await this.getEntityUuidUrl(entity);\n const entityUuid = await this.getEntityUuid(entityUuidUrl).then(data => {\n return data.uuid;\n });\n const entityUuidBadgeSpecsUrl = await this.getEntityUuidBadgeSpecsUrl(\n entityUuid,\n );\n\n const response = await this.fetchApi.fetch(entityUuidBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n // If obfuscation is disabled, get the badge specs directly as the previous implementation\n const entityBadgeSpecsUrl = await this.getEntityBadgeSpecsUrl(\n entity,\n badgeOptions,\n );\n const response = await this.fetchApi.fetch(entityBadgeSpecsUrl);\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return await response.json();\n }\n\n private async getEntityUuidUrl(entity: Entity): Promise<string> {\n const routeParams = this.getEntityRouteParams(entity);\n const path = generatePath(`:namespace/:kind/:name`, routeParams);\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n const obfuscatedEntityUrl = `${baseUrl}/entity/${path}/obfuscated`;\n\n return obfuscatedEntityUrl;\n }\n\n private async getEntityUuid(entityUuidUrl: string): Promise<any> {\n const responseEntityUuid = await this.fetchApi.fetch(entityUuidUrl);\n\n if (!responseEntityUuid.ok) {\n throw await ResponseError.fromResponse(responseEntityUuid);\n }\n return await responseEntityUuid.json();\n }\n\n private async getEntityUuidBadgeSpecsUrl(entityUuid: {\n uuid: string;\n }): Promise<string> {\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n return `${baseUrl}/entity/${entityUuid}/badge-specs`;\n }\n\n private async getEntityBadgeSpecsUrl(\n entity: Entity,\n badgeOptions: BadgeStyleOptions,\n ): Promise<string> {\n const routeParams = this.getEntityRouteParams(entity);\n const path = generatePath(`:namespace/:kind/:name`, routeParams);\n const baseUrl = await this.discoveryApi.getBaseUrl('badges');\n const queries: string[] = [];\n if (badgeOptions.style) {\n queries.push(`style=${badgeOptions.style}`);\n }\n if (badgeOptions.color) {\n queries.push(`color=${badgeOptions.color}`);\n }\n return `${baseUrl}/entity/${path}/badge-specs?${queries.join('&')}`;\n }\n\n // This function is used to generate the route parameters using the entity kind, namespace and name\n private getEntityRouteParams(entity: Entity) {\n return {\n kind: entity.kind.toLocaleLowerCase('en-US'),\n namespace:\n entity.metadata.namespace?.toLocaleLowerCase('en-US') ??\n DEFAULT_NAMESPACE,\n name: entity.metadata.name,\n };\n }\n}\n"],"names":["response"],"mappings":";;;;AAsBO,MAAM,YAAkC,CAAA;AAAA,EAC5B,YAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EACA,SAAA,CAAA;AAAA,EAEjB,YAAY,OAIT,EAAA;AACD,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA,CAAA;AAC5B,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA,CAAA;AACxB,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA,CAAA;AAAA,GAC3B;AAAA,EAEA,OAAO,WAAW,OAIf,EAAA;AACD,IAAO,OAAA,IAAI,aAAa,OAAO,CAAA,CAAA;AAAA,GACjC;AAAA,EAEA,MAAa,mBACX,CAAA,MAAA,EACA,YACsB,EAAA;AAEtB,IAAA,MAAM,SAAY,GAAA,IAAA,CAAK,SAAU,CAAA,kBAAA,CAAmB,sBAAsB,CAAA,CAAA;AAE1E,IAAA,IAAI,SAAW,EAAA;AACb,MAAA,MAAM,aAAgB,GAAA,MAAM,IAAK,CAAA,gBAAA,CAAiB,MAAM,CAAA,CAAA;AACxD,MAAA,MAAM,aAAa,MAAM,IAAA,CAAK,cAAc,aAAa,CAAA,CAAE,KAAK,CAAQ,IAAA,KAAA;AACtE,QAAA,OAAO,IAAK,CAAA,IAAA,CAAA;AAAA,OACb,CAAA,CAAA;AACD,MAAM,MAAA,uBAAA,GAA0B,MAAM,IAAK,CAAA,0BAAA;AAAA,QACzC,UAAA;AAAA,OACF,CAAA;AAEA,MAAA,MAAMA,SAAW,GAAA,MAAM,IAAK,CAAA,QAAA,CAAS,MAAM,uBAAuB,CAAA,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AAA,QAAA,CAAS,SAAW,EAAA,iBAAA,CAAkB,OAAO,CACpD,IAAA,iBAAA;AAAA,MACF,IAAA,EAAM,OAAO,QAAS,CAAA,IAAA;AAAA,KACxB,CAAA;AAAA,GACF;AACF;;;;"}
|
package/dist/api/types.esm.js
CHANGED
|
@@ -3,6 +3,13 @@ import { createApiRef } from '@backstage/core-plugin-api';
|
|
|
3
3
|
const badgesApiRef = createApiRef({
|
|
4
4
|
id: "plugin.badges.client"
|
|
5
5
|
});
|
|
6
|
+
const BADGE_STYLES = [
|
|
7
|
+
"plastic",
|
|
8
|
+
"flat",
|
|
9
|
+
"flat-square",
|
|
10
|
+
"for-the-badge",
|
|
11
|
+
"social"
|
|
12
|
+
];
|
|
6
13
|
|
|
7
|
-
export { badgesApiRef };
|
|
14
|
+
export { BADGE_STYLES, badgesApiRef };
|
|
8
15
|
//# sourceMappingURL=types.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.esm.js","sources":["../../src/api/types.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity } from '@backstage/catalog-model';\nimport { createApiRef } from '@backstage/core-plugin-api';\n\nexport const badgesApiRef = createApiRef<BadgesApi>({\n id: 'plugin.badges.client',\n});\n\nexport
|
|
1
|
+
{"version":3,"file":"types.esm.js","sources":["../../src/api/types.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity } from '@backstage/catalog-model';\nimport { createApiRef } from '@backstage/core-plugin-api';\n\nexport const badgesApiRef = createApiRef<BadgesApi>({\n id: 'plugin.badges.client',\n});\n\nexport const BADGE_STYLES = [\n 'plastic',\n 'flat',\n 'flat-square',\n 'for-the-badge',\n 'social',\n] as const;\n\nexport type BadgeStyle = (typeof BADGE_STYLES)[number];\n\ninterface Badge {\n color?: string;\n description?: string;\n kind?: 'entity';\n label: string;\n labelColor?: string;\n link?: string;\n message: string;\n style?: BadgeStyle;\n}\n\nexport interface BadgeSpec {\n /** Badge id */\n id: string;\n\n /** Badge data */\n badge: Badge;\n\n /** The URL to the badge image */\n url: string;\n\n /** The markdown code to use the badge */\n markdown: string;\n}\n\nexport interface BadgeStyleOptions {\n style?: BadgeStyle;\n color?: string;\n}\n\nexport interface BadgesApi {\n getEntityBadgeSpecs(\n entity: Entity,\n bsOptions?: BadgeStyleOptions,\n ): Promise<BadgeSpec[]>;\n}\n"],"names":[],"mappings":";;AAmBO,MAAM,eAAe,YAAwB,CAAA;AAAA,EAClD,EAAI,EAAA,sBAAA;AACN,CAAC,EAAA;AAEM,MAAM,YAAe,GAAA;AAAA,EAC1B,SAAA;AAAA,EACA,MAAA;AAAA,EACA,aAAA;AAAA,EACA,eAAA;AAAA,EACA,QAAA;AACF;;;;"}
|
|
@@ -7,14 +7,19 @@ import DialogContent from '@material-ui/core/DialogContent';
|
|
|
7
7
|
import DialogContentText from '@material-ui/core/DialogContentText';
|
|
8
8
|
import DialogTitle from '@material-ui/core/DialogTitle';
|
|
9
9
|
import useMediaQuery from '@material-ui/core/useMediaQuery';
|
|
10
|
+
import InputLabel from '@material-ui/core/InputLabel';
|
|
11
|
+
import MenuItem from '@material-ui/core/MenuItem';
|
|
12
|
+
import FormControl from '@material-ui/core/FormControl';
|
|
13
|
+
import Select from '@material-ui/core/Select';
|
|
14
|
+
import Typography from '@material-ui/core/Typography';
|
|
10
15
|
import { useTheme } from '@material-ui/core/styles';
|
|
11
|
-
import React from 'react';
|
|
16
|
+
import React, { useState } from 'react';
|
|
12
17
|
import useAsync from 'react-use/esm/useAsync';
|
|
13
18
|
import 'react-router-dom';
|
|
14
19
|
import '@backstage/errors';
|
|
15
20
|
import '@backstage/catalog-model';
|
|
16
|
-
import { badgesApiRef } from '../api/types.esm.js';
|
|
17
|
-
import {
|
|
21
|
+
import { badgesApiRef, BADGE_STYLES } from '../api/types.esm.js';
|
|
22
|
+
import { Progress, ResponseErrorPanel, CodeSnippet } from '@backstage/core-components';
|
|
18
23
|
import { useApi } from '@backstage/core-plugin-api';
|
|
19
24
|
|
|
20
25
|
const EntityBadgesDialog = (props) => {
|
|
@@ -23,20 +28,44 @@ const EntityBadgesDialog = (props) => {
|
|
|
23
28
|
const { entity } = useAsyncEntity();
|
|
24
29
|
const fullScreen = useMediaQuery(theme.breakpoints.down("sm"));
|
|
25
30
|
const badgesApi = useApi(badgesApiRef);
|
|
31
|
+
const [style, setStyle] = useState();
|
|
26
32
|
const {
|
|
27
33
|
value: badges,
|
|
28
34
|
loading,
|
|
29
35
|
error
|
|
30
36
|
} = useAsync(async () => {
|
|
31
37
|
if (open && entity) {
|
|
32
|
-
return await badgesApi.getEntityBadgeSpecs(entity);
|
|
38
|
+
return await badgesApi.getEntityBadgeSpecs(entity, { style });
|
|
33
39
|
}
|
|
34
40
|
return [];
|
|
35
|
-
}, [badgesApi, entity, open]);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
}, [badgesApi, entity, open, style]);
|
|
42
|
+
return /* @__PURE__ */ React.createElement(Dialog, { fullScreen, open, onClose }, /* @__PURE__ */ React.createElement(DialogTitle, null, "Entity Badges"), /* @__PURE__ */ React.createElement(DialogContent, null, /* @__PURE__ */ React.createElement(DialogContentText, null, "Embed badges in other web sites that link back to this entity. Copy the relevant snippet of Markdown code to use the badge."), /* @__PURE__ */ React.createElement(Typography, { variant: "subtitle1" }, "Select Badge Style"), /* @__PURE__ */ React.createElement(
|
|
43
|
+
FormControl,
|
|
44
|
+
{
|
|
45
|
+
variant: "standard",
|
|
46
|
+
style: { width: "100%", marginBottom: "16px" }
|
|
47
|
+
},
|
|
48
|
+
/* @__PURE__ */ React.createElement(InputLabel, { id: "badge-style-label" }, "Style"),
|
|
49
|
+
/* @__PURE__ */ React.createElement(
|
|
50
|
+
Select,
|
|
51
|
+
{
|
|
52
|
+
labelId: "badge-style-label",
|
|
53
|
+
id: "badge-style",
|
|
54
|
+
value: style,
|
|
55
|
+
label: "Style",
|
|
56
|
+
onChange: (e) => setStyle(e.target.value)
|
|
57
|
+
},
|
|
58
|
+
/* @__PURE__ */ React.createElement(MenuItem, { value: void 0 }, /* @__PURE__ */ React.createElement("em", null, "Default")),
|
|
59
|
+
BADGE_STYLES.map((s) => /* @__PURE__ */ React.createElement(MenuItem, { key: s, value: s }, s))
|
|
60
|
+
)
|
|
61
|
+
), loading && /* @__PURE__ */ React.createElement(Progress, null), error && /* @__PURE__ */ React.createElement(ResponseErrorPanel, { error }), badges && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { variant: "subtitle1" }, "Badge Previews"), badges.map(({ badge: { description }, id, url, markdown }) => /* @__PURE__ */ React.createElement(Box, { marginTop: 2, marginBottom: 2, key: id }, /* @__PURE__ */ React.createElement(DialogContentText, { component: "div" }, /* @__PURE__ */ React.createElement("img", { alt: description || id, src: url }), /* @__PURE__ */ React.createElement(
|
|
62
|
+
CodeSnippet,
|
|
63
|
+
{
|
|
64
|
+
language: "markdown",
|
|
65
|
+
text: markdown,
|
|
66
|
+
showCopyCodeButton: true
|
|
67
|
+
}
|
|
68
|
+
)))))), /* @__PURE__ */ React.createElement(DialogActions, null, /* @__PURE__ */ React.createElement(Button, { onClick: onClose, color: "primary" }, "Close")));
|
|
40
69
|
};
|
|
41
70
|
|
|
42
71
|
export { EntityBadgesDialog };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityBadgesDialog.esm.js","sources":["../../src/components/EntityBadgesDialog.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useAsyncEntity } from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport Button from '@material-ui/core/Button';\nimport Dialog from '@material-ui/core/Dialog';\nimport DialogActions from '@material-ui/core/DialogActions';\nimport DialogContent from '@material-ui/core/DialogContent';\nimport DialogContentText from '@material-ui/core/DialogContentText';\nimport DialogTitle from '@material-ui/core/DialogTitle';\nimport useMediaQuery from '@material-ui/core/useMediaQuery';\nimport { useTheme } from '@material-ui/core/styles';\nimport React from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport { badgesApiRef } from '../api';\n\nimport {\n CodeSnippet,\n Progress,\n ResponseErrorPanel,\n} from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\n\nexport const EntityBadgesDialog = (props: {\n open: boolean;\n onClose?: () => any;\n}) => {\n const { open, onClose } = props;\n const theme = useTheme();\n const { entity } = useAsyncEntity();\n const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));\n const badgesApi = useApi(badgesApiRef);\n\n const {\n value: badges,\n loading,\n error,\n } = useAsync(async () => {\n if (open && entity) {\n return await badgesApi.getEntityBadgeSpecs(entity);\n }\n return [];\n }, [badgesApi, entity, open
|
|
1
|
+
{"version":3,"file":"EntityBadgesDialog.esm.js","sources":["../../src/components/EntityBadgesDialog.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useAsyncEntity } from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport Button from '@material-ui/core/Button';\nimport Dialog from '@material-ui/core/Dialog';\nimport DialogActions from '@material-ui/core/DialogActions';\nimport DialogContent from '@material-ui/core/DialogContent';\nimport DialogContentText from '@material-ui/core/DialogContentText';\nimport DialogTitle from '@material-ui/core/DialogTitle';\nimport useMediaQuery from '@material-ui/core/useMediaQuery';\nimport InputLabel from '@material-ui/core/InputLabel';\nimport MenuItem from '@material-ui/core/MenuItem';\nimport FormControl from '@material-ui/core/FormControl';\nimport Select from '@material-ui/core/Select';\nimport Typography from '@material-ui/core/Typography';\nimport { useTheme } from '@material-ui/core/styles';\nimport React, { useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport { BadgeStyle, BADGE_STYLES, badgesApiRef } from '../api';\n\nimport {\n CodeSnippet,\n Progress,\n ResponseErrorPanel,\n} from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\n\nexport const EntityBadgesDialog = (props: {\n open: boolean;\n onClose?: () => any;\n}) => {\n const { open, onClose } = props;\n const theme = useTheme();\n const { entity } = useAsyncEntity();\n const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));\n const badgesApi = useApi(badgesApiRef);\n\n const [style, setStyle] = useState<BadgeStyle>();\n\n const {\n value: badges,\n loading,\n error,\n } = useAsync(async () => {\n if (open && entity) {\n return await badgesApi.getEntityBadgeSpecs(entity, { style });\n }\n return [];\n }, [badgesApi, entity, open, style]);\n\n return (\n <Dialog fullScreen={fullScreen} open={open} onClose={onClose}>\n <DialogTitle>Entity Badges</DialogTitle>\n <DialogContent>\n <DialogContentText>\n Embed badges in other web sites that link back to this entity. Copy\n the relevant snippet of Markdown code to use the badge.\n </DialogContentText>\n\n <Typography variant=\"subtitle1\">Select Badge Style</Typography>\n <FormControl\n variant=\"standard\"\n style={{ width: '100%', marginBottom: '16px' }}\n >\n <InputLabel id=\"badge-style-label\">Style</InputLabel>\n <Select\n labelId=\"badge-style-label\"\n id=\"badge-style\"\n value={style}\n label=\"Style\"\n onChange={e => setStyle(e.target.value as BadgeStyle)}\n >\n <MenuItem value={undefined}>\n <em>Default</em>\n </MenuItem>\n {BADGE_STYLES.map(s => (\n <MenuItem key={s} value={s}>\n {s}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n\n {loading && <Progress />}\n {error && <ResponseErrorPanel error={error} />}\n\n {badges && (\n <>\n <Typography variant=\"subtitle1\">Badge Previews</Typography>\n {badges.map(({ badge: { description }, id, url, markdown }) => (\n <Box marginTop={2} marginBottom={2} key={id}>\n <DialogContentText component=\"div\">\n <img alt={description || id} src={url} />\n <CodeSnippet\n language=\"markdown\"\n text={markdown}\n showCopyCodeButton\n />\n </DialogContentText>\n </Box>\n ))}\n </>\n )}\n </DialogContent>\n\n <DialogActions>\n <Button onClick={onClose} color=\"primary\">\n Close\n </Button>\n </DialogActions>\n </Dialog>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0Ca,MAAA,kBAAA,GAAqB,CAAC,KAG7B,KAAA;AACJ,EAAM,MAAA,EAAE,IAAM,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAC1B,EAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,EAAM,MAAA,EAAE,MAAO,EAAA,GAAI,cAAe,EAAA,CAAA;AAClC,EAA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A;AAAA,MACN,kBAAkB,EAAA,IAAA;AAAA,KAAA;AAAA,GAEtB,CACF,CACD,CACH,CAEJ,mBAEC,KAAA,CAAA,aAAA,CAAA,aAAA,EAAA,IAAA,kBACE,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAO,SAAS,OAAS,EAAA,KAAA,EAAM,SAAU,EAAA,EAAA,OAE1C,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-badges",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A Backstage plugin that generates README badges for your entities",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "frontend-plugin",
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"test": "backstage-cli package test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@backstage/catalog-model": "^1.
|
|
42
|
-
"@backstage/core-components": "^0.14.
|
|
41
|
+
"@backstage/catalog-model": "^1.6.0",
|
|
42
|
+
"@backstage/core-components": "^0.14.10",
|
|
43
43
|
"@backstage/core-plugin-api": "^1.9.3",
|
|
44
44
|
"@backstage/errors": "^1.2.4",
|
|
45
|
-
"@backstage/plugin-catalog-react": "^1.12.
|
|
45
|
+
"@backstage/plugin-catalog-react": "^1.12.3",
|
|
46
46
|
"@material-ui/core": "^4.12.2",
|
|
47
47
|
"@types/react": "^16.13.1 || ^17.0.0 || ^18.0.0",
|
|
48
48
|
"react-use": "^17.2.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@backstage/cli": "^0.
|
|
52
|
-
"@backstage/dev-utils": "^1.0.
|
|
53
|
-
"@backstage/test-utils": "^1.5.
|
|
51
|
+
"@backstage/cli": "^0.27.0",
|
|
52
|
+
"@backstage/dev-utils": "^1.0.37",
|
|
53
|
+
"@backstage/test-utils": "^1.5.10",
|
|
54
54
|
"@testing-library/dom": "^10.0.0",
|
|
55
55
|
"@testing-library/jest-dom": "^6.0.0",
|
|
56
56
|
"@testing-library/react": "^15.0.0",
|