Skip to content

Commit

Permalink
fix #2228 [new feature] Use pagination when more than 100 files in fi…
Browse files Browse the repository at this point in the history
…le manager
  • Loading branch information
zxdong262 committed Oct 9, 2021
1 parent 5fbee21 commit 0e3b8e4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "electerm",
"version": "1.16.20",
"version": "1.16.21",
"description": "Terminal/ssh/sftp client(linux, mac, win) based on electron/ssh2/node-pty/xterm/antd/subx and other libs",
"main": "app.js",
"bin": "npm/electerm",
Expand Down
43 changes: 34 additions & 9 deletions src/client/components/sftp/list-table-ui.jsx
Expand Up @@ -21,6 +21,7 @@ import {
import copy from 'json-deep-copy'
import { CheckOutlined } from '@ant-design/icons'
import FileSection from './file-item'
import PagedList from './paged-list'

const { prefix } = window
const e = prefix('sftp')
Expand Down Expand Up @@ -113,6 +114,7 @@ export default class FileListTable extends React.Component {
]
}, [])
return {
pageSize: 100,
properties,
splitHandles
}
Expand Down Expand Up @@ -432,6 +434,17 @@ export default class FileListTable extends React.Component {

onDoubleClick = () => this.resetWidth()

hasPager = () => {
const {
pageSize
} = this.state
const {
fileList
} = this.props
const len = fileList.length
return len > pageSize
}

rebuildStyle = (name) => {
let { style, parentWidth } = this.oldStyles[name]
style = copy(style)
Expand Down Expand Up @@ -486,20 +499,32 @@ export default class FileListTable extends React.Component {
render () {
const { fileList, height, type } = this.props
const tableHeaderHeight = 30
const props = {
className: 'sftp-table-content overscroll-y relative',
style: {
height: height - sftpControlHeight - tableHeaderHeight
},
draggable: false
}
const hasPager = this.hasPager()
const cls = classnames(
'sftp-table relative',
{
'sftp-has-pager': hasPager
}
)
return (
<div className='sftp-table relative'>
<div className={cls}>
{this.renderTableHeader()}
<div
className='sftp-table-content overscroll-y relative'
style={{
height: height - sftpControlHeight - tableHeaderHeight
}}
draggable={false}
{...props}
>
{this.props.renderEmptyFile(type)}
{
fileList.map(this.renderItem)
}
<PagedList
list={fileList}
renderItem={this.renderItem}
hasPager={hasPager}
/>
</div>
</div>
)
Expand Down
60 changes: 60 additions & 0 deletions src/client/components/sftp/paged-list.jsx
@@ -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
}
}

0 comments on commit 0e3b8e4

Please sign in to comment.