Skip to content

Commit

Permalink
When an index is deleted, and it's selected in the table, then it's r…
Browse files Browse the repository at this point in the history
…emoved from the selection. (#22242) (#22301)
  • Loading branch information
cjcenizal authored Aug 24, 2018
1 parent 3fc85f7 commit 7dd8429
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ const HEADERS = {
};

export class IndexTableUi extends Component {
static getDerivedStateFromProps(props, state) {
// Deselct any indices which no longer exist, e.g. they've been deleted.
const { selectedIndicesMap } = state;
const indexNames = props.indices.map(index => index.name);
const selectedIndexNames = Object.keys(selectedIndicesMap);
const missingIndexNames = selectedIndexNames.filter(selectedIndexName => {
return !indexNames.includes(selectedIndexName);
});

if (missingIndexNames.length) {
const newMap = { ...selectedIndicesMap };
missingIndexNames.forEach(missingIndexName => delete newMap[missingIndexName]);
return { selectedIndicesMap: newMap };
}

return null;
}

constructor(props) {
super(props);

Expand All @@ -82,6 +100,7 @@ export class IndexTableUi extends Component {
const newIsSortAscending = sortField === column ? !isSortAscending : true;
sortChanged(column, newIsSortAscending);
};

toggleAll = () => {
const allSelected = this.areAllItemsSelected();
if (allSelected) {
Expand All @@ -96,6 +115,7 @@ export class IndexTableUi extends Component {
selectedIndicesMap
});
};

toggleItem = name => {
this.setState(({ selectedIndicesMap }) => {
const newMap = { ...selectedIndicesMap };
Expand All @@ -109,6 +129,7 @@ export class IndexTableUi extends Component {
};
});
};

isItemSelected = name => {
return !!this.state.selectedIndicesMap[name];
};
Expand Down Expand Up @@ -159,6 +180,7 @@ export class IndexTableUi extends Component {
}
return value;
}

buildRowCells(index) {
return Object.keys(HEADERS).map(fieldName => {
const { name } = index;
Expand All @@ -174,6 +196,7 @@ export class IndexTableUi extends Component {
);
});
}

buildRows() {
const { indices = [], detailPanelIndexName } = this.props;
return indices.map(index => {
Expand Down Expand Up @@ -221,7 +244,6 @@ export class IndexTableUi extends Component {
};

render() {

const {
filterChanged,
filter,
Expand Down Expand Up @@ -336,4 +358,4 @@ export class IndexTableUi extends Component {
}
}

export const IndexTable = injectI18n(IndexTableUi);
export const IndexTable = injectI18n(IndexTableUi);

0 comments on commit 7dd8429

Please sign in to comment.