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+ }
0 commit comments