diff --git a/plugins/entity-validation/api-report.md b/plugins/entity-validation/api-report.md index 1a3b92a7c1..2fccbf9471 100644 --- a/plugins/entity-validation/api-report.md +++ b/plugins/entity-validation/api-report.md @@ -9,12 +9,9 @@ import { BackstagePlugin } from '@backstage/core-plugin-api'; import { RouteRef } from '@backstage/core-plugin-api'; // @public (undocumented) -export const EntityValidationPage: ({ - defaultPreviewCatalog, - locationPlaceholder, -}: { - defaultPreviewCatalog?: string | undefined; - locationPlaceholder?: string | undefined; +export const EntityValidationPage: (props: { + defaultYaml?: string | undefined; + defaultLocation?: string | undefined; }) => JSX.Element; // @public (undocumented) diff --git a/plugins/entity-validation/package.json b/plugins/entity-validation/package.json index a6ea724473..3ff4f0ad5c 100644 --- a/plugins/entity-validation/package.json +++ b/plugins/entity-validation/package.json @@ -31,8 +31,8 @@ "@backstage/catalog-model": "workspace:^", "@backstage/core-components": "workspace:^", "@backstage/core-plugin-api": "workspace:^", + "@backstage/errors": "workspace:^", "@backstage/plugin-catalog-common": "workspace:^", - "@backstage/plugin-catalog-node": "workspace:^", "@backstage/plugin-catalog-react": "workspace:^", "@backstage/theme": "workspace:^", "@codemirror/language": "^6.0.0", diff --git a/plugins/entity-validation/src/components/EntityValidationOutput/EntityValidationOutput.tsx b/plugins/entity-validation/src/components/EntityValidationOutput/EntityValidationOutput.tsx index f58fc90559..bc7e22ef54 100644 --- a/plugins/entity-validation/src/components/EntityValidationOutput/EntityValidationOutput.tsx +++ b/plugins/entity-validation/src/components/EntityValidationOutput/EntityValidationOutput.tsx @@ -15,7 +15,6 @@ */ import React from 'react'; import { identityApiRef, useApi } from '@backstage/core-plugin-api'; -import { CatalogProcessorResult } from '@backstage/plugin-catalog-node'; import { catalogApiRef, humanizeEntityRef, @@ -25,6 +24,7 @@ import useAsync from 'react-use/lib/useAsync'; import { InfoCard, Progress } from '@backstage/core-components'; import Alert from '@material-ui/lab/Alert'; import { + CatalogProcessorResult, ValidationOutput, ValidationOutputError, ValidationOutputOk, diff --git a/plugins/entity-validation/src/components/EntityValidationPage/EntityValidationPage.tsx b/plugins/entity-validation/src/components/EntityValidationPage/EntityValidationPage.tsx index d39b234342..dc86af8763 100644 --- a/plugins/entity-validation/src/components/EntityValidationPage/EntityValidationPage.tsx +++ b/plugins/entity-validation/src/components/EntityValidationPage/EntityValidationPage.tsx @@ -17,7 +17,7 @@ import React, { useState } from 'react'; import { Button, Content, Header, Page } from '@backstage/core-components'; import { EntityTextArea } from '../EntityTextArea'; import { Grid, TextField } from '@material-ui/core'; -import { CatalogProcessorResult } from '@backstage/plugin-catalog-node'; +import { CatalogProcessorResult } from '../../types'; import { parseEntityYaml } from '../../utils'; import { EntityValidationOutput } from '../EntityValidationOutput'; @@ -36,14 +36,16 @@ spec: owner: owner `; -export const EntityValidationPage = ({ - defaultPreviewCatalog = EXAMPLE_CATALOG_INFO_YAML, - locationPlaceholder = 'https://github.com/backstage/backstage/blob/master/catalog-info.yaml', -}: { - defaultPreviewCatalog?: string; - locationPlaceholder?: string; +export const EntityValidationPage = (props: { + defaultYaml?: string; + defaultLocation?: string; }) => { - const [catalogYaml, setCatalogYaml] = useState(defaultPreviewCatalog); + const { + defaultYaml = EXAMPLE_CATALOG_INFO_YAML, + defaultLocation = 'https://github.com/backstage/backstage/blob/master/catalog-info.yaml', + } = props; + + const [catalogYaml, setCatalogYaml] = useState(defaultYaml); const [yamlFiles, setYamlFiles] = useState(); const [locationUrl, setLocationUrl] = useState(''); @@ -72,7 +74,8 @@ export const EntityValidationPage = ({ margin="normal" variant="outlined" required - placeholder={locationPlaceholder} + value={defaultLocation} + placeholder={defaultLocation} helperText="Location where you catalog-info.yaml file is, or will be, located" onChange={e => setLocationUrl(e.target.value)} /> diff --git a/plugins/entity-validation/src/processingResult.ts b/plugins/entity-validation/src/processingResult.ts new file mode 100644 index 0000000000..de9d8adbbd --- /dev/null +++ b/plugins/entity-validation/src/processingResult.ts @@ -0,0 +1,73 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// File copied from https://github.com/backstage/backstage/blob/master/plugins/catalog-node/src/api/processingResult.ts +import { InputError, NotFoundError } from '@backstage/errors'; +import { Entity } from '@backstage/catalog-model'; +import { LocationSpec } from '@backstage/plugin-catalog-common'; +import { CatalogProcessorResult, EntityRelationSpec } from './types'; + +/** + * Factory functions for the standard processing result types. + * + * @public + */ +export const processingResult = Object.freeze({ + notFoundError( + atLocation: LocationSpec, + message: string, + ): CatalogProcessorResult { + return { + type: 'error', + location: atLocation, + error: new NotFoundError(message), + }; + }, + + inputError( + atLocation: LocationSpec, + message: string, + ): CatalogProcessorResult { + return { + type: 'error', + location: atLocation, + error: new InputError(message), + }; + }, + + generalError( + atLocation: LocationSpec, + message: string, + ): CatalogProcessorResult { + return { type: 'error', location: atLocation, error: new Error(message) }; + }, + + location(newLocation: LocationSpec): CatalogProcessorResult { + return { type: 'location', location: newLocation }; + }, + + entity(atLocation: LocationSpec, newEntity: Entity): CatalogProcessorResult { + return { type: 'entity', location: atLocation, entity: newEntity }; + }, + + relation(spec: EntityRelationSpec): CatalogProcessorResult { + return { type: 'relation', relation: spec }; + }, + + refresh(key: string): CatalogProcessorResult { + return { type: 'refresh', key }; + }, +} as const); diff --git a/plugins/entity-validation/src/types.ts b/plugins/entity-validation/src/types.ts index 69caf79e33..7ecc27bb25 100644 --- a/plugins/entity-validation/src/types.ts +++ b/plugins/entity-validation/src/types.ts @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Entity } from '@backstage/catalog-model'; +import { CompoundEntityRef, Entity } from '@backstage/catalog-model'; import { ValidateEntityResponse } from '@backstage/catalog-client'; +import { LocationSpec } from '@backstage/plugin-catalog-common'; export type ValidationOutputError = { type: 'error'; @@ -28,3 +29,54 @@ export type ValidationOutputOk = { }; export type ValidationOutput = ValidationOutputOk | ValidationOutputError; + +export type EntityRelationSpec = { + /** + * The source entity of this relation. + */ + source: CompoundEntityRef; + + /** + * The type of the relation. + */ + type: string; + + /** + * The target entity of this relation. + */ + target: CompoundEntityRef; +}; + +type CatalogProcessorLocationResult = { + type: 'location'; + location: LocationSpec; +}; + +type CatalogProcessorEntityResult = { + type: 'entity'; + entity: Entity; + location: LocationSpec; +}; + +type CatalogProcessorRelationResult = { + type: 'relation'; + relation: EntityRelationSpec; +}; + +type CatalogProcessorErrorResult = { + type: 'error'; + error: Error; + location: LocationSpec; +}; + +type CatalogProcessorRefreshKeysResult = { + type: 'refresh'; + key: string; +}; + +export type CatalogProcessorResult = + | CatalogProcessorLocationResult + | CatalogProcessorEntityResult + | CatalogProcessorRelationResult + | CatalogProcessorErrorResult + | CatalogProcessorRefreshKeysResult; diff --git a/plugins/entity-validation/src/utils/utils.ts b/plugins/entity-validation/src/utils.ts similarity index 95% rename from plugins/entity-validation/src/utils/utils.ts rename to plugins/entity-validation/src/utils.ts index dde50d2f9c..d81de6f6c9 100644 --- a/plugins/entity-validation/src/utils/utils.ts +++ b/plugins/entity-validation/src/utils.ts @@ -17,10 +17,8 @@ import { Entity, stringifyLocationRef } from '@backstage/catalog-model'; import lodash from 'lodash'; import yaml from 'yaml'; import { LocationSpec } from '@backstage/plugin-catalog-common'; -import { - CatalogProcessorResult, - processingResult, -} from '@backstage/plugin-catalog-node'; +import { CatalogProcessorResult } from './types'; +import { processingResult } from './processingResult'; // Copy from: https://github.com/backstage/backstage/blob/master/plugins/catalog-backend/src/modules/util/parse.ts export function* parseEntityYaml( diff --git a/plugins/entity-validation/src/utils/index.ts b/plugins/entity-validation/src/utils/index.ts deleted file mode 100644 index 8d45a67a36..0000000000 --- a/plugins/entity-validation/src/utils/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2023 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export * from './utils'; diff --git a/yarn.lock b/yarn.lock index a3e9612ca6..7e53aaf8bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5770,8 +5770,8 @@ __metadata: "@backstage/core-components": "workspace:^" "@backstage/core-plugin-api": "workspace:^" "@backstage/dev-utils": "workspace:^" + "@backstage/errors": "workspace:^" "@backstage/plugin-catalog-common": "workspace:^" - "@backstage/plugin-catalog-node": "workspace:^" "@backstage/plugin-catalog-react": "workspace:^" "@backstage/test-utils": "workspace:^" "@backstage/theme": "workspace:^"