Renames component to EntityProcessingErrorsPanel
Only checks for catalog processing type of errors now Signed-off-by: Nicolas Torres <nicolast@backbase.com>
This commit is contained in:
+24
-12
@@ -18,9 +18,8 @@ import { EntityProvider } from '@backstage/plugin-catalog-react';
|
||||
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import React from 'react';
|
||||
import { EntityProcessErrors } from './EntityProcessErrors';
|
||||
import { EntityProcessingErrorsPanel } from './EntityProcessingErrorsPanel';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
|
||||
describe('<EntityProcessErrors />', () => {
|
||||
it('renders EntityProcessErrors if the entity has errors', async () => {
|
||||
@@ -55,6 +54,20 @@ describe('<EntityProcessErrors />', () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
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',
|
||||
@@ -73,19 +86,18 @@ describe('<EntityProcessErrors />', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
const { getByText, queryByText } = await renderInTestApp(
|
||||
<EntityProvider entity={entity}>
|
||||
<EntityProcessErrors />
|
||||
<EntityProcessingErrorsPanel />
|
||||
</EntityProvider>,
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText(
|
||||
'Error: Policy check failed; caused by Error: Malformed envelope, /metadata/labels should be object',
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
expect(getByText('Error: Foo')).toBeInTheDocument();
|
||||
});
|
||||
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();
|
||||
});
|
||||
});
|
||||
+19
-11
@@ -14,30 +14,38 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
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 '../../../../../packages/catalog-client/src';
|
||||
|
||||
export const hasErrors = (entity: Entity) => entity?.status?.items?.length! > 0;
|
||||
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 EntityProcessErrors = () => {
|
||||
export const EntityProcessingErrorsPanel = () => {
|
||||
const { entity } = useEntity();
|
||||
const catalogProcessingErrors =
|
||||
(entity?.status?.items?.filter(
|
||||
errorfilter,
|
||||
) as Required<UNSTABLE_EntityStatusItem>[]) || [];
|
||||
|
||||
return (
|
||||
<>
|
||||
{entity?.status?.items?.map(
|
||||
({ error }, index) =>
|
||||
error && (
|
||||
<Box key={index} mb={1}>
|
||||
<ResponseErrorPanel error={error} />
|
||||
</Box>
|
||||
),
|
||||
)}
|
||||
{catalogProcessingErrors.map(({ error }, index) => (
|
||||
<Box key={index} mb={1}>
|
||||
<ResponseErrorPanel error={error} />
|
||||
</Box>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
||||
+4
-1
@@ -14,4 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { EntityProcessErrors, hasErrors } from './EntityProcessErrors';
|
||||
export {
|
||||
EntityProcessingErrorsPanel,
|
||||
hasCatalogProcessingErrors,
|
||||
} from './EntityProcessingErrorsPanel';
|
||||
@@ -23,7 +23,7 @@ export * from './components/CatalogTable/columns';
|
||||
export * from './components/CreateComponentButton';
|
||||
export * from './components/EntityLayout';
|
||||
export * from './components/EntityOrphanWarning';
|
||||
export * from './components/EntityProcessErrors';
|
||||
export * from './components/EntityProcessingErrorsPanel';
|
||||
export * from './components/EntityPageLayout';
|
||||
export * from './components/EntitySwitch';
|
||||
export * from './components/FilteredEntityLayout';
|
||||
|
||||
Reference in New Issue
Block a user