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',
30 transition: 'width 150ms',
31 transitionTimingFunction: 'ease',
34 transition: 'width 150ms',
35 transitionTimingFunction: 'ease-in',
39 backgroundColor: '#017ead',
48 type MultiselectToolbarAction = {
53 export const defaultActions: Array<MultiselectToolbarAction> = [
56 action: 'copySelected',
60 action: 'moveSelected',
64 action: 'removeSelected',
68 export type MultiselectToolbarProps = {
69 buttons: Array<MultiselectToolbarAction>;
71 checkedList: TCheckedList;
72 copySelected: () => void;
73 moveSelected: () => void;
74 removeSelected: (selectedList: TCheckedList) => void;
77 export const MultiselectToolbar = connect(
81 withStyles(styles)((props: MultiselectToolbarProps & WithStyles<CssRules>) => {
82 // console.log(props);
83 const { classes, buttons, isVisible, checkedList } = props;
85 <Toolbar className={isVisible ? `${classes.root} ${classes.expanded}` : classes.root}>
86 {buttons.map((btn) => (
87 <Button key={btn.name} className={`${classes.button} ${classes.expanded}`} onClick={() => props[btn.action](checkedList)}>
96 function selectedToString(checkedList: TCheckedList) {
97 let stringifiedSelectedList: string = '';
98 for (const [key, value] of Object.entries(checkedList)) {
100 stringifiedSelectedList += key + ',';
103 return stringifiedSelectedList.slice(0, -1);
106 function selectedToArray<T>(checkedList: TCheckedList): Array<T | string> {
107 const arrayifiedSelectedList: Array<T | string> = [];
108 for (const [key, value] of Object.entries(checkedList)) {
109 if (value === true) {
110 arrayifiedSelectedList.push(key);
113 return arrayifiedSelectedList;
116 function mapStateToProps(state: RootState) {
117 // console.log(state.resources, state.multiselect.checkedList);
118 const { isVisible, checkedList } = state.multiselect;
120 isVisible: isVisible,
121 checkedList: checkedList as TCheckedList,
122 // selectedList: state.multiselect.checkedList.forEach(processUUID=>containerRequestUUID)
126 function mapDispatchToProps(dispatch: Dispatch) {
128 copySelected: () => {},
129 moveSelected: () => {},
130 removeSelected: (checkedList: TCheckedList) => removeMany(dispatch, checkedList),
134 function removeMany(dispatch: Dispatch, checkedList: TCheckedList): void {
135 dispatch<any>(openRemoveManyProcessesDialog(selectedToArray(checkedList)));