|
|
@ -1,7 +1,14 @@
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
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 LoadingIndicator from 'Components/Loading/LoadingIndicator';
|
|
|
|
|
|
|
|
import ConfirmModal from 'Components/Modal/ConfirmModal';
|
|
|
|
import Table from 'Components/Table/Table';
|
|
|
|
import Table from 'Components/Table/Table';
|
|
|
|
import TableBody from 'Components/Table/TableBody';
|
|
|
|
import TableBody from 'Components/Table/TableBody';
|
|
|
|
import TableOptionsModalWrapper from 'Components/Table/TableOptions/TableOptionsModalWrapper';
|
|
|
|
import TableOptionsModalWrapper from 'Components/Table/TableOptions/TableOptionsModalWrapper';
|
|
|
@ -15,6 +22,72 @@ import BlacklistRowConnector from './BlacklistRowConnector';
|
|
|
|
|
|
|
|
|
|
|
|
class Blacklist extends Component {
|
|
|
|
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
|
|
|
|
// Render
|
|
|
|
|
|
|
|
|
|
|
@ -26,15 +99,33 @@ class Blacklist extends Component {
|
|
|
|
items,
|
|
|
|
items,
|
|
|
|
columns,
|
|
|
|
columns,
|
|
|
|
totalRecords,
|
|
|
|
totalRecords,
|
|
|
|
|
|
|
|
isRemoving,
|
|
|
|
isClearingBlacklistExecuting,
|
|
|
|
isClearingBlacklistExecuting,
|
|
|
|
onClearBlacklistPress,
|
|
|
|
onClearBlacklistPress,
|
|
|
|
...otherProps
|
|
|
|
...otherProps
|
|
|
|
} = this.props;
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
allSelected,
|
|
|
|
|
|
|
|
allUnselected,
|
|
|
|
|
|
|
|
selectedState,
|
|
|
|
|
|
|
|
isConfirmRemoveModalOpen
|
|
|
|
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const selectedIds = this.getSelectedIds();
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<PageContent title="Blacklist">
|
|
|
|
<PageContent title="Blacklist">
|
|
|
|
<PageToolbar>
|
|
|
|
<PageToolbar>
|
|
|
|
<PageToolbarSection>
|
|
|
|
<PageToolbarSection>
|
|
|
|
|
|
|
|
<PageToolbarButton
|
|
|
|
|
|
|
|
label="Remove Selected"
|
|
|
|
|
|
|
|
iconName={icons.REMOVE}
|
|
|
|
|
|
|
|
isDisabled={!selectedIds.length}
|
|
|
|
|
|
|
|
isSpinning={isRemoving}
|
|
|
|
|
|
|
|
onPress={this.onRemoveSelectedPress}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<PageToolbarButton
|
|
|
|
<PageToolbarButton
|
|
|
|
label="Clear"
|
|
|
|
label="Clear"
|
|
|
|
iconName={icons.CLEAR}
|
|
|
|
iconName={icons.CLEAR}
|
|
|
@ -59,51 +150,67 @@ class Blacklist extends Component {
|
|
|
|
<PageContentBody>
|
|
|
|
<PageContentBody>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
isFetching && !isPopulated &&
|
|
|
|
isFetching && !isPopulated &&
|
|
|
|
<LoadingIndicator />
|
|
|
|
<LoadingIndicator />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
!isFetching && !!error &&
|
|
|
|
!isFetching && !!error &&
|
|
|
|
<div>Unable to load blacklist</div>
|
|
|
|
<div>Unable to load blacklist</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
isPopulated && !error && !items.length &&
|
|
|
|
isPopulated && !error && !items.length &&
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
No history blacklist
|
|
|
|
No history blacklist
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
isPopulated && !error && !!items.length &&
|
|
|
|
isPopulated && !error && !!items.length &&
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<Table
|
|
|
|
<Table
|
|
|
|
columns={columns}
|
|
|
|
selectAll={true}
|
|
|
|
{...otherProps}
|
|
|
|
allSelected={allSelected}
|
|
|
|
>
|
|
|
|
allUnselected={allUnselected}
|
|
|
|
<TableBody>
|
|
|
|
columns={columns}
|
|
|
|
{
|
|
|
|
{...otherProps}
|
|
|
|
items.map((item) => {
|
|
|
|
onSelectAllChange={this.onSelectAllChange}
|
|
|
|
return (
|
|
|
|
>
|
|
|
|
<BlacklistRowConnector
|
|
|
|
<TableBody>
|
|
|
|
key={item.id}
|
|
|
|
{
|
|
|
|
columns={columns}
|
|
|
|
items.map((item) => {
|
|
|
|
{...item}
|
|
|
|
return (
|
|
|
|
/>
|
|
|
|
<BlacklistRowConnector
|
|
|
|
);
|
|
|
|
key={item.id}
|
|
|
|
})
|
|
|
|
isSelected={selectedState[item.id] || false}
|
|
|
|
}
|
|
|
|
columns={columns}
|
|
|
|
</TableBody>
|
|
|
|
{...item}
|
|
|
|
</Table>
|
|
|
|
onSelectedChange={this.onSelectedChange}
|
|
|
|
|
|
|
|
/>
|
|
|
|
<TablePager
|
|
|
|
);
|
|
|
|
totalRecords={totalRecords}
|
|
|
|
})
|
|
|
|
isFetching={isFetching}
|
|
|
|
}
|
|
|
|
{...otherProps}
|
|
|
|
</TableBody>
|
|
|
|
/>
|
|
|
|
</Table>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<TablePager
|
|
|
|
|
|
|
|
totalRecords={totalRecords}
|
|
|
|
|
|
|
|
isFetching={isFetching}
|
|
|
|
|
|
|
|
{...otherProps}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</PageContentBody>
|
|
|
|
</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>
|
|
|
|
</PageContent>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -116,7 +223,9 @@ Blacklist.propTypes = {
|
|
|
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
totalRecords: PropTypes.number,
|
|
|
|
totalRecords: PropTypes.number,
|
|
|
|
|
|
|
|
isRemoving: PropTypes.bool.isRequired,
|
|
|
|
isClearingBlacklistExecuting: PropTypes.bool.isRequired,
|
|
|
|
isClearingBlacklistExecuting: PropTypes.bool.isRequired,
|
|
|
|
|
|
|
|
onRemoveSelected: PropTypes.func.isRequired,
|
|
|
|
onClearBlacklistPress: PropTypes.func.isRequired
|
|
|
|
onClearBlacklistPress: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|