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

Refactorying the repoHome view #399

Merged
merged 1 commit into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/views/Repo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { init, activate, repoSlice as slice } from '../redux/repo'

import ActivateButton from "../components/ActivateButton"
import Main from './main'
import RepoHome from './RepoHome'
import RepoHome from './repoHome'
import RepoLock from "./RepoLock";
import RepoDeploy from './RepoDeploy'
import RepoRollabck from './RepoRollback'
Expand Down
64 changes: 64 additions & 0 deletions ui/src/views/repoHome/ActivityLogs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { shallowEqual } from "react-redux";
import { Timeline, Typography } from 'antd'
import { SyncOutlined } from '@ant-design/icons'
import moment from "moment"

import { useAppSelector } from '../../redux/hooks'
import { DeploymentStatusEnum } from "../../models"

import DeploymentStatusBadge from "../../components/DeploymentStatusBadge"
import UserAvatar from '../../components/UserAvatar'
import DeploymentRefCode from '../../components/DeploymentRefCode'

const { Text } = Typography

export default function ActivityLogs(): JSX.Element {
const {
deployments,
} = useAppSelector(state => state.repoHome, shallowEqual)

return (
<Timeline>
{deployments.map((d, idx) => {
const dot = (d.status === DeploymentStatusEnum.Running)?
<SyncOutlined style={{color: "purple"}} spin />
:
<></>
const avatar = <UserAvatar user={d.deployer} />

return (
<Timeline.Item key={idx} color={getStatusColor(d.status)} dot={dot}>
<p>
<Text strong>{d.env}</Text> <DeploymentRefCode deployment={d}/> <a href={`/${d.repo?.namespace}/${d.repo?.name}/deployments/${d.number}`}>• View detail #{d.number}</a>
</p>
<p>
Deployed by {avatar} {moment(d.createdAt).fromNow()} <DeploymentStatusBadge deployment={d}/>
</p>
</Timeline.Item>
)
})}
</Timeline>
)
}

// https://ant.design/components/timeline/#Timeline.Item
const getStatusColor = (status: DeploymentStatusEnum) => {
switch (status) {
case DeploymentStatusEnum.Waiting:
return "gray"
case DeploymentStatusEnum.Created:
return "purple"
case DeploymentStatusEnum.Queued:
return "purple"
case DeploymentStatusEnum.Running:
return "purple"
case DeploymentStatusEnum.Success:
return "green"
case DeploymentStatusEnum.Failure:
return "red"
case DeploymentStatusEnum.Canceled:
return "gray"
default:
return "gray"
}
}
17 changes: 9 additions & 8 deletions ui/src/views/RepoHome.tsx → ui/src/views/repoHome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useParams } from "react-router-dom";
import { shallowEqual } from "react-redux";
import { PageHeader, Select } from 'antd'

import { useAppSelector, useAppDispatch } from '../redux/hooks'
import { repoHomeSlice as slice, fetchEnvs, fetchDeployments, perPage } from '../redux/repoHome'
import { subscribeEvents } from "../apis"
import { useAppSelector, useAppDispatch } from '../../redux/hooks'
import { repoHomeSlice as slice, fetchEnvs, fetchDeployments, perPage } from '../../redux/repoHome'
import { subscribeEvents } from "../../apis"

import ActivityLogs from '../components/ActivityLogs'
import Spin from '../components/Spin'
import Pagination from '../components/Pagination'
import ActivityLogs from './ActivityLogs'
import Spin from '../../components/Spin'
import Pagination from '../../components/Pagination'

const { Option } = Select

Expand Down Expand Up @@ -78,8 +78,9 @@ export default function RepoHome(): JSX.Element {
</div>
<div style={{marginTop: "30px", padding: "16px 24px"}}>
{(loading)?
<div style={{textAlign: "center"}}><Spin /></div> :
<ActivityLogs deployments={deployments}/>
<div style={{textAlign: "center"}}><Spin /></div>
:
<ActivityLogs />
}
</div>
<div style={{marginTop: "20px", textAlign: "center"}}>
Expand Down