|
|
|
@ -1,7 +1,14 @@
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import { align, icons } from 'Helpers/Props';
|
|
|
|
|
import getRemovedItems from 'Utilities/Object/getRemovedItems';
|
|
|
|
|
import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
|
|
|
|
|
import getSelectedIds from 'Utilities/Table/getSelectedIds';
|
|
|
|
|
import removeOldSelectedState from 'Utilities/Table/removeOldSelectedState';
|
|
|
|
|
import selectAll from 'Utilities/Table/selectAll';
|
|
|
|
|
import toggleSelected from 'Utilities/Table/toggleSelected';
|
|
|
|
|
import { align, icons, kinds } from 'Helpers/Props';
|
|
|
|
|
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
|
|
|
|
|
import ConfirmModal from 'Components/Modal/ConfirmModal';
|
|
|
|
|
import Table from 'Components/Table/Table';
|
|
|
|
|
import TableBody from 'Components/Table/TableBody';
|
|
|
|
|
import TableOptionsModalWrapper from 'Components/Table/TableOptions/TableOptionsModalWrapper';
|
|
|
|
@ -15,6 +22,72 @@ import BlacklistRowConnector from './BlacklistRowConnector';
|
|
|
|
|
|
|
|
|
|
class Blacklist extends Component {
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
allSelected: false,
|
|
|
|
|
allUnselected: false,
|
|
|
|
|
lastToggled: null,
|
|
|
|
|
selectedState: {},
|
|
|
|
|
isConfirmRemoveModalOpen: false,
|
|
|
|
|
items: props.items
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
|
const {
|
|
|
|
|
items
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (hasDifferentItems(prevProps.items, items)) {
|
|
|
|
|
this.setState((state) => {
|
|
|
|
|
return {
|
|
|
|
|
...removeOldSelectedState(state, getRemovedItems(prevProps.items, items)),
|
|
|
|
|
items
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Control
|
|
|
|
|
|
|
|
|
|
getSelectedIds = () => {
|
|
|
|
|
return getSelectedIds(this.state.selectedState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
|
|
onSelectAllChange = ({ value }) => {
|
|
|
|
|
this.setState(selectAll(this.state.selectedState, value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSelectedChange = ({ id, value, shiftKey = false }) => {
|
|
|
|
|
this.setState((state) => {
|
|
|
|
|
return toggleSelected(state, this.props.items, id, value, shiftKey);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onRemoveSelectedPress = () => {
|
|
|
|
|
this.setState({ isConfirmRemoveModalOpen: true });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onRemoveSelectedConfirmed = () => {
|
|
|
|
|
this.props.onRemoveSelected(this.getSelectedIds());
|
|
|
|
|
this.setState({ isConfirmRemoveModalOpen: false });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onConfirmRemoveModalClose = () => {
|
|
|
|
|
this.setState({ isConfirmRemoveModalOpen: false });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Render
|
|
|
|
|
|
|
|
|
@ -26,15 +99,33 @@ class Blacklist extends Component {
|
|
|
|
|
items,
|
|
|
|
|
columns,
|
|
|
|
|
totalRecords,
|
|
|
|
|
isRemoving,
|
|
|
|
|
isClearingBlacklistExecuting,
|
|
|
|
|
onClearBlacklistPress,
|
|
|
|
|
...otherProps
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
allSelected,
|
|
|
|
|
allUnselected,
|
|
|
|
|
selectedState,
|
|
|
|
|
isConfirmRemoveModalOpen
|
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
|
|
const selectedIds = this.getSelectedIds();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<PageContent title="Blacklist">
|
|
|
|
|
<PageToolbar>
|
|
|
|
|
<PageToolbarSection>
|
|
|
|
|
<PageToolbarButton
|
|
|
|
|
label="Remove Selected"
|
|
|
|
|
iconName={icons.REMOVE}
|
|
|
|
|
isDisabled={!selectedIds.length}
|
|
|
|
|
isSpinning={isRemoving}
|
|
|
|
|
onPress={this.onRemoveSelectedPress}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<PageToolbarButton
|
|
|
|
|
label="Clear"
|
|
|
|
|
iconName={icons.CLEAR}
|
|
|
|
@ -59,51 +150,67 @@ class Blacklist extends Component {
|
|
|
|
|
<PageContentBody>
|
|
|
|
|
{
|
|
|
|
|
isFetching && !isPopulated &&
|
|
|
|
|
<LoadingIndicator />
|
|
|
|
|
<LoadingIndicator />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
!isFetching && !!error &&
|
|
|
|
|
<div>Unable to load blacklist</div>
|
|
|
|
|
<div>Unable to load blacklist</div>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
isPopulated && !error && !items.length &&
|
|
|
|
|
<div>
|
|
|
|
|
No history blacklist
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
No history blacklist
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
isPopulated && !error && !!items.length &&
|
|
|
|
|
<div>
|
|
|
|
|
<Table
|
|
|
|
|
columns={columns}
|
|
|
|
|
{...otherProps}
|
|
|
|
|
>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{
|
|
|
|
|
items.map((item) => {
|
|
|
|
|
return (
|
|
|
|
|
<BlacklistRowConnector
|
|
|
|
|
key={item.id}
|
|
|
|
|
columns={columns}
|
|
|
|
|
{...item}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
|
|
|
|
|
<TablePager
|
|
|
|
|
totalRecords={totalRecords}
|
|
|
|
|
isFetching={isFetching}
|
|
|
|
|
{...otherProps}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<Table
|
|
|
|
|
selectAll={true}
|
|
|
|
|
allSelected={allSelected}
|
|
|
|
|
allUnselected={allUnselected}
|
|
|
|
|
columns={columns}
|
|
|
|
|
{...otherProps}
|
|
|
|
|
onSelectAllChange={this.onSelectAllChange}
|
|
|
|
|
>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{
|
|
|
|
|
items.map((item) => {
|
|
|
|
|
return (
|
|
|
|
|
<BlacklistRowConnector
|
|
|
|
|
key={item.id}
|
|
|
|
|
isSelected={selectedState[item.id] || false}
|
|
|
|
|
columns={columns}
|
|
|
|
|
{...item}
|
|
|
|
|
onSelectedChange={this.onSelectedChange}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
|
|
|
|
|
<TablePager
|
|
|
|
|
totalRecords={totalRecords}
|
|
|
|
|
isFetching={isFetching}
|
|
|
|
|
{...otherProps}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</PageContentBody>
|
|
|
|
|
|
|
|
|
|
<ConfirmModal
|
|
|
|
|
isOpen={isConfirmRemoveModalOpen}
|
|
|
|
|
kind={kinds.DANGER}
|
|
|
|
|
title="Remove Selected"
|
|
|
|
|
message={'Are you sure you want to remove the selected items from the blacklist?'}
|
|
|
|
|
confirmLabel="Remove Selected"
|
|
|
|
|
onConfirm={this.onRemoveSelectedConfirmed}
|
|
|
|
|
onCancel={this.onConfirmRemoveModalClose}
|
|
|
|
|
/>
|
|
|
|
|
</PageContent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@ -116,7 +223,9 @@ Blacklist.propTypes = {
|
|
|
|
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
|
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
|
totalRecords: PropTypes.number,
|
|
|
|
|
isRemoving: PropTypes.bool.isRequired,
|
|
|
|
|
isClearingBlacklistExecuting: PropTypes.bool.isRequired,
|
|
|
|
|
onRemoveSelected: PropTypes.func.isRequired,
|
|
|
|
|
onClearBlacklistPress: PropTypes.func.isRequired
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|