X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/02501b107b00164979eaf6fc5dbc4e3b60deefc9..ad6090e461361094bb43d7171fea060e556b8f36:/src/components/multiselect-toolbar/MultiselectToolbar.tsx

diff --git a/src/components/multiselect-toolbar/MultiselectToolbar.tsx b/src/components/multiselect-toolbar/MultiselectToolbar.tsx
index 471576972a..56c363afed 100644
--- a/src/components/multiselect-toolbar/MultiselectToolbar.tsx
+++ b/src/components/multiselect-toolbar/MultiselectToolbar.tsx
@@ -22,7 +22,6 @@ import { copyToClipboardAction } from "store/open-in-new-tab/open-in-new-tab.act
 import { ContainerRequestResource } from "models/container-request";
 import { FavoritesState } from "store/favorites/favorites-reducer";
 import { resourceIsFrozen } from "common/frozen-resources";
-import { ProjectResource } from "models/project";
 import { getResourceWithEditableStatus } from "store/resources/resources";
 import { GroupResource } from "models/group";
 import { EditableResource } from "models/resource";
@@ -32,8 +31,9 @@ import { isProcessCancelable } from "store/processes/process";
 import { CollectionResource } from "models/collection";
 import { getProcess } from "store/processes/process";
 import { Process } from "store/processes/process";
+import { PublicFavoritesState } from "store/public-favorites/public-favorites-reducer";
 
-type CssRules = "root" | "button";
+type CssRules = "root" | "button" | "iconContainer";
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
@@ -49,19 +49,24 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
         width: "2.5rem",
         height: "2.5rem ",
     },
+    iconContainer: {
+        height: '100%'
+    }
 });
 
 export type MultiselectToolbarProps = {
     checkedList: TCheckedList;
-    selectedUuid: string | null
+    singleSelectedUuid: string | null
     iconProps: IconProps
-    user: User
+    user: User | null
+    disabledButtons: Set<string>
     executeMulti: (action: ContextMenuAction, checkedList: TCheckedList, resources: ResourcesState) => void;
 };
 
 type IconProps = {
     resources: ResourcesState;
-    favorites: FavoritesState
+    favorites: FavoritesState;
+    publicFavorites: PublicFavoritesState;
 }
 
 export const MultiselectToolbar = connect(
@@ -69,35 +74,37 @@ export const MultiselectToolbar = connect(
     mapDispatchToProps
 )(
     withStyles(styles)((props: MultiselectToolbarProps & WithStyles<CssRules>) => {
-        const { classes, checkedList, selectedUuid: singleSelectedUuid, iconProps, user } = props;
+        const { classes, checkedList, singleSelectedUuid, iconProps, user , disabledButtons} = props;
         const singleResourceKind = singleSelectedUuid ? [resourceToMsResourceKind(singleSelectedUuid, iconProps.resources, user)] : null
         const currentResourceKinds = singleResourceKind ? singleResourceKind : Array.from(selectedToKindSet(checkedList));
         const currentPathIsTrash = window.location.pathname === "/trash";
-
+        
         const actions =
-            currentPathIsTrash && selectedToKindSet(checkedList).size
-                ? [msToggleTrashAction]
-                : selectActionsByKind(currentResourceKinds as string[], multiselectActionsFilters)
-                .filter((action) => (singleSelectedUuid === null ? action.isForMulti : true));
-
+        currentPathIsTrash && selectedToKindSet(checkedList).size
+        ? [msToggleTrashAction]
+        : selectActionsByKind(currentResourceKinds as string[], multiselectActionsFilters)
+        .filter((action) => (singleSelectedUuid === null ? action.isForMulti : true));
+        
         return (
             <React.Fragment>
                 <Toolbar
                     className={classes.root}
-                    style={{ width: `${actions.length * 2.5}rem` }}
-                >
+                    style={{ width: `${(actions.length * 2.5) + 1}rem` }}
+                    >
                     {actions.length ? (
                         actions.map((action, i) =>
-                            action.hasAlts ? (
-                                <Tooltip
-                                    className={classes.button}
-                                    title={currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altName : action.name}
-                                    key={i}
-                                    disableFocusListener
-                                >
-                                    <IconButton onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>
-                                        {currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altIcon && action.altIcon({}) :  action.icon({})}
-                                    </IconButton>
+                        action.hasAlts ? (
+                            <Tooltip
+                            className={classes.button}
+                            title={currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altName : action.name}
+                            key={i}
+                            disableFocusListener
+                            >
+                                    <span className={classes.iconContainer}>
+                                        <IconButton disabled={disabledButtons.has(action.name)} onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>
+                                            {currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altIcon && action.altIcon({}) :  action.icon({})}
+                                        </IconButton>
+                                    </span>
                                 </Tooltip>
                             ) : (
                                 <Tooltip
@@ -106,7 +113,9 @@ export const MultiselectToolbar = connect(
                                     key={i}
                                     disableFocusListener
                                 >
-                                    <IconButton onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>{action.icon({})}</IconButton>
+                                    <span className={classes.iconContainer}>
+                                        <IconButton onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>{action.icon({})}</IconButton>
+                                    </span>
                                 </Tooltip>
                             )
                         )
@@ -153,7 +162,8 @@ function filterActions(actionArray: MultiSelectMenuActionSet, filters: Set<strin
     return actionArray[0].filter(action => filters.has(action.name as string));
 }
 
-const resourceToMsResourceKind = (uuid: string, resources: ResourcesState, user: User, readonly = false): (msMenuResourceKind | ResourceKind) | undefined => {
+const resourceToMsResourceKind = (uuid: string, resources: ResourcesState, user: User | null, readonly = false): (msMenuResourceKind | ResourceKind) | undefined => {
+    if (!user) return;
     const resource = getResourceWithEditableStatus<GroupResource & EditableResource>(uuid, user.uuid)(resources);
     const { isAdmin } = user;
     const kind = extractUuidKind(uuid);
@@ -229,7 +239,7 @@ function selectActionsByKind(currentResourceKinds: Array<string>, filterSet: TMu
             });
         }
     });
-console.log(currentResourceKinds,allFiltersArray)
+
     const filteredNameSet = allFiltersArray.map(filterArray => {
         const resultSet = new Set<string>();
         filterArray.forEach(action => resultSet.add(action.name as string || ""));
@@ -270,14 +280,16 @@ export const isExactlyOneSelected = (checkedList: TCheckedList) => {
 
 //--------------------------------------------------//
 
-function mapStateToProps({auth, multiselect, resources, favorites}: RootState) {
+function mapStateToProps({auth, multiselect, resources, favorites, publicFavorites}: RootState) {
     return {
         checkedList: multiselect.checkedList as TCheckedList,
-        selectedUuid: isExactlyOneSelected(multiselect.checkedList),
-        user: auth.user,
+        singleSelectedUuid: isExactlyOneSelected(multiselect.checkedList),
+        user: auth && auth.user ? auth.user : null,
+        disabledButtons: new Set<string>(multiselect.disabledButtons),
         iconProps: {
             resources,
-            favorites
+            favorites,
+            publicFavorites
         }
     }
 }
