From 9a2e3b93de060e5ffb11c7a6b5550502a374ab6b Mon Sep 17 00:00:00 2001 From: ebarrios Date: Thu, 27 Aug 2020 17:39:22 +0200 Subject: [PATCH] Added Widget for listing workflows run --- .../src/components/Widget/Widget.tsx | 53 ++++++++++++++++++- .../src/components/Widget/index.ts | 2 +- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/plugins/github-actions/src/components/Widget/Widget.tsx b/plugins/github-actions/src/components/Widget/Widget.tsx index 031364c8ce..201004f46e 100644 --- a/plugins/github-actions/src/components/Widget/Widget.tsx +++ b/plugins/github-actions/src/components/Widget/Widget.tsx @@ -15,7 +15,7 @@ */ import React, { useEffect } from 'react'; import { useWorkflowRuns } from '../useWorkflowRuns'; -import { WorkflowRun } from '../WorkflowRunsTable'; +import { WorkflowRun, WorkflowRunsTable } from '../WorkflowRunsTable'; import { Entity } from '@backstage/catalog-model'; import { WorkflowRunStatus } from '../WorkflowRunStatus'; import { @@ -108,3 +108,54 @@ export const Widget = ({ ); }; + +const WidgetListContent = ({ + error, + loading, + branch, +}: { + error?: Error; + loading?: boolean; + lastRun: WorkflowRun; + branch: string; +}) => { + if (error) return Couldn't fetch {branch} runs; + if (loading) return ; + return ; +}; + +export const WidgetList = ({ + entity, + branch = 'master', +}: { + entity: Entity; + branch: string; +}) => { + const errorApi = useApi(errorApiRef); + const [owner, repo] = ( + entity?.metadata.annotations?.['backstage.io/github-actions-id'] ?? '/' + ).split('/'); + const [{ runs, loading, error }] = useWorkflowRuns({ + owner, + repo, + branch, + }); + + const lastRun = runs?.[0] ?? ({} as WorkflowRun); + useEffect(() => { + if (error) { + errorApi.post(error); + } + }, [error, errorApi]); + + return ( + + + + ); +}; diff --git a/plugins/github-actions/src/components/Widget/index.ts b/plugins/github-actions/src/components/Widget/index.ts index 2b34671ab5..0efc84d952 100644 --- a/plugins/github-actions/src/components/Widget/index.ts +++ b/plugins/github-actions/src/components/Widget/index.ts @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { Widget } from './Widget'; +export { Widget, WidgetList } from './Widget';