21128: multiselect vs details panel resolved Arvados-DCO-1.1-Signed-off-by: Lisa...
[arvados-workbench2.git] / src / store / multiselect / multiselect-actions.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { TCheckedList } from "components/data-table/data-table";
6 import { isExactlyOneSelected } from "components/multiselect-toolbar/MultiselectToolbar";
7
8 export const multiselectActionContants = {
9     TOGGLE_VISIBLITY: "TOGGLE_VISIBLITY",
10     SET_CHECKEDLIST: "SET_CHECKEDLIST",
11     SELECT_ONE: 'SELECT_ONE',
12     DESELECT_ONE: "DESELECT_ONE",
13     TOGGLE_ONE: 'TOGGLE_ONE',
14     SET_SELECTED_UUID: 'SET_SELECTED_UUID'
15 };
16
17 export const toggleMSToolbar = (isVisible: boolean) => {
18     return dispatch => {
19         dispatch({ type: multiselectActionContants.TOGGLE_VISIBLITY, payload: isVisible });
20     };
21 };
22
23 export const setCheckedListOnStore = (checkedList: TCheckedList) => {
24     return dispatch => {
25         dispatch(setSelectedUuid(isExactlyOneSelected(checkedList)))
26         dispatch({ type: multiselectActionContants.SET_CHECKEDLIST, payload: checkedList });
27     };
28 };
29
30 export const selectOne = (uuid: string) => {
31     return dispatch => {
32         dispatch({ type: multiselectActionContants.SELECT_ONE, payload: uuid });
33     };
34 };
35
36 export const deselectOne = (uuid: string) => {
37     return dispatch => {
38         dispatch({ type: multiselectActionContants.DESELECT_ONE, payload: uuid });
39     };
40 };
41
42 export const toggleOne = (uuid: string) => {
43     return dispatch => {
44         dispatch({ type: multiselectActionContants.TOGGLE_ONE, payload: uuid });
45     };
46 };
47
48 export const setSelectedUuid = (uuid: string | null) => {
49     return dispatch => {
50         dispatch({ type: multiselectActionContants.SET_SELECTED_UUID, payload: uuid });
51     };
52 };
53
54 export const multiselectActions = {
55     toggleMSToolbar,
56     setCheckedListOnStore,
57     selectOne,
58     deselectOne,
59     toggleOne,
60     setSelectedUuid
61 };