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

Commit a1925f8

Browse files
author
Noah Lee
authored
Refactoring the home view (#396)
* Move the `RepoList` component into the view
1 parent 7da4fde commit a1925f8

File tree

4 files changed

+79
-46
lines changed

4 files changed

+79
-46
lines changed

ui/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Route,
66
} from "react-router-dom";
77

8-
import Home from "./views/Home"
8+
import Home from "./views/home"
99
import Repo from "./views/Repo"
1010
import Deployment from "./views/Deployment"
1111
import Settings from "./views/Settings"

ui/src/components/SyncButton.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

ui/src/views/home/RepoList.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { shallowEqual } from 'react-redux'
2+
import { List, Typography } from 'antd'
3+
import moment from "moment"
4+
5+
import { useAppSelector } from '../../redux/hooks'
6+
import { Deployment } from '../../models'
7+
import UserAvatar from '../../components/UserAvatar'
8+
import DeploymentStatusBadge from "../../components/DeploymentStatusBadge"
9+
import DeploymentRefCode from "../../components/DeploymentRefCode"
10+
import Spin from '../../components/Spin'
11+
12+
const { Text, Paragraph } = Typography
13+
14+
export default function RepoList(): JSX.Element {
15+
const { loading, repos } = useAppSelector(state => state.home, shallowEqual)
16+
17+
if (loading) {
18+
return (
19+
<div style={{textAlign: "center"}}>
20+
<Spin />
21+
</div>
22+
)
23+
}
24+
25+
return (
26+
<List
27+
dataSource={repos}
28+
renderItem={repo => {
29+
// deployments is undeinfed if there is no deployments of the repository.
30+
const deployment = (repo.deployments)? repo.deployments[0] : null
31+
32+
return (
33+
<List.Item>
34+
<List.Item.Meta
35+
title={<a href={`/${repo.namespace}/${repo.name}`}>{repo.namespace} / {repo.name}</a>}
36+
description={<Description deployment={deployment}/>}
37+
/>
38+
</List.Item>
39+
)
40+
}}
41+
/>
42+
)
43+
}
44+
45+
interface DescriptionProps {
46+
deployment: Deployment | null
47+
}
48+
49+
function Description(props: DescriptionProps): JSX.Element {
50+
if (!props.deployment) {
51+
return <></>
52+
}
53+
54+
return (
55+
<Paragraph style={{marginTop: "10px", marginBottom: 0}}>
56+
<UserAvatar user={props.deployment.deployer} /> deployed <DeploymentRefCode deployment={props.deployment}/> to the <Text strong>{props.deployment.env}</Text> environment {moment(props.deployment.createdAt).fromNow()} <DeploymentStatusBadge deployment={props.deployment}/>
57+
</Paragraph>
58+
)
59+
}

ui/src/views/Home.tsx renamed to ui/src/views/home/index.tsx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { useEffect } from 'react'
22
import { shallowEqual } from 'react-redux'
3-
import { Input, Breadcrumb } from 'antd'
43
import { Helmet } from "react-helmet"
4+
import { Input, Breadcrumb, Button } from 'antd'
5+
import { RedoOutlined } from "@ant-design/icons"
56

6-
import { useAppSelector, useAppDispatch } from '../redux/hooks'
7-
import { homeSlice, listRepos, perPage, sync, homeSlice as slice } from '../redux/home'
8-
import { RequestStatus } from '../models'
9-
import { subscribeEvents } from "../apis"
7+
import { useAppSelector, useAppDispatch } from '../../redux/hooks'
8+
import { homeSlice, listRepos, perPage, sync, homeSlice as slice } from '../../redux/home'
9+
import { RequestStatus } from '../../models'
10+
import { subscribeEvents } from "../../apis"
1011

11-
import Main from './main'
12-
import SyncButton from "../components/SyncButton"
13-
import RepoList from '../components/RepoList'
14-
import Pagination from '../components/Pagination'
12+
import Main from '../main'
13+
import RepoList from './RepoList'
14+
import Pagination from '../../components/Pagination'
1515

1616
const { Search } = Input
1717
const { actions } = homeSlice
1818

1919
export default function Home(): JSX.Element {
20-
const { loading, repos, page, syncing } = useAppSelector(state => state.home, shallowEqual)
20+
const { repos, page, syncing } = useAppSelector(state => state.home, shallowEqual)
2121
const dispatch = useAppDispatch()
2222

2323
useEffect(() => {
@@ -57,20 +57,6 @@ export default function Home(): JSX.Element {
5757
f()
5858
}
5959

60-
if (loading) {
61-
return (
62-
<Main>
63-
<div >
64-
<Breadcrumb>
65-
<Breadcrumb.Item>
66-
<a href="/">Repositories</a>
67-
</Breadcrumb.Item>
68-
</Breadcrumb>
69-
</div>
70-
</Main>
71-
)
72-
}
73-
7460
return (
7561
<Main>
7662
<Helmet>
@@ -84,13 +70,19 @@ export default function Home(): JSX.Element {
8470
</Breadcrumb>
8571
</div>
8672
<div style={{textAlign: "right"}}>
87-
<SyncButton loading={syncing === RequestStatus.Pending} onClickSync={onClickSync}></SyncButton>
73+
<Button
74+
loading={syncing === RequestStatus.Pending}
75+
icon={<RedoOutlined />}
76+
onClick={onClickSync}
77+
>
78+
Sync
79+
</Button>
8880
</div>
8981
<div style={{"marginTop": "20px"}}>
9082
<Search placeholder="Search repository ..." onSearch={search} size="large" enterButton />
9183
</div>
9284
<div style={{"marginTop": "20px"}}>
93-
<RepoList repos={repos}></RepoList>
85+
<RepoList />
9486
</div>
9587
<div style={{marginTop: "20px", textAlign: "center"}}>
9688
<Pagination
@@ -102,4 +94,4 @@ export default function Home(): JSX.Element {
10294
</div>
10395
</Main>
10496
)
105-
}
97+
}

0 commit comments

Comments
 (0)