Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / views-components / details-panel / details-panel.tsx
index 058db81b89ce71e4a907d45d3590c14039e31305..2653a2103345fe40a99cf9deb467e162efb05572 100644 (file)
@@ -18,6 +18,7 @@ import { ProjectDetails } from "./project-details";
 import { CollectionDetails } from "./collection-details";
 import { ProcessDetails } from "./process-details";
 import { EmptyDetails } from "./empty-details";
+import { WorkflowDetails } from "./workflow-details";
 import { DetailsData } from "./details-data";
 import { DetailsResource } from "models/details";
 import { Config } from 'common/config';
@@ -26,6 +27,7 @@ import { getResource } from 'store/resources/resources';
 import { toggleDetailsPanel, SLIDE_TIMEOUT, openDetailsPanel } from 'store/details-panel/details-panel-action';
 import { FileDetails } from 'views-components/details-panel/file-details';
 import { getNode } from 'models/tree';
+import { resourceIsFrozen } from 'common/frozen-resources';
 
 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
 
@@ -71,6 +73,8 @@ const getItem = (res: DetailsResource): DetailsData => {
                 return new CollectionDetails(res);
             case ResourceKind.PROCESS:
                 return new ProcessDetails(res);
+            case ResourceKind.WORKFLOW:
+                return new WorkflowDetails(res);
             default:
                 return new EmptyDetails(res);
         }
@@ -79,12 +83,22 @@ const getItem = (res: DetailsResource): DetailsData => {
     }
 };
 
-const mapStateToProps = ({ auth, detailsPanel, resources, collectionPanelFiles }: RootState) => {
-    const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource | undefined;
+const mapStateToProps = ({ auth, detailsPanel, resources, collectionPanelFiles, multiselect, router }: RootState) => {
+    const isDetailsResourceChecked = multiselect.checkedList[detailsPanel.resourceUuid]
+    const currentRoute = router.location ? router.location.pathname : "";
+    const currentItemUuid = isDetailsResourceChecked || currentRoute.includes('collections') ? detailsPanel.resourceUuid : multiselect.selectedUuid ? multiselect.selectedUuid : currentRoute.split('/')[2];
+    const resource = getResource(currentItemUuid)(resources) as DetailsResource | undefined;
     const file = resource
         ? undefined
         : getNode(detailsPanel.resourceUuid)(collectionPanelFiles);
+
+    let isFrozen = false;
+    if (resource) {
+        isFrozen = resourceIsFrozen(resource, resources);
+    }
+
     return {
+        isFrozen,
         authConfig: auth.config,
         isOpened: detailsPanel.isOpened,
         tabNr: detailsPanel.tabNr,
@@ -108,6 +122,7 @@ export interface DetailsPanelDataProps {
     isOpened: boolean;
     tabNr: number;
     res: DetailsResource;
+    isFrozen: boolean;
 }
 
 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
@@ -152,14 +167,15 @@ export const DetailsPanel = withStyles(styles)(
                 let shouldShowInlinePreview = false;
                 if (!('kind' in res)) {
                     shouldShowInlinePreview = isInlineFileUrlSafe(
-                      res ? res.url : "",
-                      authConfig.keepWebServiceUrl,
-                      authConfig.keepWebInlineServiceUrl
+                        res ? res.url : "",
+                        authConfig.keepWebServiceUrl,
+                        authConfig.keepWebInlineServiceUrl
                     ) || authConfig.clusterConfig.Collections.TrustAllContent;
                 }
 
                 const item = getItem(res);
                 return <Grid
+                    data-cy='details-panel'
                     container
                     direction="column"
                     item
@@ -190,14 +206,14 @@ export const DetailsPanel = withStyles(styles)(
                     </Grid>
                     <Grid item>
                         <Tabs onChange={this.handleChange}
-                            value={(item.getTabLabels().length >= tabNr+1) ? tabNr : 0}>
-                            { item.getTabLabels().map((tabLabel, idx) =>
+                            value={(item.getTabLabels().length >= tabNr + 1) ? tabNr : 0}>
+                            {item.getTabLabels().map((tabLabel, idx) =>
                                 <Tab key={`tab-label-${idx}`} disableRipple label={tabLabel} />)
                             }
                         </Tabs>
                     </Grid>
                     <Grid item xs className={this.props.classes.tabContainer} >
-                        {item.getDetails({tabNr, showPreview: shouldShowInlinePreview})}
+                        {item.getDetails({ tabNr, showPreview: shouldShowInlinePreview })}
                     </Grid>
                 </Grid >;
             }