Another round of improvements
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -31,17 +31,18 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
this.identityApi = options.identityApi;
|
||||
}
|
||||
|
||||
getRepoBuilds(
|
||||
async getRepoBuilds(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
options?: RepoBuildOptions,
|
||||
): Promise<{ items: RepoBuild[] }> {
|
||||
return this.get(
|
||||
const items = await this.get<RepoBuild[]>(
|
||||
`repo-builds/${projectName}/${repoName}?top=${options?.top}`,
|
||||
);
|
||||
return { items };
|
||||
}
|
||||
|
||||
private async get(path: string): Promise<{ items: any }> {
|
||||
private async get<T>(path: string): Promise<T> {
|
||||
const baseUrl = `${await this.discoveryApi.getBaseUrl('azure-devops')}/`;
|
||||
const url = new URL(path, baseUrl);
|
||||
|
||||
@@ -54,6 +55,6 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
throw await ResponseError.fromResponse(response);
|
||||
}
|
||||
|
||||
return response.json() as Promise<{ items: any }>;
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -19,9 +19,13 @@ import React from 'react';
|
||||
import { useRepoBuilds } from '../../hooks/useRepoBuilds';
|
||||
import { BuildTable } from '../BuildTable/BuildTable';
|
||||
|
||||
export const EntityPageAzurePipelines = () => {
|
||||
export const EntityPageAzurePipelines = ({
|
||||
defaultLimit,
|
||||
}: {
|
||||
defaultLimit?: number;
|
||||
}) => {
|
||||
const { entity } = useEntity();
|
||||
const { items, loading, error } = useRepoBuilds(entity);
|
||||
const { items, loading, error } = useRepoBuilds(entity, defaultLimit);
|
||||
|
||||
return <BuildTable items={items} loading={loading} error={error} />;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ import { MissingAnnotationEmptyState } from '@backstage/core-components';
|
||||
export const isAzureDevOpsAvailable = (entity: Entity) =>
|
||||
Boolean(entity.metadata.annotations?.[AZURE_DEVOPS_ANNOTATION]);
|
||||
|
||||
export const Router = () => {
|
||||
export const Router = ({ defaultLimit }: { defaultLimit?: number }) => {
|
||||
const { entity } = useEntity();
|
||||
|
||||
if (!isAzureDevOpsAvailable(entity)) {
|
||||
@@ -36,7 +36,7 @@ export const Router = () => {
|
||||
<Routes>
|
||||
<Route
|
||||
path={`/${azureDevOpsRouteRef.path}`}
|
||||
element={<EntityPageAzurePipelines />}
|
||||
element={<EntityPageAzurePipelines defaultLimit={defaultLimit} />}
|
||||
/>
|
||||
</Routes>
|
||||
);
|
||||
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
import { useAsync } from 'react-use';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { useApi, configApiRef } from '@backstage/core-plugin-api';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { azureDevOpsApiRef } from '../api';
|
||||
import { RepoBuild, RepoBuildOptions } from '../api/types';
|
||||
import { useProjectRepoFromEntity } from './useProjectRepoFromEntity';
|
||||
import { AZURE_DEVOPS_DEFAULT_TOP } from '../constants';
|
||||
|
||||
export function useRepoBuilds(entity: Entity): {
|
||||
export function useRepoBuilds(
|
||||
entity: Entity,
|
||||
defaultLimit?: number,
|
||||
): {
|
||||
items: RepoBuild[];
|
||||
loading: boolean;
|
||||
error: any;
|
||||
} {
|
||||
const config = useApi(configApiRef);
|
||||
const top =
|
||||
config.getOptionalNumber('azureDevOps.azurePipelines.top') ??
|
||||
AZURE_DEVOPS_DEFAULT_TOP;
|
||||
const top = defaultLimit ?? AZURE_DEVOPS_DEFAULT_TOP;
|
||||
const options: RepoBuildOptions = {
|
||||
top: top,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user