X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/79b9d798b16384d7429124ab99ff5bf54ec36411..f501640554ba22533acfa4b4d106c67e2c80a8cc:/src/components/multiselect-toolbar/MultiselectToolbar.tsx diff --git a/src/components/multiselect-toolbar/MultiselectToolbar.tsx b/src/components/multiselect-toolbar/MultiselectToolbar.tsx index 6cf94dd0..a3606d83 100644 --- a/src/components/multiselect-toolbar/MultiselectToolbar.tsx +++ b/src/components/multiselect-toolbar/MultiselectToolbar.tsx @@ -13,7 +13,8 @@ import { ContextMenuResource } from "store/context-menu/context-menu-actions"; import { Resource, ResourceKind, extractUuidKind } from "models/resource"; import { getResource } from "store/resources/resources"; import { ResourcesState } from "store/resources/resources"; -import { MultiSelectMenuAction, MultiSelectMenuActionSet, MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions"; +import { MultiSelectMenuAction, MultiSelectMenuActionSet } from "views-components/multiselect-toolbar/ms-menu-actions"; +import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions"; import { ContextMenuAction } from "views-components/context-menu/context-menu-action-set"; import { multiselectActionsFilters, TMultiselectActionsFilters, msMenuResourceKind } from "./ms-toolbar-action-filters"; import { kindToActionSet, findActionByName } from "./ms-kind-action-differentiator"; @@ -31,36 +32,57 @@ 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"; +import { isExactlyOneSelected } from "store/multiselect/multiselect-actions"; -type CssRules = "root" | "button"; +type CssRules = "root" | "button" | "iconContainer"; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ root: { display: "flex", flexDirection: "row", width: 0, + height: '2.7rem', padding: 0, margin: "1rem auto auto 0.5rem", - overflowY: 'scroll', + overflowY: 'auto', transition: "width 150ms", + scrollBehavior: 'smooth', + '&::-webkit-scrollbar': { + width: 0, + height: 2 + }, + '&::-webkit-scrollbar-track': { + width: 0, + height: 2 + }, + '&::-webkit-scrollbar-thumb': { + backgroundColor: theme.customs.colors.grey600, + borderRadius: 2 + } }, button: { width: "2.5rem", height: "2.5rem ", }, + iconContainer: { + height: '100%' + } }); export type MultiselectToolbarProps = { checkedList: TCheckedList; - selectedUuid: string | null + singleSelectedUuid: string | null iconProps: IconProps user: User | null + disabledButtons: Set executeMulti: (action: ContextMenuAction, checkedList: TCheckedList, resources: ResourcesState) => void; }; type IconProps = { resources: ResourcesState; - favorites: FavoritesState + favorites: FavoritesState; + publicFavorites: PublicFavoritesState; } export const MultiselectToolbar = connect( @@ -68,35 +90,38 @@ export const MultiselectToolbar = connect( mapDispatchToProps )( withStyles(styles)((props: MultiselectToolbarProps & WithStyles) => { - 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 ( + > {actions.length ? ( - actions.map((action, i) => - action.hasAlts ? ( - - props.executeMulti(action, checkedList, iconProps.resources)}> - {currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altIcon && action.altIcon({}) : action.icon({})} - + actions.map((action, i) =>{ + const { hasAlts, useAlts, name, altName, icon, altIcon } = action; + return hasAlts ? ( + + + props.executeMulti(action, checkedList, iconProps.resources)}> + {currentPathIsTrash || (useAlts && useAlts(singleSelectedUuid, iconProps)) ? altIcon && altIcon({}) : icon({})} + + ) : ( - props.executeMulti(action, checkedList, iconProps.resources)}>{action.icon({})} + + props.executeMulti(action, checkedList, iconProps.resources)}>{action.icon({})} + ) - ) + }) ) : ( <> )} @@ -256,28 +283,19 @@ function selectActionsByKind(currentResourceKinds: Array, 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({auth, multiselect, resources, favorites}: RootState) { +function mapStateToProps({auth, multiselect, resources, favorites, publicFavorites}: RootState) { return { checkedList: multiselect.checkedList as TCheckedList, - selectedUuid: isExactlyOneSelected(multiselect.checkedList), + singleSelectedUuid: isExactlyOneSelected(multiselect.checkedList), user: auth && auth.user ? auth.user : null, + disabledButtons: new Set(multiselect.disabledButtons), iconProps: { resources, - favorites + favorites, + publicFavorites } } }