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

Commit ca70e61

Browse files
committed
refactor(table): extract general jobs table
1 parent 4911eb1 commit ca70e61

File tree

7 files changed

+258
-158
lines changed

7 files changed

+258
-158
lines changed

components/JobsTable/index.js

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/*
2+
*
3+
* JobsTable
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, cutFrom } from '../../utils'
22+
23+
/* eslint-disable no-unused-vars */
24+
const debug = makeDebugger('c:JobsTable:index')
25+
/* eslint-enable no-unused-vars */
26+
27+
class JobsTable 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+
dataIndex: 'title',
50+
align: 'center',
51+
fixed: 'left',
52+
render: text => {
53+
return <div>{cutFrom(text, 50)}</div>
54+
},
55+
},
56+
{
57+
title: '作者',
58+
width: 200,
59+
dataIndex: 'author',
60+
align: 'center',
61+
render: author => {
62+
return <UserCell user={author} />
63+
},
64+
},
65+
{
66+
title: '社区',
67+
width: 150,
68+
dataIndex: 'communities',
69+
align: 'center',
70+
render: (communities, record) => {
71+
return (
72+
<CommunityCell
73+
array={communities}
74+
source={record}
75+
thread="JOB"
76+
onDelete={unsetCommunity}
77+
onAdd={setCommunity}
78+
withSetter
79+
/>
80+
)
81+
},
82+
},
83+
{
84+
title: '标签',
85+
width: 250,
86+
dataIndex: 'tags',
87+
align: 'center',
88+
render: (tags, record) => (
89+
<TagsCell
90+
thread="JOB"
91+
source={record}
92+
onDelete={unsetTag}
93+
onAdd={setTag}
94+
/>
95+
),
96+
},
97+
{
98+
title: '浏览',
99+
width: 100,
100+
dataIndex: 'views',
101+
align: 'center',
102+
},
103+
{
104+
title: '评论数',
105+
width: 100,
106+
dataIndex: 'commentsCount',
107+
align: 'center',
108+
},
109+
/*
110+
{
111+
title: '收藏',
112+
width: 100,
113+
dataIndex: 'favoritedCount',
114+
align: 'center',
115+
},
116+
*/
117+
{
118+
title: '时间戳',
119+
width: 120,
120+
align: 'center',
121+
render: (text, record) => <TimeStampCell data={record} />,
122+
},
123+
{
124+
title: '操作',
125+
width: 200,
126+
dataIndex: '',
127+
align: 'center',
128+
render: (text, record) => (
129+
<OperationWrapper>
130+
<Button
131+
size="small"
132+
type="primary"
133+
ghost
134+
onClick={onEdit.bind(this, record)}
135+
>
136+
编辑
137+
</Button>
138+
<Space right="10px" />
139+
<Button
140+
size="small"
141+
type="red"
142+
ghost
143+
onClick={onDelete.bind(this, record)}
144+
>
145+
删除
146+
</Button>
147+
</OperationWrapper>
148+
),
149+
},
150+
]
151+
}
152+
153+
render() {
154+
const { data, loading, pageChange } = this.props
155+
156+
return (
157+
<React.Fragment>
158+
{data ? (
159+
<div>
160+
<Table
161+
columns={this.columns()}
162+
dataSource={data.entries}
163+
scroll={{ x: 2000 }}
164+
loading={TableLoading(loading)}
165+
pagination={false}
166+
/>
167+
<Pagi
168+
left="-10px"
169+
pageNumber={data.pageNumber}
170+
pageSize={data.pageSize}
171+
totalCount={data.totalCount}
172+
onChange={pageChange}
173+
/>
174+
</div>
175+
) : null}
176+
</React.Fragment>
177+
)
178+
}
179+
}
180+
181+
JobsTable.propTypes = {
182+
data: PropTypes.any.isRequired,
183+
loading: PropTypes.bool,
184+
pageChange: PropTypes.func,
185+
setCommunity: PropTypes.func,
186+
unsetCommunity: PropTypes.func,
187+
unsetTag: PropTypes.func,
188+
setTag: PropTypes.func,
189+
onEdit: PropTypes.func,
190+
onDelete: PropTypes.func,
191+
}
192+
193+
JobsTable.defaultProps = {
194+
loading: false,
195+
pageChange: debug,
196+
setCommunity: debug,
197+
unsetCommunity: debug,
198+
unsetTag: debug,
199+
setTag: debug,
200+
onEdit: debug,
201+
onDelete: debug,
202+
}
203+
204+
export default JobsTable
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 JobsTable from '../index'
5+
6+
describe('TODO <JobsTable />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

containers/CommunitiesBanner/JobsBanner.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import React from 'react'
22

33
import { ICON_CMD } from '../../config'
4-
import { Tag, Popover, BannerCountBrief } from '../../components'
4+
import { Popover, BannerCountBrief } from '../../components'
55

66
import {
77
BannerContentWrapper,
88
Operation,
99
OperationItem,
1010
OperationDivider,
1111
OperationTitle,
12-
FilterTags,
1312
OperationIcon,
1413
OperationIconChart,
1514
} from './styles/common_banner'
@@ -31,6 +30,11 @@ class JobsBanner extends React.Component {
3130
thread="招聘贴"
3231
/>
3332
<Operation>
33+
<OperationItem onClick={console.log}>
34+
<OperationIconChart src={`${ICON_CMD}/refresh.svg`} />
35+
刷新
36+
</OperationItem>
37+
<OperationDivider />
3438
<OperationItem>
3539
<OperationIcon src={`${ICON_CMD}/filter2.svg`} />
3640
<Popover
@@ -39,10 +43,6 @@ class JobsBanner extends React.Component {
3943
>
4044
<OperationTitle>过滤</OperationTitle>
4145
</Popover>
42-
<FilterTags>
43-
<Tag closable>最多xx</Tag>
44-
<Tag closable>最少..</Tag>
45-
</FilterTags>
4646
</OperationItem>
4747
<OperationDivider />
4848
<OperationItem onClick={logic.onAdd}>

0 commit comments

Comments
 (0)