1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { TCheckedList } from "components/data-table/data-table";
6 import { ContainerRequestResource } from "models/container-request";
7 import { Dispatch } from "redux";
8 import { navigateTo } from "store/navigation/navigation-action";
9 import { snackbarActions } from "store/snackbar/snackbar-actions";
10 import { RootState } from "store/store";
11 import { ServiceRepository } from "services/services";
12 import { SnackbarKind } from "store/snackbar/snackbar-actions";
13 import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
15 export const multiselectActionConstants = {
16 TOGGLE_VISIBLITY: "TOGGLE_VISIBLITY",
17 SET_CHECKEDLIST: "SET_CHECKEDLIST",
18 SELECT_ONE: 'SELECT_ONE',
19 DESELECT_ONE: "DESELECT_ONE",
20 DESELECT_ALL_OTHERS: 'DESELECT_ALL_OTHERS',
21 TOGGLE_ONE: 'TOGGLE_ONE',
22 SET_SELECTED_UUID: 'SET_SELECTED_UUID',
23 ADD_DISABLED: 'ADD_DISABLED',
24 REMOVE_DISABLED: 'REMOVE_DISABLED',
27 export const msNavigateToOutput = (resource: ContextMenuResource | ContainerRequestResource) => async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
29 await services.collectionService.get(resource.outputUuid || '');
30 dispatch<any>(navigateTo(resource.outputUuid || ''));
32 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Output collection was trashed or deleted.", hideDuration: 4000, kind: SnackbarKind.WARNING }));
36 export const isExactlyOneSelected = (checkedList: TCheckedList) => {
39 for (const uuid in checkedList) {
40 if (checkedList[uuid] === true) {
45 return tally === 1 ? current : null
48 export const toggleMSToolbar = (isVisible: boolean) => {
50 dispatch({ type: multiselectActionConstants.TOGGLE_VISIBLITY, payload: isVisible });
54 export const setCheckedListOnStore = (checkedList: TCheckedList) => {
56 dispatch(setSelectedUuid(isExactlyOneSelected(checkedList)))
57 dispatch({ type: multiselectActionConstants.SET_CHECKEDLIST, payload: checkedList });
61 export const selectOne = (uuid: string) => {
63 dispatch({ type: multiselectActionConstants.SELECT_ONE, payload: uuid });
67 export const deselectOne = (uuid: string) => {
69 dispatch({ type: multiselectActionConstants.DESELECT_ONE, payload: uuid });
73 export const deselectAllOthers = (uuid: string) => {
75 dispatch({ type: multiselectActionConstants.DESELECT_ALL_OTHERS, payload: uuid });
79 export const toggleOne = (uuid: string) => {
81 dispatch({ type: multiselectActionConstants.TOGGLE_ONE, payload: uuid });
85 export const setSelectedUuid = (uuid: string | null) => {
87 dispatch({ type: multiselectActionConstants.SET_SELECTED_UUID, payload: uuid });
91 export const addDisabledButton = (buttonName: string) => {
93 dispatch({ type: multiselectActionConstants.ADD_DISABLED, payload: buttonName });
97 export const removeDisabledButton = (buttonName: string) => {
99 dispatch({ type: multiselectActionConstants.REMOVE_DISABLED, payload: buttonName });