X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9f1850a385ee8e0a011474de19ee6507b0b168f3..01ca27ba0a1ef84c53e223004249505435a788b6:/services/workbench2/src/store/multiselect/multiselect-reducer.tsx

diff --git a/services/workbench2/src/store/multiselect/multiselect-reducer.tsx b/services/workbench2/src/store/multiselect/multiselect-reducer.tsx
index 26b853933c..9bcb46d018 100644
--- a/services/workbench2/src/store/multiselect/multiselect-reducer.tsx
+++ b/services/workbench2/src/store/multiselect/multiselect-reducer.tsx
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { multiselectActionContants } from "./multiselect-actions";
+import { multiselectActionConstants } from "./multiselect-actions";
 import { TCheckedList } from "components/data-table/data-table";
 
 type MultiselectToolbarState = {
@@ -19,7 +19,21 @@ const multiselectToolbarInitialState = {
     disabledButtons: []
 };
 
-const { TOGGLE_VISIBLITY, SET_CHECKEDLIST, SELECT_ONE, DESELECT_ONE, TOGGLE_ONE, SET_SELECTED_UUID, ADD_DISABLED, REMOVE_DISABLED } = multiselectActionContants;
+const uncheckAllOthers = (inputList: TCheckedList, uuid: string) => {
+    const checkedlist = {...inputList}
+    for (const key in checkedlist) {
+        if (key !== uuid) checkedlist[key] = false;
+    }
+    return checkedlist;
+};
+
+const toggleOneCheck = (inputList: TCheckedList, uuid: string)=>{
+    const checkedlist = { ...inputList };
+    const isOnlyOneSelected = Object.values(checkedlist).filter(x => x === true).length === 1;
+    return { ...inputList, [uuid]: (checkedlist[uuid] && checkedlist[uuid] === true) && isOnlyOneSelected ? false : true };
+}
+
+const { TOGGLE_VISIBLITY, SET_CHECKEDLIST, SELECT_ONE, DESELECT_ONE, DESELECT_ALL_OTHERS, TOGGLE_ONE, SET_SELECTED_UUID, ADD_DISABLED, REMOVE_DISABLED } = multiselectActionConstants;
 
 export const multiselectReducer = (state: MultiselectToolbarState = multiselectToolbarInitialState, action) => {
     switch (action.type) {
@@ -31,8 +45,10 @@ export const multiselectReducer = (state: MultiselectToolbarState = multiselectT
             return { ...state, checkedList: { ...state.checkedList, [action.payload]: true } };
         case DESELECT_ONE:
             return { ...state, checkedList: { ...state.checkedList, [action.payload]: false } };
+        case DESELECT_ALL_OTHERS:
+            return { ...state, checkedList: uncheckAllOthers(state.checkedList, action.payload) };
         case TOGGLE_ONE:
-            return { ...state, checkedList: { ...state.checkedList, [action.payload]: !state.checkedList[action.payload] } };
+            return { ...state, checkedList: toggleOneCheck(state.checkedList, action.payload) };
         case SET_SELECTED_UUID:
             return {...state, selectedUuid: action.payload || ''}
         case ADD_DISABLED:
