Improve useProjectName semantics

This commit is contained in:
Dominik Henneke
2020-12-17 12:21:47 +01:00
parent 439377a728
commit b4507515fd
5 changed files with 9 additions and 10 deletions
+1 -1
View File
@@ -30,5 +30,5 @@ export const fossaApiRef = createApiRef<FossaApi>({
});
export type FossaApi = {
getFindingSummary(projectTitle?: string): Promise<FindingSummary | undefined>;
getFindingSummary(projectTitle: string): Promise<FindingSummary | undefined>;
};
+1 -1
View File
@@ -69,7 +69,7 @@ describe('FossaClient', () => {
} as FindingSummary);
});
it('should report finding summary without licenseing_issue_count', async () => {
it('should report finding summary without licensing_issue_count', async () => {
server.use(
rest.get(`${mockBaseUrl}/fossa/projects`, (req, res, ctx) => {
expect(req.url.searchParams.toString()).toBe(
+1 -5
View File
@@ -43,12 +43,8 @@ export class FossaClient implements FossaApi {
}
async getFindingSummary(
projectTitle?: string,
projectTitle: string,
): Promise<FindingSummary | undefined> {
if (!projectTitle) {
return undefined;
}
const project = await this.callApi(
`projects?count=1&title=${projectTitle}${
this.organizationId ? `&organizationId=${this.organizationId}` : ''
@@ -77,7 +77,8 @@ export const FossaCard = ({
const projectTitle = useProjectName(entity);
const { value, loading } = useAsync(
async () => fossaApi.getFindingSummary(projectTitle),
async () =>
projectTitle ? fossaApi.getFindingSummary(projectTitle) : undefined,
[fossaApi, projectTitle],
);
@@ -18,6 +18,8 @@ import { Entity } from '@backstage/catalog-model';
export const FOSSA_PROJECT_NAME_ANNOTATION = 'fossa.io/project-name';
export const useProjectName = (entity: Entity) => {
return entity?.metadata.annotations?.[FOSSA_PROJECT_NAME_ANNOTATION] ?? '';
export const useProjectName = (entity: Entity): string | undefined => {
return (
entity?.metadata.annotations?.[FOSSA_PROJECT_NAME_ANNOTATION] ?? undefined
);
};