Merge pull request #6586 from ntgussoni/feature/show-catalog-errors
Show catalog-parsing related errors in entity page
This commit is contained in:
@@ -327,6 +327,11 @@ export const EntityPageLayout: {
|
||||
}) => null;
|
||||
};
|
||||
|
||||
// Warning: (ae-missing-release-tag) "EntityProcessingErrorsPanel" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public
|
||||
export const EntityProcessingErrorsPanel: () => JSX.Element;
|
||||
|
||||
// Warning: (ae-missing-release-tag) "EntitySwitch" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
@@ -358,6 +363,11 @@ export const FilteredEntityLayout: ({
|
||||
children,
|
||||
}: PropsWithChildren<{}>) => JSX.Element;
|
||||
|
||||
// Warning: (ae-missing-release-tag) "hasCatalogProcessingErrors" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export const hasCatalogProcessingErrors: (entity: Entity) => boolean;
|
||||
|
||||
// Warning: (ae-missing-release-tag) "isComponentType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import { EntityProvider } from '@backstage/plugin-catalog-react';
|
||||
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import React from 'react';
|
||||
import { EntityProcessingErrorsPanel } from './EntityProcessingErrorsPanel';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
|
||||
describe('<EntityProcessErrors />', () => {
|
||||
it('renders EntityProcessErrors if the entity has errors', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'v1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'software',
|
||||
description: 'This is the description',
|
||||
},
|
||||
|
||||
spec: {
|
||||
owner: 'guest',
|
||||
type: 'service',
|
||||
lifecycle: 'production',
|
||||
},
|
||||
status: {
|
||||
items: [
|
||||
{
|
||||
type: 'backstage.io/catalog-processing',
|
||||
level: 'error',
|
||||
message:
|
||||
'InputError: Policy check failed; caused by Error: Malformed envelope, /metadata/labels should be object',
|
||||
error: {
|
||||
name: 'InputError',
|
||||
message:
|
||||
'Policy check failed; caused by Error: Malformed envelope, /metadata/labels should be object',
|
||||
cause: {
|
||||
name: 'Error',
|
||||
message:
|
||||
'Malformed envelope, /metadata/labels should be object',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'foo',
|
||||
level: 'error',
|
||||
message: 'InputError: This should not be rendered',
|
||||
error: {
|
||||
name: 'InputError',
|
||||
message: 'Foo',
|
||||
cause: {
|
||||
name: 'Error',
|
||||
message:
|
||||
'Malformed envelope, /metadata/labels should be object',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'backstage.io/catalog-processing',
|
||||
level: 'error',
|
||||
message: 'InputError: Foo',
|
||||
error: {
|
||||
name: 'InputError',
|
||||
message: 'Foo',
|
||||
cause: {
|
||||
name: 'Error',
|
||||
message:
|
||||
'Malformed envelope, /metadata/labels should be object',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const { getByText, queryByText } = await renderInTestApp(
|
||||
<EntityProvider entity={entity}>
|
||||
<EntityProcessingErrorsPanel />
|
||||
</EntityProvider>,
|
||||
);
|
||||
|
||||
expect(
|
||||
getByText(
|
||||
'Error: Policy check failed; caused by Error: Malformed envelope, /metadata/labels should be object',
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
expect(getByText('Error: Foo')).toBeInTheDocument();
|
||||
expect(queryByText('Error: This should not be rendered')).toBeNull();
|
||||
});
|
||||
});
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
|
||||
import { Entity, UNSTABLE_EntityStatusItem } from '@backstage/catalog-model';
|
||||
import { useEntity } from '@backstage/plugin-catalog-react';
|
||||
import { Box } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { ResponseErrorPanel } from '@backstage/core-components';
|
||||
import { ENTITY_STATUS_CATALOG_PROCESSING_TYPE } from '@backstage/catalog-client';
|
||||
|
||||
const errorfilter = (i: UNSTABLE_EntityStatusItem) =>
|
||||
i.error &&
|
||||
i.level === 'error' &&
|
||||
i.type === ENTITY_STATUS_CATALOG_PROCESSING_TYPE;
|
||||
|
||||
export const hasCatalogProcessingErrors = (entity: Entity) =>
|
||||
entity?.status?.items?.filter(errorfilter).length! > 0;
|
||||
|
||||
/**
|
||||
* Displays a list of errors if the entity is invalid.
|
||||
*/
|
||||
export const EntityProcessingErrorsPanel = () => {
|
||||
const { entity } = useEntity();
|
||||
const catalogProcessingErrors =
|
||||
(entity?.status?.items?.filter(
|
||||
errorfilter,
|
||||
) as Required<UNSTABLE_EntityStatusItem>[]) || [];
|
||||
|
||||
return (
|
||||
<>
|
||||
{catalogProcessingErrors.map(({ error }, index) => (
|
||||
<Box key={index} mb={1}>
|
||||
<ResponseErrorPanel error={error} />
|
||||
</Box>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2021 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 {
|
||||
EntityProcessingErrorsPanel,
|
||||
hasCatalogProcessingErrors,
|
||||
} from './EntityProcessingErrorsPanel';
|
||||
@@ -23,6 +23,7 @@ export * from './components/CatalogTable/columns';
|
||||
export * from './components/CreateComponentButton';
|
||||
export * from './components/EntityLayout';
|
||||
export * from './components/EntityOrphanWarning';
|
||||
export * from './components/EntityProcessingErrorsPanel';
|
||||
export * from './components/EntityPageLayout';
|
||||
export * from './components/EntitySwitch';
|
||||
export * from './components/FilteredEntityLayout';
|
||||
|
||||
@@ -100,7 +100,7 @@ describe('<GroupsExplorerContent />', () => {
|
||||
const catalogError = new Error('Network timeout');
|
||||
catalogApi.getEntities.mockRejectedValueOnce(catalogError);
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
const { getAllByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<GroupsExplorerContent />
|
||||
</Wrapper>,
|
||||
@@ -108,7 +108,7 @@ describe('<GroupsExplorerContent />', () => {
|
||||
);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(getByText(/Warning: Network timeout/)).toBeInTheDocument(),
|
||||
expect(getAllByText(/Error: Network timeout/).length).not.toBe(0),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('<FossaCard />', () => {
|
||||
|
||||
fossaApi.getFindingSummary.mockRejectedValue(new Error('My Error'));
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
const { getAllByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<EntityProvider entity={entity}>
|
||||
<FossaCard />
|
||||
@@ -82,7 +82,7 @@ describe('<FossaCard />', () => {
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
expect(getByText(/Warning: My Error/i)).toBeInTheDocument();
|
||||
expect(getAllByText(/Error: My Error/i).length).not.toBe(0);
|
||||
});
|
||||
|
||||
it('shows empty', async () => {
|
||||
|
||||
@@ -311,7 +311,7 @@ describe('github-deployments', () => {
|
||||
|
||||
expect(
|
||||
await rendered.findByText(
|
||||
'Warning: No apiBaseUrl available for host my-github-3.com, please check your integrations config',
|
||||
'Error: No apiBaseUrl available for host my-github-3.com, please check your integrations config',
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
@@ -336,7 +336,7 @@ describe('github-deployments', () => {
|
||||
|
||||
expect(
|
||||
await rendered.findByText(
|
||||
'Warning: No matching GitHub integration configuration for host my-github-unknown.com, please check your integrations config',
|
||||
'Error: No matching GitHub integration configuration for host my-github-unknown.com, please check your integrations config',
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user