Skip to content

Commit e3c233a

Browse files
jinchanzyouluna
authored andcommitted
chore(Transfer): clean code
1 parent 2841951 commit e3c233a

File tree

1 file changed

+16
-80
lines changed

1 file changed

+16
-80
lines changed

src/transfer/view/transfer-panel.jsx

Lines changed: 16 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,8 @@ export default class TransferPanel extends Component {
4747
dragValue: null,
4848
dragOverValue: null,
4949
};
50-
this.footerId = props.baseId
51-
? htmlId.escapeForId(
52-
`${props.baseId}-panel-footer-${props.position}`
53-
)
54-
: '';
55-
this.headerId = props.baseId
56-
? htmlId.escapeForId(
57-
`${props.baseId}-panel-header-${props.position}`
58-
)
59-
: '';
50+
this.footerId = props.baseId ? htmlId.escapeForId(`${props.baseId}-panel-footer-${props.position}`) : '';
51+
this.headerId = props.baseId ? htmlId.escapeForId(`${props.baseId}-panel-header-${props.position}`) : '';
6052

6153
bindCtx(this, [
6254
'handleCheck',
@@ -76,10 +68,7 @@ export default class TransferPanel extends Component {
7668
}
7769

7870
componentDidUpdate(prevProps) {
79-
if (
80-
prevProps.dataSource.length !== this.props.dataSource.length &&
81-
this.list
82-
) {
71+
if (prevProps.dataSource.length !== this.props.dataSource.length && this.list) {
8372
if (this.list.scrollTop > 0) {
8473
this.list.scrollTop = 0;
8574
}
@@ -93,16 +82,7 @@ export default class TransferPanel extends Component {
9382
}
9483

9584
getListData(dataSource, disableHighlight) {
96-
const {
97-
prefix,
98-
position,
99-
mode,
100-
value,
101-
onMove,
102-
disabled,
103-
itemRender,
104-
sortable,
105-
} = this.props;
85+
const { prefix, position, mode, value, onMove, disabled, itemRender, sortable } = this.props;
10686
const { dragPosition, dragValue, dragOverValue } = this.state;
10787
return dataSource.map(item => {
10888
const others =
@@ -122,9 +102,7 @@ export default class TransferPanel extends Component {
122102
item={item}
123103
onCheck={this.handleCheck}
124104
onClick={onMove}
125-
needHighlight={
126-
!this.firstRender && !this.searched && !disableHighlight
127-
}
105+
needHighlight={!this.firstRender && !this.searched && !disableHighlight}
128106
itemRender={itemRender}
129107
draggable={sortable}
130108
onDragStart={this.handleItemDragStart}
@@ -209,10 +187,7 @@ export default class TransferPanel extends Component {
209187
const { title, prefix } = this.props;
210188

211189
return (
212-
<div
213-
id={this.headerId}
214-
className={`${prefix}transfer-panel-header`}
215-
>
190+
<div id={this.headerId} className={`${prefix}transfer-panel-header`}>
216191
{title}
217192
</div>
218193
);
@@ -232,13 +207,7 @@ export default class TransferPanel extends Component {
232207
}
233208

234209
renderList(dataSource) {
235-
const {
236-
prefix,
237-
listClassName,
238-
listStyle,
239-
customerList,
240-
useVirtual,
241-
} = this.props;
210+
const { prefix, listClassName, listStyle, customerList, useVirtual } = this.props;
242211
const newClassName = cx({
243212
[`${prefix}transfer-panel-list`]: true,
244213
[listClassName]: !!listClassName,
@@ -247,11 +216,7 @@ export default class TransferPanel extends Component {
247216
const customerPanel = customerList && customerList(this.props);
248217
if (customerPanel) {
249218
return (
250-
<div
251-
className={newClassName}
252-
style={listStyle}
253-
ref={this.getListDOM}
254-
>
219+
<div className={newClassName} style={listStyle} ref={this.getListDOM}>
255220
{customerPanel}
256221
</div>
257222
);
@@ -267,10 +232,7 @@ export default class TransferPanel extends Component {
267232

268233
if (useVirtual) {
269234
return (
270-
<div
271-
className={newClassName}
272-
style={{ position: 'relative', ...listStyle }}
273-
>
235+
<div className={newClassName} style={{ position: 'relative', ...listStyle }}>
274236
<VirtualList
275237
itemsRenderer={(items, ref) => (
276238
<Menu style={{ border: 'none' }} ref={ref}>
@@ -285,11 +247,7 @@ export default class TransferPanel extends Component {
285247
}
286248

287249
return (
288-
<Menu
289-
className={newClassName}
290-
style={listStyle}
291-
ref={this.getListDOM}
292-
>
250+
<Menu className={newClassName} style={listStyle} ref={this.getListDOM}>
293251
{this.getListData(dataSource)}
294252
</Menu>
295253
);
@@ -300,22 +258,13 @@ export default class TransferPanel extends Component {
300258

301259
return (
302260
<div className={`${prefix}transfer-panel-not-found-container`}>
303-
<div className={`${prefix}transfer-panel-not-found`}>
304-
{notFoundContent}
305-
</div>
261+
<div className={`${prefix}transfer-panel-not-found`}>{notFoundContent}</div>
306262
</div>
307263
);
308264
}
309265

310266
renderFooter() {
311-
const {
312-
prefix,
313-
position,
314-
mode,
315-
disabled,
316-
locale,
317-
showCheckAll,
318-
} = this.props;
267+
const { prefix, position, mode, disabled, locale, showCheckAll } = this.props;
319268
if (mode === 'simple') {
320269
const { onMoveAll } = this.props;
321270
const classNames = cx({
@@ -324,13 +273,7 @@ export default class TransferPanel extends Component {
324273
});
325274
return (
326275
<div className={`${prefix}transfer-panel-footer`}>
327-
<a
328-
className={classNames}
329-
onClick={onMoveAll.bind(
330-
this,
331-
position === 'left' ? 'right' : 'left'
332-
)}
333-
>
276+
<a className={classNames} onClick={onMoveAll.bind(this, position === 'left' ? 'right' : 'left')}>
334277
{locale.moveAll}
335278
</a>
336279
</div>
@@ -342,13 +285,9 @@ export default class TransferPanel extends Component {
342285
const totalCount = dataSource.length;
343286
const totalEnabledCount = this.enabledDatasource.length;
344287
const checked = checkedCount > 0 && checkedCount >= totalEnabledCount;
345-
const indeterminate =
346-
checkedCount > 0 && checkedCount < totalEnabledCount;
288+
const indeterminate = checkedCount > 0 && checkedCount < totalEnabledCount;
347289
const items = totalCount > 1 ? locale.items : locale.item;
348-
const countLabel =
349-
checkedCount === 0
350-
? `${totalCount} ${items}`
351-
: `${checkedCount}/${totalCount} ${items}`;
290+
const countLabel = checkedCount === 0 ? `${totalCount} ${items}` : `${checkedCount}/${totalCount} ${items}`;
352291

353292
return (
354293
<div className={`${prefix}transfer-panel-footer`}>
@@ -361,10 +300,7 @@ export default class TransferPanel extends Component {
361300
aria-labelledby={this.footerId}
362301
/>
363302
)}
364-
<span
365-
className={`${prefix}transfer-panel-count`}
366-
id={this.footerId}
367-
>
303+
<span className={`${prefix}transfer-panel-count`} id={this.footerId}>
368304
{countLabel}
369305
</span>
370306
</div>

0 commit comments

Comments
 (0)