From 09c106b96cc07dbfb6cce54997ed4fea84cdbcfb Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Fri, 15 Oct 2021 12:22:44 +0200 Subject: [PATCH 1/2] Add `entitiesFilter` option to `FossaPage` Signed-off-by: Oliver Sand --- .changeset/giant-phones-exercise.md | 5 +++ plugins/fossa/api-report.md | 3 +- .../components/FossaPage/FossaPage.test.tsx | 34 +++++++++++++++++++ .../src/components/FossaPage/FossaPage.tsx | 21 +++++++++--- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 .changeset/giant-phones-exercise.md diff --git a/.changeset/giant-phones-exercise.md b/.changeset/giant-phones-exercise.md new file mode 100644 index 0000000000..b190c2e7f0 --- /dev/null +++ b/.changeset/giant-phones-exercise.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-fossa': patch +--- + +Add `entitiesFilter` option to `FossaPage` to filter entities displayed in the table. diff --git a/plugins/fossa/api-report.md b/plugins/fossa/api-report.md index 50e382d3d4..da9d057db4 100644 --- a/plugins/fossa/api-report.md +++ b/plugins/fossa/api-report.md @@ -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) // diff --git a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx index 78c8b7bb40..778f5ee9c6 100644 --- a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx +++ b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx @@ -142,4 +142,38 @@ describe('', () => { 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( + + + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); + + expect(catalogApi.getEntities).toBeCalledWith( + expect.objectContaining({ + filter: { kind: 'API' }, + }), + ); + expect(getByText(/my-name-0/i)).toBeInTheDocument(); + }); }); diff --git a/plugins/fossa/src/components/FossaPage/FossaPage.tsx b/plugins/fossa/src/components/FossaPage/FossaPage.tsx index 3e16085968..fbdaf85717 100644 --- a/plugins/fossa/src/components/FossaPage/FossaPage.tsx +++ b/plugins/fossa/src/components/FossaPage/FossaPage.tsx @@ -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[] + | Record + | 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( From a6a283d760b208e1f3ba398cb0b127408193799e Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Mon, 18 Oct 2021 09:54:13 +0200 Subject: [PATCH 2/2] Export `FossaPageProps` Signed-off-by: Oliver Sand --- plugins/fossa/api-report.md | 11 ++++++++++- plugins/fossa/src/components/FossaPage/index.ts | 1 + plugins/fossa/src/components/index.ts | 2 +- plugins/fossa/src/index.ts | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/fossa/api-report.md b/plugins/fossa/api-report.md index da9d057db4..d6e229d3d6 100644 --- a/plugins/fossa/api-report.md +++ b/plugins/fossa/api-report.md @@ -18,12 +18,21 @@ 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: ({ entitiesFilter }: FossaPageProps) => JSX.Element; +// Warning: (ae-missing-release-tag) "FossaPageProps" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type FossaPageProps = { + entitiesFilter?: + | Record[] + | Record + | undefined; +}; + // Warning: (ae-missing-release-tag) "fossaPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) diff --git a/plugins/fossa/src/components/FossaPage/index.ts b/plugins/fossa/src/components/FossaPage/index.ts index 7be77be441..13dd680a95 100644 --- a/plugins/fossa/src/components/FossaPage/index.ts +++ b/plugins/fossa/src/components/FossaPage/index.ts @@ -15,3 +15,4 @@ */ export { FossaPage } from './FossaPage'; +export type { FossaPageProps } from './FossaPage'; diff --git a/plugins/fossa/src/components/index.ts b/plugins/fossa/src/components/index.ts index 12632d4fff..f108626e88 100644 --- a/plugins/fossa/src/components/index.ts +++ b/plugins/fossa/src/components/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './FossaCard'; +export type { FossaPageProps } from './FossaPage'; diff --git a/plugins/fossa/src/index.ts b/plugins/fossa/src/index.ts index 200b977f3b..7f75fad178 100644 --- a/plugins/fossa/src/index.ts +++ b/plugins/fossa/src/index.ts @@ -20,5 +20,6 @@ * @packageDocumentation */ -export { fossaPlugin } from './plugin'; +export * from './components'; export { EntityFossaCard, FossaPage } from './extensions'; +export { fossaPlugin } from './plugin';