Bazaar: Added 'isBazaarAvailable' helper
The EntityBazaarInfoCard shows the bazaar data for components that have a bazaar item linked. The isBazaarAvailable helper makes it possible to only include the EntityBazaarInfoCard for components that actually have a bazaar project linked. Closes #15013 Signed-off-by: Niklas Aronsson <niklasar@axis.com>
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
|
||||
import {
|
||||
ApiHolder,
|
||||
createApiRef,
|
||||
DiscoveryApi,
|
||||
FetchApi,
|
||||
@@ -46,6 +48,25 @@ export interface BazaarApi {
|
||||
deleteProject(id: number): Promise<void>;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export const isBazaarAvailable = async (
|
||||
entity: Entity,
|
||||
context: { apis: ApiHolder },
|
||||
): Promise<boolean> => {
|
||||
const bazaarClient = context.apis.get(bazaarApiRef);
|
||||
if (bazaarClient === undefined) {
|
||||
return false;
|
||||
}
|
||||
const entityRef = stringifyEntityRef({
|
||||
kind: entity.kind,
|
||||
name: entity.metadata.name,
|
||||
namespace: entity.metadata.namespace,
|
||||
});
|
||||
const response = await bazaarClient.getProjectByRef(entityRef);
|
||||
const project = await response.json();
|
||||
return project.data.length > 0;
|
||||
};
|
||||
|
||||
export class BazaarClient implements BazaarApi {
|
||||
private readonly identityApi: IdentityApi;
|
||||
private readonly discoveryApi: DiscoveryApi;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
export { bazaarPlugin, BazaarPage } from './plugin';
|
||||
export { isBazaarAvailable } from './api';
|
||||
export { BazaarOverviewCard } from './components/BazaarOverviewCard';
|
||||
export type { BazaarOverviewCardProps } from './components/BazaarOverviewCard';
|
||||
export { EntityBazaarInfoCard } from './components/EntityBazaarInfoCard';
|
||||
|
||||
Reference in New Issue
Block a user