Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit c702383

Browse files
author
Noah Lee
authored
Refactoring the deployment view (#400)
* Add the `deployment` dir for the view * Move the `ReviewList` component into the dir * Remove the state from components * Move the `DeploymentDescriptor` component * Move the `DeploymentStatusSteps` into the view * Bind the state to the page
1 parent 1beb11a commit c702383

File tree

9 files changed

+188
-107
lines changed

9 files changed

+188
-107
lines changed

Diff for: ui/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77

88
import Home from "./views/home"
99
import Repo from "./views/Repo"
10-
import Deployment from "./views/Deployment"
10+
import Deployment from "./views/deployment"
1111
import Settings from "./views/settings"
1212
import Members from "./views/members"
1313

Diff for: ui/src/components/DeploymentDescriptor/index.tsx

-3
This file was deleted.

Diff for: ui/src/components/DeploymentDescriptor/DeploymentDescriptor.tsx renamed to ui/src/views/deployment/DeploymentDescriptor.tsx

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1+
import { useState } from "react"
12
import { Button, Descriptions, Modal, Typography } from "antd"
23
import moment from "moment"
34

4-
import DeploymentStatusBadge from "../DeploymentStatusBadge"
5-
import UserAvatar from "../UserAvatar"
65
import CommitChanges from "./CommitChanges"
6+
import DeploymentStatusBadge from "../../components/DeploymentStatusBadge"
7+
import UserAvatar from "../../components/UserAvatar"
78

89
import { Commit, Deployment } from "../../models"
910
import { getShortRef } from "../../libs"
10-
import { useState } from "react"
1111

1212
const { Text } = Typography
1313

14-
interface DeploymentDescriptorProps {
14+
export interface DeploymentDescriptorProps {
1515
deployment: Deployment
16-
commits: Commit[]
16+
changes: Commit[]
1717
}
1818

19-
export default function DeploymentDescriptor(props: DeploymentDescriptorProps): JSX.Element {
19+
export default function DeploymentDescriptor({
20+
deployment,
21+
changes
22+
}: DeploymentDescriptorProps): JSX.Element {
2023
const [visible, setVisible] = useState<boolean>(false)
2124

2225
const showModal = () => {
@@ -29,18 +32,20 @@ export default function DeploymentDescriptor(props: DeploymentDescriptorProps):
2932

3033
return (
3134
<Descriptions title="Information" bordered column={1}>
32-
<Descriptions.Item label="Environment">{props.deployment.env}</Descriptions.Item>
35+
<Descriptions.Item label="Environment">
36+
{deployment.env}
37+
</Descriptions.Item>
3338
<Descriptions.Item label="Ref">
34-
<Text className="gitploy-code" code>{getShortRef(props.deployment)}</Text>
39+
<Text className="gitploy-code" code>{getShortRef(deployment)}</Text>
3540
</Descriptions.Item>
3641
<Descriptions.Item label="Status">
37-
<DeploymentStatusBadge deployment={props.deployment}/>
42+
<DeploymentStatusBadge deployment={deployment}/>
3843
</Descriptions.Item>
3944
<Descriptions.Item label="Deployer">
40-
<UserAvatar user={props.deployment.deployer} boldName={false}/>
45+
<UserAvatar user={deployment.deployer} boldName={false}/>
4146
</Descriptions.Item>
4247
<Descriptions.Item label="Deploy Time">
43-
{moment(props.deployment.createdAt).format("YYYY-MM-DD HH:mm:ss")}
48+
{moment(deployment.createdAt).format("YYYY-MM-DD HH:mm:ss")}
4449
</Descriptions.Item>
4550
<Descriptions.Item label="Changes">
4651
<Button
@@ -59,7 +64,7 @@ export default function DeploymentDescriptor(props: DeploymentDescriptorProps):
5964
cancelText="Close"
6065
onCancel={hideModal}
6166
>
62-
<CommitChanges changes={props.commits}/>
67+
<CommitChanges changes={changes}/>
6368
</Modal>
6469
</Descriptions.Item>
6570
</Descriptions>

Diff for: ui/src/components/DeploymentStatusSteps.tsx renamed to ui/src/views/deployment/DeploymentStatusSteps.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Timeline, Typography } from "antd"
22
import { ClockCircleOutlined } from "@ant-design/icons"
33
import moment from "moment"
44

5-
import { DeploymentStatus } from "../models"
5+
import { DeploymentStatus } from "../../models"
66

77
const { Text, Link } = Typography
88

9-
interface DeploymentStatusStepsProps {
9+
export interface DeploymentStatusStepsProps {
1010
statuses: DeploymentStatus[]
1111
}
1212

@@ -40,6 +40,6 @@ const getStatusColor = (status: string) => {
4040
case "failure":
4141
return "red"
4242
default:
43-
return "#722ed1"
43+
return "purple"
4444
}
4545
}

Diff for: ui/src/views/deployment/HeaderBreadcrumb.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Breadcrumb } from "antd"
2+
3+
export interface HeaderBreadcrumbProps {
4+
namespace: string
5+
name: string
6+
number: string
7+
}
8+
9+
export default function HeaderBreadcrumb({
10+
namespace,
11+
name,
12+
number
13+
}: HeaderBreadcrumbProps): JSX.Element {
14+
15+
return (
16+
<Breadcrumb>
17+
<Breadcrumb.Item>
18+
<a href="/">Repositories</a>
19+
</Breadcrumb.Item>
20+
<Breadcrumb.Item>
21+
{namespace}
22+
</Breadcrumb.Item>
23+
<Breadcrumb.Item>
24+
<a href={`/${namespace}/${name}`}>{name}</a>
25+
</Breadcrumb.Item>
26+
<Breadcrumb.Item>
27+
Deployments
28+
</Breadcrumb.Item>
29+
<Breadcrumb.Item>
30+
{number}
31+
</Breadcrumb.Item>
32+
</Breadcrumb>
33+
)
34+
}

Diff for: ui/src/components/ReviewModal.tsx renamed to ui/src/views/deployment/ReviewButton.tsx

+28-22
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import { useState } from "react"
22
import { Button, Modal, Space, Input } from "antd"
33

4-
import { Review, ReviewStatusEnum } from "../models"
4+
import { Review, ReviewStatusEnum, } from "../../models"
55

6-
const { TextArea } = Input
7-
8-
interface ReviewModalProps {
9-
review: Review
6+
export interface ReviewButtonProps {
7+
review?: Review
108
onClickApprove(comment: string): void
119
onClickApproveAndDeploy(comment: string): void
1210
onClickReject(comment: string): void
1311
}
1412

15-
export default function ReviewModal(props: ReviewModalProps): JSX.Element {
16-
const [comment, setComment] = useState(props.review.comment)
13+
export default function ReviewButton(props: ReviewButtonProps): JSX.Element {
14+
const { review } = props
15+
16+
// If no review has been assigned, an empty value is returned.
17+
if (!review) {
18+
return <></>
19+
}
20+
21+
// Stores the review comment state and passes it as a parameter when updating.
22+
const [comment, setComment] = useState(review.comment)
1723

1824
const onChangeComment = (e: any) => {
1925
setComment(e.target.value)
@@ -24,6 +30,10 @@ export default function ReviewModal(props: ReviewModalProps): JSX.Element {
2430
const showModal = () => {
2531
setIsModalVisible(true);
2632
}
33+
34+
const onClickCancel = () => {
35+
setIsModalVisible(false)
36+
}
2737

2838
const onClickApprove = () => {
2939
props.onClickApprove(comment)
@@ -40,34 +50,30 @@ export default function ReviewModal(props: ReviewModalProps): JSX.Element {
4050
setIsModalVisible(false)
4151
}
4252

43-
const onClickCancel = () => {
44-
setIsModalVisible(false)
45-
}
46-
4753
return (
4854
<>
55+
{(review.status === ReviewStatusEnum.Pending)?
56+
<Button type="primary" onClick={showModal}>
57+
Review
58+
</Button>
59+
:
60+
<Button onClick={showModal}>
61+
Reviewed
62+
</Button>}
4963
<Modal
5064
title="Review"
5165
visible={isModalVisible}
5266
onCancel={onClickCancel}
53-
footer={
67+
footer={(
5468
<Space>
5569
<Button type="primary" danger onClick={onClickReject}>Reject</Button>
5670
<Button type="primary" onClick={onClickApproveAndDeploy}>Approve and Deploy</Button>
5771
<Button type="primary" onClick={onClickApprove}>Approve</Button>
5872
</Space>
59-
}
73+
)}
6074
>
61-
<TextArea rows={3} onChange={onChangeComment} value={comment}/>
75+
<Input.TextArea rows={3} onChange={onChangeComment} value={comment}/>
6276
</Modal>
63-
{(props.review.status === ReviewStatusEnum.Pending)?
64-
<Button type="primary" onClick={showModal}>
65-
Review
66-
</Button> :
67-
<Button onClick={showModal}>
68-
Reviewed
69-
</Button>
70-
}
7177
</>
7278
)
7379

Diff for: ui/src/components/ReviewerList.tsx renamed to ui/src/views/deployment/ReviewList.tsx

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
import { Popover, Button, Descriptions, Typography } from "antd"
22
import { CheckOutlined, CloseOutlined, CommentOutlined, ClockCircleOutlined } from "@ant-design/icons"
33

4-
import { Review, ReviewStatusEnum } from "../models"
5-
import UserAvatar from "./UserAvatar"
4+
import { Review, ReviewStatusEnum } from "../../models"
5+
import UserAvatar from "../../components/UserAvatar"
66

77
const { Text } = Typography
8-
export interface ReviewerListProps {
8+
9+
export interface ReviewListProps {
910
reviews: Review[]
1011
}
1112

12-
export default function ReviewerList(props: ReviewerListProps): JSX.Element {
13-
if (props.reviews.length === 0) {
13+
export default function ReviewList({ reviews }: ReviewListProps): JSX.Element {
14+
if (reviews.length === 0) {
1415
return (
1516
<Descriptions title="Reviewers" >
16-
<Descriptions.Item><Text type="secondary">No reviewers</Text></Descriptions.Item>
17+
<Descriptions.Item>
18+
<Text type="secondary">No reviewers</Text>
19+
</Descriptions.Item>
1720
</Descriptions>
1821
)
1922
}
2023

2124
return (
2225
<Descriptions title="Reviewers" size="small" column={1}>
23-
{props.reviews.map((review, idx) => {
26+
{reviews.map((review, idx) => {
2427
return (
2528
<Descriptions.Item key={idx}>
2629
<ReviewStatusIcon review={review} />&nbsp;
@@ -50,13 +53,11 @@ function ReviewCommentIcon(props: {review: Review}): JSX.Element {
5053
const comment = props.review.comment
5154

5255
return (
53-
comment?
56+
(comment)?
5457
<Popover
5558
title="Comment"
5659
trigger="click"
57-
content={
58-
<div style={{whiteSpace: "pre"}}>{comment}</div>
59-
}
60+
content={<div style={{whiteSpace: "pre"}}>{comment}</div>}
6061
>
6162
<Button
6263
type="text"

0 commit comments

Comments
 (0)