-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
616 add patch setction pr page team tier #2337
Changes from 2 commits
1cb3000
c0b761c
b7205f5
96cb9a0
b287e11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,23 @@ | ||
import cs from 'classnames' | ||
import capitalize from 'lodash/capitalize' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import { formatTimeToNow } from 'shared/utils/dates' | ||
import { getProviderPullURL } from 'shared/utils/provider' | ||
import A from 'ui/A' | ||
import CIStatusLabel from 'ui/CIStatus' | ||
import Icon from 'ui/Icon' | ||
import { TierNames, useTier } from 'services/tier' | ||
import { useFlags } from 'shared/featureFlags' | ||
|
||
import { usePullHeadData } from './hooks' | ||
import PendoLink from './PendoLink' | ||
|
||
const pullStateToColor = { | ||
OPEN: 'bg-ds-primary-green', | ||
CLOSED: 'bg-ds-primary-red', | ||
MERGED: 'bg-ds-primary-purple', | ||
} | ||
import HeaderDefault from './HeaderDefault' | ||
import HeaderTeam from './HeaderTeam' | ||
|
||
function Header() { | ||
const { provider, owner, repo, pullId } = useParams() | ||
const { data } = usePullHeadData({ provider, owner, repo, pullId }) | ||
const { provider, owner } = useParams() | ||
const { data: tierData } = useTier({ provider, owner }) | ||
const { multipleTiers } = useFlags({ | ||
Check warning on line 12 in src/pages/PullRequestPage/Header/Header.jsx Codecov - Staging / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L10-L12
Check warning on line 12 in src/pages/PullRequestPage/Header/Header.jsx Codecov - QA / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L10-L12
Check warning on line 12 in src/pages/PullRequestPage/Header/Header.jsx Codecov Public QA / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L10-L12
|
||
multipleTiers: false, | ||
}) | ||
|
||
if (multipleTiers && tierData === TierNames.TEAM) { | ||
return <HeaderTeam /> | ||
Check warning on line 17 in src/pages/PullRequestPage/Header/Header.jsx Codecov - Staging / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L17
Check warning on line 17 in src/pages/PullRequestPage/Header/Header.jsx Codecov - QA / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L17
Check warning on line 17 in src/pages/PullRequestPage/Header/Header.jsx Codecov Public QA / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L17
|
||
} | ||
|
||
return ( | ||
<div className="flex flex-col justify-between gap-2 border-b border-ds-gray-secondary pb-2 text-xs md:flex-row"> | ||
<div> | ||
<h1 className="flex items-center gap-2 text-lg font-semibold"> | ||
{data?.pull?.title} | ||
<span | ||
className={cs( | ||
'text-white font-bold px-3 py-0.5 text-xs rounded', | ||
pullStateToColor[data?.pull?.state] | ||
)} | ||
> | ||
{capitalize(data?.pull?.state)} | ||
</span> | ||
</h1> | ||
<p className="flex items-center gap-2"> | ||
<span> | ||
{data?.pull?.updatestamp && | ||
formatTimeToNow(data?.pull?.updatestamp)}{' '} | ||
<span className="bold">{data?.pull?.author?.username}</span>{' '} | ||
authored{' '} | ||
{data?.pull?.pullId && ( | ||
<A | ||
href={getProviderPullURL({ | ||
provider, | ||
owner, | ||
repo, | ||
pullId: data?.pull?.pullId, | ||
})} | ||
hook="provider-pr-link" | ||
isExternal={true} | ||
> | ||
#{data?.pull?.pullId} | ||
</A> | ||
)} | ||
</span> | ||
<CIStatusLabel ciPassed={data?.pull?.head?.ciPassed} /> | ||
<span className="flex items-center"> | ||
<Icon name="branch" variant="developer" size="sm" /> | ||
{data?.pull?.head?.branchName} | ||
</span> | ||
</p> | ||
</div> | ||
<PendoLink /> | ||
</div> | ||
) | ||
return <HeaderDefault /> | ||
Check warning on line 20 in src/pages/PullRequestPage/Header/Header.jsx Codecov - Staging / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L20
Check warning on line 20 in src/pages/PullRequestPage/Header/Header.jsx Codecov - QA / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L20
Check warning on line 20 in src/pages/PullRequestPage/Header/Header.jsx Codecov Public QA / codecov/patchsrc/pages/PullRequestPage/Header/Header.jsx#L20
|
||
} | ||
|
||
export default Header |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import cs from 'classnames' | ||
import capitalize from 'lodash/capitalize' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import { formatTimeToNow } from 'shared/utils/dates' | ||
import { getProviderPullURL } from 'shared/utils/provider' | ||
import A from 'ui/A' | ||
import CIStatusLabel from 'ui/CIStatus' | ||
import Icon from 'ui/Icon' | ||
|
||
import { usePullHeadData } from './hooks' | ||
|
||
import { pullStateToColor } from '../constants' | ||
import PendoLink from '../PendoLink' | ||
|
||
function HeaderDefault() { | ||
const { provider, owner, repo, pullId } = useParams() | ||
const { data } = usePullHeadData({ provider, owner, repo, pullId }) | ||
Check warning on line 18 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - Staging / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L16-L18
Check warning on line 18 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L16-L18
Check warning on line 18 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov Public QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L16-L18
|
||
|
||
const pull = data?.pull | ||
Check warning on line 20 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - Staging / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L20
Check warning on line 20 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L20
Check warning on line 20 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov Public QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L20
|
||
|
||
return ( | ||
Check warning on line 22 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - Staging / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L22
Check warning on line 22 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L22
Check warning on line 22 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov Public QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L22
|
||
<div className="flex flex-col justify-between gap-2 border-b border-ds-gray-secondary pb-2 text-xs md:flex-row"> | ||
<div> | ||
<h1 className="flex items-center gap-2 text-lg font-semibold"> | ||
{pull?.title} | ||
<span | ||
className={cs( | ||
'text-white font-bold px-3 py-0.5 text-xs rounded', | ||
pullStateToColor[pull?.state] | ||
)} | ||
> | ||
{capitalize(pull?.state)} | ||
</span> | ||
</h1> | ||
<p className="flex items-center gap-2"> | ||
<span> | ||
{pull?.updatestamp && formatTimeToNow(pull?.updatestamp)}{' '} | ||
<span className="bold">{pull?.author?.username}</span> authored{' '} | ||
{pull?.pullId && ( | ||
<A | ||
Check warning on line 41 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - Staging / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L41
Check warning on line 41 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov - QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L41
Check warning on line 41 in src/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx Codecov Public QA / codecov/patchsrc/pages/PullRequestPage/Header/HeaderDefault/HeaderDefault.jsx#L41
|
||
href={getProviderPullURL({ | ||
provider, | ||
owner, | ||
repo, | ||
pullId: pull?.pullId, | ||
})} | ||
hook="provider-pr-link" | ||
isExternal={true} | ||
> | ||
#{pull?.pullId} | ||
</A> | ||
)} | ||
</span> | ||
<CIStatusLabel ciPassed={pull?.head?.ciPassed} /> | ||
<span className="flex items-center"> | ||
<Icon name="branch" variant="developer" size="sm" /> | ||
{pull?.head?.branchName} | ||
</span> | ||
</p> | ||
</div> | ||
<PendoLink /> | ||
</div> | ||
) | ||
} | ||
export default HeaderDefault |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No new logic here, straight up copy-paste from what previously was |
||
import { render, screen, waitFor } from '@testing-library/react' | ||
import { graphql } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
import { MemoryRouter, Route } from 'react-router-dom' | ||
|
||
import Header from './HeaderDefault' | ||
|
||
const mockPullData = { | ||
owner: { | ||
repository: { | ||
__typename: 'Repository', | ||
pull: { | ||
pullId: 1, | ||
title: 'Cool Pull Request', | ||
state: 'OPEN', | ||
author: { | ||
username: 'cool-user', | ||
}, | ||
head: { | ||
branchName: 'cool-branch', | ||
ciPassed: true, | ||
}, | ||
updatestamp: '2020-01-01T12:00:00.000000', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { queries: { retry: false } }, | ||
}) | ||
const server = setupServer() | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={['/gh/test-org/test-repo/pull/12']}> | ||
<Route path="/:provider/:owner/:repo/pull/:pullId">{children}</Route> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
|
||
beforeAll(() => { | ||
server.listen() | ||
}) | ||
|
||
afterEach(() => { | ||
queryClient.clear() | ||
server.resetHandlers() | ||
}) | ||
|
||
afterAll(() => { | ||
server.close() | ||
}) | ||
|
||
describe('Header', () => { | ||
function setup() { | ||
server.use( | ||
graphql.query('PullHeadData', (req, res, ctx) => | ||
res(ctx.status(200), ctx.data(mockPullData)) | ||
) | ||
) | ||
} | ||
|
||
describe('when rendered', () => { | ||
beforeEach(() => { | ||
setup() | ||
}) | ||
|
||
it('renders the pr overview', async () => { | ||
render(<Header />, { wrapper }) | ||
|
||
await waitFor(() => queryClient.isFetching) | ||
await waitFor(() => !queryClient.isFetching) | ||
|
||
const heading = await screen.findByRole('heading', { | ||
name: /Cool Pull Request/, | ||
}) | ||
expect(heading).toBeInTheDocument() | ||
|
||
const open = await screen.findByText(/open/i) | ||
expect(open).toBeInTheDocument() | ||
|
||
const prNumber = await screen.findByText(/#1/i) | ||
expect(prNumber).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './HeaderDefault' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No new logic here, straight up copy-paste from what previously was
Header