diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx index 678132bd8f..615ad9614c 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx @@ -24,12 +24,18 @@ import { OAuthApi, } from '@backstage/core'; +import { fireEvent } from '@testing-library/react'; import { msw, renderInTestApp } from '@backstage/test-utils'; import { GithubDeploymentsApiClient, githubDeploymentsApiRef } from '../api'; import { githubDeploymentsPlugin } from '../plugin'; import { GithubDeploymentsCard } from './GithubDeploymentsCard'; -import { entityStub, noDataResponseStub, responseStub } from '../mocks/mocks'; +import { + entityStub, + noDataResponseStub, + refreshedResponseStub, + responseStub, +} from '../mocks/mocks'; import { setupServer } from 'msw/node'; import { graphql } from 'msw'; @@ -81,6 +87,9 @@ describe('github-deployments', () => { , ); + expect( + await rendered.findByText('GitHub Deployments'), + ).toBeInTheDocument(); expect(await rendered.findByText('active')).toBeInTheDocument(); expect(await rendered.findByText('prd')).toBeInTheDocument(); expect(await rendered.findByText('12345')).toHaveAttribute( @@ -109,9 +118,46 @@ describe('github-deployments', () => { , ); + expect( + await rendered.findByText('GitHub Deployments'), + ).toBeInTheDocument(); expect( await rendered.findByText('No deployments found for this entity.'), ).toBeInTheDocument(); }); + + it('should shows new data on reload', async () => { + worker.use( + graphql.query('deployments', (_, res, ctx) => + res(ctx.data(responseStub)), + ), + ); + + const rendered = await renderInTestApp( + + + , + ); + + expect( + await rendered.findByText('GitHub Deployments'), + ).toBeInTheDocument(); + expect(await rendered.findByText('pending')).toBeInTheDocument(); + + worker.resetHandlers(); + worker.use( + graphql.query('deployments', (_, res, ctx) => + res(ctx.data(refreshedResponseStub)), + ), + ); + + const refreshButton = await rendered.findByTitle('Refresh'); + fireEvent.click(refreshButton); + + expect( + await rendered.findByText('GitHub Deployments'), + ).toBeInTheDocument(); + expect(await rendered.findByText('failure')).toBeInTheDocument(); + }); }); }); diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx index 6be4a5a6b3..5f0ef07659 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx @@ -15,13 +15,11 @@ */ import React from 'react'; import { - InfoCard, MissingAnnotationEmptyState, - Progress, ResponseErrorPanel, useApi, } from '@backstage/core'; -import { useAsync } from 'react-use'; +import { useAsyncRetry } from 'react-use'; import { githubDeploymentsApiRef } from '../api'; import { useEntity } from '@backstage/plugin-catalog-react'; import { @@ -40,22 +38,21 @@ const GithubDeploymentsComponent = ({ const api = useApi(githubDeploymentsApiRef); const [owner, repo] = projectSlug.split('/'); - const { loading, value, error } = useAsync( + const { loading, value, error, retry } = useAsyncRetry( async () => await api.listDeployments({ owner, repo, last }), ); - if (loading) { - return ( - - - - ); - } if (error) { return ; } - return ; + return ( + + ); }; export const GithubDeploymentsCard = ({ last }: { last?: number }) => { diff --git a/plugins/github-deployments/src/components/GithubDeploymentsTable/GithubDeploymentsTable.tsx b/plugins/github-deployments/src/components/GithubDeploymentsTable/GithubDeploymentsTable.tsx index f5fae7f449..1eddfd4dd2 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsTable/GithubDeploymentsTable.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsTable/GithubDeploymentsTable.tsx @@ -26,6 +26,7 @@ import { import { GithubDeployment } from '../../api'; import { DateTime } from 'luxon'; import { Box, Typography, Link, makeStyles } from '@material-ui/core'; +import SyncIcon from '@material-ui/icons/Sync'; const useStyles = makeStyles(theme => ({ empty: { @@ -83,10 +84,14 @@ const columns: TableColumn[] = [ type GithubDeploymentsTableProps = { deployments: GithubDeployment[]; + isLoading: boolean; + retry: () => void; }; const GithubDeploymentsTable = ({ deployments, + isLoading, + retry, }: GithubDeploymentsTableProps) => { const classes = useStyles(); @@ -96,6 +101,15 @@ const GithubDeploymentsTable = ({ options={{ padding: 'dense', paging: true, search: false, pageSize: 5 }} title="GitHub Deployments" data={deployments} + isLoading={isLoading} + actions={[ + { + icon: () => , + tooltip: 'Refresh', + isFreeAction: true, + onClick: () => retry(), + }, + ]} emptyContent={
diff --git a/plugins/github-deployments/src/mocks/mocks.ts b/plugins/github-deployments/src/mocks/mocks.ts index 6a394b54bf..f636a08558 100644 --- a/plugins/github-deployments/src/mocks/mocks.ts +++ b/plugins/github-deployments/src/mocks/mocks.ts @@ -64,4 +64,31 @@ export const responseStub: QueryResponse = { }, }; +export const refreshedResponseStub: QueryResponse = { + repository: { + deployments: { + nodes: [ + { + state: 'active', + environment: 'prd', + updatedAt: '2021-03-25T12:08:45Z', + commit: { + commitUrl: 'https://exampleapi.com/123456789', + abbreviatedOid: '12345', + }, + }, + { + state: 'failure', + environment: 'lab', + updatedAt: '2021-03-25T12:09:47Z', + commit: { + commitUrl: 'https://exampleapi.com/543212345', + abbreviatedOid: '54321', + }, + }, + ], + }, + }, +}; + export const noDataResponseStub: QueryResponse = {};