From 1bdb0bf24b3b8ef134e1a475492e24aee33d42c7 Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Mon, 12 Sep 2022 09:49:19 +0200 Subject: [PATCH 1/4] Modify RecentWorkflowRunsCard use constructed routeRef instead of hardcoded route. Signed-off-by: Jussi Hallila --- .changeset/brown-kings-greet.md | 5 +++++ .../components/Cards/RecentWorkflowRunsCard.tsx | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .changeset/brown-kings-greet.md diff --git a/.changeset/brown-kings-greet.md b/.changeset/brown-kings-greet.md new file mode 100644 index 0000000000..00e82675ee --- /dev/null +++ b/.changeset/brown-kings-greet.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-github-actions': patch +--- + +Modify RecentWorkflowRunsCard use constructed routeRef instead of hardcoded route. diff --git a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx index fcd0f194a3..931b5b676e 100644 --- a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx +++ b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx @@ -16,19 +16,25 @@ import { readGitHubIntegrationConfigs } from '@backstage/integration'; import { useEntity } from '@backstage/plugin-catalog-react'; import React, { useEffect } from 'react'; -import { generatePath, Link as RouterLink } from 'react-router-dom'; +import { Link as RouterLink } from 'react-router-dom'; import { GITHUB_ACTIONS_ANNOTATION } from '../getProjectNameFromEntity'; import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns'; import { WorkflowRunStatus } from '../WorkflowRunStatus'; import { Typography } from '@material-ui/core'; -import { configApiRef, errorApiRef, useApi } from '@backstage/core-plugin-api'; +import { + configApiRef, + errorApiRef, + useApi, + useRouteRef, +} from '@backstage/core-plugin-api'; import { InfoCard, InfoCardVariants, Link, Table, } from '@backstage/core-components'; +import { buildRouteRef } from '../../routes'; const firstLine = (message: string): string => message.split('\n')[0]; @@ -69,7 +75,7 @@ export const RecentWorkflowRunsCard = (props: { }, [error, errorApi]); const githubHost = hostname || 'github.com'; - + const routeLink = useRouteRef(buildRouteRef); return ( ( - + {firstLine(data.message ?? '')} ), From 3d184f17130506397f300a57e2fe6e9a6653abc9 Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Mon, 12 Sep 2022 09:56:52 +0200 Subject: [PATCH 2/4] Add routes to tests. Signed-off-by: Jussi Hallila --- .../Cards/RecentWorkflowRunsCard.test.tsx | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx index 7a20501072..5e0a5f3e15 100644 --- a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx +++ b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx @@ -15,21 +15,19 @@ */ import { EntityProvider } from '@backstage/plugin-catalog-react'; -import { lightTheme } from '@backstage/theme'; -import { ThemeProvider } from '@material-ui/core'; -import { render } from '@testing-library/react'; import React from 'react'; -import { MemoryRouter } from 'react-router'; import { useWorkflowRuns } from '../useWorkflowRuns'; import { RecentWorkflowRunsCard } from './RecentWorkflowRunsCard'; import { ConfigReader } from '@backstage/core-app-api'; import { - errorApiRef, - configApiRef, ConfigApi, + configApiRef, + errorApiRef, } from '@backstage/core-plugin-api'; -import { TestApiProvider } from '@backstage/test-utils'; +import { TestApiProvider, wrapInTestApp } from '@backstage/test-utils'; +import { rootRouteRef } from '../../routes'; +import { render } from '@testing-library/react'; jest.mock('../useWorkflowRuns', () => ({ useWorkflowRuns: jest.fn(), @@ -76,24 +74,27 @@ describe('', () => { const renderSubject = (props: any = {}) => render( - - - - - - - - - , + wrapInTestApp( + + + + + , + { + mountedRoutes: { + '/ci-cd': rootRouteRef, + }, + }, + ), ); it('renders a table with a row for each workflow', async () => { - const subject = renderSubject(); + const subject = await renderSubject(); workflowRuns.forEach(run => { expect(subject.getByText(run.message)).toBeInTheDocument(); @@ -101,7 +102,7 @@ describe('', () => { }); it('renders a workflow row correctly', async () => { - const subject = renderSubject(); + const subject = await renderSubject(); const [run] = workflowRuns; expect(subject.getByText(run.message).closest('a')).toHaveAttribute( 'href', From 65c990705dfc3a8c396826e7d6cd2388cc955dd8 Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Mon, 12 Sep 2022 10:01:54 +0200 Subject: [PATCH 3/4] Modify changeset wording to appease vale. Signed-off-by: Jussi Hallila --- .changeset/brown-kings-greet.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.changeset/brown-kings-greet.md b/.changeset/brown-kings-greet.md index 00e82675ee..918474baf7 100644 --- a/.changeset/brown-kings-greet.md +++ b/.changeset/brown-kings-greet.md @@ -1,5 +1,6 @@ ---- +4--- '@backstage/plugin-github-actions': patch + --- -Modify RecentWorkflowRunsCard use constructed routeRef instead of hardcoded route. +Modify RecentWorkflowRunsCard use constructed route instead of hardcoded route. From 83b1b5ee5b899507bf1d6808e56db565a7091410 Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Mon, 12 Sep 2022 10:09:29 +0200 Subject: [PATCH 4/4] Remove extra character. Signed-off-by: Jussi Hallila --- .changeset/brown-kings-greet.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/brown-kings-greet.md b/.changeset/brown-kings-greet.md index 918474baf7..8271b40bb4 100644 --- a/.changeset/brown-kings-greet.md +++ b/.changeset/brown-kings-greet.md @@ -1,6 +1,5 @@ -4--- +--- '@backstage/plugin-github-actions': patch - --- Modify RecentWorkflowRunsCard use constructed route instead of hardcoded route.