Removed total_count from ActionsListWorkflowRunsForRepoResponseData type and calculate it on the fly. Clean up types.ts to remove duplicated entry (builds = ActionsListWorkflowRunsForRepoResponseData). Remove redundant line on router.tsx. Removed extra space in title for WarningPanel in Router.ts.

This commit is contained in:
ebarrios
2020-09-23 17:21:23 +02:00
parent 6002842bfb
commit bd26c9c8da
4 changed files with 5 additions and 17 deletions
@@ -18,7 +18,6 @@ import { CloudbuildApi } from './CloudbuildApi';
import {
ActionsListWorkflowRunsForRepoResponseData,
ActionsGetWorkflowResponseData,
Builds,
} from '../api/types';
import { OAuthApi } from '@backstage/core';
@@ -61,14 +60,9 @@ export class CloudbuildClient implements CloudbuildApi {
},
);
const builds: Builds = await workflowRuns.json();
const builds: ActionsListWorkflowRunsForRepoResponseData = await workflowRuns.json();
const response: ActionsListWorkflowRunsForRepoResponseData = {
total_count: builds.builds.length,
builds: builds.builds,
};
return response;
return builds;
}
async getWorkflow({
projectId,
-5
View File
@@ -15,14 +15,9 @@
*/
export interface ActionsListWorkflowRunsForRepoResponseData {
total_count: number;
builds: ActionsGetWorkflowResponseData[];
}
export type Builds = {
builds: ActionsGetWorkflowResponseData[];
};
export type ActionsGetWorkflowResponseData = {
id: string;
status: string;
+2 -3
View File
@@ -23,13 +23,12 @@ import { CLOUDBUILD_ANNOTATION } from './useProjectName';
import { WarningPanel } from '@backstage/core';
export const isPluginApplicableToEntity = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[CLOUDBUILD_ANNOTATION]) &&
entity.metadata.annotations?.[CLOUDBUILD_ANNOTATION] !== '';
Boolean(entity.metadata.annotations?.[CLOUDBUILD_ANNOTATION]);
export const Router = ({ entity }: { entity: Entity }) =>
// TODO(shmidt-i): move warning to a separate standardized component
!isPluginApplicableToEntity(entity) ? (
<WarningPanel title=" Cloudbuild plugin:">
<WarningPanel title="Cloudbuild plugin:">
<pre>{CLOUDBUILD_ANNOTATION}</pre> annotation is missing on the entity.
</WarningPanel>
) : (
@@ -39,7 +39,7 @@ export function useWorkflowRuns({ projectId }: { projectId: string }) {
(
workflowRunsData: ActionsListWorkflowRunsForRepoResponseData,
): WorkflowRun[] => {
setTotal(workflowRunsData.total_count);
setTotal(workflowRunsData.builds.length);
// Transformation here
return workflowRunsData.builds.map(run => ({
message: run.substitutions.REPO_NAME,