@backstage/plugin-catalog-import 0.11.0 → 0.12.0-next.1
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 +29 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.esm.js +4 -4
- package/dist/alpha.esm.js.map +1 -1
- package/dist/api/CatalogImportClient.esm.js +17 -31
- package/dist/api/CatalogImportClient.esm.js.map +1 -1
- package/dist/components/EntityListComponent/EntityListComponent.esm.js +1 -1
- package/dist/components/EntityListComponent/EntityListComponent.esm.js.map +1 -1
- package/dist/components/StepFinishImportLocation/StepFinishImportLocation.esm.js +1 -2
- package/dist/components/StepFinishImportLocation/StepFinishImportLocation.esm.js.map +1 -1
- package/dist/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.esm.js +1 -2
- package/dist/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.esm.js.map +1 -1
- package/dist/components/StepPrepareCreatePullRequest/AutocompleteTextField.esm.js +2 -2
- package/dist/components/StepPrepareCreatePullRequest/AutocompleteTextField.esm.js.map +1 -1
- package/dist/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.esm.js +2 -2
- package/dist/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.esm.js.map +1 -1
- package/dist/components/StepPrepareCreatePullRequest/PreviewPullRequestComponent.esm.js +1 -1
- package/dist/components/StepPrepareCreatePullRequest/PreviewPullRequestComponent.esm.js.map +1 -1
- package/dist/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.esm.js +5 -6
- package/dist/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.esm.js.map +1 -1
- package/dist/components/StepPrepareSelectLocations/StepPrepareSelectLocations.esm.js +2 -2
- package/dist/components/StepPrepareSelectLocations/StepPrepareSelectLocations.esm.js.map +1 -1
- package/dist/components/StepReviewLocation/StepReviewLocation.esm.js +1 -2
- package/dist/components/StepReviewLocation/StepReviewLocation.esm.js.map +1 -1
- package/dist/components/helpers.esm.js +2 -4
- package/dist/components/helpers.esm.js.map +1 -1
- package/dist/components/useImportState.esm.js +5 -5
- package/dist/components/useImportState.esm.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/plugin.esm.js +4 -4
- package/dist/plugin.esm.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-import
|
|
2
2
|
|
|
3
|
+
## 0.12.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4f92394: Migrate from identityApi to fetchApi in frontend plugins.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/plugin-catalog-react@1.12.1-next.0
|
|
13
|
+
|
|
14
|
+
## 0.11.1-next.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/core-components@0.14.8-next.0
|
|
20
|
+
- @backstage/catalog-client@1.6.5
|
|
21
|
+
- @backstage/catalog-model@1.5.0
|
|
22
|
+
- @backstage/config@1.2.0
|
|
23
|
+
- @backstage/core-compat-api@0.2.6-next.0
|
|
24
|
+
- @backstage/core-plugin-api@1.9.2
|
|
25
|
+
- @backstage/errors@1.2.4
|
|
26
|
+
- @backstage/frontend-plugin-api@0.6.6-next.0
|
|
27
|
+
- @backstage/integration@1.11.0
|
|
28
|
+
- @backstage/integration-react@1.1.27
|
|
29
|
+
- @backstage/plugin-catalog-common@1.0.23
|
|
30
|
+
- @backstage/plugin-catalog-react@1.12.1-next.0
|
|
31
|
+
|
|
3
32
|
## 0.11.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
package/alpha/package.json
CHANGED
package/dist/alpha.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createApiFactory, discoveryApiRef,
|
|
1
|
+
import { createApiFactory, discoveryApiRef, fetchApiRef, configApiRef } from '@backstage/core-plugin-api';
|
|
2
2
|
import { convertLegacyRouteRef, compatWrapper } from '@backstage/core-compat-api';
|
|
3
3
|
import { createPageExtension, createApiExtension, createPlugin } from '@backstage/frontend-plugin-api';
|
|
4
4
|
import { scmAuthApiRef, scmIntegrationsApiRef } from '@backstage/integration-react';
|
|
@@ -21,7 +21,7 @@ const catalogImportApi = createApiExtension({
|
|
|
21
21
|
deps: {
|
|
22
22
|
discoveryApi: discoveryApiRef,
|
|
23
23
|
scmAuthApi: scmAuthApiRef,
|
|
24
|
-
|
|
24
|
+
fetchApi: fetchApiRef,
|
|
25
25
|
scmIntegrationsApi: scmIntegrationsApiRef,
|
|
26
26
|
catalogApi: catalogApiRef,
|
|
27
27
|
configApi: configApiRef
|
|
@@ -29,7 +29,7 @@ const catalogImportApi = createApiExtension({
|
|
|
29
29
|
factory: ({
|
|
30
30
|
discoveryApi,
|
|
31
31
|
scmAuthApi,
|
|
32
|
-
|
|
32
|
+
fetchApi,
|
|
33
33
|
scmIntegrationsApi,
|
|
34
34
|
catalogApi,
|
|
35
35
|
configApi
|
|
@@ -37,7 +37,7 @@ const catalogImportApi = createApiExtension({
|
|
|
37
37
|
discoveryApi,
|
|
38
38
|
scmAuthApi,
|
|
39
39
|
scmIntegrationsApi,
|
|
40
|
-
|
|
40
|
+
fetchApi,
|
|
41
41
|
catalogApi,
|
|
42
42
|
configApi
|
|
43
43
|
})
|
package/dist/alpha.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alpha.esm.js","sources":["../src/alpha.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 {\n configApiRef,\n createApiFactory,\n discoveryApiRef,\n
|
|
1
|
+
{"version":3,"file":"alpha.esm.js","sources":["../src/alpha.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 {\n configApiRef,\n createApiFactory,\n discoveryApiRef,\n fetchApiRef,\n} from '@backstage/core-plugin-api';\nimport {\n compatWrapper,\n convertLegacyRouteRef,\n} from '@backstage/core-compat-api';\nimport {\n createApiExtension,\n createPageExtension,\n createPlugin,\n} from '@backstage/frontend-plugin-api';\nimport {\n scmAuthApiRef,\n scmIntegrationsApiRef,\n} from '@backstage/integration-react';\nimport React from 'react';\nimport { CatalogImportClient, catalogImportApiRef } from './api';\nimport { rootRouteRef } from './plugin';\nimport { catalogApiRef } from '@backstage/plugin-catalog-react';\n\n// TODO: It's currently possible to override the import page with a custom one. We need to decide\n// whether this type of override is typically done with an input or by overriding the entire extension.\nconst catalogImportPage = createPageExtension({\n defaultPath: '/catalog-import',\n routeRef: convertLegacyRouteRef(rootRouteRef),\n loader: () =>\n import('./components/ImportPage').then(m =>\n compatWrapper(<m.ImportPage />),\n ),\n});\n\nconst catalogImportApi = createApiExtension({\n factory: createApiFactory({\n api: catalogImportApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n scmAuthApi: scmAuthApiRef,\n fetchApi: fetchApiRef,\n scmIntegrationsApi: scmIntegrationsApiRef,\n catalogApi: catalogApiRef,\n configApi: configApiRef,\n },\n factory: ({\n discoveryApi,\n scmAuthApi,\n fetchApi,\n scmIntegrationsApi,\n catalogApi,\n configApi,\n }) =>\n new CatalogImportClient({\n discoveryApi,\n scmAuthApi,\n scmIntegrationsApi,\n fetchApi,\n catalogApi,\n configApi,\n }),\n }),\n});\n\n/** @alpha */\nexport default createPlugin({\n id: 'catalog-import',\n extensions: [catalogImportApi, catalogImportPage],\n routes: {\n importPage: convertLegacyRouteRef(rootRouteRef),\n },\n});\n"],"names":[],"mappings":";;;;;;;;;;AA0CA,MAAM,oBAAoB,mBAAoB,CAAA;AAAA,EAC5C,WAAa,EAAA,iBAAA;AAAA,EACb,QAAA,EAAU,sBAAsB,YAAY,CAAA;AAAA,EAC5C,MAAQ,EAAA,MACN,OAAO,sCAAyB,CAAE,CAAA,IAAA;AAAA,IAAK,OACrC,aAAc,iBAAA,KAAA,CAAA,aAAA,CAAC,CAAE,CAAA,UAAA,EAAF,IAAa,CAAE,CAAA;AAAA,GAChC;AACJ,CAAC,CAAA,CAAA;AAED,MAAM,mBAAmB,kBAAmB,CAAA;AAAA,EAC1C,SAAS,gBAAiB,CAAA;AAAA,IACxB,GAAK,EAAA,mBAAA;AAAA,IACL,IAAM,EAAA;AAAA,MACJ,YAAc,EAAA,eAAA;AAAA,MACd,UAAY,EAAA,aAAA;AAAA,MACZ,QAAU,EAAA,WAAA;AAAA,MACV,kBAAoB,EAAA,qBAAA;AAAA,MACpB,UAAY,EAAA,aAAA;AAAA,MACZ,SAAW,EAAA,YAAA;AAAA,KACb;AAAA,IACA,SAAS,CAAC;AAAA,MACR,YAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA,kBAAA;AAAA,MACA,UAAA;AAAA,MACA,SAAA;AAAA,KACF,KACE,IAAI,mBAAoB,CAAA;AAAA,MACtB,YAAA;AAAA,MACA,UAAA;AAAA,MACA,kBAAA;AAAA,MACA,QAAA;AAAA,MACA,UAAA;AAAA,MACA,SAAA;AAAA,KACD,CAAA;AAAA,GACJ,CAAA;AACH,CAAC,CAAA,CAAA;AAGD,YAAe,YAAa,CAAA;AAAA,EAC1B,EAAI,EAAA,gBAAA;AAAA,EACJ,UAAA,EAAY,CAAC,gBAAA,EAAkB,iBAAiB,CAAA;AAAA,EAChD,MAAQ,EAAA;AAAA,IACN,UAAA,EAAY,sBAAsB,YAAY,CAAA;AAAA,GAChD;AACF,CAAC,CAAA;;;;"}
|
|
@@ -4,30 +4,23 @@ import YAML from 'yaml';
|
|
|
4
4
|
import { getGithubIntegrationConfig } from './GitHub.esm.js';
|
|
5
5
|
import { getCatalogFilename, getBranchName } from '../components/helpers.esm.js';
|
|
6
6
|
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __publicField = (obj, key, value) => {
|
|
10
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
-
return value;
|
|
12
|
-
};
|
|
13
7
|
class CatalogImportClient {
|
|
8
|
+
discoveryApi;
|
|
9
|
+
fetchApi;
|
|
10
|
+
scmAuthApi;
|
|
11
|
+
scmIntegrationsApi;
|
|
12
|
+
catalogApi;
|
|
13
|
+
configApi;
|
|
14
14
|
constructor(options) {
|
|
15
|
-
__publicField(this, "discoveryApi");
|
|
16
|
-
__publicField(this, "identityApi");
|
|
17
|
-
__publicField(this, "scmAuthApi");
|
|
18
|
-
__publicField(this, "scmIntegrationsApi");
|
|
19
|
-
__publicField(this, "catalogApi");
|
|
20
|
-
__publicField(this, "configApi");
|
|
21
15
|
this.discoveryApi = options.discoveryApi;
|
|
22
16
|
this.scmAuthApi = options.scmAuthApi;
|
|
23
|
-
this.
|
|
17
|
+
this.fetchApi = options.fetchApi;
|
|
24
18
|
this.scmIntegrationsApi = options.scmIntegrationsApi;
|
|
25
19
|
this.catalogApi = options.catalogApi;
|
|
26
20
|
this.configApi = options.configApi;
|
|
27
21
|
}
|
|
28
22
|
async analyzeUrl(url) {
|
|
29
|
-
|
|
30
|
-
if (new URL(url).pathname.match(/\.ya?ml$/) || ((_a = new URL(url).searchParams.get("path")) == null ? void 0 : _a.match(/.ya?ml$/))) {
|
|
23
|
+
if (new URL(url).pathname.match(/\.ya?ml$/) || new URL(url).searchParams.get("path")?.match(/.ya?ml$/)) {
|
|
31
24
|
const location = await this.catalogApi.addLocation({
|
|
32
25
|
type: "url",
|
|
33
26
|
target: url,
|
|
@@ -39,14 +32,11 @@ class CatalogImportClient {
|
|
|
39
32
|
{
|
|
40
33
|
exists: location.exists,
|
|
41
34
|
target: location.location.target,
|
|
42
|
-
entities: location.entities.map((e) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
name: e.metadata.name
|
|
48
|
-
};
|
|
49
|
-
})
|
|
35
|
+
entities: location.entities.map((e) => ({
|
|
36
|
+
kind: e.kind,
|
|
37
|
+
namespace: e.metadata.namespace ?? "default",
|
|
38
|
+
name: e.metadata.name
|
|
39
|
+
}))
|
|
50
40
|
}
|
|
51
41
|
]
|
|
52
42
|
};
|
|
@@ -69,7 +59,6 @@ class CatalogImportClient {
|
|
|
69
59
|
});
|
|
70
60
|
if (analyzation.existingEntityFiles.length > 0) {
|
|
71
61
|
const locations = analyzation.existingEntityFiles.reduce((state, curr) => {
|
|
72
|
-
var _a2;
|
|
73
62
|
state[curr.location.target] = {
|
|
74
63
|
target: curr.location.target,
|
|
75
64
|
exists: curr.isRegistered,
|
|
@@ -77,7 +66,7 @@ class CatalogImportClient {
|
|
|
77
66
|
...curr.location.target in state ? state[curr.location.target].entities : [],
|
|
78
67
|
{
|
|
79
68
|
name: curr.entity.metadata.name,
|
|
80
|
-
namespace:
|
|
69
|
+
namespace: curr.entity.metadata.namespace ?? "default",
|
|
81
70
|
kind: curr.entity.kind
|
|
82
71
|
}
|
|
83
72
|
]
|
|
@@ -97,8 +86,7 @@ class CatalogImportClient {
|
|
|
97
86
|
};
|
|
98
87
|
}
|
|
99
88
|
async preparePullRequest() {
|
|
100
|
-
|
|
101
|
-
const appTitle = (_a = this.configApi.getOptionalString("app.title")) != null ? _a : "Backstage";
|
|
89
|
+
const appTitle = this.configApi.getOptionalString("app.title") ?? "Backstage";
|
|
102
90
|
const appBaseUrl = this.configApi.getString("app.baseUrl");
|
|
103
91
|
const catalogFilename = getCatalogFilename(this.configApi);
|
|
104
92
|
return {
|
|
@@ -137,13 +125,11 @@ For more information, read an [overview of the Backstage software catalog](https
|
|
|
137
125
|
}
|
|
138
126
|
// TODO: this could be part of the catalog api
|
|
139
127
|
async analyzeLocation(options) {
|
|
140
|
-
const
|
|
141
|
-
const response = await fetch(
|
|
128
|
+
const response = await this.fetchApi.fetch(
|
|
142
129
|
`${await this.discoveryApi.getBaseUrl("catalog")}/analyze-location`,
|
|
143
130
|
{
|
|
144
131
|
headers: {
|
|
145
|
-
"Content-Type": "application/json"
|
|
146
|
-
...token && { Authorization: `Bearer ${token}` }
|
|
132
|
+
"Content-Type": "application/json"
|
|
147
133
|
},
|
|
148
134
|
method: "POST",
|
|
149
135
|
body: JSON.stringify({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CatalogImportClient.esm.js","sources":["../../src/api/CatalogImportClient.ts"],"sourcesContent":["/*\n * Copyright 2020 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 { CatalogApi } from '@backstage/catalog-client';\nimport {\n ConfigApi,\n DiscoveryApi,\n IdentityApi,\n} from '@backstage/core-plugin-api';\nimport {\n GithubIntegrationConfig,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { ScmAuthApi } from '@backstage/integration-react';\nimport { Octokit } from '@octokit/rest';\nimport { Base64 } from 'js-base64';\nimport { AnalyzeResult, CatalogImportApi } from './CatalogImportApi';\nimport YAML from 'yaml';\nimport { getGithubIntegrationConfig } from './GitHub';\nimport { getBranchName, getCatalogFilename } from '../components/helpers';\nimport { AnalyzeLocationResponse } from '@backstage/plugin-catalog-common';\nimport { CompoundEntityRef } from '@backstage/catalog-model';\n\n/**\n * The default implementation of the {@link CatalogImportApi}.\n *\n * @public\n */\nexport class CatalogImportClient implements CatalogImportApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly identityApi: IdentityApi;\n private readonly scmAuthApi: ScmAuthApi;\n private readonly scmIntegrationsApi: ScmIntegrationRegistry;\n private readonly catalogApi: CatalogApi;\n private readonly configApi: ConfigApi;\n\n constructor(options: {\n discoveryApi: DiscoveryApi;\n scmAuthApi: ScmAuthApi;\n identityApi: IdentityApi;\n scmIntegrationsApi: ScmIntegrationRegistry;\n catalogApi: CatalogApi;\n configApi: ConfigApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.scmAuthApi = options.scmAuthApi;\n this.identityApi = options.identityApi;\n this.scmIntegrationsApi = options.scmIntegrationsApi;\n this.catalogApi = options.catalogApi;\n this.configApi = options.configApi;\n }\n\n async analyzeUrl(url: string): Promise<AnalyzeResult> {\n if (\n new URL(url).pathname.match(/\\.ya?ml$/) ||\n new URL(url).searchParams.get('path')?.match(/.ya?ml$/)\n ) {\n const location = await this.catalogApi.addLocation({\n type: 'url',\n target: url,\n dryRun: true,\n });\n\n return {\n type: 'locations',\n locations: [\n {\n exists: location.exists,\n target: location.location.target,\n entities: location.entities.map(e => ({\n kind: e.kind,\n namespace: e.metadata.namespace ?? 'default',\n name: e.metadata.name,\n })),\n },\n ],\n };\n }\n\n const ghConfig = getGithubIntegrationConfig(this.scmIntegrationsApi, url);\n if (!ghConfig) {\n const other = this.scmIntegrationsApi.byUrl(url);\n const catalogFilename = getCatalogFilename(this.configApi);\n\n if (other) {\n throw new Error(\n `The ${other.title} integration only supports full URLs to ${catalogFilename} files. Did you try to pass in the URL of a directory instead?`,\n );\n }\n throw new Error(\n `This URL was not recognized as a valid GitHub URL because there was no configured integration that matched the given host name. You could try to paste the full URL to a ${catalogFilename} file instead.`,\n );\n }\n\n const analyzation = await this.analyzeLocation({\n repo: url,\n });\n\n if (analyzation.existingEntityFiles.length > 0) {\n const locations = analyzation.existingEntityFiles.reduce<\n Record<\n string,\n {\n target: string;\n exists?: boolean;\n entities: CompoundEntityRef[];\n }\n >\n >((state, curr) => {\n state[curr.location.target] = {\n target: curr.location.target,\n exists: curr.isRegistered,\n entities: [\n ...(curr.location.target in state\n ? state[curr.location.target].entities\n : []),\n {\n name: curr.entity.metadata.name,\n namespace: curr.entity.metadata.namespace ?? 'default',\n kind: curr.entity.kind,\n },\n ],\n };\n return state;\n }, {});\n return {\n type: 'locations',\n locations: Object.values(locations),\n };\n }\n\n return {\n type: 'repository',\n integrationType: 'github',\n url: url,\n generatedEntities: analyzation.generateEntities.map(x => x.entity),\n };\n }\n\n async preparePullRequest(): Promise<{\n title: string;\n body: string;\n }> {\n const appTitle =\n this.configApi.getOptionalString('app.title') ?? 'Backstage';\n const appBaseUrl = this.configApi.getString('app.baseUrl');\n const catalogFilename = getCatalogFilename(this.configApi);\n\n return {\n title: `Add ${catalogFilename} config file`,\n body: `This pull request adds a **Backstage entity metadata file** \\\nto this repository so that the component can be added to the \\\n[${appTitle} software catalog](${appBaseUrl}).\\n\\nAfter this pull request is merged, \\\nthe component will become available.\\n\\nFor more information, read an \\\n[overview of the Backstage software catalog](https://backstage.io/docs/features/software-catalog/).`,\n };\n }\n\n async submitPullRequest(options: {\n repositoryUrl: string;\n fileContent: string;\n title: string;\n body: string;\n }): Promise<{ link: string; location: string }> {\n const { repositoryUrl, fileContent, title, body } = options;\n const parseData = YAML.parse(fileContent);\n\n const validationResponse = await this.catalogApi.validateEntity(\n parseData,\n `url:${repositoryUrl}`,\n );\n if (!validationResponse.valid) {\n throw new Error(validationResponse.errors[0].message);\n }\n const ghConfig = getGithubIntegrationConfig(\n this.scmIntegrationsApi,\n repositoryUrl,\n );\n\n if (ghConfig) {\n return await this.submitGitHubPrToRepo({\n ...ghConfig,\n repositoryUrl,\n fileContent,\n title,\n body,\n });\n }\n throw new Error('unimplemented!');\n }\n\n // TODO: this could be part of the catalog api\n private async analyzeLocation(options: {\n repo: string;\n }): Promise<AnalyzeLocationResponse> {\n const { token } = await this.identityApi.getCredentials();\n const response = await fetch(\n `${await this.discoveryApi.getBaseUrl('catalog')}/analyze-location`,\n {\n headers: {\n 'Content-Type': 'application/json',\n ...(token && { Authorization: `Bearer ${token}` }),\n },\n method: 'POST',\n body: JSON.stringify({\n location: { type: 'url', target: options.repo },\n ...(this.configApi.getOptionalString(\n 'catalog.import.entityFilename',\n ) && {\n catalogFilename: this.configApi.getOptionalString(\n 'catalog.import.entityFilename',\n ),\n }),\n }),\n },\n ).catch(e => {\n throw new Error(`Failed to generate entity definitions, ${e.message}`);\n });\n if (!response.ok) {\n throw new Error(\n `Failed to generate entity definitions. Received http response ${response.status}: ${response.statusText}`,\n );\n }\n\n const payload = await response.json();\n return payload;\n }\n\n // TODO: extract this function and implement for non-github\n private async submitGitHubPrToRepo(options: {\n owner: string;\n repo: string;\n title: string;\n body: string;\n fileContent: string;\n repositoryUrl: string;\n githubIntegrationConfig: GithubIntegrationConfig;\n }): Promise<{ link: string; location: string }> {\n const {\n owner,\n repo,\n title,\n body,\n fileContent,\n repositoryUrl,\n githubIntegrationConfig,\n } = options;\n\n const { token } = await this.scmAuthApi.getCredentials({\n url: repositoryUrl,\n additionalScope: {\n repoWrite: true,\n },\n });\n\n const octo = new Octokit({\n auth: token,\n baseUrl: githubIntegrationConfig.apiBaseUrl,\n });\n\n const branchName = getBranchName(this.configApi);\n const fileName = getCatalogFilename(this.configApi);\n\n const repoData = await octo.repos\n .get({\n owner,\n repo,\n })\n .catch(e => {\n throw new Error(formatHttpErrorMessage(\"Couldn't fetch repo data\", e));\n });\n\n const parentRef = await octo.git\n .getRef({\n owner,\n repo,\n ref: `heads/${repoData.data.default_branch}`,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\"Couldn't fetch default branch data\", e),\n );\n });\n\n await octo.git\n .createRef({\n owner,\n repo,\n ref: `refs/heads/${branchName}`,\n sha: parentRef.data.object.sha,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\n `Couldn't create a new branch with name '${branchName}'`,\n e,\n ),\n );\n });\n\n await octo.repos\n .createOrUpdateFileContents({\n owner,\n repo,\n path: fileName,\n message: title,\n content: Base64.encode(fileContent),\n branch: branchName,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\n `Couldn't create a commit with ${fileName} file added`,\n e,\n ),\n );\n });\n\n const pullRequestResponse = await octo.pulls\n .create({\n owner,\n repo,\n title,\n head: branchName,\n body,\n base: repoData.data.default_branch,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\n `Couldn't create a pull request for ${branchName} branch`,\n e,\n ),\n );\n });\n\n return {\n link: pullRequestResponse.data.html_url,\n location: `https://${githubIntegrationConfig.host}/${owner}/${repo}/blob/${repoData.data.default_branch}/${fileName}`,\n };\n }\n}\n\nfunction formatHttpErrorMessage(\n message: string,\n error: { status: number; message: string },\n) {\n return `${message}, received http response status code ${error.status}: ${error.message}`;\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;AAyCO,MAAM,mBAAgD,CAAA;AAAA,EAQ3D,YAAY,OAOT,EAAA;AAdH,IAAiB,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,oBAAA,CAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,E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,CAAA;AAAA,KACD,CAAA,CAAA;AAEH,IAAO,OAAA;AAAA,MACL,IAAA,EAAM,oBAAoB,IAAK,CAAA,QAAA;AAAA,MAC/B,QAAU,EAAA,CAAA,QAAA,EAAW,uBAAwB,CAAA,IAAI,CAAI,CAAA,EAAA,KAAK,CAAI,CAAA,EAAA,IAAI,CAAS,MAAA,EAAA,QAAA,CAAS,IAAK,CAAA,cAAc,IAAI,QAAQ,CAAA,CAAA;AAAA,KACrH,CAAA;AAAA,GACF;AACF,CAAA;AAEA,SAAS,sBAAA,CACP,SACA,KACA,EAAA;AACA,EAAA,OAAO,GAAG,OAAO,CAAA,qCAAA,EAAwC,MAAM,MAAM,CAAA,EAAA,EAAK,MAAM,OAAO,CAAA,CAAA,CAAA;AACzF;;;;"}
|
|
1
|
+
{"version":3,"file":"CatalogImportClient.esm.js","sources":["../../src/api/CatalogImportClient.ts"],"sourcesContent":["/*\n * Copyright 2020 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 { CatalogApi } from '@backstage/catalog-client';\nimport { ConfigApi, DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';\nimport {\n GithubIntegrationConfig,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { ScmAuthApi } from '@backstage/integration-react';\nimport { Octokit } from '@octokit/rest';\nimport { Base64 } from 'js-base64';\nimport { AnalyzeResult, CatalogImportApi } from './CatalogImportApi';\nimport YAML from 'yaml';\nimport { getGithubIntegrationConfig } from './GitHub';\nimport { getBranchName, getCatalogFilename } from '../components/helpers';\nimport { AnalyzeLocationResponse } from '@backstage/plugin-catalog-common';\nimport { CompoundEntityRef } from '@backstage/catalog-model';\n\n/**\n * The default implementation of the {@link CatalogImportApi}.\n *\n * @public\n */\nexport class CatalogImportClient implements CatalogImportApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n private readonly scmAuthApi: ScmAuthApi;\n private readonly scmIntegrationsApi: ScmIntegrationRegistry;\n private readonly catalogApi: CatalogApi;\n private readonly configApi: ConfigApi;\n\n constructor(options: {\n discoveryApi: DiscoveryApi;\n scmAuthApi: ScmAuthApi;\n fetchApi: FetchApi;\n scmIntegrationsApi: ScmIntegrationRegistry;\n catalogApi: CatalogApi;\n configApi: ConfigApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.scmAuthApi = options.scmAuthApi;\n this.fetchApi = options.fetchApi;\n this.scmIntegrationsApi = options.scmIntegrationsApi;\n this.catalogApi = options.catalogApi;\n this.configApi = options.configApi;\n }\n\n async analyzeUrl(url: string): Promise<AnalyzeResult> {\n if (\n new URL(url).pathname.match(/\\.ya?ml$/) ||\n new URL(url).searchParams.get('path')?.match(/.ya?ml$/)\n ) {\n const location = await this.catalogApi.addLocation({\n type: 'url',\n target: url,\n dryRun: true,\n });\n\n return {\n type: 'locations',\n locations: [\n {\n exists: location.exists,\n target: location.location.target,\n entities: location.entities.map(e => ({\n kind: e.kind,\n namespace: e.metadata.namespace ?? 'default',\n name: e.metadata.name,\n })),\n },\n ],\n };\n }\n\n const ghConfig = getGithubIntegrationConfig(this.scmIntegrationsApi, url);\n if (!ghConfig) {\n const other = this.scmIntegrationsApi.byUrl(url);\n const catalogFilename = getCatalogFilename(this.configApi);\n\n if (other) {\n throw new Error(\n `The ${other.title} integration only supports full URLs to ${catalogFilename} files. Did you try to pass in the URL of a directory instead?`,\n );\n }\n throw new Error(\n `This URL was not recognized as a valid GitHub URL because there was no configured integration that matched the given host name. You could try to paste the full URL to a ${catalogFilename} file instead.`,\n );\n }\n\n const analyzation = await this.analyzeLocation({\n repo: url,\n });\n\n if (analyzation.existingEntityFiles.length > 0) {\n const locations = analyzation.existingEntityFiles.reduce<\n Record<\n string,\n {\n target: string;\n exists?: boolean;\n entities: CompoundEntityRef[];\n }\n >\n >((state, curr) => {\n state[curr.location.target] = {\n target: curr.location.target,\n exists: curr.isRegistered,\n entities: [\n ...(curr.location.target in state\n ? state[curr.location.target].entities\n : []),\n {\n name: curr.entity.metadata.name,\n namespace: curr.entity.metadata.namespace ?? 'default',\n kind: curr.entity.kind,\n },\n ],\n };\n return state;\n }, {});\n return {\n type: 'locations',\n locations: Object.values(locations),\n };\n }\n\n return {\n type: 'repository',\n integrationType: 'github',\n url: url,\n generatedEntities: analyzation.generateEntities.map(x => x.entity),\n };\n }\n\n async preparePullRequest(): Promise<{\n title: string;\n body: string;\n }> {\n const appTitle =\n this.configApi.getOptionalString('app.title') ?? 'Backstage';\n const appBaseUrl = this.configApi.getString('app.baseUrl');\n const catalogFilename = getCatalogFilename(this.configApi);\n\n return {\n title: `Add ${catalogFilename} config file`,\n body: `This pull request adds a **Backstage entity metadata file** \\\nto this repository so that the component can be added to the \\\n[${appTitle} software catalog](${appBaseUrl}).\\n\\nAfter this pull request is merged, \\\nthe component will become available.\\n\\nFor more information, read an \\\n[overview of the Backstage software catalog](https://backstage.io/docs/features/software-catalog/).`,\n };\n }\n\n async submitPullRequest(options: {\n repositoryUrl: string;\n fileContent: string;\n title: string;\n body: string;\n }): Promise<{ link: string; location: string }> {\n const { repositoryUrl, fileContent, title, body } = options;\n const parseData = YAML.parse(fileContent);\n\n const validationResponse = await this.catalogApi.validateEntity(\n parseData,\n `url:${repositoryUrl}`,\n );\n if (!validationResponse.valid) {\n throw new Error(validationResponse.errors[0].message);\n }\n const ghConfig = getGithubIntegrationConfig(\n this.scmIntegrationsApi,\n repositoryUrl,\n );\n\n if (ghConfig) {\n return await this.submitGitHubPrToRepo({\n ...ghConfig,\n repositoryUrl,\n fileContent,\n title,\n body,\n });\n }\n throw new Error('unimplemented!');\n }\n\n // TODO: this could be part of the catalog api\n private async analyzeLocation(options: {\n repo: string;\n }): Promise<AnalyzeLocationResponse> {\n const response = await this.fetchApi\n .fetch(\n `${await this.discoveryApi.getBaseUrl('catalog')}/analyze-location`,\n {\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({\n location: { type: 'url', target: options.repo },\n ...(this.configApi.getOptionalString(\n 'catalog.import.entityFilename',\n ) && {\n catalogFilename: this.configApi.getOptionalString(\n 'catalog.import.entityFilename',\n ),\n }),\n }),\n },\n )\n .catch(e => {\n throw new Error(`Failed to generate entity definitions, ${e.message}`);\n });\n if (!response.ok) {\n throw new Error(\n `Failed to generate entity definitions. Received http response ${response.status}: ${response.statusText}`,\n );\n }\n\n const payload = await response.json();\n return payload;\n }\n\n // TODO: extract this function and implement for non-github\n private async submitGitHubPrToRepo(options: {\n owner: string;\n repo: string;\n title: string;\n body: string;\n fileContent: string;\n repositoryUrl: string;\n githubIntegrationConfig: GithubIntegrationConfig;\n }): Promise<{ link: string; location: string }> {\n const {\n owner,\n repo,\n title,\n body,\n fileContent,\n repositoryUrl,\n githubIntegrationConfig,\n } = options;\n\n const { token } = await this.scmAuthApi.getCredentials({\n url: repositoryUrl,\n additionalScope: {\n repoWrite: true,\n },\n });\n\n const octo = new Octokit({\n auth: token,\n baseUrl: githubIntegrationConfig.apiBaseUrl,\n });\n\n const branchName = getBranchName(this.configApi);\n const fileName = getCatalogFilename(this.configApi);\n\n const repoData = await octo.repos\n .get({\n owner,\n repo,\n })\n .catch(e => {\n throw new Error(formatHttpErrorMessage(\"Couldn't fetch repo data\", e));\n });\n\n const parentRef = await octo.git\n .getRef({\n owner,\n repo,\n ref: `heads/${repoData.data.default_branch}`,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\"Couldn't fetch default branch data\", e),\n );\n });\n\n await octo.git\n .createRef({\n owner,\n repo,\n ref: `refs/heads/${branchName}`,\n sha: parentRef.data.object.sha,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\n `Couldn't create a new branch with name '${branchName}'`,\n e,\n ),\n );\n });\n\n await octo.repos\n .createOrUpdateFileContents({\n owner,\n repo,\n path: fileName,\n message: title,\n content: Base64.encode(fileContent),\n branch: branchName,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\n `Couldn't create a commit with ${fileName} file added`,\n e,\n ),\n );\n });\n\n const pullRequestResponse = await octo.pulls\n .create({\n owner,\n repo,\n title,\n head: branchName,\n body,\n base: repoData.data.default_branch,\n })\n .catch(e => {\n throw new Error(\n formatHttpErrorMessage(\n `Couldn't create a pull request for ${branchName} branch`,\n e,\n ),\n );\n });\n\n return {\n link: pullRequestResponse.data.html_url,\n location: `https://${githubIntegrationConfig.host}/${owner}/${repo}/blob/${repoData.data.default_branch}/${fileName}`,\n };\n }\n}\n\nfunction formatHttpErrorMessage(\n message: string,\n error: { status: number; message: string },\n) {\n return `${message}, received http response status code ${error.status}: ${error.message}`;\n}\n"],"names":[],"mappings":";;;;;;AAqCO,MAAM,mBAAgD,CAAA;AAAA,EAC1C,YAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EACA,kBAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EACA,SAAA,CAAA;AAAA,EAEjB,YAAY,OAOT,EAAA;AACD,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA,CAAA;AAC5B,IAAA,IAAA,CAAK,aAAa,OAAQ,CAAA,UAAA,CAAA;AAC1B,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA,CAAA;AACxB,IAAA,IAAA,CAAK,qBAAqB,OAAQ,CAAA,kBAAA,CAAA;AAClC,IAAA,IAAA,CAAK,aAAa,OAAQ,CAAA,UAAA,CAAA;AAC1B,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA,CAAA;AAAA,GAC3B;AAAA,EAEA,MAAM,WAAW,GAAqC,EAAA;AACpD,IAAA,IACE,IAAI,GAAI,CAAA,GA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AM,EAAA,UAAA;AAAA,MACN,IAAA;AAAA,MACA,IAAA,EAAM,SAAS,IAAK,CAAA,cAAA;AAAA,KACrB,CACA,CAAA,KAAA,CAAM,CAAK,CAAA,KAAA;AACV,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,sBAAA;AAAA,UACE,sCAAsC,UAAU,CAAA,OAAA,CAAA;AAAA,UAChD,CAAA;AAAA,SACF;AAAA,OACF,CAAA;AAAA,KACD,CAAA,CAAA;AAEH,IAAO,OAAA;AAAA,MACL,IAAA,EAAM,oBAAoB,IAAK,CAAA,QAAA;AAAA,MAC/B,QAAU,EAAA,CAAA,QAAA,EAAW,uBAAwB,CAAA,IAAI,CAAI,CAAA,EAAA,KAAK,CAAI,CAAA,EAAA,IAAI,CAAS,MAAA,EAAA,QAAA,CAAS,IAAK,CAAA,cAAc,IAAI,QAAQ,CAAA,CAAA;AAAA,KACrH,CAAA;AAAA,GACF;AACF,CAAA;AAEA,SAAS,sBAAA,CACP,SACA,KACA,EAAA;AACA,EAAA,OAAO,GAAG,OAAO,CAAA,qCAAA,EAAwC,MAAM,MAAM,CAAA,EAAA,EAAK,MAAM,OAAO,CAAA,CAAA,CAAA;AACzF;;;;"}
|
|
@@ -47,7 +47,7 @@ const EntityListComponent = (props) => {
|
|
|
47
47
|
{
|
|
48
48
|
dense: true,
|
|
49
49
|
button: Boolean(onItemClick),
|
|
50
|
-
onClick: () => onItemClick
|
|
50
|
+
onClick: () => onItemClick?.(r.target)
|
|
51
51
|
},
|
|
52
52
|
/* @__PURE__ */ React.createElement(ListItemIcon, null, locationListItemIcon(r.target)),
|
|
53
53
|
/* @__PURE__ */ React.createElement(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityListComponent.esm.js","sources":["../../../src/components/EntityListComponent/EntityListComponent.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 {\n Entity,\n CompoundEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n EntityDisplayName,\n EntityRefLink,\n entityPresentationApiRef,\n} from '@backstage/plugin-catalog-react';\nimport Collapse from '@material-ui/core/Collapse';\nimport IconButton from '@material-ui/core/IconButton';\nimport List from '@material-ui/core/List';\nimport ListItem from '@material-ui/core/ListItem';\nimport ListItemIcon from '@material-ui/core/ListItemIcon';\nimport ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';\nimport ListItemText from '@material-ui/core/ListItemText';\nimport { makeStyles } from '@material-ui/core/styles';\nimport ExpandLessIcon from '@material-ui/icons/ExpandLess';\nimport ExpandMoreIcon from '@material-ui/icons/ExpandMore';\nimport React, { useState } from 'react';\n\nconst useStyles = makeStyles(theme => ({\n nested: {\n paddingLeft: theme.spacing(4),\n },\n}));\n\n/**\n * Props for {@link EntityListComponent}.\n *\n * @public\n */\nexport interface EntityListComponentProps {\n locations: Array<{\n target: string;\n entities: (Entity | CompoundEntityRef)[];\n }>;\n locationListItemIcon: (target: string) => React.ReactElement;\n collapsed?: boolean;\n firstListItem?: React.ReactElement;\n onItemClick?: (target: string) => void;\n withLinks?: boolean;\n}\n\n/**\n * Shows a result list of entities.\n *\n * @public\n */\nexport const EntityListComponent = (props: EntityListComponentProps) => {\n const {\n locations,\n collapsed = false,\n locationListItemIcon,\n onItemClick,\n firstListItem,\n withLinks = false,\n } = props;\n\n const classes = useStyles();\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const [expandedUrls, setExpandedUrls] = useState<string[]>([]);\n\n const handleClick = (url: string) => {\n setExpandedUrls(urls =>\n urls.includes(url) ? urls.filter(u => u !== url) : urls.concat(url),\n );\n };\n\n function sortEntities(entities: Array<CompoundEntityRef | Entity>) {\n return entities.sort((a, b) =>\n entityPresentationApi\n .forEntity(stringifyEntityRef(a))\n .snapshot.entityRef.localeCompare(\n entityPresentationApi.forEntity(stringifyEntityRef(b)).snapshot\n .entityRef,\n ),\n );\n }\n\n return (\n <List>\n {firstListItem}\n {locations.map(r => (\n <React.Fragment key={r.target}>\n <ListItem\n dense\n button={Boolean(onItemClick) as any}\n onClick={() => onItemClick?.(r.target)}\n >\n <ListItemIcon>{locationListItemIcon(r.target)}</ListItemIcon>\n\n <ListItemText\n primary={r.target}\n secondary={`Entities: ${r.entities.length}`}\n />\n\n {collapsed && (\n <ListItemSecondaryAction>\n <IconButton edge=\"end\" onClick={() => handleClick(r.target)}>\n {expandedUrls.includes(r.target) ? (\n <ExpandLessIcon />\n ) : (\n <ExpandMoreIcon />\n )}\n </IconButton>\n </ListItemSecondaryAction>\n )}\n </ListItem>\n\n <Collapse\n in={!collapsed || expandedUrls.includes(r.target)}\n timeout=\"auto\"\n unmountOnExit\n >\n <List component=\"div\" disablePadding dense>\n {sortEntities(r.entities).map(entity => {\n return (\n <ListItem\n key={stringifyEntityRef(entity)}\n className={classes.nested}\n {...(withLinks\n ? {\n component: EntityRefLink,\n entityRef: entity,\n button: withLinks as any,\n }\n : {})}\n >\n <ListItemText\n primary={<EntityDisplayName entityRef={entity} />}\n />\n </ListItem>\n );\n })}\n </List>\n </Collapse>\n </React.Fragment>\n ))}\n </List>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuCA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,MAAQ,EAAA;AAAA,IACN,WAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,GAC9B;AACF,CAAE,CAAA,CAAA,CAAA;AAwBW,MAAA,mBAAA,GAAsB,CAAC,KAAoC,KAAA;AACtE,EAA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ACC,KAAK,EAAA,IAAA;AAAA,MACL,MAAA,EAAQ,QAAQ,WAAW,CAAA;AAAA,MAC3B,
|
|
1
|
+
{"version":3,"file":"EntityListComponent.esm.js","sources":["../../../src/components/EntityListComponent/EntityListComponent.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 {\n Entity,\n CompoundEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n EntityDisplayName,\n EntityRefLink,\n entityPresentationApiRef,\n} from '@backstage/plugin-catalog-react';\nimport Collapse from '@material-ui/core/Collapse';\nimport IconButton from '@material-ui/core/IconButton';\nimport List from '@material-ui/core/List';\nimport ListItem from '@material-ui/core/ListItem';\nimport ListItemIcon from '@material-ui/core/ListItemIcon';\nimport ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';\nimport ListItemText from '@material-ui/core/ListItemText';\nimport { makeStyles } from '@material-ui/core/styles';\nimport ExpandLessIcon from '@material-ui/icons/ExpandLess';\nimport ExpandMoreIcon from '@material-ui/icons/ExpandMore';\nimport React, { useState } from 'react';\n\nconst useStyles = makeStyles(theme => ({\n nested: {\n paddingLeft: theme.spacing(4),\n },\n}));\n\n/**\n * Props for {@link EntityListComponent}.\n *\n * @public\n */\nexport interface EntityListComponentProps {\n locations: Array<{\n target: string;\n entities: (Entity | CompoundEntityRef)[];\n }>;\n locationListItemIcon: (target: string) => React.ReactElement;\n collapsed?: boolean;\n firstListItem?: React.ReactElement;\n onItemClick?: (target: string) => void;\n withLinks?: boolean;\n}\n\n/**\n * Shows a result list of entities.\n *\n * @public\n */\nexport const EntityListComponent = (props: EntityListComponentProps) => {\n const {\n locations,\n collapsed = false,\n locationListItemIcon,\n onItemClick,\n firstListItem,\n withLinks = false,\n } = props;\n\n const classes = useStyles();\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const [expandedUrls, setExpandedUrls] = useState<string[]>([]);\n\n const handleClick = (url: string) => {\n setExpandedUrls(urls =>\n urls.includes(url) ? urls.filter(u => u !== url) : urls.concat(url),\n );\n };\n\n function sortEntities(entities: Array<CompoundEntityRef | Entity>) {\n return entities.sort((a, b) =>\n entityPresentationApi\n .forEntity(stringifyEntityRef(a))\n .snapshot.entityRef.localeCompare(\n entityPresentationApi.forEntity(stringifyEntityRef(b)).snapshot\n .entityRef,\n ),\n );\n }\n\n return (\n <List>\n {firstListItem}\n {locations.map(r => (\n <React.Fragment key={r.target}>\n <ListItem\n dense\n button={Boolean(onItemClick) as any}\n onClick={() => onItemClick?.(r.target)}\n >\n <ListItemIcon>{locationListItemIcon(r.target)}</ListItemIcon>\n\n <ListItemText\n primary={r.target}\n secondary={`Entities: ${r.entities.length}`}\n />\n\n {collapsed && (\n <ListItemSecondaryAction>\n <IconButton edge=\"end\" onClick={() => handleClick(r.target)}>\n {expandedUrls.includes(r.target) ? (\n <ExpandLessIcon />\n ) : (\n <ExpandMoreIcon />\n )}\n </IconButton>\n </ListItemSecondaryAction>\n )}\n </ListItem>\n\n <Collapse\n in={!collapsed || expandedUrls.includes(r.target)}\n timeout=\"auto\"\n unmountOnExit\n >\n <List component=\"div\" disablePadding dense>\n {sortEntities(r.entities).map(entity => {\n return (\n <ListItem\n key={stringifyEntityRef(entity)}\n className={classes.nested}\n {...(withLinks\n ? {\n component: EntityRefLink,\n entityRef: entity,\n button: withLinks as any,\n }\n : {})}\n >\n <ListItemText\n primary={<EntityDisplayName entityRef={entity} />}\n />\n </ListItem>\n );\n })}\n </List>\n </Collapse>\n </React.Fragment>\n ))}\n </List>\n );\n};\n"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AQ,EAAA,MAAA;AAAA,MACR,aAAa,EAAA,IAAA;AAAA,KAAA;AAAA,oBAEZ,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,SAAU,EAAA,KAAA,EAAM,cAAc,EAAA,IAAA,EAAC,KAAK,EAAA,IAAA,EAAA,EACvC,YAAa,CAAA,CAAA,CAAE,QAAQ,CAAA,CAAE,IAAI,CAAU,MAAA,KAAA;AACtC,MACE,uBAAA,KAAA,CAAA,aAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,GAAA,EAAK,mBAAmB,MAAM,CAAA;AAAA,UAC9B,WAAW,OAAQ,CAAA,MAAA;AAAA,UAClB,GAAI,SACD,GAAA;AAAA,YACE,SAAW,EAAA,aAAA;AAAA,YACX,SAAW,EAAA,MAAA;AAAA,YACX,MAAQ,EAAA,SAAA;AAAA,cAEV,EAAC;AAAA,SAAA;AAAA,wBAEL,KAAA,CAAA,aAAA;AAAA,UAAC,YAAA;AAAA,UAAA;AAAA,YACC,OAAS,kBAAA,KAAA,CAAA,aAAA,CAAC,iBAAkB,EAAA,EAAA,SAAA,EAAW,MAAQ,EAAA,CAAA;AAAA,WAAA;AAAA,SACjD;AAAA,OACF,CAAA;AAAA,KAEH,CACH,CAAA;AAAA,GAEJ,CACD,CACH,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -11,7 +11,6 @@ import { entityRouteRef } from '@backstage/plugin-catalog-react';
|
|
|
11
11
|
import { useRouteRef } from '@backstage/core-plugin-api';
|
|
12
12
|
|
|
13
13
|
const filterComponentEntity = (newLocations) => {
|
|
14
|
-
var _a, _b;
|
|
15
14
|
for (const location of newLocations) {
|
|
16
15
|
for (const entity of location.entities) {
|
|
17
16
|
if (["component", "api", "resource"].includes(
|
|
@@ -19,7 +18,7 @@ const filterComponentEntity = (newLocations) => {
|
|
|
19
18
|
)) {
|
|
20
19
|
return {
|
|
21
20
|
kind: entity.kind.toLocaleLowerCase("en-US"),
|
|
22
|
-
namespace:
|
|
21
|
+
namespace: entity.namespace?.toLocaleLowerCase("en-US") ?? DEFAULT_NAMESPACE,
|
|
23
22
|
name: entity.name
|
|
24
23
|
};
|
|
25
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepFinishImportLocation.esm.js","sources":["../../../src/components/StepFinishImportLocation/StepFinishImportLocation.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 Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport LocationOnIcon from '@material-ui/icons/LocationOn';\nimport React from 'react';\nimport { BackButton, ViewComponentButton } from '../Buttons';\nimport { EntityListComponent } from '../EntityListComponent';\nimport { PrepareResult } from '../useImportState';\nimport { Link } from '@backstage/core-components';\nimport partition from 'lodash/partition';\nimport { CompoundEntityRef, DEFAULT_NAMESPACE } from '@backstage/catalog-model';\nimport { entityRouteRef } from '@backstage/plugin-catalog-react';\nimport { useRouteRef } from '@backstage/core-plugin-api';\n\ntype Props = {\n prepareResult: PrepareResult;\n onReset: () => void;\n};\n\n// Among the newly registered entities, return a software entity (e.g. Component, API, Resource)\nconst filterComponentEntity = (\n newLocations: Array<{\n exists?: boolean;\n target: string;\n entities: CompoundEntityRef[];\n }>,\n): CompoundEntityRef | null => {\n for (const location of newLocations) {\n for (const entity of location.entities) {\n if (\n ['component', 'api', 'resource'].includes(\n entity.kind.toLocaleLowerCase('en-US'),\n )\n ) {\n return {\n kind: entity.kind.toLocaleLowerCase('en-US'),\n namespace:\n entity.namespace?.toLocaleLowerCase('en-US') ?? DEFAULT_NAMESPACE,\n name: entity.name,\n };\n }\n }\n }\n\n return null;\n};\n\nexport const StepFinishImportLocation = ({ prepareResult, onReset }: Props) => {\n const entityRoute = useRouteRef(entityRouteRef);\n\n if (prepareResult.type === 'repository') {\n return (\n <>\n <Typography paragraph>\n The following Pull Request has been opened:{' '}\n <Link\n to={prepareResult.pullRequest.url}\n target=\"_blank\"\n rel=\"noreferrer\"\n >\n {prepareResult.pullRequest.url}\n </Link>\n </Typography>\n <Typography paragraph>\n Your entities will be imported as soon as the Pull Request is merged.\n </Typography>\n <Grid container spacing={0}>\n <BackButton onClick={onReset}>Register another</BackButton>\n </Grid>\n </>\n );\n }\n\n const [existingLocations, newLocations] = partition(\n prepareResult.locations,\n l => l.exists,\n );\n const newComponentEntity = filterComponentEntity(newLocations);\n return (\n <>\n {newLocations.length > 0 && (\n <>\n <Typography>\n The following entities have been added to the catalog:\n </Typography>\n\n <EntityListComponent\n locations={newLocations}\n locationListItemIcon={() => <LocationOnIcon />}\n withLinks\n />\n </>\n )}\n {existingLocations.length > 0 && (\n <>\n <Typography>\n A refresh was triggered for the following locations:\n </Typography>\n\n <EntityListComponent\n locations={existingLocations}\n locationListItemIcon={() => <LocationOnIcon />}\n withLinks\n />\n </>\n )}\n <Grid container spacing={0}>\n {newComponentEntity && (\n <ViewComponentButton to={entityRoute(newComponentEntity)}>\n View Component\n </ViewComponentButton>\n )}\n <BackButton onClick={onReset}>Register another</BackButton>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAmCA,MAAM,qBAAA,GAAwB,CAC5B,YAK6B,KAAA;
|
|
1
|
+
{"version":3,"file":"StepFinishImportLocation.esm.js","sources":["../../../src/components/StepFinishImportLocation/StepFinishImportLocation.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 Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport LocationOnIcon from '@material-ui/icons/LocationOn';\nimport React from 'react';\nimport { BackButton, ViewComponentButton } from '../Buttons';\nimport { EntityListComponent } from '../EntityListComponent';\nimport { PrepareResult } from '../useImportState';\nimport { Link } from '@backstage/core-components';\nimport partition from 'lodash/partition';\nimport { CompoundEntityRef, DEFAULT_NAMESPACE } from '@backstage/catalog-model';\nimport { entityRouteRef } from '@backstage/plugin-catalog-react';\nimport { useRouteRef } from '@backstage/core-plugin-api';\n\ntype Props = {\n prepareResult: PrepareResult;\n onReset: () => void;\n};\n\n// Among the newly registered entities, return a software entity (e.g. Component, API, Resource)\nconst filterComponentEntity = (\n newLocations: Array<{\n exists?: boolean;\n target: string;\n entities: CompoundEntityRef[];\n }>,\n): CompoundEntityRef | null => {\n for (const location of newLocations) {\n for (const entity of location.entities) {\n if (\n ['component', 'api', 'resource'].includes(\n entity.kind.toLocaleLowerCase('en-US'),\n )\n ) {\n return {\n kind: entity.kind.toLocaleLowerCase('en-US'),\n namespace:\n entity.namespace?.toLocaleLowerCase('en-US') ?? DEFAULT_NAMESPACE,\n name: entity.name,\n };\n }\n }\n }\n\n return null;\n};\n\nexport const StepFinishImportLocation = ({ prepareResult, onReset }: Props) => {\n const entityRoute = useRouteRef(entityRouteRef);\n\n if (prepareResult.type === 'repository') {\n return (\n <>\n <Typography paragraph>\n The following Pull Request has been opened:{' '}\n <Link\n to={prepareResult.pullRequest.url}\n target=\"_blank\"\n rel=\"noreferrer\"\n >\n {prepareResult.pullRequest.url}\n </Link>\n </Typography>\n <Typography paragraph>\n Your entities will be imported as soon as the Pull Request is merged.\n </Typography>\n <Grid container spacing={0}>\n <BackButton onClick={onReset}>Register another</BackButton>\n </Grid>\n </>\n );\n }\n\n const [existingLocations, newLocations] = partition(\n prepareResult.locations,\n l => l.exists,\n );\n const newComponentEntity = filterComponentEntity(newLocations);\n return (\n <>\n {newLocations.length > 0 && (\n <>\n <Typography>\n The following entities have been added to the catalog:\n </Typography>\n\n <EntityListComponent\n locations={newLocations}\n locationListItemIcon={() => <LocationOnIcon />}\n withLinks\n />\n </>\n )}\n {existingLocations.length > 0 && (\n <>\n <Typography>\n A refresh was triggered for the following locations:\n </Typography>\n\n <EntityListComponent\n locations={existingLocations}\n locationListItemIcon={() => <LocationOnIcon />}\n withLinks\n />\n </>\n )}\n <Grid container spacing={0}>\n {newComponentEntity && (\n <ViewComponentButton to={entityRoute(newComponentEntity)}>\n View Component\n </ViewComponentButton>\n )}\n <BackButton onClick={onReset}>Register another</BackButton>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAmCA,MAAM,qBAAA,GAAwB,CAC5B,YAK6B,KAAA;AAC7B,EAAA,KAAA,MAAW,YAAY,YAAc,EAAA;AACnC,IAAW,KAAA,MAAA,MAAA,IAAU,SAAS,QAAU,EAAA;AACtC,MAAA,IACE,CAAC,WAAA,EAAa,KAAO,EAAA,UAAU,CAAE,CAAA,QAAA;AAAA,QAC/B,MAAA,CAAO,IAAK,CAAA,iBAAA,CAAkB,OAAO,CAAA;AAAA,OAEvC,EAAA;AACA,QAAO,OAAA;AAAA,UACL,IAAM,EAAA,MAAA,CAAO,IAAK,CAAA,iBAAA,CAAkB,OAAO,CAAA;AAAA,UAC3C,SACE,EAAA,MAAA,CAAO,SAAW,EAAA,iBAAA,CAAkB,OAAO,CAAK,IAAA,iBAAA;AAAA,UAClD,MAAM,MAAO,CAAA,IAAA;AAAA,SACf,CAAA;AAAA,OACF;AAAA,KACF;AAAA,GACF;AAEA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA,CAAA;AAEO,MAAM,wBAA2B,GAAA,CAAC,EAAE,aAAA,EAAe,SAAqB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C,cAAe,EAAA,IAAA,CAAA;AAAA,MAC5C,SAAS,EAAA,IAAA;AAAA,KAAA;AAAA,GAEb,GAED,iBAAkB,CAAA,MAAA,GAAS,qBAExB,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,UAAW,EAAA,IAAA,EAAA,sDAEZ,CAEA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,mBAAA;AAAA,IAAA;AAAA,MACC,SAAW,EAAA,iBAAA;AAAA,MACX,oBAAA,EAAsB,sBAAM,KAAA,CAAA,aAAA,CAAC,cAAe,EAAA,IAAA,CAAA;AAAA,MAC5C,SAAS,EAAA,IAAA;AAAA,KAAA;AAAA,GAEb,mBAED,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,WAAS,IAAC,EAAA,OAAA,EAAS,CACtB,EAAA,EAAA,kBAAA,oBACE,KAAA,CAAA,aAAA,CAAA,mBAAA,EAAA,EAAoB,IAAI,WAAY,CAAA,kBAAkB,CAAG,EAAA,EAAA,gBAE1D,CAEF,kBAAA,KAAA,CAAA,aAAA,CAAC,cAAW,OAAS,EAAA,OAAA,EAAA,EAAS,kBAAgB,CAChD,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -36,7 +36,6 @@ const StepInitAnalyzeUrl = (props) => {
|
|
|
36
36
|
const [error, setError] = useState(void 0);
|
|
37
37
|
const handleResult = useCallback(
|
|
38
38
|
async ({ url }) => {
|
|
39
|
-
var _a, _b, _c;
|
|
40
39
|
setSubmitted(true);
|
|
41
40
|
try {
|
|
42
41
|
const analysisResult = await catalogImportApi.analyzeUrl(url);
|
|
@@ -71,7 +70,7 @@ const StepInitAnalyzeUrl = (props) => {
|
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
} catch (e) {
|
|
74
|
-
setError(
|
|
73
|
+
setError(e?.data?.error?.message ?? e.message);
|
|
75
74
|
setSubmitted(false);
|
|
76
75
|
}
|
|
77
76
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepInitAnalyzeUrl.esm.js","sources":["../../../src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.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 { errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport TextField from '@material-ui/core/TextField';\nimport React, { useCallback, useState } from 'react';\nimport { useForm } from 'react-hook-form';\nimport { AnalyzeResult, catalogImportApiRef } from '../../api';\nimport { NextButton } from '../Buttons';\nimport { asInputRef } from '../helpers';\nimport { ImportFlows, PrepareResult } from '../useImportState';\n\ntype FormData = {\n url: string;\n};\n\n/**\n * Props for {@link StepInitAnalyzeUrl}.\n *\n * @public\n */\nexport interface StepInitAnalyzeUrlProps {\n onAnalysis: (\n flow: ImportFlows,\n url: string,\n result: AnalyzeResult,\n opts?: { prepareResult?: PrepareResult },\n ) => void;\n disablePullRequest?: boolean;\n analysisUrl?: string;\n exampleLocationUrl?: string;\n}\n\n/**\n * A form that lets the user input a url and analyze it for existing locations or potential entities.\n *\n * @param onAnalysis - is called when the analysis was successful\n * @param analysisUrl - a url that can be used as a default value\n * @param disablePullRequest - if true, repositories without entities will abort the wizard\n * @public\n */\nexport const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => {\n const {\n onAnalysis,\n analysisUrl = '',\n disablePullRequest = false,\n exampleLocationUrl = 'https://github.com/backstage/backstage/blob/master/catalog-info.yaml',\n } = props;\n\n const errorApi = useApi(errorApiRef);\n const catalogImportApi = useApi(catalogImportApiRef);\n\n const {\n register,\n handleSubmit,\n formState: { errors },\n watch,\n } = useForm<FormData>({\n mode: 'onTouched',\n defaultValues: {\n url: analysisUrl,\n },\n });\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string | undefined>(undefined);\n\n const handleResult = useCallback(\n async ({ url }: FormData) => {\n setSubmitted(true);\n\n try {\n const analysisResult = await catalogImportApi.analyzeUrl(url);\n\n switch (analysisResult.type) {\n case 'repository':\n if (\n !disablePullRequest &&\n analysisResult.generatedEntities.length > 0\n ) {\n onAnalysis('no-location', url, analysisResult);\n } else {\n setError(\"Couldn't generate entities for your repository\");\n setSubmitted(false);\n }\n break;\n\n case 'locations': {\n if (analysisResult.locations.length === 1) {\n onAnalysis('single-location', url, analysisResult, {\n prepareResult: analysisResult,\n });\n } else if (analysisResult.locations.length > 1) {\n onAnalysis('multiple-locations', url, analysisResult);\n } else {\n setError('There are no entities at this location');\n setSubmitted(false);\n }\n break;\n }\n\n default: {\n const err = `Received unknown analysis result of type ${\n (analysisResult as any).type\n }. Please contact the support team.`;\n setError(err);\n setSubmitted(false);\n\n errorApi.post(new Error(err));\n break;\n }\n }\n } catch (e: any) {\n setError(e?.data?.error?.message ?? e.message);\n setSubmitted(false);\n }\n },\n [catalogImportApi, disablePullRequest, errorApi, onAnalysis],\n );\n\n return (\n <form onSubmit={handleSubmit(handleResult)}>\n <TextField\n {...asInputRef(\n register('url', {\n required: true,\n validate: {\n httpsValidator: (value: any) =>\n (typeof value === 'string' &&\n value.match(/^http[s]?:\\/\\//) !== null) ||\n 'Must start with http:// or https://.',\n },\n }),\n )}\n fullWidth\n id=\"url\"\n label=\"URL\"\n placeholder={exampleLocationUrl}\n helperText=\"Enter the full path to your entity file to start tracking your component\"\n margin=\"normal\"\n variant=\"outlined\"\n error={Boolean(errors.url)}\n required\n />\n\n {errors.url && (\n <FormHelperText error>{errors.url.message}</FormHelperText>\n )}\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n <NextButton\n disabled={Boolean(errors.url) || !watch('url')}\n loading={submitted}\n type=\"submit\"\n >\n Analyze\n </NextButton>\n </Grid>\n </form>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAwDa,MAAA,kBAAA,GAAqB,CAAC,KAAmC,KAAA;AACpE,EAAM,MAAA;AAAA,IACJ,UAAA;AAAA,IACA,WAAc,GAAA,EAAA;AAAA,IACd,kBAAqB,GAAA,KAAA;AAAA,IACrB,kBAAqB,GAAA,sEAAA;AAAA,GACnB,GAAA,KAAA,CAAA;AAEJ,EAAM,MAAA,QAAA,GAAW,OAAO,WAAW,CAAA,CAAA;AACnC,EAAM,MAAA,gBAAA,GAAmB,OAAO,mBAAmB,CAAA,CAAA;AAEnD,EAAM,MAAA;AAAA,IACJ,QAAA;AAAA,IACA,YAAA;AAAA,IACA,SAAA,EAAW,EAAE,MAAO,EAAA;AAAA,IACpB,KAAA;AAAA,MACE,OAAkB,CAAA;AAAA,IACpB,IAAM,EAAA,WAAA;AAAA,IACN,aAAe,EAAA;AAAA,MACb,GAAK,EAAA,WAAA;AAAA,KACP;AAAA,GACD,CAAA,CAAA;AAED,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAChD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA6B,KAAS,CAAA,CAAA,CAAA;AAEhE,EAAA,MAAM,YAAe,GAAA,WAAA;AAAA,IACnB,OAAO,EAAE,GAAA,EAAoB,KAAA;
|
|
1
|
+
{"version":3,"file":"StepInitAnalyzeUrl.esm.js","sources":["../../../src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.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 { errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport TextField from '@material-ui/core/TextField';\nimport React, { useCallback, useState } from 'react';\nimport { useForm } from 'react-hook-form';\nimport { AnalyzeResult, catalogImportApiRef } from '../../api';\nimport { NextButton } from '../Buttons';\nimport { asInputRef } from '../helpers';\nimport { ImportFlows, PrepareResult } from '../useImportState';\n\ntype FormData = {\n url: string;\n};\n\n/**\n * Props for {@link StepInitAnalyzeUrl}.\n *\n * @public\n */\nexport interface StepInitAnalyzeUrlProps {\n onAnalysis: (\n flow: ImportFlows,\n url: string,\n result: AnalyzeResult,\n opts?: { prepareResult?: PrepareResult },\n ) => void;\n disablePullRequest?: boolean;\n analysisUrl?: string;\n exampleLocationUrl?: string;\n}\n\n/**\n * A form that lets the user input a url and analyze it for existing locations or potential entities.\n *\n * @param onAnalysis - is called when the analysis was successful\n * @param analysisUrl - a url that can be used as a default value\n * @param disablePullRequest - if true, repositories without entities will abort the wizard\n * @public\n */\nexport const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => {\n const {\n onAnalysis,\n analysisUrl = '',\n disablePullRequest = false,\n exampleLocationUrl = 'https://github.com/backstage/backstage/blob/master/catalog-info.yaml',\n } = props;\n\n const errorApi = useApi(errorApiRef);\n const catalogImportApi = useApi(catalogImportApiRef);\n\n const {\n register,\n handleSubmit,\n formState: { errors },\n watch,\n } = useForm<FormData>({\n mode: 'onTouched',\n defaultValues: {\n url: analysisUrl,\n },\n });\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string | undefined>(undefined);\n\n const handleResult = useCallback(\n async ({ url }: FormData) => {\n setSubmitted(true);\n\n try {\n const analysisResult = await catalogImportApi.analyzeUrl(url);\n\n switch (analysisResult.type) {\n case 'repository':\n if (\n !disablePullRequest &&\n analysisResult.generatedEntities.length > 0\n ) {\n onAnalysis('no-location', url, analysisResult);\n } else {\n setError(\"Couldn't generate entities for your repository\");\n setSubmitted(false);\n }\n break;\n\n case 'locations': {\n if (analysisResult.locations.length === 1) {\n onAnalysis('single-location', url, analysisResult, {\n prepareResult: analysisResult,\n });\n } else if (analysisResult.locations.length > 1) {\n onAnalysis('multiple-locations', url, analysisResult);\n } else {\n setError('There are no entities at this location');\n setSubmitted(false);\n }\n break;\n }\n\n default: {\n const err = `Received unknown analysis result of type ${\n (analysisResult as any).type\n }. Please contact the support team.`;\n setError(err);\n setSubmitted(false);\n\n errorApi.post(new Error(err));\n break;\n }\n }\n } catch (e: any) {\n setError(e?.data?.error?.message ?? e.message);\n setSubmitted(false);\n }\n },\n [catalogImportApi, disablePullRequest, errorApi, onAnalysis],\n );\n\n return (\n <form onSubmit={handleSubmit(handleResult)}>\n <TextField\n {...asInputRef(\n register('url', {\n required: true,\n validate: {\n httpsValidator: (value: any) =>\n (typeof value === 'string' &&\n value.match(/^http[s]?:\\/\\//) !== null) ||\n 'Must start with http:// or https://.',\n },\n }),\n )}\n fullWidth\n id=\"url\"\n label=\"URL\"\n placeholder={exampleLocationUrl}\n helperText=\"Enter the full path to your entity file to start tracking your component\"\n margin=\"normal\"\n variant=\"outlined\"\n error={Boolean(errors.url)}\n required\n />\n\n {errors.url && (\n <FormHelperText error>{errors.url.message}</FormHelperText>\n )}\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n <NextButton\n disabled={Boolean(errors.url) || !watch('url')}\n loading={submitted}\n type=\"submit\"\n >\n Analyze\n </NextButton>\n </Grid>\n </form>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAwDa,MAAA,kBAAA,GAAqB,CAAC,KAAmC,KAAA;AACpE,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|
|
36
36
|
{
|
|
37
37
|
...params,
|
|
38
|
-
helperText:
|
|
39
|
-
error: Boolean(errors
|
|
38
|
+
helperText: errors?.[name] && errorHelperText || helperText,
|
|
39
|
+
error: Boolean(errors?.[name]),
|
|
40
40
|
margin: "normal",
|
|
41
41
|
variant: "outlined",
|
|
42
42
|
required,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteTextField.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/AutocompleteTextField.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 CircularProgress from '@material-ui/core/CircularProgress';\nimport TextField from '@material-ui/core/TextField';\nimport { TextFieldProps } from '@material-ui/core/TextField/TextField';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport React from 'react';\nimport { Controller, FieldErrors } from 'react-hook-form';\n\n/**\n * Props for {@link AutocompleteTextField}.\n *\n * @public\n */\nexport interface AutocompleteTextFieldProps<TFieldValue extends string> {\n name: TFieldValue;\n options: string[];\n required?: boolean;\n\n errors?: FieldErrors;\n rules?: React.ComponentProps<typeof Controller>['rules'];\n\n loading?: boolean;\n loadingText?: string;\n\n helperText?: React.ReactNode;\n errorHelperText?: string;\n\n textFieldProps?: Omit<TextFieldProps, 'required' | 'fullWidth'>;\n}\n\n/**\n * An autocompletion text field for the catalog import flows.\n *\n * @public\n */\nexport const AutocompleteTextField = <TFieldValue extends string>(\n props: AutocompleteTextFieldProps<TFieldValue>,\n) => {\n const {\n name,\n options,\n required,\n errors,\n rules,\n loading = false,\n loadingText,\n helperText,\n errorHelperText,\n textFieldProps = {},\n } = props;\n\n return (\n <Controller\n name={name}\n rules={rules}\n render={({ field: { onChange } }) => (\n <Autocomplete\n loading={loading}\n loadingText={loadingText}\n options={options || []}\n autoSelect\n freeSolo\n onChange={(_event: React.ChangeEvent<{}>, value: string | null) =>\n onChange(value)\n }\n renderInput={params => (\n <TextField\n {...params}\n helperText={(errors?.[name] && errorHelperText) || helperText}\n error={Boolean(errors?.[name])}\n margin=\"normal\"\n variant=\"outlined\"\n required={required}\n InputProps={{\n ...params.InputProps,\n endAdornment: (\n <React.Fragment>\n {loading ? (\n <CircularProgress color=\"inherit\" size=\"1em\" />\n ) : null}\n {params.InputProps.endAdornment}\n </React.Fragment>\n ),\n }}\n {...textFieldProps}\n />\n )}\n />\n )}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AAkDa,MAAA,qBAAA,GAAwB,CACnC,KACG,KAAA;AACH,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,OAAU,GAAA,KAAA;AAAA,IACV,WAAA;AAAA,IACA,UAAA;AAAA,IACA,eAAA;AAAA,IACA,iBAAiB,EAAC;AAAA,GAChB,GAAA,KAAA,CAAA;AAEJ,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,IAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAA,IAClB,qBAAA,KAAA,CAAA,aAAA;AAAA,QAAC,YAAA;AAAA,QAAA;AAAA,UACC,OAAA;AAAA,UACA,WAAA;AAAA,UACA,OAAA,EAAS,WAAW,EAAC;AAAA,UACrB,UAAU,EAAA,IAAA;AAAA,UACV,QAAQ,EAAA,IAAA;AAAA,UACR,QAAU,EAAA,CAAC,MAA+B,EAAA,KAAA,KACxC,SAAS,KAAK,CAAA;AAAA,UAEhB,aAAa,CACX,MAAA,qBAAA,KAAA,CAAA,aAAA;AAAA,YAAC,SAAA;AAAA,YAAA;AAAA,cACE,GAAG,MAAA;AAAA,cACJ,
|
|
1
|
+
{"version":3,"file":"AutocompleteTextField.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/AutocompleteTextField.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 CircularProgress from '@material-ui/core/CircularProgress';\nimport TextField from '@material-ui/core/TextField';\nimport { TextFieldProps } from '@material-ui/core/TextField/TextField';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport React from 'react';\nimport { Controller, FieldErrors } from 'react-hook-form';\n\n/**\n * Props for {@link AutocompleteTextField}.\n *\n * @public\n */\nexport interface AutocompleteTextFieldProps<TFieldValue extends string> {\n name: TFieldValue;\n options: string[];\n required?: boolean;\n\n errors?: FieldErrors;\n rules?: React.ComponentProps<typeof Controller>['rules'];\n\n loading?: boolean;\n loadingText?: string;\n\n helperText?: React.ReactNode;\n errorHelperText?: string;\n\n textFieldProps?: Omit<TextFieldProps, 'required' | 'fullWidth'>;\n}\n\n/**\n * An autocompletion text field for the catalog import flows.\n *\n * @public\n */\nexport const AutocompleteTextField = <TFieldValue extends string>(\n props: AutocompleteTextFieldProps<TFieldValue>,\n) => {\n const {\n name,\n options,\n required,\n errors,\n rules,\n loading = false,\n loadingText,\n helperText,\n errorHelperText,\n textFieldProps = {},\n } = props;\n\n return (\n <Controller\n name={name}\n rules={rules}\n render={({ field: { onChange } }) => (\n <Autocomplete\n loading={loading}\n loadingText={loadingText}\n options={options || []}\n autoSelect\n freeSolo\n onChange={(_event: React.ChangeEvent<{}>, value: string | null) =>\n onChange(value)\n }\n renderInput={params => (\n <TextField\n {...params}\n helperText={(errors?.[name] && errorHelperText) || helperText}\n error={Boolean(errors?.[name])}\n margin=\"normal\"\n variant=\"outlined\"\n required={required}\n InputProps={{\n ...params.InputProps,\n endAdornment: (\n <React.Fragment>\n {loading ? (\n <CircularProgress color=\"inherit\" size=\"1em\" />\n ) : null}\n {params.InputProps.endAdornment}\n </React.Fragment>\n ),\n }}\n {...textFieldProps}\n />\n )}\n />\n )}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AAkDa,MAAA,qBAAA,GAAwB,CACnC,KACG,KAAA;AACH,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,OAAU,GAAA,KAAA;AAAA,IACV,WAAA;AAAA,IACA,UAAA;AAAA,IACA,eAAA;AAAA,IACA,iBAAiB,EAAC;AAAA,GAChB,GAAA,KAAA,CAAA;AAEJ,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,IAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAA,IAClB,qBAAA,KAAA,CAAA,aAAA;AAAA,QAAC,YAAA;AAAA,QAAA;AAAA,UACC,OAAA;AAAA,UACA,WAAA;AAAA,UACA,OAAA,EAAS,WAAW,EAAC;AAAA,UACrB,UAAU,EAAA,IAAA;AAAA,UACV,QAAQ,EAAA,IAAA;AAAA,UACR,QAAU,EAAA,CAAC,MAA+B,EAAA,KAAA,KACxC,SAAS,KAAK,CAAA;AAAA,UAEhB,aAAa,CACX,MAAA,qBAAA,KAAA,CAAA,aAAA;AAAA,YAAC,SAAA;AAAA,YAAA;AAAA,cACE,GAAG,MAAA;AAAA,cACJ,UAAa,EAAA,MAAA,GAAS,IAAI,CAAA,IAAK,eAAoB,IAAA,UAAA;AAAA,cACnD,KAAO,EAAA,OAAA,CAAQ,MAAS,GAAA,IAAI,CAAC,CAAA;AAAA,cAC7B,MAAO,EAAA,QAAA;AAAA,cACP,OAAQ,EAAA,UAAA;AAAA,cACR,QAAA;AAAA,cACA,UAAY,EAAA;AAAA,gBACV,GAAG,MAAO,CAAA,UAAA;AAAA,gBACV,8BACG,KAAA,CAAA,aAAA,CAAA,KAAA,CAAM,QAAN,EAAA,IAAA,EACE,0BACE,KAAA,CAAA,aAAA,CAAA,gBAAA,EAAA,EAAiB,KAAM,EAAA,SAAA,EAAU,MAAK,KAAM,EAAA,CAAA,GAC3C,IACH,EAAA,MAAA,CAAO,WAAW,YACrB,CAAA;AAAA,eAEJ;AAAA,cACC,GAAG,cAAA;AAAA,aAAA;AAAA,WACN;AAAA,SAAA;AAAA,OAEJ;AAAA,KAAA;AAAA,GAEJ,CAAA;AAEJ;;;;"}
|
|
@@ -10,12 +10,12 @@ import { useCatalogFilename } from '../../hooks/useCatalogFilename.esm.js';
|
|
|
10
10
|
const PreviewCatalogInfoComponent = (props) => {
|
|
11
11
|
const { repositoryUrl, entities, classes } = props;
|
|
12
12
|
const catalogFilename = useCatalogFilename();
|
|
13
|
-
return /* @__PURE__ */ React.createElement(Card, { variant: "outlined", className: classes
|
|
13
|
+
return /* @__PURE__ */ React.createElement(Card, { variant: "outlined", className: classes?.card }, /* @__PURE__ */ React.createElement(
|
|
14
14
|
CardHeader,
|
|
15
15
|
{
|
|
16
16
|
title: /* @__PURE__ */ React.createElement("code", null, `${trimEnd(repositoryUrl, "/")}/${catalogFilename}`)
|
|
17
17
|
}
|
|
18
|
-
), /* @__PURE__ */ React.createElement(CardContent, { className: classes
|
|
18
|
+
), /* @__PURE__ */ React.createElement(CardContent, { className: classes?.cardContent }, /* @__PURE__ */ React.createElement(
|
|
19
19
|
CodeSnippet,
|
|
20
20
|
{
|
|
21
21
|
text: entities.map((e) => YAML.stringify(e)).join("---\n").trim(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewCatalogInfoComponent.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.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 { Entity } from '@backstage/catalog-model';\nimport Card from '@material-ui/core/Card';\nimport CardContent from '@material-ui/core/CardContent';\nimport CardHeader from '@material-ui/core/CardHeader';\nimport React from 'react';\nimport YAML from 'yaml';\nimport { CodeSnippet } from '@backstage/core-components';\nimport { trimEnd } from 'lodash';\nimport { useCatalogFilename } from '../../hooks';\n\n/**\n * Props for {@link PreviewCatalogInfoComponent}.\n *\n * @public\n */\nexport interface PreviewCatalogInfoComponentProps {\n repositoryUrl: string;\n entities: Entity[];\n classes?: { card?: string; cardContent?: string };\n}\n\n/**\n * Previews information about an entity to create.\n *\n * @public\n */\nexport const PreviewCatalogInfoComponent = (\n props: PreviewCatalogInfoComponentProps,\n) => {\n const { repositoryUrl, entities, classes } = props;\n const catalogFilename = useCatalogFilename();\n\n return (\n <Card variant=\"outlined\" className={classes?.card}>\n <CardHeader\n title={\n <code>{`${trimEnd(repositoryUrl, '/')}/${catalogFilename}`}</code>\n }\n />\n\n <CardContent className={classes?.cardContent}>\n <CodeSnippet\n text={entities\n .map(e => YAML.stringify(e))\n .join('---\\n')\n .trim()}\n language=\"yaml\"\n />\n </CardContent>\n </Card>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AA0Ca,MAAA,2BAAA,GAA8B,CACzC,KACG,KAAA;AACH,EAAA,MAAM,EAAE,aAAA,EAAe,QAAU,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAC7C,EAAA,MAAM,kBAAkB,kBAAmB,EAAA,CAAA;AAE3C,EAAA,2CACG,IAAK,EAAA,EAAA,OAAA,EAAQ,UAAW,EAAA,SAAA,EAAW,
|
|
1
|
+
{"version":3,"file":"PreviewCatalogInfoComponent.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.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 { Entity } from '@backstage/catalog-model';\nimport Card from '@material-ui/core/Card';\nimport CardContent from '@material-ui/core/CardContent';\nimport CardHeader from '@material-ui/core/CardHeader';\nimport React from 'react';\nimport YAML from 'yaml';\nimport { CodeSnippet } from '@backstage/core-components';\nimport { trimEnd } from 'lodash';\nimport { useCatalogFilename } from '../../hooks';\n\n/**\n * Props for {@link PreviewCatalogInfoComponent}.\n *\n * @public\n */\nexport interface PreviewCatalogInfoComponentProps {\n repositoryUrl: string;\n entities: Entity[];\n classes?: { card?: string; cardContent?: string };\n}\n\n/**\n * Previews information about an entity to create.\n *\n * @public\n */\nexport const PreviewCatalogInfoComponent = (\n props: PreviewCatalogInfoComponentProps,\n) => {\n const { repositoryUrl, entities, classes } = props;\n const catalogFilename = useCatalogFilename();\n\n return (\n <Card variant=\"outlined\" className={classes?.card}>\n <CardHeader\n title={\n <code>{`${trimEnd(repositoryUrl, '/')}/${catalogFilename}`}</code>\n }\n />\n\n <CardContent className={classes?.cardContent}>\n <CodeSnippet\n text={entities\n .map(e => YAML.stringify(e))\n .join('---\\n')\n .trim()}\n language=\"yaml\"\n />\n </CardContent>\n </Card>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AA0Ca,MAAA,2BAAA,GAA8B,CACzC,KACG,KAAA;AACH,EAAA,MAAM,EAAE,aAAA,EAAe,QAAU,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAC7C,EAAA,MAAM,kBAAkB,kBAAmB,EAAA,CAAA;AAE3C,EAAA,2CACG,IAAK,EAAA,EAAA,OAAA,EAAQ,UAAW,EAAA,SAAA,EAAW,SAAS,IAC3C,EAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAA,kBACG,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA,IAAA,EAAM,CAAG,EAAA,OAAA,CAAQ,eAAe,GAAG,CAAC,CAAI,CAAA,EAAA,eAAe,CAAG,CAAA,CAAA;AAAA,KAAA;AAAA,GAI/D,kBAAA,KAAA,CAAA,aAAA,CAAC,WAAY,EAAA,EAAA,SAAA,EAAW,SAAS,WAC/B,EAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,IAAM,EAAA,QAAA,CACH,GAAI,CAAA,CAAA,CAAA,KAAK,IAAK,CAAA,SAAA,CAAU,CAAC,CAAC,CAC1B,CAAA,IAAA,CAAK,OAAO,CAAA,CACZ,IAAK,EAAA;AAAA,MACR,QAAS,EAAA,MAAA;AAAA,KAAA;AAAA,GAEb,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -6,7 +6,7 @@ import { MarkdownContent } from '@backstage/core-components';
|
|
|
6
6
|
|
|
7
7
|
const PreviewPullRequestComponent = (props) => {
|
|
8
8
|
const { title, description, classes } = props;
|
|
9
|
-
return /* @__PURE__ */ React.createElement(Card, { variant: "outlined", className: classes
|
|
9
|
+
return /* @__PURE__ */ React.createElement(Card, { variant: "outlined", className: classes?.card }, /* @__PURE__ */ React.createElement(CardHeader, { title, subheader: "Create a new Pull Request" }), /* @__PURE__ */ React.createElement(CardContent, { className: classes?.cardContent }, /* @__PURE__ */ React.createElement(MarkdownContent, { content: description })));
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export { PreviewPullRequestComponent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewPullRequestComponent.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/PreviewPullRequestComponent.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 Card from '@material-ui/core/Card';\nimport CardContent from '@material-ui/core/CardContent';\nimport CardHeader from '@material-ui/core/CardHeader';\nimport React from 'react';\nimport { MarkdownContent } from '@backstage/core-components';\n\n/**\n * Props for {@link PreviewPullRequestComponent}.\n *\n * @public\n */\nexport interface PreviewPullRequestComponentProps {\n title: string;\n description: string;\n classes?: { card?: string; cardContent?: string };\n}\n\n/**\n * Previews a pull request.\n *\n * @public\n */\nexport const PreviewPullRequestComponent = (\n props: PreviewPullRequestComponentProps,\n) => {\n const { title, description, classes } = props;\n return (\n <Card variant=\"outlined\" className={classes?.card}>\n <CardHeader title={title} subheader=\"Create a new Pull Request\" />\n <CardContent className={classes?.cardContent}>\n <MarkdownContent content={description} />\n </CardContent>\n </Card>\n );\n};\n"],"names":[],"mappings":";;;;;;AAsCa,MAAA,2BAAA,GAA8B,CACzC,KACG,KAAA;AACH,EAAA,MAAM,EAAE,KAAA,EAAO,WAAa,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AACxC,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,QAAK,OAAQ,EAAA,UAAA,EAAW,WAAW,OAAS,
|
|
1
|
+
{"version":3,"file":"PreviewPullRequestComponent.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/PreviewPullRequestComponent.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 Card from '@material-ui/core/Card';\nimport CardContent from '@material-ui/core/CardContent';\nimport CardHeader from '@material-ui/core/CardHeader';\nimport React from 'react';\nimport { MarkdownContent } from '@backstage/core-components';\n\n/**\n * Props for {@link PreviewPullRequestComponent}.\n *\n * @public\n */\nexport interface PreviewPullRequestComponentProps {\n title: string;\n description: string;\n classes?: { card?: string; cardContent?: string };\n}\n\n/**\n * Previews a pull request.\n *\n * @public\n */\nexport const PreviewPullRequestComponent = (\n props: PreviewPullRequestComponentProps,\n) => {\n const { title, description, classes } = props;\n return (\n <Card variant=\"outlined\" className={classes?.card}>\n <CardHeader title={title} subheader=\"Create a new Pull Request\" />\n <CardContent className={classes?.cardContent}>\n <MarkdownContent content={description} />\n </CardContent>\n </Card>\n );\n};\n"],"names":[],"mappings":";;;;;;AAsCa,MAAA,2BAAA,GAA8B,CACzC,KACG,KAAA;AACH,EAAA,MAAM,EAAE,KAAA,EAAO,WAAa,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AACxC,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,QAAK,OAAQ,EAAA,UAAA,EAAW,WAAW,OAAS,EAAA,IAAA,EAAA,kBAC1C,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,KAAc,EAAA,SAAA,EAAU,6BAA4B,CAChE,kBAAA,KAAA,CAAA,aAAA,CAAC,WAAY,EAAA,EAAA,SAAA,EAAW,OAAS,EAAA,WAAA,EAAA,sCAC9B,eAAgB,EAAA,EAAA,OAAA,EAAS,WAAa,EAAA,CACzC,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -43,7 +43,6 @@ function generateEntities(entities, componentName, owner) {
|
|
|
43
43
|
}));
|
|
44
44
|
}
|
|
45
45
|
const StepPrepareCreatePullRequest = (props) => {
|
|
46
|
-
var _a, _b, _c, _d, _e, _f;
|
|
47
46
|
const { analyzeResult, onPrepare, onGoBack, renderFormFields } = props;
|
|
48
47
|
const classes = useStyles();
|
|
49
48
|
const catalogApi = useApi(catalogApiRef);
|
|
@@ -129,10 +128,10 @@ const StepPrepareCreatePullRequest = (props) => {
|
|
|
129
128
|
{
|
|
130
129
|
onSubmit: handleResult,
|
|
131
130
|
defaultValues: {
|
|
132
|
-
title:
|
|
133
|
-
body:
|
|
134
|
-
owner:
|
|
135
|
-
componentName:
|
|
131
|
+
title: prDefaults?.title ?? "",
|
|
132
|
+
body: prDefaults?.body ?? "",
|
|
133
|
+
owner: analyzeResult.generatedEntities[0]?.spec?.owner || "",
|
|
134
|
+
componentName: analyzeResult.generatedEntities[0]?.metadata?.name || "",
|
|
136
135
|
useCodeowners: false
|
|
137
136
|
},
|
|
138
137
|
render: ({ values, formState, register, setValue }) => /* @__PURE__ */ React.createElement(React.Fragment, null, renderFormFields({
|
|
@@ -140,7 +139,7 @@ const StepPrepareCreatePullRequest = (props) => {
|
|
|
140
139
|
formState,
|
|
141
140
|
register,
|
|
142
141
|
setValue,
|
|
143
|
-
groups: groups
|
|
142
|
+
groups: groups ?? [],
|
|
144
143
|
groupsLoading
|
|
145
144
|
}), /* @__PURE__ */ React.createElement(Box, { marginTop: 2 }, /* @__PURE__ */ React.createElement(Typography, { variant: "h6" }, "Preview Pull Request")), /* @__PURE__ */ React.createElement(
|
|
146
145
|
PreviewPullRequestComponent,
|
package/dist/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepPrepareCreatePullRequest.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.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 { Entity } from '@backstage/catalog-model';\nimport { errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport { assertError } from '@backstage/errors';\nimport {\n catalogApiRef,\n humanizeEntityRef,\n} from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport { UnpackNestedValue, UseFormReturn } from 'react-hook-form';\nimport useAsync from 'react-use/esm/useAsync';\nimport YAML from 'yaml';\nimport { AnalyzeResult, catalogImportApiRef } from '../../api';\nimport { useCatalogFilename } from '../../hooks';\nimport { PartialEntity } from '../../types';\nimport { BackButton, NextButton } from '../Buttons';\nimport { PrepareResult } from '../useImportState';\nimport { PreparePullRequestForm } from './PreparePullRequestForm';\nimport { PreviewCatalogInfoComponent } from './PreviewCatalogInfoComponent';\nimport { PreviewPullRequestComponent } from './PreviewPullRequestComponent';\n\nconst useStyles = makeStyles(theme => ({\n previewCard: {\n marginTop: theme.spacing(1),\n },\n previewCardContent: {\n paddingTop: 0,\n },\n}));\n\ntype FormData = {\n title: string;\n body: string;\n componentName: string;\n owner: string;\n useCodeowners: boolean;\n};\n\n/**\n * Props for {@link StepPrepareCreatePullRequest}.\n *\n * @public\n */\nexport interface StepPrepareCreatePullRequestProps {\n analyzeResult: Extract<AnalyzeResult, { type: 'repository' }>;\n onPrepare: (\n result: PrepareResult,\n opts?: { notRepeatable?: boolean },\n ) => void;\n onGoBack?: () => void;\n\n renderFormFields: (\n props: Pick<\n UseFormReturn<FormData>,\n 'register' | 'setValue' | 'formState'\n > & {\n values: UnpackNestedValue<FormData>;\n groups: string[];\n groupsLoading: boolean;\n },\n ) => React.ReactNode;\n}\n\nexport function generateEntities(\n entities: PartialEntity[],\n componentName: string,\n owner?: string,\n): Entity[] {\n return entities.map(e => ({\n ...e,\n apiVersion: e.apiVersion!,\n kind: e.kind!,\n metadata: {\n ...e.metadata,\n name: componentName,\n },\n spec: {\n ...e.spec,\n ...(owner ? { owner } : {}),\n },\n }));\n}\n\n/**\n * Prepares a pull request.\n *\n * @public\n */\nexport const StepPrepareCreatePullRequest = (\n props: StepPrepareCreatePullRequestProps,\n) => {\n const { analyzeResult, onPrepare, onGoBack, renderFormFields } = props;\n\n const classes = useStyles();\n const catalogApi = useApi(catalogApiRef);\n const catalogImportApi = useApi(catalogImportApiRef);\n const errorApi = useApi(errorApiRef);\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string>();\n\n const catalogFilename = useCatalogFilename();\n\n const {\n loading: prDefaultsLoading,\n value: prDefaults,\n error: prDefaultsError,\n } = useAsync(\n () => catalogImportApi.preparePullRequest!(),\n [catalogImportApi.preparePullRequest],\n );\n\n useEffect(() => {\n if (prDefaultsError) {\n errorApi.post(prDefaultsError);\n }\n }, [prDefaultsError, errorApi]);\n\n const { loading: groupsLoading, value: groups } = useAsync(async () => {\n const groupEntities = await catalogApi.getEntities({\n filter: { kind: 'group' },\n });\n\n return groupEntities.items\n .map(e => humanizeEntityRef(e, { defaultKind: 'group' }))\n .sort();\n });\n\n const handleResult = useCallback(\n async (data: FormData) => {\n setSubmitted(true);\n\n try {\n const pr = await catalogImportApi.submitPullRequest({\n repositoryUrl: analyzeResult.url,\n title: data.title,\n body: data.body,\n fileContent: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n )\n .map(e => YAML.stringify(e))\n .join('---\\n'),\n });\n\n onPrepare(\n {\n type: 'repository',\n url: analyzeResult.url,\n integrationType: analyzeResult.integrationType,\n pullRequest: {\n url: pr.link,\n },\n locations: [\n {\n target: pr.location,\n entities: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n ).map(e => ({\n kind: e.kind,\n namespace: e.metadata.namespace!,\n name: e.metadata.name,\n })),\n },\n ],\n },\n { notRepeatable: true },\n );\n } catch (e) {\n assertError(e);\n setError(e.message);\n setSubmitted(false);\n }\n },\n [\n analyzeResult.generatedEntities,\n analyzeResult.integrationType,\n analyzeResult.url,\n catalogImportApi,\n onPrepare,\n ],\n );\n\n return (\n <>\n <Typography>\n You entered a link to a {analyzeResult.integrationType} repository but a{' '}\n <code>{catalogFilename}</code> could not be found. Use this form to open\n a Pull Request that creates one.\n </Typography>\n\n {!prDefaultsLoading && (\n <PreparePullRequestForm<FormData>\n onSubmit={handleResult}\n defaultValues={{\n title: prDefaults?.title ?? '',\n body: prDefaults?.body ?? '',\n owner:\n (analyzeResult.generatedEntities[0]?.spec?.owner as string) || '',\n componentName:\n analyzeResult.generatedEntities[0]?.metadata?.name || '',\n useCodeowners: false,\n }}\n render={({ values, formState, register, setValue }) => (\n <>\n {renderFormFields({\n values,\n formState,\n register,\n setValue,\n groups: groups ?? [],\n groupsLoading,\n })}\n\n <Box marginTop={2}>\n <Typography variant=\"h6\">Preview Pull Request</Typography>\n </Box>\n\n <PreviewPullRequestComponent\n title={values.title}\n description={values.body}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n <Box marginTop={2} marginBottom={1}>\n <Typography variant=\"h6\">Preview Entities</Typography>\n </Box>\n\n <PreviewCatalogInfoComponent\n entities={generateEntities(\n analyzeResult.generatedEntities,\n values.componentName,\n values.owner,\n )}\n repositoryUrl={analyzeResult.url}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n {onGoBack && (\n <BackButton onClick={onGoBack} disabled={submitted} />\n )}\n <NextButton\n type=\"submit\"\n disabled={Boolean(\n formState.errors.title ||\n formState.errors.body ||\n formState.errors.owner,\n )}\n loading={submitted}\n >\n Create PR\n </NextButton>\n </Grid>\n </>\n )}\n />\n )}\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,WAAa,EAAA;AAAA,IACX,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,GAC5B;AAAA,EACA,kBAAoB,EAAA;AAAA,IAClB,UAAY,EAAA,CAAA;AAAA,GACd;AACF,CAAE,CAAA,CAAA,CAAA;AAmCc,SAAA,gBAAA,CACd,QACA,EAAA,aAAA,EACA,KACU,EAAA;AACV,EAAO,OAAA,QAAA,CAAS,IAAI,CAAM,CAAA,MAAA;AAAA,IACxB,GAAG,CAAA;AAAA,IACH,YAAY,CAAE,CAAA,UAAA;AAAA,IACd,MAAM,CAAE,CAAA,IAAA;AAAA,IACR,QAAU,EAAA;AAAA,MACR,GAAG,CAAE,CAAA,QAAA;AAAA,MACL,IAAM,EAAA,aAAA;AAAA,KACR;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,GAAG,CAAE,CAAA,IAAA;AAAA,MACL,GAAI,KAAA,GAAQ,EAAE,KAAA,KAAU,EAAC;AAAA,KAC3B;AAAA,GACA,CAAA,CAAA,CAAA;AACJ,CAAA;AAOa,MAAA,4BAAA,GAA+B,CAC1C,KACG,KA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C3C,CAEA,kBAAA,KAAA,CAAA,aAAA;AAAA,QAAC,2BAAA;AAAA,QAAA;AAAA,UACC,QAAU,EAAA,gBAAA;AAAA,YACR,aAAc,CAAA,iBAAA;AAAA,YACd,MAAO,CAAA,aAAA;AAAA,YACP,MAAO,CAAA,KAAA;AAAA,WACT;AAAA,UACA,eAAe,aAAc,CAAA,GAAA;AAAA,UAC7B,OAAS,EAAA;AAAA,YACP,MAAM,OAAQ,CAAA,WAAA;AAAA,YACd,aAAa,OAAQ,CAAA,kBAAA;AAAA,WACvB;AAAA,SAAA;AAAA,OACF,EAEC,yBAAU,KAAA,CAAA,aAAA,CAAA,cAAA,EAAA,EAAe,OAAK,IAAE,EAAA,EAAA,KAAM,mBAEtC,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,WAAS,IAAC,EAAA,OAAA,EAAS,KACtB,QACC,oBAAA,KAAA,CAAA,aAAA,CAAC,cAAW,OAAS,EAAA,QAAA,EAAU,QAAU,EAAA,SAAA,EAAW,CAEtD,kBAAA,KAAA,CAAA,aAAA;AAAA,QAAC,UAAA;AAAA,QAAA;AAAA,UACC,IAAK,EAAA,QAAA;AAAA,UACL,QAAU,EAAA,OAAA;AAAA,YACR,UAAU,MAAO,CAAA,KAAA,IACf,UAAU,MAAO,CAAA,IAAA,IACjB,UAAU,MAAO,CAAA,KAAA;AAAA,WACrB;AAAA,UACA,OAAS,EAAA,SAAA;AAAA,SAAA;AAAA,QACV,WAAA;AAAA,OAGH,CACF,CAAA;AAAA,KAAA;AAAA,GAIR,CAAA,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"StepPrepareCreatePullRequest.esm.js","sources":["../../../src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.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 { Entity } from '@backstage/catalog-model';\nimport { errorApiRef, useApi } from '@backstage/core-plugin-api';\nimport { assertError } from '@backstage/errors';\nimport {\n catalogApiRef,\n humanizeEntityRef,\n} from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport { UnpackNestedValue, UseFormReturn } from 'react-hook-form';\nimport useAsync from 'react-use/esm/useAsync';\nimport YAML from 'yaml';\nimport { AnalyzeResult, catalogImportApiRef } from '../../api';\nimport { useCatalogFilename } from '../../hooks';\nimport { PartialEntity } from '../../types';\nimport { BackButton, NextButton } from '../Buttons';\nimport { PrepareResult } from '../useImportState';\nimport { PreparePullRequestForm } from './PreparePullRequestForm';\nimport { PreviewCatalogInfoComponent } from './PreviewCatalogInfoComponent';\nimport { PreviewPullRequestComponent } from './PreviewPullRequestComponent';\n\nconst useStyles = makeStyles(theme => ({\n previewCard: {\n marginTop: theme.spacing(1),\n },\n previewCardContent: {\n paddingTop: 0,\n },\n}));\n\ntype FormData = {\n title: string;\n body: string;\n componentName: string;\n owner: string;\n useCodeowners: boolean;\n};\n\n/**\n * Props for {@link StepPrepareCreatePullRequest}.\n *\n * @public\n */\nexport interface StepPrepareCreatePullRequestProps {\n analyzeResult: Extract<AnalyzeResult, { type: 'repository' }>;\n onPrepare: (\n result: PrepareResult,\n opts?: { notRepeatable?: boolean },\n ) => void;\n onGoBack?: () => void;\n\n renderFormFields: (\n props: Pick<\n UseFormReturn<FormData>,\n 'register' | 'setValue' | 'formState'\n > & {\n values: UnpackNestedValue<FormData>;\n groups: string[];\n groupsLoading: boolean;\n },\n ) => React.ReactNode;\n}\n\nexport function generateEntities(\n entities: PartialEntity[],\n componentName: string,\n owner?: string,\n): Entity[] {\n return entities.map(e => ({\n ...e,\n apiVersion: e.apiVersion!,\n kind: e.kind!,\n metadata: {\n ...e.metadata,\n name: componentName,\n },\n spec: {\n ...e.spec,\n ...(owner ? { owner } : {}),\n },\n }));\n}\n\n/**\n * Prepares a pull request.\n *\n * @public\n */\nexport const StepPrepareCreatePullRequest = (\n props: StepPrepareCreatePullRequestProps,\n) => {\n const { analyzeResult, onPrepare, onGoBack, renderFormFields } = props;\n\n const classes = useStyles();\n const catalogApi = useApi(catalogApiRef);\n const catalogImportApi = useApi(catalogImportApiRef);\n const errorApi = useApi(errorApiRef);\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string>();\n\n const catalogFilename = useCatalogFilename();\n\n const {\n loading: prDefaultsLoading,\n value: prDefaults,\n error: prDefaultsError,\n } = useAsync(\n () => catalogImportApi.preparePullRequest!(),\n [catalogImportApi.preparePullRequest],\n );\n\n useEffect(() => {\n if (prDefaultsError) {\n errorApi.post(prDefaultsError);\n }\n }, [prDefaultsError, errorApi]);\n\n const { loading: groupsLoading, value: groups } = useAsync(async () => {\n const groupEntities = await catalogApi.getEntities({\n filter: { kind: 'group' },\n });\n\n return groupEntities.items\n .map(e => humanizeEntityRef(e, { defaultKind: 'group' }))\n .sort();\n });\n\n const handleResult = useCallback(\n async (data: FormData) => {\n setSubmitted(true);\n\n try {\n const pr = await catalogImportApi.submitPullRequest({\n repositoryUrl: analyzeResult.url,\n title: data.title,\n body: data.body,\n fileContent: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n )\n .map(e => YAML.stringify(e))\n .join('---\\n'),\n });\n\n onPrepare(\n {\n type: 'repository',\n url: analyzeResult.url,\n integrationType: analyzeResult.integrationType,\n pullRequest: {\n url: pr.link,\n },\n locations: [\n {\n target: pr.location,\n entities: generateEntities(\n analyzeResult.generatedEntities,\n data.componentName,\n data.owner,\n ).map(e => ({\n kind: e.kind,\n namespace: e.metadata.namespace!,\n name: e.metadata.name,\n })),\n },\n ],\n },\n { notRepeatable: true },\n );\n } catch (e) {\n assertError(e);\n setError(e.message);\n setSubmitted(false);\n }\n },\n [\n analyzeResult.generatedEntities,\n analyzeResult.integrationType,\n analyzeResult.url,\n catalogImportApi,\n onPrepare,\n ],\n );\n\n return (\n <>\n <Typography>\n You entered a link to a {analyzeResult.integrationType} repository but a{' '}\n <code>{catalogFilename}</code> could not be found. Use this form to open\n a Pull Request that creates one.\n </Typography>\n\n {!prDefaultsLoading && (\n <PreparePullRequestForm<FormData>\n onSubmit={handleResult}\n defaultValues={{\n title: prDefaults?.title ?? '',\n body: prDefaults?.body ?? '',\n owner:\n (analyzeResult.generatedEntities[0]?.spec?.owner as string) || '',\n componentName:\n analyzeResult.generatedEntities[0]?.metadata?.name || '',\n useCodeowners: false,\n }}\n render={({ values, formState, register, setValue }) => (\n <>\n {renderFormFields({\n values,\n formState,\n register,\n setValue,\n groups: groups ?? [],\n groupsLoading,\n })}\n\n <Box marginTop={2}>\n <Typography variant=\"h6\">Preview Pull Request</Typography>\n </Box>\n\n <PreviewPullRequestComponent\n title={values.title}\n description={values.body}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n <Box marginTop={2} marginBottom={1}>\n <Typography variant=\"h6\">Preview Entities</Typography>\n </Box>\n\n <PreviewCatalogInfoComponent\n entities={generateEntities(\n analyzeResult.generatedEntities,\n values.componentName,\n values.owner,\n )}\n repositoryUrl={analyzeResult.url}\n classes={{\n card: classes.previewCard,\n cardContent: classes.previewCardContent,\n }}\n />\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n {onGoBack && (\n <BackButton onClick={onGoBack} disabled={submitted} />\n )}\n <NextButton\n type=\"submit\"\n disabled={Boolean(\n formState.errors.title ||\n formState.errors.body ||\n formState.errors.owner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A,KAAA,IACf,UAAU,MAAO,CAAA,IAAA,IACjB,UAAU,MAAO,CAAA,KAAA;AAAA,WACrB;AAAA,UACA,OAAS,EAAA,SAAA;AAAA,SAAA;AAAA,QACV,WAAA;AAAA,OAGH,CACF,CAAA;AAAA,KAAA;AAAA,GAIR,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -17,10 +17,10 @@ const StepPrepareSelectLocations = ({
|
|
|
17
17
|
onGoBack
|
|
18
18
|
}) => {
|
|
19
19
|
const [selectedUrls, setSelectedUrls] = useState(
|
|
20
|
-
|
|
20
|
+
prepareResult?.locations.map((l) => l.target) || []
|
|
21
21
|
);
|
|
22
22
|
const [existingLocations, locations] = partition(
|
|
23
|
-
analyzeResult
|
|
23
|
+
analyzeResult?.locations,
|
|
24
24
|
(l) => l.exists
|
|
25
25
|
);
|
|
26
26
|
const handleResult = useCallback(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepPrepareSelectLocations.esm.js","sources":["../../../src/components/StepPrepareSelectLocations/StepPrepareSelectLocations.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 Checkbox from '@material-ui/core/Checkbox';\nimport Grid from '@material-ui/core/Grid';\nimport ListItem from '@material-ui/core/ListItem';\nimport ListItemIcon from '@material-ui/core/ListItemIcon';\nimport ListItemText from '@material-ui/core/ListItemText';\nimport Typography from '@material-ui/core/Typography';\nimport LocationOnIcon from '@material-ui/icons/LocationOn';\nimport React, { useCallback, useState } from 'react';\nimport { AnalyzeResult } from '../../api';\nimport { BackButton, NextButton } from '../Buttons';\nimport { EntityListComponent } from '../EntityListComponent';\nimport { PrepareResult } from '../useImportState';\nimport partition from 'lodash/partition';\n\ntype Props = {\n analyzeResult: Extract<AnalyzeResult, { type: 'locations' }>;\n prepareResult?: PrepareResult;\n onPrepare: (result: PrepareResult) => void;\n onGoBack?: () => void;\n};\n\n/**\n * A form that lets a user select one of a list of locations to import\n *\n * @param analyzeResult - the result of the analysis\n * @param prepareResult - the selectected locations from a previous step\n * @param onPrepare - called after the selection\n * @param onGoBack - called to go back to the previous step\n */\nexport const StepPrepareSelectLocations = ({\n analyzeResult,\n prepareResult,\n onPrepare,\n onGoBack,\n}: Props) => {\n const [selectedUrls, setSelectedUrls] = useState<string[]>(\n prepareResult?.locations.map(l => l.target) || [],\n );\n\n const [existingLocations, locations] = partition(\n analyzeResult?.locations,\n l => l.exists,\n );\n\n const handleResult = useCallback(async () => {\n onPrepare({\n type: 'locations',\n locations: locations.filter((l: any) => selectedUrls.includes(l.target)),\n });\n }, [locations, onPrepare, selectedUrls]);\n\n const onItemClick = (url: string) => {\n setSelectedUrls(urls =>\n urls.includes(url) ? urls.filter(u => u !== url) : urls.concat(url),\n );\n };\n\n const onSelectAll = () => {\n setSelectedUrls(urls =>\n urls.length < locations.length ? locations.map(l => l.target) : [],\n );\n };\n\n return (\n <>\n {locations.length > 0 && (\n <>\n <Typography>\n Select one or more locations that are present in your git\n repository:\n </Typography>\n <EntityListComponent\n firstListItem={\n <ListItem dense button onClick={onSelectAll}>\n <ListItemIcon>\n <Checkbox\n edge=\"start\"\n checked={selectedUrls.length === locations.length}\n indeterminate={\n selectedUrls.length > 0 &&\n selectedUrls.length < locations.length\n }\n tabIndex={-1}\n disableRipple\n />\n </ListItemIcon>\n <ListItemText primary=\"Select All\" />\n </ListItem>\n }\n onItemClick={onItemClick}\n locations={locations}\n locationListItemIcon={target => (\n <Checkbox\n edge=\"start\"\n checked={selectedUrls.includes(target)}\n tabIndex={-1}\n disableRipple\n />\n )}\n collapsed\n />\n </>\n )}\n\n {existingLocations.length > 0 && (\n <>\n <Typography>These locations already exist in the catalog:</Typography>\n <EntityListComponent\n locations={existingLocations}\n locationListItemIcon={() => <LocationOnIcon />}\n withLinks\n collapsed\n />\n </>\n )}\n\n <Grid container spacing={0}>\n {onGoBack && <BackButton onClick={onGoBack} />}\n <NextButton disabled={selectedUrls.length === 0} onClick={handleResult}>\n Review\n </NextButton>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA6CO,MAAM,6BAA6B,CAAC;AAAA,EACzC,aAAA;AAAA,EACA,aAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AACF,CAAa,KAAA;AACX,EAAM,MAAA,CAAC,YAAc,EAAA,eAAe,CAAI,GAAA,QAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"StepPrepareSelectLocations.esm.js","sources":["../../../src/components/StepPrepareSelectLocations/StepPrepareSelectLocations.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 Checkbox from '@material-ui/core/Checkbox';\nimport Grid from '@material-ui/core/Grid';\nimport ListItem from '@material-ui/core/ListItem';\nimport ListItemIcon from '@material-ui/core/ListItemIcon';\nimport ListItemText from '@material-ui/core/ListItemText';\nimport Typography from '@material-ui/core/Typography';\nimport LocationOnIcon from '@material-ui/icons/LocationOn';\nimport React, { useCallback, useState } from 'react';\nimport { AnalyzeResult } from '../../api';\nimport { BackButton, NextButton } from '../Buttons';\nimport { EntityListComponent } from '../EntityListComponent';\nimport { PrepareResult } from '../useImportState';\nimport partition from 'lodash/partition';\n\ntype Props = {\n analyzeResult: Extract<AnalyzeResult, { type: 'locations' }>;\n prepareResult?: PrepareResult;\n onPrepare: (result: PrepareResult) => void;\n onGoBack?: () => void;\n};\n\n/**\n * A form that lets a user select one of a list of locations to import\n *\n * @param analyzeResult - the result of the analysis\n * @param prepareResult - the selectected locations from a previous step\n * @param onPrepare - called after the selection\n * @param onGoBack - called to go back to the previous step\n */\nexport const StepPrepareSelectLocations = ({\n analyzeResult,\n prepareResult,\n onPrepare,\n onGoBack,\n}: Props) => {\n const [selectedUrls, setSelectedUrls] = useState<string[]>(\n prepareResult?.locations.map(l => l.target) || [],\n );\n\n const [existingLocations, locations] = partition(\n analyzeResult?.locations,\n l => l.exists,\n );\n\n const handleResult = useCallback(async () => {\n onPrepare({\n type: 'locations',\n locations: locations.filter((l: any) => selectedUrls.includes(l.target)),\n });\n }, [locations, onPrepare, selectedUrls]);\n\n const onItemClick = (url: string) => {\n setSelectedUrls(urls =>\n urls.includes(url) ? urls.filter(u => u !== url) : urls.concat(url),\n );\n };\n\n const onSelectAll = () => {\n setSelectedUrls(urls =>\n urls.length < locations.length ? locations.map(l => l.target) : [],\n );\n };\n\n return (\n <>\n {locations.length > 0 && (\n <>\n <Typography>\n Select one or more locations that are present in your git\n repository:\n </Typography>\n <EntityListComponent\n firstListItem={\n <ListItem dense button onClick={onSelectAll}>\n <ListItemIcon>\n <Checkbox\n edge=\"start\"\n checked={selectedUrls.length === locations.length}\n indeterminate={\n selectedUrls.length > 0 &&\n selectedUrls.length < locations.length\n }\n tabIndex={-1}\n disableRipple\n />\n </ListItemIcon>\n <ListItemText primary=\"Select All\" />\n </ListItem>\n }\n onItemClick={onItemClick}\n locations={locations}\n locationListItemIcon={target => (\n <Checkbox\n edge=\"start\"\n checked={selectedUrls.includes(target)}\n tabIndex={-1}\n disableRipple\n />\n )}\n collapsed\n />\n </>\n )}\n\n {existingLocations.length > 0 && (\n <>\n <Typography>These locations already exist in the catalog:</Typography>\n <EntityListComponent\n locations={existingLocations}\n locationListItemIcon={() => <LocationOnIcon />}\n withLinks\n collapsed\n />\n </>\n )}\n\n <Grid container spacing={0}>\n {onGoBack && <BackButton onClick={onGoBack} />}\n <NextButton disabled={selectedUrls.length === 0} onClick={handleResult}>\n Review\n </NextButton>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA6CO,MAAM,6BAA6B,CAAC;AAAA,EACzC,aAAA;AAAA,EACA,aAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AACF,CAAa,KAAA;AACX,EAAM,MAAA,CAAC,YAAc,EAAA,eAAe,CAAI,GAAA,QAAA;AAAA,IACtC,eAAe,SAAU,CAAA,GAAA,CAAI,OAAK,CAAE,CAAA,MAAM,KAAK,EAAC;AAAA,GAClD,CAAA;AAEA,EAAM,MAAA,CAAC,iBAAmB,EAAA,SAAS,CAAI,GAAA,SAAA;AAAA,IACrC,aAAe,EAAA,SAAA;AAAA,IACf,OAAK,CAAE,CAAA,MAAA;AAAA,GACT,CAAA;AAEA,EAAM,MAAA,YAAA,GAAe,YAAY,YAAY;AAC3C,IAAU,SAAA,CAAA;AAAA,MACR,IAAM,EAAA,WAAA;AAAA,MACN,SAAA,EAAW,UAAU,MAAO,CAAA,CAAC,MAAW,YAAa,CAAA,QAAA,CAAS,CAAE,CAAA,MAAM,CAAC,CAAA;AAAA,KACxE,CAAA,CAAA;AAAA,GACA,EAAA,CAAC,SAAW,EAAA,SAAA,EAAW,YAAY,CAAC,CAAA,CAAA;AAEvC,EAAM,MAAA,WAAA,GAAc,CAAC,GAAgB,KAAA;AACnC,IAAA,eAAA;AAAA,MAAgB,CACd,IAAA,KAAA,IAAA,CAAK,QAAS,CAAA,GAAG,CAAI,GAAA,IAAA,CAAK,MAAO,CAAA,CAAA,CAAA,KAAK,CAAM,KAAA,GAAG,CAAI,GAAA,IAAA,CAAK,OAAO,GAAG,CAAA;AAAA,KACpE,CAAA;AAAA,GACF,CAAA;AAEA,EAAA,MAAM,cAAc,M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,MAAM,CAAA;AAAA,UACrC,QAAU,EAAA,CAAA,CAAA;AAAA,UACV,aAAa,EAAA,IAAA;AAAA,SAAA;AAAA,OACf;AAAA,MAEF,SAAS,EAAA,IAAA;AAAA,KAAA;AAAA,GAEb,GAGD,iBAAkB,CAAA,MAAA,GAAS,qBAExB,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,UAAW,EAAA,IAAA,EAAA,+CAA6C,CACzD,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,mBAAA;AAAA,IAAA;AAAA,MACC,SAAW,EAAA,iBAAA;AAAA,MACX,oBAAA,EAAsB,sBAAM,KAAA,CAAA,aAAA,CAAC,cAAe,EAAA,IAAA,CAAA;AAAA,MAC5C,SAAS,EAAA,IAAA;AAAA,MACT,SAAS,EAAA,IAAA;AAAA,KAAA;AAAA,GAEb,CAGF,kBAAA,KAAA,CAAA,aAAA,CAAC,IAAK,EAAA,EAAA,SAAA,EAAS,MAAC,OAAS,EAAA,CAAA,EAAA,EACtB,QAAY,oBAAA,KAAA,CAAA,aAAA,CAAC,UAAW,EAAA,EAAA,OAAA,EAAS,UAAU,CAC5C,kBAAA,KAAA,CAAA,aAAA,CAAC,UAAW,EAAA,EAAA,QAAA,EAAU,YAAa,CAAA,MAAA,KAAW,GAAG,OAAS,EAAA,YAAA,EAAA,EAAc,QAExE,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -31,8 +31,7 @@ const StepReviewLocation = ({
|
|
|
31
31
|
if (prepareResult.type === "locations") {
|
|
32
32
|
refreshed = await Promise.all(
|
|
33
33
|
prepareResult.locations.filter((l) => l.exists).map(async (l) => {
|
|
34
|
-
|
|
35
|
-
const ref = stringifyEntityRef((_a = l.entities[0]) != null ? _a : l);
|
|
34
|
+
const ref = stringifyEntityRef(l.entities[0] ?? l);
|
|
36
35
|
await catalogApi.refreshEntity(ref);
|
|
37
36
|
return { target: l.target };
|
|
38
37
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepReviewLocation.esm.js","sources":["../../../src/components/StepReviewLocation/StepReviewLocation.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 { catalogApiRef } from '@backstage/plugin-catalog-react';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport LocationOnIcon from '@material-ui/icons/LocationOn';\nimport React, { useCallback, useState } from 'react';\nimport { BackButton, NextButton } from '../Buttons';\nimport { EntityListComponent } from '../EntityListComponent';\nimport { PrepareResult, ReviewResult } from '../useImportState';\n\nimport { configApiRef, useAnalytics, useApi } from '@backstage/core-plugin-api';\nimport { Link } from '@backstage/core-components';\nimport { stringifyEntityRef } from '@backstage/catalog-model';\nimport { assertError } from '@backstage/errors';\n\ntype Props = {\n prepareResult: PrepareResult;\n onReview: (result: ReviewResult) => void;\n onGoBack?: () => void;\n};\n\nexport const StepReviewLocation = ({\n prepareResult,\n onReview,\n onGoBack,\n}: Props) => {\n const catalogApi = useApi(catalogApiRef);\n const configApi = useApi(configApiRef);\n const analytics = useAnalytics();\n\n const appTitle = configApi.getOptionalString('app.title') || 'Backstage';\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string>();\n const exists =\n prepareResult.type === 'locations' &&\n prepareResult.locations.some(l => l.exists)\n ? true\n : false;\n const handleClick = useCallback(async () => {\n setSubmitted(true);\n analytics.captureEvent('click', 'import entity');\n try {\n let refreshed = new Array<{ target: string }>();\n if (prepareResult.type === 'locations') {\n refreshed = await Promise.all(\n prepareResult.locations\n .filter(l => l.exists)\n .map(async l => {\n const ref = stringifyEntityRef(l.entities[0] ?? l);\n await catalogApi.refreshEntity(ref);\n return { target: l.target };\n }),\n );\n }\n\n const locations = await Promise.all(\n prepareResult.locations\n .filter((l: unknown) => !(l as { exists?: boolean }).exists)\n .map(async l => {\n const result = await catalogApi.addLocation({\n type: 'url',\n target: l.target,\n });\n return {\n target: result.location.target,\n entities: result.entities,\n };\n }),\n );\n\n onReview({\n ...prepareResult,\n ...{ refreshed },\n locations,\n });\n } catch (e) {\n assertError(e);\n // TODO: this error should be handled differently. We add it as 'optional' and\n // it is not uncommon that a PR has not been merged yet.\n if (\n prepareResult.type === 'repository' &&\n e.message.startsWith(\n 'Location was added but has no entities specified yet',\n )\n ) {\n onReview({\n ...prepareResult,\n locations: prepareResult.locations.map(l => ({\n target: l.target,\n entities: [],\n })),\n });\n } else {\n setError(e.message);\n setSubmitted(false);\n }\n }\n }, [prepareResult, onReview, catalogApi, analytics]);\n\n return (\n <>\n {prepareResult.type === 'repository' && (\n <>\n <Typography paragraph>\n The following Pull Request has been opened:{' '}\n <Link\n to={prepareResult.pullRequest.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n {prepareResult.pullRequest.url}\n </Link>\n </Typography>\n\n <Typography paragraph>\n You can already import the location and {appTitle} will fetch the\n entities as soon as the Pull Request is merged.\n </Typography>\n </>\n )}\n\n <Typography>\n {exists\n ? 'The following locations already exist in the catalog:'\n : 'The following entities will be added to the catalog:'}\n </Typography>\n\n <EntityListComponent\n locations={prepareResult.locations}\n locationListItemIcon={() => <LocationOnIcon />}\n />\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n {onGoBack && <BackButton onClick={onGoBack} disabled={submitted} />}\n <NextButton\n disabled={submitted}\n loading={submitted}\n onClick={() => handleClick()}\n >\n {exists ? 'Refresh' : 'Import'}\n </NextButton>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAqCO,MAAM,qBAAqB,CAAC;AAAA,EACjC,aAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AACF,CAAa,KAAA;AACX,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA,CAAA;AACvC,EAAM,MAAA,SAAA,GAAY,OAAO,YAAY,CAAA,CAAA;AACrC,EAAA,MAAM,YAAY,YAAa,EAAA,CAAA;AAE/B,EAAA,MAAM,QAAW,GAAA,SAAA,CAAU,iBAAkB,CAAA,WAAW,CAAK,IAAA,WAAA,CAAA;AAE7D,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAChD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,QAAiB,EAAA,CAAA;AAC3C,EAAM,MAAA,MAAA,GACJ,aAAc,CAAA,IAAA,KAAS,WACvB,IAAA,aAAA,CAAc,SAAU,CAAA,IAAA,CAAK,CAAK,CAAA,KAAA,CAAA,CAAE,MAAM,CAAA,GACtC,IACA,GAAA,KAAA,CAAA;AACN,EAAM,MAAA,WAAA,GAAc,YAAY,YAAY;AAC1C,IAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AACjB,IAAU,SAAA,CAAA,YAAA,CAAa,SAAS,eAAe,CAAA,CAAA;AAC/C,IAAI,IAAA;AACF,MAAI,IAAA,SAAA,GAAY,IAAI,KAA0B,EAAA,CAAA;AAC9C,MAAI,IAAA,aAAA,CAAc,SAAS,WAAa,EAAA;AACtC,QAAA,SAAA,GAAY,MAAM,OAAQ,CAAA,GAAA;AAAA,UACxB,aAAA,CAAc,UACX,MAAO,CAAA,CAAA,CAAA,KAAK,EAAE,MAAM,CAAA,CACpB,GAAI,CAAA,OAAM,CAAK,KAAA;
|
|
1
|
+
{"version":3,"file":"StepReviewLocation.esm.js","sources":["../../../src/components/StepReviewLocation/StepReviewLocation.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 { catalogApiRef } from '@backstage/plugin-catalog-react';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport Grid from '@material-ui/core/Grid';\nimport Typography from '@material-ui/core/Typography';\nimport LocationOnIcon from '@material-ui/icons/LocationOn';\nimport React, { useCallback, useState } from 'react';\nimport { BackButton, NextButton } from '../Buttons';\nimport { EntityListComponent } from '../EntityListComponent';\nimport { PrepareResult, ReviewResult } from '../useImportState';\n\nimport { configApiRef, useAnalytics, useApi } from '@backstage/core-plugin-api';\nimport { Link } from '@backstage/core-components';\nimport { stringifyEntityRef } from '@backstage/catalog-model';\nimport { assertError } from '@backstage/errors';\n\ntype Props = {\n prepareResult: PrepareResult;\n onReview: (result: ReviewResult) => void;\n onGoBack?: () => void;\n};\n\nexport const StepReviewLocation = ({\n prepareResult,\n onReview,\n onGoBack,\n}: Props) => {\n const catalogApi = useApi(catalogApiRef);\n const configApi = useApi(configApiRef);\n const analytics = useAnalytics();\n\n const appTitle = configApi.getOptionalString('app.title') || 'Backstage';\n\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string>();\n const exists =\n prepareResult.type === 'locations' &&\n prepareResult.locations.some(l => l.exists)\n ? true\n : false;\n const handleClick = useCallback(async () => {\n setSubmitted(true);\n analytics.captureEvent('click', 'import entity');\n try {\n let refreshed = new Array<{ target: string }>();\n if (prepareResult.type === 'locations') {\n refreshed = await Promise.all(\n prepareResult.locations\n .filter(l => l.exists)\n .map(async l => {\n const ref = stringifyEntityRef(l.entities[0] ?? l);\n await catalogApi.refreshEntity(ref);\n return { target: l.target };\n }),\n );\n }\n\n const locations = await Promise.all(\n prepareResult.locations\n .filter((l: unknown) => !(l as { exists?: boolean }).exists)\n .map(async l => {\n const result = await catalogApi.addLocation({\n type: 'url',\n target: l.target,\n });\n return {\n target: result.location.target,\n entities: result.entities,\n };\n }),\n );\n\n onReview({\n ...prepareResult,\n ...{ refreshed },\n locations,\n });\n } catch (e) {\n assertError(e);\n // TODO: this error should be handled differently. We add it as 'optional' and\n // it is not uncommon that a PR has not been merged yet.\n if (\n prepareResult.type === 'repository' &&\n e.message.startsWith(\n 'Location was added but has no entities specified yet',\n )\n ) {\n onReview({\n ...prepareResult,\n locations: prepareResult.locations.map(l => ({\n target: l.target,\n entities: [],\n })),\n });\n } else {\n setError(e.message);\n setSubmitted(false);\n }\n }\n }, [prepareResult, onReview, catalogApi, analytics]);\n\n return (\n <>\n {prepareResult.type === 'repository' && (\n <>\n <Typography paragraph>\n The following Pull Request has been opened:{' '}\n <Link\n to={prepareResult.pullRequest.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n {prepareResult.pullRequest.url}\n </Link>\n </Typography>\n\n <Typography paragraph>\n You can already import the location and {appTitle} will fetch the\n entities as soon as the Pull Request is merged.\n </Typography>\n </>\n )}\n\n <Typography>\n {exists\n ? 'The following locations already exist in the catalog:'\n : 'The following entities will be added to the catalog:'}\n </Typography>\n\n <EntityListComponent\n locations={prepareResult.locations}\n locationListItemIcon={() => <LocationOnIcon />}\n />\n\n {error && <FormHelperText error>{error}</FormHelperText>}\n\n <Grid container spacing={0}>\n {onGoBack && <BackButton onClick={onGoBack} disabled={submitted} />}\n <NextButton\n disabled={submitted}\n loading={submitted}\n onClick={() => handleClick()}\n >\n {exists ? 'Refresh' : 'Import'}\n </NextButton>\n </Grid>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAqCO,MAAM,qBAAqB,CAAC;AAAA,EACjC,aAAA;AAAA,EACA,QAAA;AAAA,EACA,QA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IAAA;AAAA,MACC,QAAU,EAAA,SAAA;AAAA,MACV,OAAS,EAAA,SAAA;AAAA,MACT,OAAA,EAAS,MAAM,WAAY,EAAA;AAAA,KAAA;AAAA,IAE1B,SAAS,SAAY,GAAA,QAAA;AAAA,GAE1B,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -6,12 +6,10 @@ function asInputRef(renderResult) {
|
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
8
|
function getCatalogFilename(config) {
|
|
9
|
-
|
|
10
|
-
return (_a = config.getOptionalString("catalog.import.entityFilename")) != null ? _a : "catalog-info.yaml";
|
|
9
|
+
return config.getOptionalString("catalog.import.entityFilename") ?? "catalog-info.yaml";
|
|
11
10
|
}
|
|
12
11
|
function getBranchName(config) {
|
|
13
|
-
|
|
14
|
-
return (_a = config.getOptionalString("catalog.import.pullRequestBranchName")) != null ? _a : "backstage-integration";
|
|
12
|
+
return config.getOptionalString("catalog.import.pullRequestBranchName") ?? "backstage-integration";
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
export { asInputRef, getBranchName, getCatalogFilename };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.esm.js","sources":["../../src/components/helpers.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 type { Config } from '@backstage/config';\nimport { UseFormRegisterReturn } from 'react-hook-form';\n\n/**\n * A helper that converts the result of a render('name', opts) to make it compatible with material-ui.\n *\n * See also https://github.com/react-hook-form/react-hook-form/issues/4629#issuecomment-815840872\n * TODO: remove when updating to material-ui v5 (https://github.com/mui-org/material-ui/pull/23174)\n *\n * @param renderResult - the result of a render('name', opts)\n */\nexport function asInputRef(renderResult: UseFormRegisterReturn) {\n const { ref, ...rest } = renderResult;\n return {\n inputRef: ref,\n ...rest,\n };\n}\n\nexport function getCatalogFilename(config: Config): string {\n return (\n config.getOptionalString('catalog.import.entityFilename') ??\n 'catalog-info.yaml'\n );\n}\n\nexport function getBranchName(config: Config): string {\n return (\n config.getOptionalString('catalog.import.pullRequestBranchName') ??\n 'backstage-integration'\n );\n}\n"],"names":[],"mappings":"AA2BO,SAAS,WAAW,YAAqC,EAAA;AAC9D,EAAA,MAAM,EAAE,GAAA,EAAK,GAAG,IAAA,EAAS,GAAA,YAAA,CAAA;AACzB,EAAO,OAAA;AAAA,IACL,QAAU,EAAA,GAAA;AAAA,IACV,GAAG,IAAA;AAAA,GACL,CAAA;AACF,CAAA;AAEO,SAAS,mBAAmB,MAAwB,EAAA;
|
|
1
|
+
{"version":3,"file":"helpers.esm.js","sources":["../../src/components/helpers.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 type { Config } from '@backstage/config';\nimport { UseFormRegisterReturn } from 'react-hook-form';\n\n/**\n * A helper that converts the result of a render('name', opts) to make it compatible with material-ui.\n *\n * See also https://github.com/react-hook-form/react-hook-form/issues/4629#issuecomment-815840872\n * TODO: remove when updating to material-ui v5 (https://github.com/mui-org/material-ui/pull/23174)\n *\n * @param renderResult - the result of a render('name', opts)\n */\nexport function asInputRef(renderResult: UseFormRegisterReturn) {\n const { ref, ...rest } = renderResult;\n return {\n inputRef: ref,\n ...rest,\n };\n}\n\nexport function getCatalogFilename(config: Config): string {\n return (\n config.getOptionalString('catalog.import.entityFilename') ??\n 'catalog-info.yaml'\n );\n}\n\nexport function getBranchName(config: Config): string {\n return (\n config.getOptionalString('catalog.import.pullRequestBranchName') ??\n 'backstage-integration'\n );\n}\n"],"names":[],"mappings":"AA2BO,SAAS,WAAW,YAAqC,EAAA;AAC9D,EAAA,MAAM,EAAE,GAAA,EAAK,GAAG,IAAA,EAAS,GAAA,YAAA,CAAA;AACzB,EAAO,OAAA;AAAA,IACL,QAAU,EAAA,GAAA;AAAA,IACV,GAAG,IAAA;AAAA,GACL,CAAA;AACF,CAAA;AAEO,SAAS,mBAAmB,MAAwB,EAAA;AACzD,EACE,OAAA,MAAA,CAAO,iBAAkB,CAAA,+BAA+B,CACxD,IAAA,mBAAA,CAAA;AAEJ,CAAA;AAEO,SAAS,cAAc,MAAwB,EAAA;AACpD,EACE,OAAA,MAAA,CAAO,iBAAkB,CAAA,sCAAsC,CAC/D,IAAA,uBAAA,CAAA;AAEJ;;;;"}
|
|
@@ -21,8 +21,8 @@ function reducer(state, action) {
|
|
|
21
21
|
analysisUrl,
|
|
22
22
|
activeFlow,
|
|
23
23
|
analyzeResult,
|
|
24
|
-
prepareResult: opts
|
|
25
|
-
activeState:
|
|
24
|
+
prepareResult: opts?.prepareResult,
|
|
25
|
+
activeState: opts?.prepareResult === void 0 ? "prepare" : "review",
|
|
26
26
|
previousStates: previousStates.concat(activeState)
|
|
27
27
|
};
|
|
28
28
|
}
|
|
@@ -36,7 +36,7 @@ function reducer(state, action) {
|
|
|
36
36
|
...state,
|
|
37
37
|
prepareResult,
|
|
38
38
|
activeState: "review",
|
|
39
|
-
previousStates:
|
|
39
|
+
previousStates: opts?.notRepeatable ? [] : previousStates.concat(activeState)
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
case "onReview": {
|
|
@@ -72,7 +72,7 @@ function reducer(state, action) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
const useImportState = (options) => {
|
|
75
|
-
const [state, dispatch] = useReducer(reducer, options
|
|
75
|
+
const [state, dispatch] = useReducer(reducer, options?.initialUrl, init);
|
|
76
76
|
const { activeFlow, activeState, analysisUrl, previousStates } = state;
|
|
77
77
|
return {
|
|
78
78
|
activeFlow,
|
|
@@ -94,7 +94,7 @@ const useImportState = (options) => {
|
|
|
94
94
|
}),
|
|
95
95
|
onReview: (result) => dispatch({ type: "onReview", args: [result] }),
|
|
96
96
|
onGoBack: previousStates.length > 0 ? () => dispatch({ type: "onGoBack" }) : void 0,
|
|
97
|
-
onReset: () => dispatch({ type: "onReset", initialUrl: options
|
|
97
|
+
onReset: () => dispatch({ type: "onReset", initialUrl: options?.initialUrl })
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
100
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useImportState.esm.js","sources":["../../src/components/useImportState.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, CompoundEntityRef } from '@backstage/catalog-model';\nimport { useReducer } from 'react';\nimport { AnalyzeResult } from '../api';\n\n/**\n * The configuration of the stepper.\n *\n * @public\n */\nexport type ImportFlows =\n | 'unknown'\n | 'single-location'\n | 'multiple-locations'\n | 'no-location';\n\n// the available states of the stepper\ntype ImportStateTypes = 'analyze' | 'prepare' | 'review' | 'finish';\n\n/**\n * Result of the prepare state.\n *\n * @public\n */\nexport type PrepareResult =\n | {\n type: 'locations';\n locations: Array<{\n exists?: boolean;\n target: string;\n entities: CompoundEntityRef[];\n }>;\n }\n | {\n type: 'repository';\n url: string;\n integrationType: string;\n pullRequest: {\n url: string;\n };\n locations: Array<{\n target: string;\n entities: CompoundEntityRef[];\n }>;\n };\n\n// result of the review result\nexport type ReviewResult =\n | {\n type: 'locations';\n locations: Array<{\n target: string;\n entities: Entity[];\n }>;\n refreshed: Array<{ target: string }>;\n }\n | {\n type: 'repository';\n url: string;\n integrationType: string;\n pullRequest: {\n url: string;\n };\n locations: Array<{\n target: string;\n entities: Entity[];\n }>;\n };\n\n// function type for the 'analysis' -> 'prepare'/'review' transition\ntype onAnalysisFn = (\n flow: ImportFlows,\n url: string,\n result: AnalyzeResult,\n opts?: { prepareResult?: PrepareResult },\n) => void;\n\n// function type for the 'prepare' -> 'review' transition\ntype onPrepareFn = (\n result: PrepareResult,\n opts?: { notRepeatable?: boolean },\n) => void;\n\n// function type for the 'review' -> 'finish' transition\ntype onReviewFn = (result: ReviewResult) => void;\n\n// the type interfaces that are available in each state. every state provides\n// already known information and means to go to the next, or the previous step.\ntype State =\n | {\n activeState: 'analyze';\n onAnalysis: onAnalysisFn;\n }\n | {\n activeState: 'prepare';\n analyzeResult: AnalyzeResult;\n prepareResult?: PrepareResult;\n onPrepare: onPrepareFn;\n }\n | {\n activeState: 'review';\n analyzeResult: AnalyzeResult;\n prepareResult: PrepareResult;\n onReview: onReviewFn;\n }\n | {\n activeState: 'finish';\n analyzeResult: AnalyzeResult;\n prepareResult: PrepareResult;\n reviewResult: ReviewResult;\n };\n\nexport type ImportState = State & {\n activeFlow: ImportFlows;\n activeStepNumber: number;\n analysisUrl?: string;\n\n onGoBack?: () => void;\n onReset: () => void;\n};\n\ntype ReducerActions =\n | { type: 'onAnalysis'; args: Parameters<onAnalysisFn> }\n | { type: 'onPrepare'; args: Parameters<onPrepareFn> }\n | { type: 'onReview'; args: Parameters<onReviewFn> }\n | { type: 'onGoBack' }\n | { type: 'onReset'; initialUrl?: string };\n\ntype ReducerState = {\n activeFlow: ImportFlows;\n activeState: ImportStateTypes;\n analysisUrl?: string;\n analyzeResult?: AnalyzeResult;\n prepareResult?: PrepareResult;\n reviewResult?: ReviewResult;\n\n previousStates: ImportStateTypes[];\n};\n\nfunction init(initialUrl?: string): ReducerState {\n return {\n activeFlow: 'unknown',\n activeState: 'analyze',\n analysisUrl: initialUrl,\n previousStates: [],\n };\n}\n\nfunction reducer(state: ReducerState, action: ReducerActions): ReducerState {\n switch (action.type) {\n case 'onAnalysis': {\n if (state.activeState !== 'analyze') {\n return state;\n }\n\n const { activeState, previousStates } = state;\n const [activeFlow, analysisUrl, analyzeResult, opts] = action.args;\n\n return {\n ...state,\n analysisUrl,\n activeFlow,\n analyzeResult,\n prepareResult: opts?.prepareResult,\n\n activeState: opts?.prepareResult === undefined ? 'prepare' : 'review',\n previousStates: previousStates.concat(activeState),\n };\n }\n\n case 'onPrepare': {\n if (state.activeState !== 'prepare') {\n return state;\n }\n\n const { activeState, previousStates } = state;\n const [prepareResult, opts] = action.args;\n\n return {\n ...state,\n prepareResult,\n\n activeState: 'review',\n previousStates: opts?.notRepeatable\n ? []\n : previousStates.concat(activeState),\n };\n }\n\n case 'onReview': {\n if (state.activeState !== 'review') {\n return state;\n }\n\n const { activeState, previousStates } = state;\n const [reviewResult] = action.args;\n\n return {\n ...state,\n reviewResult,\n\n activeState: 'finish',\n previousStates: previousStates.concat(activeState),\n };\n }\n\n case 'onGoBack': {\n const { activeState, previousStates } = state;\n\n return {\n ...state,\n\n activeState:\n previousStates.length > 0\n ? previousStates[previousStates.length - 1]\n : activeState,\n previousStates: previousStates.slice(0, previousStates.length - 1),\n };\n }\n\n case 'onReset':\n return {\n ...init(action.initialUrl),\n\n // we keep the old prepareResult since the form is animated and an\n // undefined value might crash the last step.\n prepareResult: state.prepareResult,\n };\n\n default:\n throw new Error();\n }\n}\n\n/**\n * A hook that manages the state machine of the form. It handles different flows\n * which each can implement up to four states:\n * 1. analyze\n * 2. preview (skippable from analyze->review)\n * 3. review\n * 4. finish\n *\n * @param options - options\n */\nexport const useImportState = (options?: {\n initialUrl?: string;\n}): ImportState => {\n const [state, dispatch] = useReducer(reducer, options?.initialUrl, init);\n\n const { activeFlow, activeState, analysisUrl, previousStates } = state;\n\n return {\n activeFlow,\n activeState,\n activeStepNumber: ['analyze', 'prepare', 'review', 'finish'].indexOf(\n activeState,\n ),\n analysisUrl: analysisUrl,\n\n analyzeResult: state.analyzeResult!,\n prepareResult: state.prepareResult!,\n reviewResult: state.reviewResult!,\n\n onAnalysis: (flow, url, result, opts) =>\n dispatch({\n type: 'onAnalysis',\n args: [flow, url, result, opts],\n }),\n\n onPrepare: (result, opts) =>\n dispatch({\n type: 'onPrepare',\n args: [result, opts],\n }),\n\n onReview: result => dispatch({ type: 'onReview', args: [result] }),\n\n onGoBack:\n previousStates.length > 0\n ? () => dispatch({ type: 'onGoBack' })\n : undefined,\n\n onReset: () =>\n dispatch({ type: 'onReset', initialUrl: options?.initialUrl }),\n };\n};\n"],"names":[],"mappings":";;AA0JA,SAAS,KAAK,UAAmC,EAAA;AAC/C,EAAO,OAAA;AAAA,IACL,UAAY,EAAA,SAAA;AAAA,IACZ,WAAa,EAAA,SAAA;AAAA,IACb,WAAa,EAAA,UAAA;AAAA,IACb,gBAAgB,EAAC;AAAA,GACnB,CAAA;AACF,CAAA;AAEA,SAAS,OAAA,CAAQ,OAAqB,MAAsC,EAAA;AAC1E,EAAA,QAAQ,OAAO,IAAM;AAAA,IACnB,KAAK,YAAc,EAAA;AACjB,MAAI,IAAA,KAAA,CAAM,gBAAgB,SAAW,EAAA;AACnC,QAAO,OAAA,KAAA,CAAA;AAAA,OACT;AAEA,MAAM,MAAA,EAAE,WAAa,EAAA,cAAA,EAAmB,GAAA,KAAA,CAAA;AACxC,MAAA,MAAM,CAAC,UAAY,EAAA,WAAA,EAAa,aAAe,EAAA,IAAI,IAAI,MAAO,CAAA,IAAA,CAAA;AAE9D,MAAO,OAAA;AAAA,QACL,GAAG,KAAA;AAAA,QACH,WAAA;AAAA,QACA,UA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EAAM,GAAK,EAAA,MAAA,EAAQ,SAC9B,QAAS,CAAA;AAAA,MACP,IAAM,EAAA,YAAA;AAAA,MACN,IAAM,EAAA,CAAC,IAAM,EAAA,GAAA,EAAK,QAAQ,IAAI,CAAA;AAAA,KAC/B,CAAA;AAAA,IAEH,SAAW,EAAA,CAAC,MAAQ,EAAA,IAAA,KAClB,QAAS,CAAA;AAAA,MACP,IAAM,EAAA,WAAA;AAAA,MACN,IAAA,EAAM,CAAC,MAAA,EAAQ,IAAI,CAAA;AAAA,KACpB,CAAA;AAAA,IAEH,QAAA,EAAU,CAAU,MAAA,KAAA,QAAA,CAAS,EAAE,IAAA,EAAM,YAAY,IAAM,EAAA,CAAC,MAAM,CAAA,EAAG,CAAA;AAAA,IAEjE,QAAA,EACE,cAAe,CAAA,MAAA,GAAS,CACpB,GAAA,MAAM,SAAS,EAAE,IAAA,EAAM,UAAW,EAAC,CACnC,GAAA,KAAA,CAAA;AAAA,IAEN,OAAA,EAAS,MACP,QAAS,CAAA,EAAE,MAAM,SAAW,EAAA,UAAA,EAAY,OAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,UAAA,EAAY,CAAA;AAAA,GACjE,CAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"useImportState.esm.js","sources":["../../src/components/useImportState.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, CompoundEntityRef } from '@backstage/catalog-model';\nimport { useReducer } from 'react';\nimport { AnalyzeResult } from '../api';\n\n/**\n * The configuration of the stepper.\n *\n * @public\n */\nexport type ImportFlows =\n | 'unknown'\n | 'single-location'\n | 'multiple-locations'\n | 'no-location';\n\n// the available states of the stepper\ntype ImportStateTypes = 'analyze' | 'prepare' | 'review' | 'finish';\n\n/**\n * Result of the prepare state.\n *\n * @public\n */\nexport type PrepareResult =\n | {\n type: 'locations';\n locations: Array<{\n exists?: boolean;\n target: string;\n entities: CompoundEntityRef[];\n }>;\n }\n | {\n type: 'repository';\n url: string;\n integrationType: string;\n pullRequest: {\n url: string;\n };\n locations: Array<{\n target: string;\n entities: CompoundEntityRef[];\n }>;\n };\n\n// result of the review result\nexport type ReviewResult =\n | {\n type: 'locations';\n locations: Array<{\n target: string;\n entities: Entity[];\n }>;\n refreshed: Array<{ target: string }>;\n }\n | {\n type: 'repository';\n url: string;\n integrationType: string;\n pullRequest: {\n url: string;\n };\n locations: Array<{\n target: string;\n entities: Entity[];\n }>;\n };\n\n// function type for the 'analysis' -> 'prepare'/'review' transition\ntype onAnalysisFn = (\n flow: ImportFlows,\n url: string,\n result: AnalyzeResult,\n opts?: { prepareResult?: PrepareResult },\n) => void;\n\n// function type for the 'prepare' -> 'review' transition\ntype onPrepareFn = (\n result: PrepareResult,\n opts?: { notRepeatable?: boolean },\n) => void;\n\n// function type for the 'review' -> 'finish' transition\ntype onReviewFn = (result: ReviewResult) => void;\n\n// the type interfaces that are available in each state. every state provides\n// already known information and means to go to the next, or the previous step.\ntype State =\n | {\n activeState: 'analyze';\n onAnalysis: onAnalysisFn;\n }\n | {\n activeState: 'prepare';\n analyzeResult: AnalyzeResult;\n prepareResult?: PrepareResult;\n onPrepare: onPrepareFn;\n }\n | {\n activeState: 'review';\n analyzeResult: AnalyzeResult;\n prepareResult: PrepareResult;\n onReview: onReviewFn;\n }\n | {\n activeState: 'finish';\n analyzeResult: AnalyzeResult;\n prepareResult: PrepareResult;\n reviewResult: ReviewResult;\n };\n\nexport type ImportState = State & {\n activeFlow: ImportFlows;\n activeStepNumber: number;\n analysisUrl?: string;\n\n onGoBack?: () => void;\n onReset: () => void;\n};\n\ntype ReducerActions =\n | { type: 'onAnalysis'; args: Parameters<onAnalysisFn> }\n | { type: 'onPrepare'; args: Parameters<onPrepareFn> }\n | { type: 'onReview'; args: Parameters<onReviewFn> }\n | { type: 'onGoBack' }\n | { type: 'onReset'; initialUrl?: string };\n\ntype ReducerState = {\n activeFlow: ImportFlows;\n activeState: ImportStateTypes;\n analysisUrl?: string;\n analyzeResult?: AnalyzeResult;\n prepareResult?: PrepareResult;\n reviewResult?: ReviewResult;\n\n previousStates: ImportStateTypes[];\n};\n\nfunction init(initialUrl?: string): ReducerState {\n return {\n activeFlow: 'unknown',\n activeState: 'analyze',\n analysisUrl: initialUrl,\n previousStates: [],\n };\n}\n\nfunction reducer(state: ReducerState, action: ReducerActions): ReducerState {\n switch (action.type) {\n case 'onAnalysis': {\n if (state.activeState !== 'analyze') {\n return state;\n }\n\n const { activeState, previousStates } = state;\n const [activeFlow, analysisUrl, analyzeResult, opts] = action.args;\n\n return {\n ...state,\n analysisUrl,\n activeFlow,\n analyzeResult,\n prepareResult: opts?.prepareResult,\n\n activeState: opts?.prepareResult === undefined ? 'prepare' : 'review',\n previousStates: previousStates.concat(activeState),\n };\n }\n\n case 'onPrepare': {\n if (state.activeState !== 'prepare') {\n return state;\n }\n\n const { activeState, previousStates } = state;\n const [prepareResult, opts] = action.args;\n\n return {\n ...state,\n prepareResult,\n\n activeState: 'review',\n previousStates: opts?.notRepeatable\n ? []\n : previousStates.concat(activeState),\n };\n }\n\n case 'onReview': {\n if (state.activeState !== 'review') {\n return state;\n }\n\n const { activeState, previousStates } = state;\n const [reviewResult] = action.args;\n\n return {\n ...state,\n reviewResult,\n\n activeState: 'finish',\n previousStates: previousStates.concat(activeState),\n };\n }\n\n case 'onGoBack': {\n const { activeState, previousStates } = state;\n\n return {\n ...state,\n\n activeState:\n previousStates.length > 0\n ? previousStates[previousStates.length - 1]\n : activeState,\n previousStates: previousStates.slice(0, previousStates.length - 1),\n };\n }\n\n case 'onReset':\n return {\n ...init(action.initialUrl),\n\n // we keep the old prepareResult since the form is animated and an\n // undefined value might crash the last step.\n prepareResult: state.prepareResult,\n };\n\n default:\n throw new Error();\n }\n}\n\n/**\n * A hook that manages the state machine of the form. It handles different flows\n * which each can implement up to four states:\n * 1. analyze\n * 2. preview (skippable from analyze->review)\n * 3. review\n * 4. finish\n *\n * @param options - options\n */\nexport const useImportState = (options?: {\n initialUrl?: string;\n}): ImportState => {\n const [state, dispatch] = useReducer(reducer, options?.initialUrl, init);\n\n const { activeFlow, activeState, analysisUrl, previousStates } = state;\n\n return {\n activeFlow,\n activeState,\n activeStepNumber: ['analyze', 'prepare', 'review', 'finish'].indexOf(\n activeState,\n ),\n analysisUrl: analysisUrl,\n\n analyzeResult: state.analyzeResult!,\n prepareResult: state.prepareResult!,\n reviewResult: state.reviewResult!,\n\n onAnalysis: (flow, url, result, opts) =>\n dispatch({\n type: 'onAnalysis',\n args: [flow, url, result, opts],\n }),\n\n onPrepare: (result, opts) =>\n dispatch({\n type: 'onPrepare',\n args: [result, opts],\n }),\n\n onReview: result => dispatch({ type: 'onReview', args: [result] }),\n\n onGoBack:\n previousStates.length > 0\n ? () => dispatch({ type: 'onGoBack' })\n : undefined,\n\n onReset: () =>\n dispatch({ type: 'onReset', initialUrl: options?.initialUrl }),\n };\n};\n"],"names":[],"mappings":";;AA0JA,SAAS,KAAK,UAAmC,EAAA;AAC/C,EAAO,OAAA;AAAA,IACL,UAAY,EAAA,SAAA;AAAA,IACZ,WAAa,EAAA,SAAA;AAAA,IACb,WAAa,EAAA,UAAA;AAAA,IACb,gBAAgB,EAAC;AAAA,GACnB,CAAA;AACF,CAAA;AAEA,SAAS,OAAA,CAAQ,OAAqB,MAAsC,EAAA;AAC1E,EAAA,QAAQ,OAAO,IAAM;AAAA,IACnB,KAAK,YAAc,EAAA;AACjB,MAAI,IAAA,KAAA,CAAM,gBAAgB,SAAW,EAAA;AACnC,QAAO,OAAA,KAAA,CAAA;AAAA,OACT;A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ACrB,cAAc,KAAM,CAAA,YAAA;AAAA,IAEpB,YAAY,CAAC,IAAA,EAAM,GAAK,EAAA,MAAA,EAAQ,SAC9B,QAAS,CAAA;AAAA,MACP,IAAM,EAAA,YAAA;AAAA,MACN,IAAM,EAAA,CAAC,IAAM,EAAA,GAAA,EAAK,QAAQ,IAAI,CAAA;AAAA,KAC/B,CAAA;AAAA,IAEH,SAAW,EAAA,CAAC,MAAQ,EAAA,IAAA,KAClB,QAAS,CAAA;AAAA,MACP,IAAM,EAAA,WAAA;AAAA,MACN,IAAA,EAAM,CAAC,MAAA,EAAQ,IAAI,CAAA;AAAA,KACpB,CAAA;AAAA,IAEH,QAAA,EAAU,CAAU,MAAA,KAAA,QAAA,CAAS,EAAE,IAAA,EAAM,YAAY,IAAM,EAAA,CAAC,MAAM,CAAA,EAAG,CAAA;AAAA,IAEjE,QAAA,EACE,cAAe,CAAA,MAAA,GAAS,CACpB,GAAA,MAAM,SAAS,EAAE,IAAA,EAAM,UAAW,EAAC,CACnC,GAAA,KAAA,CAAA;AAAA,IAEN,OAAA,EAAS,MACP,QAAS,CAAA,EAAE,MAAM,SAAW,EAAA,UAAA,EAAY,OAAS,EAAA,UAAA,EAAY,CAAA;AAAA,GACjE,CAAA;AACF;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
5
|
-
import { DiscoveryApi,
|
|
5
|
+
import { DiscoveryApi, FetchApi, ConfigApi } from '@backstage/core-plugin-api';
|
|
6
6
|
import { Entity, CompoundEntityRef } from '@backstage/catalog-model';
|
|
7
7
|
import { InfoCardVariants } from '@backstage/core-components';
|
|
8
8
|
import { TextFieldProps } from '@material-ui/core/TextField/TextField';
|
|
@@ -131,7 +131,7 @@ interface CatalogImportApi {
|
|
|
131
131
|
*/
|
|
132
132
|
declare class CatalogImportClient implements CatalogImportApi {
|
|
133
133
|
private readonly discoveryApi;
|
|
134
|
-
private readonly
|
|
134
|
+
private readonly fetchApi;
|
|
135
135
|
private readonly scmAuthApi;
|
|
136
136
|
private readonly scmIntegrationsApi;
|
|
137
137
|
private readonly catalogApi;
|
|
@@ -139,7 +139,7 @@ declare class CatalogImportClient implements CatalogImportApi {
|
|
|
139
139
|
constructor(options: {
|
|
140
140
|
discoveryApi: DiscoveryApi;
|
|
141
141
|
scmAuthApi: ScmAuthApi;
|
|
142
|
-
|
|
142
|
+
fetchApi: FetchApi;
|
|
143
143
|
scmIntegrationsApi: ScmIntegrationRegistry;
|
|
144
144
|
catalogApi: CatalogApi;
|
|
145
145
|
configApi: ConfigApi;
|
package/dist/plugin.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRouteRef, createPlugin, createApiFactory, discoveryApiRef,
|
|
1
|
+
import { createRouteRef, createPlugin, createApiFactory, discoveryApiRef, fetchApiRef, configApiRef, createRoutableExtension } from '@backstage/core-plugin-api';
|
|
2
2
|
import { scmAuthApiRef, scmIntegrationsApiRef } from '@backstage/integration-react';
|
|
3
3
|
import { catalogApiRef } from '@backstage/plugin-catalog-react';
|
|
4
4
|
import { catalogImportApiRef } from './api/CatalogImportApi.esm.js';
|
|
@@ -15,7 +15,7 @@ const catalogImportPlugin = createPlugin({
|
|
|
15
15
|
deps: {
|
|
16
16
|
discoveryApi: discoveryApiRef,
|
|
17
17
|
scmAuthApi: scmAuthApiRef,
|
|
18
|
-
|
|
18
|
+
fetchApi: fetchApiRef,
|
|
19
19
|
scmIntegrationsApi: scmIntegrationsApiRef,
|
|
20
20
|
catalogApi: catalogApiRef,
|
|
21
21
|
configApi: configApiRef
|
|
@@ -23,7 +23,7 @@ const catalogImportPlugin = createPlugin({
|
|
|
23
23
|
factory: ({
|
|
24
24
|
discoveryApi,
|
|
25
25
|
scmAuthApi,
|
|
26
|
-
|
|
26
|
+
fetchApi,
|
|
27
27
|
scmIntegrationsApi,
|
|
28
28
|
catalogApi,
|
|
29
29
|
configApi
|
|
@@ -31,7 +31,7 @@ const catalogImportPlugin = createPlugin({
|
|
|
31
31
|
discoveryApi,
|
|
32
32
|
scmAuthApi,
|
|
33
33
|
scmIntegrationsApi,
|
|
34
|
-
|
|
34
|
+
fetchApi,
|
|
35
35
|
catalogApi,
|
|
36
36
|
configApi
|
|
37
37
|
})
|
package/dist/plugin.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n configApiRef,\n createApiFactory,\n createPlugin,\n createRoutableExtension,\n createRouteRef,\n discoveryApiRef,\n
|
|
1
|
+
{"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n configApiRef,\n createApiFactory,\n createPlugin,\n createRoutableExtension,\n createRouteRef,\n discoveryApiRef,\n fetchApiRef,\n} from '@backstage/core-plugin-api';\nimport {\n scmAuthApiRef,\n scmIntegrationsApiRef,\n} from '@backstage/integration-react';\nimport { catalogApiRef } from '@backstage/plugin-catalog-react';\nimport { catalogImportApiRef, CatalogImportClient } from './api';\n\nexport const rootRouteRef = createRouteRef({\n id: 'catalog-import',\n});\n\n/**\n * A plugin that helps the user in importing projects and YAML files into the\n * catalog.\n *\n * @public\n */\nexport const catalogImportPlugin = createPlugin({\n id: 'catalog-import',\n apis: [\n createApiFactory({\n api: catalogImportApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n scmAuthApi: scmAuthApiRef,\n fetchApi: fetchApiRef,\n scmIntegrationsApi: scmIntegrationsApiRef,\n catalogApi: catalogApiRef,\n configApi: configApiRef,\n },\n factory: ({\n discoveryApi,\n scmAuthApi,\n fetchApi,\n scmIntegrationsApi,\n catalogApi,\n configApi,\n }) =>\n new CatalogImportClient({\n discoveryApi,\n scmAuthApi,\n scmIntegrationsApi,\n fetchApi,\n catalogApi,\n configApi,\n }),\n }),\n ],\n routes: {\n importPage: rootRouteRef,\n },\n});\n\n/**\n * The page for importing projects and YAML files into the catalog.\n *\n * @public\n */\nexport const CatalogImportPage = catalogImportPlugin.provide(\n createRoutableExtension({\n name: 'CatalogImportPage',\n component: () => import('./components/ImportPage').then(m => m.ImportPage),\n mountPoint: rootRouteRef,\n }),\n);\n"],"names":[],"mappings":";;;;;;AAgCO,MAAM,eAAe,cAAe,CAAA;AAAA,EACzC,EAAI,EAAA,gBAAA;AACN,CAAC,EAAA;AAQM,MAAM,sBAAsB,YAAa,CAAA;AAAA,EAC9C,EAAI,EAAA,gBAAA;AAAA,EACJ,IAAM,EAAA;AAAA,IACJ,gBAAiB,CAAA;AAAA,MACf,GAAK,EAAA,mBAAA;AAAA,MACL,IAAM,EAAA;AAAA,QACJ,YAAc,EAAA,eAAA;AAAA,QACd,UAAY,EAAA,aAAA;AAAA,QACZ,QAAU,EAAA,WAAA;AAAA,QACV,kBAAoB,EAAA,qBAAA;AAAA,QACpB,UAAY,EAAA,aAAA;AAAA,QACZ,SAAW,EAAA,YAAA;AAAA,OACb;AAAA,MACA,SAAS,CAAC;AAAA,QACR,YAAA;AAAA,QACA,UAAA;AAAA,QACA,QAAA;AAAA,QACA,kBAAA;AAAA,QACA,UAAA;AAAA,QACA,SAAA;AAAA,OACF,KACE,IAAI,mBAAoB,CAAA;AAAA,QACtB,YAAA;AAAA,QACA,UAAA;AAAA,QACA,kBAAA;AAAA,QACA,QAAA;AAAA,QACA,UAAA;AAAA,QACA,SAAA;AAAA,OACD,CAAA;AAAA,KACJ,CAAA;AAAA,GACH;AAAA,EACA,MAAQ,EAAA;AAAA,IACN,UAAY,EAAA,YAAA;AAAA,GACd;AACF,CAAC,EAAA;AAOM,MAAM,oBAAoB,mBAAoB,CAAA,OAAA;AAAA,EACnD,uBAAwB,CAAA;AAAA,IACtB,IAAM,EAAA,mBAAA;AAAA,IACN,SAAA,EAAW,MAAM,OAAO,sCAAyB,EAAE,IAAK,CAAA,CAAA,CAAA,KAAK,EAAE,UAAU,CAAA;AAAA,IACzE,UAAY,EAAA,YAAA;AAAA,GACb,CAAA;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-import",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-next.1",
|
|
4
4
|
"description": "A Backstage plugin the helps you import entities into your catalog",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "frontend-plugin"
|
|
@@ -52,15 +52,15 @@
|
|
|
52
52
|
"@backstage/catalog-client": "^1.6.5",
|
|
53
53
|
"@backstage/catalog-model": "^1.5.0",
|
|
54
54
|
"@backstage/config": "^1.2.0",
|
|
55
|
-
"@backstage/core-compat-api": "^0.2.
|
|
56
|
-
"@backstage/core-components": "^0.14.
|
|
55
|
+
"@backstage/core-compat-api": "^0.2.6-next.0",
|
|
56
|
+
"@backstage/core-components": "^0.14.8-next.0",
|
|
57
57
|
"@backstage/core-plugin-api": "^1.9.2",
|
|
58
58
|
"@backstage/errors": "^1.2.4",
|
|
59
|
-
"@backstage/frontend-plugin-api": "^0.6.
|
|
59
|
+
"@backstage/frontend-plugin-api": "^0.6.6-next.0",
|
|
60
60
|
"@backstage/integration": "^1.11.0",
|
|
61
61
|
"@backstage/integration-react": "^1.1.27",
|
|
62
62
|
"@backstage/plugin-catalog-common": "^1.0.23",
|
|
63
|
-
"@backstage/plugin-catalog-react": "^1.12.0",
|
|
63
|
+
"@backstage/plugin-catalog-react": "^1.12.1-next.0",
|
|
64
64
|
"@material-ui/core": "^4.12.2",
|
|
65
65
|
"@material-ui/icons": "^4.9.1",
|
|
66
66
|
"@material-ui/lab": "4.0.0-alpha.61",
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
"yaml": "^2.0.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@backstage/cli": "^0.26.
|
|
77
|
+
"@backstage/cli": "^0.26.7-next.1",
|
|
78
78
|
"@backstage/core-app-api": "^1.12.5",
|
|
79
|
-
"@backstage/dev-utils": "^1.0.
|
|
80
|
-
"@backstage/plugin-catalog": "^1.20.
|
|
81
|
-
"@backstage/test-utils": "^1.5.
|
|
79
|
+
"@backstage/dev-utils": "^1.0.33-next.0",
|
|
80
|
+
"@backstage/plugin-catalog": "^1.20.1-next.1",
|
|
81
|
+
"@backstage/test-utils": "^1.5.6-next.0",
|
|
82
82
|
"@testing-library/dom": "^10.0.0",
|
|
83
83
|
"@testing-library/jest-dom": "^6.0.0",
|
|
84
84
|
"@testing-library/react": "^15.0.0",
|