Commit ff58583b authored by Axel Bocciarelli's avatar Axel Bocciarelli

Fix select all datasets in dataset table

parent 514c6eda
......@@ -3,20 +3,20 @@ import {
REMOVE_DATASET_BY_ID,
} from '../constants/actionTypes';
export function removeDatasetById(datasetId) {
export function addDatasetById(datasetIds) {
return function (dispatch) {
dispatch({
type: REMOVE_DATASET_BY_ID,
payload: datasetId,
type: ADD_DATASET_BY_ID,
payload: datasetIds,
});
};
}
export function addDatasetById(datasetId) {
export function removeDatasetById(datasetIds) {
return function (dispatch) {
dispatch({
type: ADD_DATASET_BY_ID,
payload: datasetId,
type: REMOVE_DATASET_BY_ID,
payload: datasetIds,
});
};
}
......@@ -195,19 +195,13 @@ class DatasetTable extends React.Component {
];
}
handleOnSelect = (row, isSelect) => {
if (isSelect) {
this.props.addDatasetById(row.id);
} else {
this.props.removeDatasetById(row.id);
}
return true;
};
handleSelect = (isSelecting, rows) => {
const action = isSelecting
? this.props.addDatasetById
: this.props.removeDatasetById;
handleOnSelectAll = (isSelect, rows) => {
if (isSelect) {
return rows.filter((r) => r.id >= 3).map((r) => r.id);
}
action(rows.map((r) => r.id));
return true;
};
render() {
......@@ -215,8 +209,8 @@ class DatasetTable extends React.Component {
mode: 'checkbox',
clickToSelect: false,
selected: this.props.selectedDatasetIds,
onSelectAll: this.handleOnSelectAll,
onSelect: this.handleOnSelect,
onSelectAll: this.handleSelect,
onSelect: (row, isSelecting) => this.handleSelect(isSelecting, [row]),
classes: 'selection-row',
};
......
......@@ -48,7 +48,11 @@ function SelectionPage() {
overlay={tooltip('Mint a DOI for all selected datasets')}
>
<LinkContainer to="/selection/mint">
<Button bsSize="small" bsStyle="primary">
<Button
bsSize="small"
bsStyle="primary"
disabled={datasetIds.length === 0}
>
<Glyphicon glyph="plus" /> Mint a DOI
</Button>
</LinkContainer>
......
......@@ -8,14 +8,16 @@ const INITIAL_STATE = {
};
function selection(state = INITIAL_STATE, action) {
const { payload: datasetId } = action;
const { payload: datasetIds } = action;
switch (action.type) {
case ADD_DATASET_BY_ID: {
return { datasetIds: [...state.datasetIds, datasetId] };
return { datasetIds: [...state.datasetIds, ...datasetIds] };
}
case REMOVE_DATASET_BY_ID: {
return { datasetIds: state.datasetIds.filter((d) => d !== datasetId) };
const set = new Set(state.datasetIds);
datasetIds.forEach((id) => set.delete(id));
return { datasetIds: [...set] };
}
default:
return state;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment