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

Commit 1beb11a

Browse files
author
Noah Lee
authored
Refactorying the repoHome view (#399)
1 parent 3e193b8 commit 1beb11a

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

Diff for: ui/src/views/Repo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { init, activate, repoSlice as slice } from '../redux/repo'
99

1010
import ActivateButton from "../components/ActivateButton"
1111
import Main from './main'
12-
import RepoHome from './RepoHome'
12+
import RepoHome from './repoHome'
1313
import RepoLock from "./RepoLock";
1414
import RepoDeploy from './RepoDeploy'
1515
import RepoRollabck from './RepoRollback'

Diff for: ui/src/views/repoHome/ActivityLogs.tsx

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { shallowEqual } from "react-redux";
2+
import { Timeline, Typography } from 'antd'
3+
import { SyncOutlined } from '@ant-design/icons'
4+
import moment from "moment"
5+
6+
import { useAppSelector } from '../../redux/hooks'
7+
import { DeploymentStatusEnum } from "../../models"
8+
9+
import DeploymentStatusBadge from "../../components/DeploymentStatusBadge"
10+
import UserAvatar from '../../components/UserAvatar'
11+
import DeploymentRefCode from '../../components/DeploymentRefCode'
12+
13+
const { Text } = Typography
14+
15+
export default function ActivityLogs(): JSX.Element {
16+
const {
17+
deployments,
18+
} = useAppSelector(state => state.repoHome, shallowEqual)
19+
20+
return (
21+
<Timeline>
22+
{deployments.map((d, idx) => {
23+
const dot = (d.status === DeploymentStatusEnum.Running)?
24+
<SyncOutlined style={{color: "purple"}} spin />
25+
:
26+
<></>
27+
const avatar = <UserAvatar user={d.deployer} />
28+
29+
return (
30+
<Timeline.Item key={idx} color={getStatusColor(d.status)} dot={dot}>
31+
<p>
32+
<Text strong>{d.env}</Text> <DeploymentRefCode deployment={d}/> <a href={`/${d.repo?.namespace}/${d.repo?.name}/deployments/${d.number}`}>• View detail #{d.number}</a>
33+
</p>
34+
<p>
35+
Deployed by {avatar} {moment(d.createdAt).fromNow()} <DeploymentStatusBadge deployment={d}/>
36+
</p>
37+
</Timeline.Item>
38+
)
39+
})}
40+
</Timeline>
41+
)
42+
}
43+
44+
// https://ant.design/components/timeline/#Timeline.Item
45+
const getStatusColor = (status: DeploymentStatusEnum) => {
46+
switch (status) {
47+
case DeploymentStatusEnum.Waiting:
48+
return "gray"
49+
case DeploymentStatusEnum.Created:
50+
return "purple"
51+
case DeploymentStatusEnum.Queued:
52+
return "purple"
53+
case DeploymentStatusEnum.Running:
54+
return "purple"
55+
case DeploymentStatusEnum.Success:
56+
return "green"
57+
case DeploymentStatusEnum.Failure:
58+
return "red"
59+
case DeploymentStatusEnum.Canceled:
60+
return "gray"
61+
default:
62+
return "gray"
63+
}
64+
}

Diff for: ui/src/views/RepoHome.tsx renamed to ui/src/views/repoHome/index.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { useParams } from "react-router-dom";
33
import { shallowEqual } from "react-redux";
44
import { PageHeader, Select } from 'antd'
55

6-
import { useAppSelector, useAppDispatch } from '../redux/hooks'
7-
import { repoHomeSlice as slice, fetchEnvs, fetchDeployments, perPage } from '../redux/repoHome'
8-
import { subscribeEvents } from "../apis"
6+
import { useAppSelector, useAppDispatch } from '../../redux/hooks'
7+
import { repoHomeSlice as slice, fetchEnvs, fetchDeployments, perPage } from '../../redux/repoHome'
8+
import { subscribeEvents } from "../../apis"
99

10-
import ActivityLogs from '../components/ActivityLogs'
11-
import Spin from '../components/Spin'
12-
import Pagination from '../components/Pagination'
10+
import ActivityLogs from './ActivityLogs'
11+
import Spin from '../../components/Spin'
12+
import Pagination from '../../components/Pagination'
1313

1414
const { Option } = Select
1515

@@ -78,8 +78,9 @@ export default function RepoHome(): JSX.Element {
7878
</div>
7979
<div style={{marginTop: "30px", padding: "16px 24px"}}>
8080
{(loading)?
81-
<div style={{textAlign: "center"}}><Spin /></div> :
82-
<ActivityLogs deployments={deployments}/>
81+
<div style={{textAlign: "center"}}><Spin /></div>
82+
:
83+
<ActivityLogs />
8384
}
8485
</div>
8586
<div style={{marginTop: "20px", textAlign: "center"}}>

0 commit comments

Comments
 (0)