From bd26c9c8da3da3c49d6b796bd5d2b3b34e3f101f Mon Sep 17 00:00:00 2001 From: ebarrios Date: Wed, 23 Sep 2020 17:21:23 +0200 Subject: [PATCH] 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. --- plugins/cloudbuild/src/api/CloudbuildClient.ts | 10 ++-------- plugins/cloudbuild/src/api/types.ts | 5 ----- plugins/cloudbuild/src/components/Router.tsx | 5 ++--- plugins/cloudbuild/src/components/useWorkflowRuns.ts | 2 +- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/plugins/cloudbuild/src/api/CloudbuildClient.ts b/plugins/cloudbuild/src/api/CloudbuildClient.ts index ead6a27b3e..0c3223aa04 100644 --- a/plugins/cloudbuild/src/api/CloudbuildClient.ts +++ b/plugins/cloudbuild/src/api/CloudbuildClient.ts @@ -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, diff --git a/plugins/cloudbuild/src/api/types.ts b/plugins/cloudbuild/src/api/types.ts index bcbde4df66..7c64fb52b8 100644 --- a/plugins/cloudbuild/src/api/types.ts +++ b/plugins/cloudbuild/src/api/types.ts @@ -15,14 +15,9 @@ */ export interface ActionsListWorkflowRunsForRepoResponseData { - total_count: number; builds: ActionsGetWorkflowResponseData[]; } -export type Builds = { - builds: ActionsGetWorkflowResponseData[]; -}; - export type ActionsGetWorkflowResponseData = { id: string; status: string; diff --git a/plugins/cloudbuild/src/components/Router.tsx b/plugins/cloudbuild/src/components/Router.tsx index 65eec7cde9..b2653a05f2 100644 --- a/plugins/cloudbuild/src/components/Router.tsx +++ b/plugins/cloudbuild/src/components/Router.tsx @@ -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) ? ( - +
{CLOUDBUILD_ANNOTATION}
annotation is missing on the entity.
) : ( diff --git a/plugins/cloudbuild/src/components/useWorkflowRuns.ts b/plugins/cloudbuild/src/components/useWorkflowRuns.ts index 7086ba1c02..2ebed17e97 100644 --- a/plugins/cloudbuild/src/components/useWorkflowRuns.ts +++ b/plugins/cloudbuild/src/components/useWorkflowRuns.ts @@ -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,