-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
207 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
webui/src/pages/repositories/repository/pulls/createPull.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, {useEffect} from "react"; | ||
import {useOutletContext} from "react-router-dom"; | ||
|
||
import {Loading} from "../../../../lib/components/controls"; | ||
import {useRefs} from "../../../../lib/hooks/repo"; | ||
import {RepoError} from "../error"; | ||
|
||
const CreatePull = () => { | ||
const {repo, loading, error} = useRefs(); | ||
|
||
if (loading) return <Loading/>; | ||
if (error) return <RepoError error={error}/>; | ||
|
||
return ( | ||
<div> | ||
<h1>Create Pull Request (in repo {repo.id})</h1> | ||
<div>TBD</div> | ||
</div> | ||
); | ||
}; | ||
|
||
|
||
const RepositoryCreatePullPage = () => { | ||
const [setActivePage] = useOutletContext(); | ||
useEffect(() => setActivePage("pulls"), [setActivePage]); | ||
return <CreatePull/>; | ||
} | ||
|
||
export default RepositoryCreatePullPage; |
106 changes: 106 additions & 0 deletions
106
webui/src/pages/repositories/repository/pulls/pullDetails.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import React, {useEffect} from "react"; | ||
import {useOutletContext} from "react-router-dom"; | ||
import Badge from "react-bootstrap/Badge"; | ||
import Button from "react-bootstrap/Button"; | ||
import Card from "react-bootstrap/Card"; | ||
import {GitMergeIcon, GitPullRequestClosedIcon, GitPullRequestIcon} from "@primer/octicons-react"; | ||
import dayjs from "dayjs"; | ||
|
||
import {AlertError, Loading} from "../../../../lib/components/controls"; | ||
import {useRefs} from "../../../../lib/hooks/repo"; | ||
import {useRouter} from "../../../../lib/hooks/router"; | ||
import {RepoError} from "../error"; | ||
import {pulls as pullsAPI} from "../../../../lib/api"; | ||
import {useAPI} from "../../../../lib/hooks/api"; | ||
import {Link} from "../../../../lib/components/nav"; | ||
|
||
const BranchLink = ({repo, branch}) => | ||
<Link href={{ | ||
pathname: '/repositories/:repoId/objects', | ||
params: {repoId: repo.id}, | ||
query: {ref: branch} | ||
}}> | ||
{branch} | ||
</Link>; | ||
|
||
const getStatusBadgeParams = status => { | ||
switch (status) { | ||
case pullsAPI.PullStatus.open: | ||
return {bgColor: "success", icon: <GitPullRequestIcon/>}; | ||
case pullsAPI.PullStatus.closed: | ||
return {bgColor: "purple", icon: <GitPullRequestClosedIcon/>}; | ||
case pullsAPI.PullStatus.merged: | ||
return {bgColor: "danger", icon: <GitMergeIcon/>}; | ||
default: | ||
return {bgColor: "secondary", icon: null}; | ||
} | ||
}; | ||
|
||
const StatusBadge = ({status}) => { | ||
const {bgColor, icon} = getStatusBadgeParams(status); | ||
return <Badge pill bg={bgColor}> | ||
{icon} <span className="text-capitalize">{status}</span> | ||
</Badge>; | ||
}; | ||
|
||
const PullDetailsContent = ({repo, pull}) => { | ||
const createdAt = dayjs.unix(pull.created_at); | ||
|
||
return ( | ||
<div className="pull-details mb-5"> | ||
<h1>{pull.title} <span className="fs-5 text-secondary">{pull.id}</span></h1> | ||
<div className="mt-3"> | ||
<StatusBadge status={pull.status}/> | ||
<span className="ms-2"> | ||
<strong>{pull.author}</strong> wants to merge {""} | ||
<BranchLink repo={repo} branch={pull.source_branch}/> {""} | ||
into <BranchLink repo={repo} branch={pull.destination_branch}/>. | ||
</span> | ||
</div> | ||
<Card className="mt-4"> | ||
<Card.Header> | ||
<strong>{pull.author}</strong> opened {""} | ||
on {createdAt.format("MMM D, YYYY")} ({createdAt.fromNow()}). | ||
</Card.Header> | ||
<Card.Body className="description"> | ||
{pull.description} | ||
</Card.Body> | ||
</Card> | ||
<div className="bottom-buttons-group mt-4 float-end"> | ||
<Button variant="outline-secondary" className="text-secondary-emphasis me-2">Close pull request</Button> | ||
<Button variant="success">Merge pull request</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const PullDetails = ({repo, pullId}) => { | ||
const {response: pull, error, loading} = useAPI(async () => { | ||
console.log({repo, pullId}); | ||
return pullsAPI.get(repo.id, pullId); | ||
}, [repo.id, pullId]); | ||
|
||
if (loading) return <Loading/>; | ||
if (error) return <AlertError error={error}/>; | ||
return <PullDetailsContent repo={repo} pull={pull}/>; | ||
} | ||
|
||
const PullDetailsContainer = () => { | ||
const router = useRouter() | ||
const {repo, loading, error} = useRefs(); | ||
const {pullId} = router.params; | ||
|
||
if (loading) return <Loading/>; | ||
if (error) return <RepoError error={error}/>; | ||
|
||
return <PullDetails repo={repo} pullId={pullId}/>; | ||
}; | ||
|
||
|
||
const RepositoryPullDetailsPage = () => { | ||
const [setActivePage] = useOutletContext(); | ||
useEffect(() => setActivePage("pulls"), [setActivePage]); | ||
return <PullDetailsContainer/>; | ||
} | ||
|
||
export default RepositoryPullDetailsPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters