@backstage-community/plugin-sonarqube
Version:
63 lines (60 loc) • 2.27 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import useAsync from 'react-use/esm/useAsync';
import { useEntity, useRelatedEntities } from '@backstage/plugin-catalog-react';
import { useApi } from '@backstage/core-plugin-api';
import { Progress, ResponseErrorPanel } from '@backstage/core-components';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { sonarQubeApiRef, getProjectInfo } from '@backstage-community/plugin-sonarqube-react';
import '../SonarQubeCard/SonarQubeCard.esm.js';
import { SonarQubeTable } from '../SonarQubeTable/SonarQubeTable.esm.js';
const SonarQubeRelatedEntitiesOverview = (props) => {
const sonarQubeApi = useApi(sonarQubeApiRef);
const { entity: parentEntity } = useEntity();
const {
entities,
loading: loadingEntities,
error: errorEntities
} = useRelatedEntities(parentEntity, {
type: props.relationType,
kind: props.entityKind
});
const findingsRequest = [];
const entityNameToProjectKey = {};
for (const entity of entities || []) {
const { projectKey, projectInstance } = getProjectInfo(entity);
if (projectKey) {
entityNameToProjectKey[entity.metadata.name] = projectKey;
findingsRequest.push({ componentKey: projectKey, projectInstance });
}
}
const {
value: findingResults,
loading: loadingFindings,
error: errorFindings
} = useAsync(
async () => sonarQubeApi.getFindingSummaries(findingsRequest),
[sonarQubeApi, entities]
);
if (loadingEntities || loadingFindings) {
return /* @__PURE__ */ jsx(Progress, {});
}
const error = errorEntities || errorFindings;
if (error) {
return /* @__PURE__ */ jsx(ResponseErrorPanel, { error });
}
const tableContent = entities?.map((entity) => {
const projectKey = entityNameToProjectKey[entity.metadata.name];
return {
id: projectKey || entity.metadata.name,
resolved: {
entityRef: stringifyEntityRef(entity),
name: entity.metadata.name,
findings: findingResults?.get(projectKey),
isSonarQubeAnnotationEnabled: !!projectKey
}
};
});
return /* @__PURE__ */ jsx(SonarQubeTable, { tableContent });
};
export { SonarQubeRelatedEntitiesOverview };
//# sourceMappingURL=SonarQubeRelatedEntitiesOverview.esm.js.map