-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CE-346] Implement user management page
Can create/edit/delete user in user management page. Change-Id: Ibd1e91afb642528c9fe63fd2c3c0ecb94843fde1 Signed-off-by: Haitao Yue <[email protected]>
- Loading branch information
Showing
12 changed files
with
749 additions
and
96 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
147 changes: 147 additions & 0 deletions
147
src/themes/react/static/dashboard/src/components/StandardTable/index.js
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,147 @@ | ||
import React, { PureComponent, Fragment } from 'react'; | ||
import { Table, Alert } from 'antd'; | ||
import { defineMessages, FormattedMessage } from 'react-intl'; | ||
import styles from './index.less'; | ||
|
||
const messages = defineMessages({ | ||
label: { | ||
selected: { | ||
id: 'Components.StandardTable.Label.Selected', | ||
defaultMessage: 'Selected', | ||
}, | ||
total: { | ||
id: 'Components.StandardTable.Label.Total', | ||
defaultMessage: 'Total', | ||
}, | ||
item: { | ||
id: 'Components.StandardTable.Label.Item', | ||
defaultMessage: 'Item', | ||
}, | ||
}, | ||
button: { | ||
clear: { | ||
id: 'Components.StandardTable.Button.Clear', | ||
defaultMessage: 'Clear', | ||
}, | ||
}, | ||
}); | ||
|
||
function initTotalList(columns) { | ||
const totalList = []; | ||
columns.forEach(column => { | ||
if (column.needTotal) { | ||
totalList.push({ ...column, total: 0 }); | ||
} | ||
}); | ||
return totalList; | ||
} | ||
|
||
class StandardTable extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
const { columns } = props; | ||
const needTotalList = initTotalList(columns); | ||
|
||
this.state = { | ||
selectedRowKeys: [], | ||
needTotalList, | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
// clean state | ||
if (nextProps.selectedRows.length === 0) { | ||
const needTotalList = initTotalList(nextProps.columns); | ||
this.setState({ | ||
selectedRowKeys: [], | ||
needTotalList, | ||
}); | ||
} | ||
} | ||
|
||
handleRowSelectChange = (selectedRowKeys, selectedRows) => { | ||
let needTotalList = [...this.state.needTotalList]; | ||
needTotalList = needTotalList.map(item => { | ||
return { | ||
...item, | ||
total: selectedRows.reduce((sum, val) => { | ||
return sum + parseFloat(val[item.dataIndex], 10); | ||
}, 0), | ||
}; | ||
}); | ||
|
||
if (this.props.onSelectRow) { | ||
this.props.onSelectRow(selectedRows); | ||
} | ||
|
||
this.setState({ selectedRowKeys, needTotalList }); | ||
}; | ||
|
||
handleTableChange = (pagination, filters, sorter) => { | ||
this.props.onChange(pagination, filters, sorter); | ||
}; | ||
|
||
cleanSelectedKeys = () => { | ||
this.handleRowSelectChange([], []); | ||
}; | ||
|
||
render() { | ||
const { selectedRowKeys, needTotalList } = this.state; | ||
const { data: { list, pagination }, loading, columns, rowKey } = this.props; | ||
|
||
const paginationProps = { | ||
showSizeChanger: true, | ||
showQuickJumper: true, | ||
...pagination, | ||
}; | ||
|
||
const rowSelection = { | ||
selectedRowKeys, | ||
onChange: this.handleRowSelectChange, | ||
getCheckboxProps: record => ({ | ||
disabled: record.disabled, | ||
}), | ||
}; | ||
|
||
return ( | ||
<div className={styles.standardTable}> | ||
<div className={styles.tableAlert}> | ||
<Alert | ||
message={ | ||
<Fragment> | ||
<FormattedMessage {...messages.label.selected} />{' '} | ||
<a style={{ fontWeight: 600 }}>{selectedRowKeys.length}</a>{' '} | ||
<FormattedMessage {...messages.label.item} /> | ||
{needTotalList.map(item => ( | ||
<span style={{ marginLeft: 8 }} key={item.dataIndex}> | ||
{item.title} | ||
<FormattedMessage {...messages.label.total} /> | ||
<span style={{ fontWeight: 600 }}> | ||
{item.render ? item.render(item.total) : item.total} | ||
</span> | ||
</span> | ||
))} | ||
<a onClick={this.cleanSelectedKeys} style={{ marginLeft: 24 }}> | ||
<FormattedMessage {...messages.button.clear} /> | ||
</a> | ||
</Fragment> | ||
} | ||
type="info" | ||
showIcon | ||
/> | ||
</div> | ||
<Table | ||
loading={loading} | ||
rowKey={rowKey || 'key'} | ||
rowSelection={rowSelection} | ||
dataSource={list} | ||
columns={columns} | ||
pagination={paginationProps} | ||
onChange={this.handleTableChange} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default StandardTable; |
13 changes: 13 additions & 0 deletions
13
src/themes/react/static/dashboard/src/components/StandardTable/index.less
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,13 @@ | ||
@import '~antd/lib/style/themes/default.less'; | ||
|
||
.standardTable { | ||
:global { | ||
.ant-table-pagination { | ||
margin-top: 24px; | ||
} | ||
} | ||
|
||
.tableAlert { | ||
margin-bottom: 16px; | ||
} | ||
} |
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
Oops, something went wrong.