Improve useProjectName semantics
This commit is contained in:
@@ -30,5 +30,5 @@ export const fossaApiRef = createApiRef<FossaApi>({
|
||||
});
|
||||
|
||||
export type FossaApi = {
|
||||
getFindingSummary(projectTitle?: string): Promise<FindingSummary | undefined>;
|
||||
getFindingSummary(projectTitle: string): Promise<FindingSummary | undefined>;
|
||||
};
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user