Merge "fix: Fix row hide in base table"

This commit is contained in:
Zuul 2022-06-07 01:19:20 +00:00 committed by Gerrit Code Review
commit 50f465eb13

View File

@ -124,7 +124,6 @@ export class BaseTable extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
hideRow: hideRow:
getLocalStorageItem(`${this.useId}-${this.props.resourceName}`) || [], getLocalStorageItem(`${this.useId}-${this.props.resourceName}`) || [],
@ -136,16 +135,6 @@ export class BaseTable extends React.Component {
this.sortKey = props.defaultSortKey; this.sortKey = props.defaultSortKey;
this.sortOrder = props.defaultSortOrder; this.sortOrder = props.defaultSortOrder;
this.hideableRow = props.columns
.filter((column) => !column.hidden)
.filter((column) => column.isHideable)
.map((column) => ({
label: column.title,
value: this.getDataIndex(column.dataIndex) || column.key,
}));
this.hideableColValues = this.hideableRow.map((item) => item.value);
this.suggestions = props.columns this.suggestions = props.columns
.filter((column) => column.search && column.dataIndex) .filter((column) => column.search && column.dataIndex)
.map((column) => ({ .map((column) => ({
@ -160,6 +149,16 @@ export class BaseTable extends React.Component {
})); }));
} }
get hideableRows() {
return this.props.columns
.filter((column) => !column.hidden)
.filter((column) => column.isHideable)
.map((column) => ({
label: column.title,
value: this.getDataIndex(column.dataIndex) || column.key,
}));
}
get useId() { get useId() {
const { user = {} } = toJS(this.props.rootStore) || {}; const { user = {} } = toJS(this.props.rootStore) || {};
const { user: { id } = {} } = user || {}; const { user: { id } = {} } = user || {};
@ -238,11 +237,10 @@ export class BaseTable extends React.Component {
}; };
handleRowHide = (columns) => { handleRowHide = (columns) => {
const hideableColValues = this.hideableRows.map((item) => item.value);
this.setState( this.setState(
{ {
hideRow: this.hideableColValues.filter( hideRow: hideableColValues.filter((value) => !columns.includes(value)),
(value) => !columns.includes(value)
),
}, },
() => { () => {
setLocalStorageItem( setLocalStorageItem(
@ -815,7 +813,7 @@ export class BaseTable extends React.Component {
const getHideColKeys = (cols) => { const getHideColKeys = (cols) => {
const results = []; const results = [];
this.hideableRow.forEach((item) => { this.hideableRows.forEach((item) => {
if (cols.indexOf(item.value) === -1) { if (cols.indexOf(item.value) === -1) {
results.push(item.value); results.push(item.value);
} }
@ -826,7 +824,7 @@ export class BaseTable extends React.Component {
return ( return (
<CustomColumns <CustomColumns
className={styles['column-menu']} className={styles['column-menu']}
options={this.hideableRow} options={this.hideableRows}
value={getHideColKeys(hideRow)} value={getHideColKeys(hideRow)}
onChange={this.handleRowHide} onChange={this.handleRowHide}
/> />