Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);