X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e5a42b5917f815fa09b8e271ebc04c0c42b2d891..bead3b2896eaaceb9b9a3c805d40e8048c93b218:/src/components/multiselect-toolbar/MultiselectToolbar.tsx

diff --git a/src/components/multiselect-toolbar/MultiselectToolbar.tsx b/src/components/multiselect-toolbar/MultiselectToolbar.tsx
index 4ba9e25d..72d375ff 100644
--- a/src/components/multiselect-toolbar/MultiselectToolbar.tsx
+++ b/src/components/multiselect-toolbar/MultiselectToolbar.tsx
@@ -13,12 +13,14 @@ import { ContextMenuResource } from "store/context-menu/context-menu-actions";
 import { Resource, extractUuidKind } from "models/resource";
 import { getResource } from "store/resources/resources";
 import { ResourcesState } from "store/resources/resources";
-import { ContextMenuAction, ContextMenuActionSet, MultiSelectMenuAction } from "views-components/context-menu/context-menu-action-set";
-import { multiselectActionsFilters, TMultiselectActionsFilters, contextMenuActionConsts } from "./ms-toolbar-action-filters";
+import { MultiSelectMenuAction, MultiSelectMenuActionSet, MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-action-set";
+import { ContextMenuAction } from "views-components/context-menu/context-menu-action-set";
+import { multiselectActionsFilters, TMultiselectActionsFilters } from "./ms-toolbar-action-filters";
 import { kindToActionSet, findActionByName } from "./ms-kind-action-differentiator";
 import { msToggleTrashAction } from "views-components/multiselect-toolbar/ms-project-action-set";
 import { copyToClipboardAction } from "store/open-in-new-tab/open-in-new-tab.actions";
 import { ContainerRequestResource } from "models/container-request";
+import { FavoritesState } from "store/favorites/favorites-reducer";
 
 type CssRules = "root" | "button";
 
@@ -29,7 +31,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
         width: 0,
         padding: 0,
         margin: "1rem auto auto 0.5rem",
-        overflow: "hidden",
+        overflowY: 'scroll',
         transition: "width 150ms",
     },
     button: {
@@ -40,51 +42,59 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 
 export type MultiselectToolbarProps = {
     checkedList: TCheckedList;
-    resources: ResourcesState;
+    selectedUuid: string | null
+    iconProps: IconProps
     executeMulti: (action: ContextMenuAction, checkedList: TCheckedList, resources: ResourcesState) => void;
 };
 
+type IconProps = {
+    resources: ResourcesState;
+    favorites: FavoritesState
+}
+
 export const MultiselectToolbar = connect(
     mapStateToProps,
     mapDispatchToProps
 )(
     withStyles(styles)((props: MultiselectToolbarProps & WithStyles<CssRules>) => {
-        const { classes, checkedList } = props;
+        const { classes, checkedList, selectedUuid: singleSelectedUuid, iconProps } = props;
         const currentResourceKinds = Array.from(selectedToKindSet(checkedList));
 
         const currentPathIsTrash = window.location.pathname === "/trash";
-        const buttons =
+
+        const actions =
             currentPathIsTrash && selectedToKindSet(checkedList).size
                 ? [msToggleTrashAction]
-                : selectActionsByKind(currentResourceKinds, multiselectActionsFilters);
+                : selectActionsByKind(currentResourceKinds, multiselectActionsFilters)
+                .filter((action) => (singleSelectedUuid === null ? action.isForMulti : true));
 
         return (
             <React.Fragment>
                 <Toolbar
                     className={classes.root}
-                    style={{ width: `${buttons.length * 2.5}rem` }}
+                    style={{ width: `${actions.length * 2.5}rem` }}
                 >
-                    {buttons.length ? (
-                        buttons.map((btn, i) =>
-                            btn.defaultText ? (
+                    {actions.length ? (
+                        actions.map((action, i) =>
+                            action.hasAlts ? (
                                 <Tooltip
                                     className={classes.button}
-                                    title={!currentPathIsTrash ? btn.defaultText : btn.altText}
+                                    title={currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altName : action.name}
                                     key={i}
                                     disableFocusListener
                                 >
-                                    <IconButton onClick={() => props.executeMulti(btn, checkedList, props.resources)}>
-                                        {!currentPathIsTrash ? btn.defaultIcon && btn.defaultIcon({}) : btn.altIcon && btn.altIcon({})}
+                                    <IconButton onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>
+                                        {currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altIcon && action.altIcon({}) :  action.icon({})}
                                     </IconButton>
                                 </Tooltip>
                             ) : (
                                 <Tooltip
                                     className={classes.button}
-                                    title={btn.name}
+                                    title={action.name}
                                     key={i}
                                     disableFocusListener
                                 >
-                                    <IconButton onClick={() => props.executeMulti(btn, checkedList, props.resources)}>{btn.icon ? btn.icon({}) : <></>}</IconButton>
+                                    <IconButton onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>{action.icon({})}</IconButton>
                                 </Tooltip>
                             )
                         )
@@ -127,7 +137,7 @@ function groupByKind(checkedList: TCheckedList, resources: ResourcesState): Reco
     return result;
 }
 
-function filterActions(actionArray: ContextMenuActionSet, filters: Set<string>): Array<ContextMenuAction> {
+function filterActions(actionArray: MultiSelectMenuActionSet, filters: Set<string>): Array<MultiSelectMenuAction> {
     return actionArray[0].filter(action => filters.has(action.name as string));
 }
 
@@ -149,14 +159,14 @@ function selectActionsByKind(currentResourceKinds: Array<string>, filterSet: TMu
     });
 
     const filteredNameSet = allFiltersArray.map(filterArray => {
-        const resultSet = new Set();
-        filterArray.forEach(action => resultSet.add(action.name || ""));
+        const resultSet = new Set<string>();
+        filterArray.forEach(action => resultSet.add(action.name as string || ""));
         return resultSet;
     });
 
     const filteredResult = Array.from(rawResult).filter(action => {
         for (let i = 0; i < filteredNameSet.length; i++) {
-            if (!filteredNameSet[i].has(action.name)) return false;
+            if (!filteredNameSet[i].has(action.name as string)) return false;
         }
         return true;
     });
@@ -174,13 +184,29 @@ function selectActionsByKind(currentResourceKinds: Array<string>, filterSet: TMu
     });
 }
 
+export const isExactlyOneSelected = (checkedList: TCheckedList) => {
+    let tally = 0;
+    let current = '';
+    for (const uuid in checkedList) {
+        if (checkedList[uuid] === true) {
+            tally++;
+            current = uuid;
+        }
+    }
+    return tally === 1 ? current : null
+};
+
 //--------------------------------------------------//
 
-function mapStateToProps(state: RootState) {
+function mapStateToProps({multiselect, resources, favorites}: RootState) {
     return {
-        checkedList: state.multiselect.checkedList as TCheckedList,
-        resources: state.resources,
-    };
+        checkedList: multiselect.checkedList as TCheckedList,
+        selectedUuid: isExactlyOneSelected(multiselect.checkedList),
+        iconProps: {
+            resources,
+            favorites
+        }
+    }
 }
 
 function mapDispatchToProps(dispatch: Dispatch) {
@@ -188,13 +214,13 @@ function mapDispatchToProps(dispatch: Dispatch) {
         executeMulti: (selectedAction: ContextMenuAction, checkedList: TCheckedList, resources: ResourcesState): void => {
             const kindGroups = groupByKind(checkedList, resources);
             switch (selectedAction.name) {
-                case contextMenuActionConsts.MOVE_TO:
-                case contextMenuActionConsts.REMOVE:
+                case MultiSelectMenuActionNames.MOVE_TO:
+                case MultiSelectMenuActionNames.REMOVE:
                     const firstResource = getResource(selectedToArray(checkedList)[0])(resources) as ContainerRequestResource | Resource;
                     const action = findActionByName(selectedAction.name as string, kindToActionSet[firstResource.kind]);
                     if (action) action.execute(dispatch, kindGroups[firstResource.kind]);
                     break;
-                case contextMenuActionConsts.COPY_TO_CLIPBOARD:
+                case MultiSelectMenuActionNames.COPY_TO_CLIPBOARD:
                     const selectedResources = selectedToArray(checkedList).map(uuid => getResource(uuid)(resources));
                     dispatch<any>(copyToClipboardAction(selectedResources));
                     break;
