21224: created global current uuid property in store state Arvados-DCO-1.1-Signed...
authorLisa Knox <lisaknox83@gmail.com>
Fri, 15 Mar 2024 15:12:16 +0000 (11:12 -0400)
committerLisa Knox <lisaknox83@gmail.com>
Fri, 15 Mar 2024 15:12:16 +0000 (11:12 -0400)
services/workbench2/src/components/multiselect-toolbar/MultiselectToolbar.tsx
services/workbench2/src/views-components/project-details-card/project-details-card.tsx
services/workbench2/src/views/main-panel/main-panel-root.tsx
services/workbench2/src/views/main-panel/main-panel.tsx

index 36b8199f30cb8b8ce7b8ed721f9f0782c8c7a638..7e462512f7156307c66f49da90bc311f85908dbe 100644 (file)
@@ -77,8 +77,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 
 export type MultiselectToolbarProps = {
     checkedList: TCheckedList;
-    singleSelectedUuid: string | null
-    inputSelectedUuid?: string
+    selectedResource: string | null;
     iconProps: IconProps
     user: User | null
     disabledButtons: Set<string>
@@ -97,9 +96,8 @@ export const MultiselectToolbar = connect(
     mapDispatchToProps
 )(
     withStyles(styles)((props: MultiselectToolbarProps & WithStyles<CssRules>) => {
-        const { classes, checkedList, inputSelectedUuid, iconProps, user, disabledButtons } = props;
-        const singleSelectedUuid = inputSelectedUuid ?? props.singleSelectedUuid
-        const singleResourceKind = singleSelectedUuid ? [resourceToMsResourceKind(singleSelectedUuid, iconProps.resources, user)] : null
+        const { classes, checkedList, iconProps, user, disabledButtons, selectedResource } = props;
+        const singleResourceKind = selectedResource ? [resourceToMsResourceKind(selectedResource, iconProps.resources, user)] : null
         const currentResourceKinds = singleResourceKind ? singleResourceKind : Array.from(selectedToKindSet(checkedList));
         const currentPathIsTrash = window.location.pathname === "/trash";
         const [isTransitioning, setIsTransitioning] = useState(false);
@@ -124,7 +122,7 @@ export const MultiselectToolbar = connect(
             currentPathIsTrash && selectedToKindSet(checkedList).size
                 ? [msToggleTrashAction]
                 : selectActionsByKind(currentResourceKinds as string[], multiselectActionsFilters).filter((action) =>
-                        singleSelectedUuid === null ? action.isForMulti : true
+                        selectedResource === null ? action.isForMulti : true
                     );
 
         return (
@@ -142,7 +140,7 @@ export const MultiselectToolbar = connect(
                                 <Tooltip
                                     className={classes.button}
                                     data-targetid={name}
-                                    title={currentPathIsTrash || (useAlts && useAlts(singleSelectedUuid, iconProps)) ? altName : name}
+                                    title={currentPathIsTrash || (useAlts && useAlts(selectedResource, iconProps)) ? altName : name}
                                     key={i}
                                     disableFocusListener
                                     >
@@ -150,10 +148,10 @@ export const MultiselectToolbar = connect(
                                         <IconButton
                                             data-cy='multiselect-button'
                                             disabled={disabledButtons.has(name)}
-                                            onClick={() => props.executeMulti(action, singleSelectedUuid, checkedList, iconProps.resources)}
+                                            onClick={() => props.executeMulti(action, selectedResource, checkedList, iconProps.resources)}
                                             className={classes.icon}
                                         >
-                                            {currentPathIsTrash || (useAlts && useAlts(singleSelectedUuid, iconProps)) ? altIcon && altIcon({}) : icon({})}
+                                            {currentPathIsTrash || (useAlts && useAlts(selectedResource, iconProps)) ? altIcon && altIcon({}) : icon({})}
                                         </IconButton>
                                     </span>
                                 </Tooltip>
@@ -170,7 +168,7 @@ export const MultiselectToolbar = connect(
                                             data-cy='multiselect-button'
                                             onClick={() => {
                                                 console.log('executing action', action.name, 'with checkedList', checkedList, 'and iconProps', iconProps.resources)
-                                                props.executeMulti(action, singleSelectedUuid, checkedList, iconProps.resources)}}
+                                                props.executeMulti(action, selectedResource, checkedList, iconProps.resources)}}
                                             className={classes.icon}
                                         >
                                             {action.icon({})}
@@ -330,13 +328,13 @@ function selectActionsByKind(currentResourceKinds: Array<string>, filterSet: TMu
 
 //--------------------------------------------------//
 
-function mapStateToProps({auth, multiselect, resources, favorites, publicFavorites}: RootState) {
+function mapStateToProps({auth, multiselect, resources, favorites, publicFavorites, selectedResource}: RootState) {
     return {
         checkedList: multiselect.checkedList as TCheckedList,
-        singleSelectedUuid: isExactlyOneSelected(multiselect.checkedList),
         user: auth && auth.user ? auth.user : null,
         disabledButtons: new Set<string>(multiselect.disabledButtons),
         auth,
+        selectedResource,
         iconProps: {
             resources,
             favorites,
index 063ea77cd985ca881638db03c8c06fa0df4b7103..0988d7c1681bf7b38ad15b91b7ca38f959fb4ba4 100644 (file)
@@ -338,7 +338,7 @@ const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, fro
                     </section>
                 }
                 action={
-                    <MultiselectToolbar inputSelectedUuid={currentResource.uuid} />
+                    <MultiselectToolbar />
                     // <section className={classes.contextMenuSection}>
                     //     <Tooltip
                     //         title='More options'
index cdfd0c300f5ca7444c8dea43503abf603be08499..d94c97adc39afbf52f1f7c88f59feb1be62d87f8 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import React from 'react';
+import React, { useEffect } from 'react';
 import { StyleRulesCallback, WithStyles, withStyles, Grid, LinearProgress } from '@material-ui/core';
 import { User } from "models/user";
 import { ArvadosTheme } from 'common/custom-theme';
@@ -35,10 +35,12 @@ export interface MainPanelRootDataProps {
     sidePanelIsCollapsed: boolean;
     isTransitioning: boolean;
     currentSideWidth: number;
+    currentRoute: string;
 }
 
 interface MainPanelRootDispatchProps {
-    toggleSidePanel: () => void
+    toggleSidePanel: () => void,
+    setCurrentRouteUuid: (uuid: string) => void;
 }
 
 type MainPanelRootProps = MainPanelRootDataProps & MainPanelRootDispatchProps & WithStyles<CssRules>;
@@ -46,7 +48,14 @@ type MainPanelRootProps = MainPanelRootDataProps & MainPanelRootDispatchProps &
 export const MainPanelRoot = withStyles(styles)(
     ({ classes, loading, working, user, buildInfo, uuidPrefix,
         isNotLinking, isLinkingPath, siteBanner, sessionIdleTimeout, 
-        sidePanelIsCollapsed, isTransitioning, currentSideWidth}: MainPanelRootProps) =>{
+        sidePanelIsCollapsed, isTransitioning, currentSideWidth, currentRoute, setCurrentRouteUuid}: MainPanelRootProps) =>{
+
+            useEffect(() => {
+                const splitRoute = currentRoute.split('/');
+                const uuid = splitRoute[splitRoute.length - 1];
+                setCurrentRouteUuid(uuid);
+            }, [currentRoute]);
+
         return loading
             ? <WorkbenchLoadingScreen />
             : <>
index 264390a8b3eec8478b9d00a796a10842ad1b04a6..556ce0d75c54aba7dc4324edcd0220389ac40434 100644 (file)
@@ -11,6 +11,7 @@ import { isWorkbenchLoading } from 'store/workbench/workbench-actions';
 import { LinkAccountPanelStatus } from 'store/link-account-panel/link-account-panel-reducer';
 import { matchLinkAccountRoute } from 'routes/routes';
 import { toggleSidePanel } from "store/side-panel/side-panel-action";
+import { propertiesActions } from 'store/properties/properties-actions';
 
 const mapStateToProps = (state: RootState): MainPanelRootDataProps => {
     return {
@@ -25,7 +26,8 @@ const mapStateToProps = (state: RootState): MainPanelRootDataProps => {
         sessionIdleTimeout: parse(state.auth.config.clusterConfig.Workbench.IdleTimeout, 's') || 0,
         sidePanelIsCollapsed: state.sidePanel.collapsedState,
         isTransitioning: state.detailsPanel.isTransitioning,
-        currentSideWidth: state.sidePanel.currentSideWidth
+        currentSideWidth: state.sidePanel.currentSideWidth,
+        currentRoute: state.router.location ? state.router.location.pathname : '',
     };
 };
 
@@ -33,7 +35,9 @@ const mapDispatchToProps = (dispatch) => {
     return {
         toggleSidePanel: (collapsedState)=>{
             return dispatch(toggleSidePanel(collapsedState))
-        }
+        },
+        setCurrentRouteUuid: (uuid: string) => {
+            return dispatch(propertiesActions.SET_PROPERTY({key: 'currentRouteUuid', value: uuid}))}
     }
 };