Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8fbac99

Browse files
committed
refactor(table): add reposTable & improve
1 parent 2c4aa2e commit 8fbac99

File tree

6 files changed

+246
-147
lines changed

6 files changed

+246
-147
lines changed

components/ReposTable/index.js

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
*
3+
* ReposTable
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import PropTypes from 'prop-types'
9+
import { Table, Button } from 'antd'
10+
11+
import Pagi from '../Pagi'
12+
import { TableLoading } from '../LoadingEffects'
13+
import { Space } from '../BaseStyled'
14+
import UserCell from '../UserCell'
15+
import CommunityCell from '../CommunityCell'
16+
import TagsCell from '../TagsCell'
17+
import TimeStampCell from '../TimeStampCell'
18+
19+
import { OperationWrapper } from './styles'
20+
21+
import { makeDebugger, TYPE } from '../../utils'
22+
23+
/* eslint-disable no-unused-vars */
24+
const debug = makeDebugger('c:ReposTable:index')
25+
/* eslint-enable no-unused-vars */
26+
27+
class ReposTable extends React.PureComponent {
28+
columns() {
29+
const {
30+
setCommunity,
31+
unsetCommunity,
32+
unsetTag,
33+
setTag,
34+
onEdit,
35+
onDelete,
36+
} = this.props
37+
38+
return [
39+
{
40+
title: 'id',
41+
dataIndex: 'id',
42+
align: 'center',
43+
width: 80,
44+
fixed: 'left',
45+
},
46+
{
47+
title: '标题',
48+
width: 300,
49+
align: 'left',
50+
fixed: 'left',
51+
render: (text, record) => (
52+
<div>
53+
<div>{record.ownerName}</div>
54+
<div>{record.title}</div>
55+
</div>
56+
),
57+
},
58+
{
59+
title: '作者',
60+
width: 200,
61+
dataIndex: 'author',
62+
align: 'center',
63+
render: author => {
64+
return <UserCell user={author} />
65+
},
66+
},
67+
{
68+
title: '社区',
69+
width: 150,
70+
dataIndex: 'communities',
71+
align: 'center',
72+
render: (communities, record) => {
73+
return (
74+
<CommunityCell
75+
array={communities}
76+
source={record}
77+
thread={TYPE.REPO}
78+
onDelete={unsetCommunity}
79+
onAdd={setCommunity}
80+
withSetter
81+
/>
82+
)
83+
},
84+
},
85+
{
86+
title: '标签',
87+
width: 250,
88+
dataIndex: 'tags',
89+
align: 'center',
90+
render: (tags, record) => (
91+
<TagsCell
92+
thread={TYPE.REPO}
93+
source={record}
94+
onDelete={unsetTag}
95+
onAdd={setTag}
96+
/>
97+
),
98+
},
99+
{
100+
title: '浏览',
101+
width: 100,
102+
dataIndex: 'views',
103+
align: 'center',
104+
},
105+
{
106+
title: '评论数',
107+
width: 100,
108+
dataIndex: 'commentsCount',
109+
align: 'center',
110+
},
111+
{
112+
title: '时间戳',
113+
width: 120,
114+
align: 'center',
115+
render: (text, record) => <TimeStampCell data={record} />,
116+
},
117+
{
118+
title: '操作',
119+
width: 200,
120+
dataIndex: '',
121+
align: 'center',
122+
render: (text, record) => {
123+
return (
124+
<OperationWrapper>
125+
<Button
126+
size="small"
127+
type="primary"
128+
ghost
129+
onClick={onEdit.bind(this, record)}
130+
>
131+
编辑
132+
</Button>
133+
<Space right="10px" />
134+
<Button
135+
size="small"
136+
type="red"
137+
ghost
138+
onClick={onDelete.bind(this, record)}
139+
>
140+
删除
141+
</Button>
142+
</OperationWrapper>
143+
)
144+
},
145+
},
146+
]
147+
}
148+
149+
render() {
150+
const { data, loading, pageChange } = this.props
151+
152+
return (
153+
<React.Fragment>
154+
{data ? (
155+
<div>
156+
<Table
157+
columns={this.columns()}
158+
dataSource={data.entries}
159+
scroll={{ x: 2000 }}
160+
loading={TableLoading(loading)}
161+
pagination={false}
162+
/>
163+
<Pagi
164+
left="-10px"
165+
pageNumber={data.pageNumber}
166+
pageSize={data.pageSize}
167+
totalCount={data.totalCount}
168+
onChange={pageChange}
169+
/>
170+
</div>
171+
) : null}
172+
</React.Fragment>
173+
)
174+
}
175+
}
176+
177+
ReposTable.propTypes = {
178+
data: PropTypes.any.isRequired,
179+
loading: PropTypes.bool,
180+
pageChange: PropTypes.func,
181+
182+
setCommunity: PropTypes.func,
183+
unsetCommunity: PropTypes.func,
184+
unsetTag: PropTypes.func,
185+
setTag: PropTypes.func,
186+
onEdit: PropTypes.func,
187+
onDelete: PropTypes.func,
188+
}
189+
190+
ReposTable.defaultProps = {
191+
loading: false,
192+
pageChange: debug,
193+
194+
setCommunity: debug,
195+
unsetCommunity: debug,
196+
unsetTag: debug,
197+
setTag: debug,
198+
onEdit: debug,
199+
onDelete: debug,
200+
}
201+
202+
export default ReposTable
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import styled from 'styled-components'
2+
3+
import { Img } from '../..'
4+
import { theme } from '../../../utils'
5+
6+
export const Wrapper = styled.div`
7+
min-height: 800px;
8+
`
9+
export const CommunityIcon = styled(Img)`
10+
fill: ${theme('banner.title')};
11+
width: 30px;
12+
height: 30px;
13+
`
14+
export const OperationWrapper = styled.div`
15+
display: flex;
16+
justify-content: center;
17+
`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import ReposTable from '../index'
5+
6+
describe('TODO <ReposTable />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

components/VideosTable/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import CommunityCell from '../CommunityCell'
1818
import TagsCell from '../TagsCell'
1919
import TimeStampCell from '../TimeStampCell'
2020

21-
import { makeDebugger, cutFrom } from '../../utils'
21+
import { makeDebugger, cutFrom, TYPE } from '../../utils'
2222

2323
/* eslint-disable no-unused-vars */
2424
const debug = makeDebugger('c:VideosTable:index')
@@ -73,7 +73,7 @@ class VideosTable extends React.Component {
7373
<CommunityCell
7474
array={communities}
7575
source={record}
76-
thread="JOB"
76+
thread={TYPE.VIDEO}
7777
onDelete={unsetCommunity}
7878
onAdd={setCommunity}
7979
withSetter
@@ -87,7 +87,7 @@ class VideosTable extends React.Component {
8787
align: 'center',
8888
render: (tags, record) => (
8989
<TagsCell
90-
thread="JOB"
90+
thread={TYPE.VIDEO}
9191
source={record}
9292
onDelete={unsetTag}
9393
onAdd={setTag}

0 commit comments

Comments
 (0)