Add entitiesFilter option to FossaPage

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-10-15 12:22:44 +02:00
parent 157843e5aa
commit 09c106b96c
4 changed files with 57 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-fossa': patch
---
Add `entitiesFilter` option to `FossaPage` to filter entities displayed in the table.
+2 -1
View File
@@ -18,10 +18,11 @@ export const EntityFossaCard: ({
variant?: InfoCardVariants | undefined;
}) => JSX.Element;
// Warning: (ae-forgotten-export) The symbol "FossaPageProps" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "FossaPage" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const FossaPage: () => JSX.Element;
export const FossaPage: ({ entitiesFilter }: FossaPageProps) => JSX.Element;
// Warning: (ae-missing-release-tag) "fossaPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@@ -142,4 +142,38 @@ describe('<FossaPage />', () => {
expect(getByText(/0 Issues/i)).toBeInTheDocument();
expect(getByText(/10 Issues/i)).toBeInTheDocument();
});
it('has configurable entity filter', async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'API',
metadata: {
name: 'my-name-0',
annotations: {
'fossa.io/project-name': 'my-name-0',
},
},
};
fossaApi.getFindingSummaries.mockResolvedValue(new Map());
catalogApi.getEntities.mockResolvedValue({ items: [entity] });
const { getByText } = await renderInTestApp(
<Wrapper>
<FossaPage entitiesFilter={{ kind: 'API' }} />
</Wrapper>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name/*': entityRouteRef,
},
},
);
expect(catalogApi.getEntities).toBeCalledWith(
expect.objectContaining({
filter: { kind: 'API' },
}),
);
expect(getByText(/my-name-0/i)).toBeInTheDocument();
});
});
@@ -30,8 +30,8 @@ import { Tooltip } from '@material-ui/core';
import { Skeleton } from '@material-ui/lab';
import { DateTime } from 'luxon';
import * as React from 'react';
import { useMemo } from 'react';
import { useAsync } from 'react-use';
import { useMemo, useState } from 'react';
import { useAsync, useDeepCompareEffect } from 'react-use';
import { FindingSummary, fossaApiRef } from '../../api';
import { getProjectName } from '../getProjectName';
@@ -166,14 +166,25 @@ const filters: TableFilter[] = [
{ column: 'Branch', type: 'select' },
];
export const FossaPage = () => {
export type FossaPageProps = {
entitiesFilter?:
| Record<string, string | symbol | (string | symbol)[]>[]
| Record<string, string | symbol | (string | symbol)[]>
| undefined;
};
export const FossaPage = ({
entitiesFilter = { kind: 'Component' },
}: FossaPageProps) => {
const catalogApi = useApi(catalogApiRef);
const fossaApi = useApi(fossaApiRef);
const [filter, setFilter] = useState(entitiesFilter);
useDeepCompareEffect(() => setFilter(entitiesFilter), [entitiesFilter]);
// Get a list of all relevant entities
const { value: entities, loading: entitiesLoading } = useAsync(() => {
return catalogApi.getEntities({
filter: { kind: 'Component' },
filter,
fields: [
'kind',
'metadata.namespace',
@@ -182,7 +193,7 @@ export const FossaPage = () => {
'relations',
],
});
});
}, [filter]);
// get the project names of all entities. the idx of both lists match.
const projectNames = useMemo(