Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #2228 [new feature] Use pagination when more than 100 files in fi…
…le manager
- Loading branch information
Showing
3 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* file list module to limit files rendered to increase performance | ||
*/ | ||
|
||
import { PureComponent } from 'react' | ||
import { Pagination } from 'antd' | ||
|
||
export default class ScrollFiles extends PureComponent { | ||
state = { | ||
page: 1, | ||
pageSize: 100 | ||
} | ||
|
||
onChange = page => { | ||
this.setState({ | ||
page | ||
}) | ||
} | ||
|
||
renderList () { | ||
const { | ||
page, pageSize | ||
} = this.state | ||
const start = (page - 1) * pageSize | ||
const end = start + pageSize | ||
const { | ||
list, hasPager | ||
} = this.props | ||
const arr = hasPager | ||
? list.slice(start, end) | ||
: list | ||
return arr.map(this.props.renderItem) | ||
} | ||
|
||
renderPager () { | ||
const props = { | ||
current: this.state.page, | ||
pageSize: this.state.pageSize, | ||
total: this.props.list.length, | ||
showSizeChanger: false, | ||
size: 'small', | ||
onChange: this.onChange | ||
} | ||
return ( | ||
<div className='pd1b'> | ||
<Pagination | ||
{...props} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
render () { | ||
const arr = this.renderList() | ||
if (this.props.hasPager) { | ||
arr.push(this.renderPager()) | ||
} | ||
return arr | ||
} | ||
} |