drone/web/src/pages/PullRequests/PullRequestsContentHeader/PullRequestsContentHeader.tsx
Tan Nhu 619fd2c9de Add PR listing page + Commits tab for PR detail page (#123)
* Add PR listing page + Commits tab for PR detail page

* Add commits place-holder in Compare view

* Add commits place-holder in Compare view

* Correct PR number after creation

* Minor CSS improvement

* Add diff sample

* Diff side by side (3.4.2 is better than latest)

* Big PR diff example

* Implement diff view

* Scrolling optimization

* Add placeholder to allow click at line number
2022-12-12 16:39:14 -08:00

79 lines
2.8 KiB
TypeScript

import { useHistory } from 'react-router-dom'
import React, { useMemo, useState } from 'react'
import { Container, Layout, FlexExpander, DropDown, ButtonVariation, TextInput, Button } from '@harness/uicore'
import { useStrings } from 'framework/strings'
import { CodeIcon, GitInfoProps, makeDiffRefs, PullRequestFilterOption } from 'utils/GitUtils'
import { useAppContext } from 'AppContext'
import css from './PullRequestsContentHeader.module.scss'
interface PullRequestsContentHeaderProps extends Pick<GitInfoProps, 'repoMetadata'> {
activePullRequestFilterOption?: string
onPullRequestFilterChanged: (filter: string) => void
onSearchTermChanged: (searchTerm: string) => void
}
export function PullRequestsContentHeader({
onPullRequestFilterChanged,
onSearchTermChanged,
activePullRequestFilterOption = PullRequestFilterOption.ALL,
repoMetadata
}: PullRequestsContentHeaderProps) {
const history = useHistory()
const { routes } = useAppContext()
const { getString } = useStrings()
const [filterOption, setFilterOption] = useState(activePullRequestFilterOption)
const [searchTerm, setSearchTerm] = useState('')
const items = useMemo(
() => [
{ label: getString('open'), value: PullRequestFilterOption.OPEN },
{ label: getString('merged'), value: PullRequestFilterOption.MERGED },
{ label: getString('closed'), value: PullRequestFilterOption.CLOSED },
{ label: getString('rejected'), value: PullRequestFilterOption.REJECTED },
{ label: getString('yours'), value: PullRequestFilterOption.YOURS },
{ label: getString('all'), value: PullRequestFilterOption.ALL }
],
[getString]
)
return (
<Container className={css.main} padding="xlarge">
<Layout.Horizontal spacing="medium">
<DropDown
value={filterOption}
items={items}
onChange={({ value }) => {
setFilterOption(value as string)
onPullRequestFilterChanged(value as string)
}}
popoverClassName={css.branchDropdown}
/>
<FlexExpander />
<TextInput
placeholder={getString('search')}
autoFocus
onFocus={event => event.target.select()}
value={searchTerm}
onInput={event => {
const value = event.currentTarget.value
setSearchTerm(value)
onSearchTermChanged(value)
}}
/>
<Button
variation={ButtonVariation.PRIMARY}
text={getString('newPullRequest')}
icon={CodeIcon.Add}
onClick={() => {
history.push(
routes.toCODECompare({
repoPath: repoMetadata?.path as string,
diffRefs: makeDiffRefs(repoMetadata?.defaultBranch as string, '')
})
)
}}
/>
</Layout.Horizontal>
</Container>
)
}