1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { ReactElement } from 'react';
6 import { connect } from 'react-redux';
7 import { StyleRulesCallback, withStyles, WithStyles, Toolbar, Button } from '@material-ui/core';
8 import { ArvadosTheme } from 'common/custom-theme';
9 import { RootState } from 'store/store';
10 import { Dispatch } from 'redux';
11 import { CopyToClipboardSnackbar } from 'components/copy-to-clipboard-snackbar/copy-to-clipboard-snackbar';
12 import { TCheckedList } from 'components/data-table/data-table';
13 import { openRemoveProcessDialog, openRemoveManyProcessesDialog } from 'store/processes/processes-actions';
14 import { processResourceActionSet } from '../../views-components/context-menu/action-sets/process-resource-action-set';
15 import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
16 import { toggleTrashed } from 'store/trash/trash-actions';
18 type CssRules = 'root' | 'expanded' | 'button';
20 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24 justifyContent: 'start',
27 margin: '1rem auto auto 0.5rem',
29 transition: 'width 150ms',
30 transitionTimingFunction: 'ease',
33 transition: 'width 150ms',
34 transitionTimingFunction: 'ease-in',
38 backgroundColor: '#017ead',
47 type MultiselectToolbarAction = {
52 export const defaultActions: Array<MultiselectToolbarAction> = [
55 action: 'copySelected',
59 action: 'moveSelected',
63 action: 'removeSelected',
67 export type MultiselectToolbarProps = {
68 buttons: Array<MultiselectToolbarAction>;
70 checkedList: TCheckedList;
71 copySelected: () => void;
72 moveSelected: () => void;
73 removeSelected: (selectedList: TCheckedList) => void;
76 export const MultiselectToolbar = connect(
80 withStyles(styles)((props: MultiselectToolbarProps & WithStyles<CssRules>) => {
81 // console.log(props);
82 const { classes, buttons, isVisible, checkedList } = props;
84 <Toolbar className={isVisible ? `${classes.root} ${classes.expanded}` : classes.root}>
85 {buttons.map((btn) => (
86 <Button key={btn.name} className={`${classes.button} ${classes.expanded}`} onClick={() => props[btn.action](checkedList)}>
95 function selectedToString(checkedList: TCheckedList) {
96 let stringifiedSelectedList: string = '';
97 for (const [key, value] of Object.entries(checkedList)) {
99 stringifiedSelectedList += key + ',';
102 return stringifiedSelectedList.slice(0, -1);
105 function selectedToArray<T>(checkedList: TCheckedList): Array<T | string> {
106 const arrayifiedSelectedList: Array<T | string> = [];
107 for (const [key, value] of Object.entries(checkedList)) {
108 if (value === true) {
109 arrayifiedSelectedList.push(key);
112 return arrayifiedSelectedList;
115 function mapStateToProps(state: RootState) {
116 // console.log(state.resources, state.multiselect.checkedList);
117 const { isVisible, checkedList } = state.multiselect;
119 isVisible: isVisible,
120 checkedList: checkedList as TCheckedList,
121 // selectedList: state.multiselect.checkedList.forEach(processUUID=>containerRequestUUID)
125 function mapDispatchToProps(dispatch: Dispatch) {
127 copySelected: () => {},
128 moveSelected: () => {},
129 removeSelected: (checkedList: TCheckedList) => removeMulti(dispatch, checkedList),
133 function removeMulti(dispatch: Dispatch, checkedList: TCheckedList): void {
134 const list: Array<string> = selectedToArray(checkedList);
135 dispatch<any>(list.length === 1 ? openRemoveProcessDialog(list[0]) : openRemoveManyProcessesDialog(list));