Metadata control improvements - #issuecomment-877168595 fix (remove sorting & filtering for hidden columns)
@@ -871,17 +871,51 @@ export default class Metadata extends React.Component {
onColumnSelect = (item) => {
const currentColumns = [...this.state.columns];
+ const column = currentColumns.find(obj => obj.key === item);
+ if (column) {
+ column.selected = !column.selected;
+ this.setState(
+ {columns: [...currentColumns]},
+ this.resetColumnsFiltersAndSorting
+ );
+ }
+ };
- const index = currentColumns.findIndex(obj => obj.key === item);
- const isSelected = currentColumns.findIndex(obj => obj.key === item && obj.selected) > -1;
-
- currentColumns[index] = {key: item, selected: !isSelected};
- this.setState({columns: currentColumns}, this.clearSelection);
+ resetColumnsFiltersAndSorting = () => {
+ const {
+ columns,
+ filterModel: oldFilters = {}
+ } = this.state;
+ const {
+ orderBy,
+ filters,
+ startDateFrom,
+ endDateTo,
+ ...filterModelRest
+ } = oldFilters;
+ const selectedColumnsKeys = new Set(
+ columns
+ .filter(column => column.selected)
+ .map(column => column.key)
+ );
+ const filterModel = {
+ orderBy: orderBy.filter(col => selectedColumnsKeys.has(col.field)),
+ filters: filters.filter(filter => selectedColumnsKeys.has(filter.key)),
+ startDateFrom: selectedColumnsKeys.has('createdDate') ? startDateFrom : undefined,
+ endDateTo: selectedColumnsKeys.has('createdDate') ? endDateTo : undefined,
+ ...filterModelRest
+ };
+ this.setState({
+ filterModel
+ }, () => {
+ this.clearSelection();
+ this.loadData();
+ });
};
onResetColumns = () => {
this.resetColumns(this.state.columns)
- .then(columns => this.setState({columns}, this.clearSelection));
+ .then(columns => this.setState({columns}, this.resetColumnsFiltersAndSorting));
};
onSetOrder = (order) => {
