refs #14525 fix breadcamps and workflow share icon
[arvados-workbench2.git] / src / views-components / data-explorer / renderers.tsx
index 9bcbcf611c288b50b5434c5a8c8ecca1d99ab334..c8c6428043f7ecf04d758aec8147457ac91a490e 100644 (file)
@@ -3,18 +3,24 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { Grid, Typography } from '@material-ui/core';
+import { Grid, Typography, withStyles, Tooltip, IconButton } from '@material-ui/core';
 import { FavoriteStar } from '../favorite-star/favorite-star';
-import { ResourceKind, TrashResource } from '~/models/resource';
-import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon } from '~/components/icon/icon';
+import { ResourceKind, TrashableResource } from '~/models/resource';
+import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon, WorkflowIcon, ShareIcon } from '~/components/icon/icon';
 import { formatDate, formatFileSize } from '~/common/formatters';
 import { resourceLabel } from '~/common/labels';
 import { connect } from 'react-redux';
 import { RootState } from '~/store/store';
 import { getResource } from '~/store/resources/resources';
 import { GroupContentsResource } from '~/services/groups-service/groups-service';
-import { ProcessResource } from '~/models/process';
-
+import { getProcess, Process, getProcessStatus, getProcessStatusColor } from '~/store/processes/process';
+import { ArvadosTheme } from '~/common/custom-theme';
+import { compose } from 'redux';
+import { WorkflowResource } from '~/models/workflow';
+import { ResourceStatus } from '~/views/workflow-panel/workflow-panel-view';
+import { getUuidPrefix } from '~/store/workflow-panel/workflow-panel-actions';
+import { CollectionResource } from "~/models/collection";
+import { getResourceData } from "~/store/resources-data/resources-data";
 
 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
     <Grid container alignItems="center" wrap="nowrap" spacing={16}>
@@ -22,7 +28,7 @@ export const renderName = (item: { name: string; uuid: string, kind: string }) =
             {renderIcon(item)}
         </Grid>
         <Grid item>
-            <Typography color="primary">
+            <Typography color="primary" style={{ width: '450px' }}>
                 {item.name}
             </Typography>
         </Grid>
@@ -47,15 +53,86 @@ export const renderIcon = (item: { kind: string }) => {
             return <CollectionIcon />;
         case ResourceKind.PROCESS:
             return <ProcessIcon />;
+        case ResourceKind.WORKFLOW:
+            return <WorkflowIcon />;
         default:
             return <DefaultIcon />;
     }
 };
 
 export const renderDate = (date?: string) => {
-    return <Typography noWrap>{formatDate(date)}</Typography>;
+    return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
+};
+
+export const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
+    <Grid container alignItems="center" wrap="nowrap" spacing={16}>
+        <Grid item>
+            {renderIcon(item)}
+        </Grid>
+        <Grid item>
+            <Typography color="primary" style={{ width: '100px' }}>
+                {item.name}
+            </Typography>
+        </Grid>
+    </Grid>;
+
+export const RosurceWorkflowName = connect(
+    (state: RootState, props: { uuid: string }) => {
+        const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
+        return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
+    })(renderWorkflowName);
+
+const getPublicUuid = (uuidPrefix: string) => {
+    return `${uuidPrefix}-tpzed-anonymouspublic`;
 };
 
+// ToDo: share onClick
+export const resourceShare = (uuidPrefix: string, ownerUuid?: string) => {
+    const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
+    return (
+        <div>
+            { isPublic &&
+                <Tooltip title="Share">
+                    <IconButton onClick={() => undefined}>
+                        <ShareIcon />
+                    </IconButton>
+                </Tooltip>
+            }
+        </div>
+    );
+};
+
+export const ResourceShare = connect(
+    (state: RootState, props: { uuid: string }) => {
+        const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
+        const uuidPrefix = getUuidPrefix(state);
+        return {
+            ownerUuid: resource ? resource.ownerUuid : '',
+            uuidPrefix
+        };
+    })((props: { ownerUuid?: string, uuidPrefix: string }) => resourceShare(props.uuidPrefix, props.ownerUuid));
+
+export const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
+    if (ownerUuid === getPublicUuid(uuidPrefix)) {
+        return renderStatus(ResourceStatus.PUBLIC);
+    } else {
+        return renderStatus(ResourceStatus.PRIVATE);
+    }
+};
+
+const renderStatus = (status: string) =>
+    <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
+
+export const ResourceWorkflowStatus = connect(
+    (state: RootState, props: { uuid: string }) => {
+        const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
+        const uuidPrefix = getUuidPrefix(state);
+        return {
+            ownerUuid: resource ? resource.ownerUuid : '',
+            uuidPrefix
+        };
+    })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
+
 export const ResourceLastModifiedDate = connect(
     (state: RootState, props: { uuid: string }) => {
         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
@@ -64,25 +141,25 @@ export const ResourceLastModifiedDate = connect(
 
 export const ResourceTrashDate = connect(
     (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<TrashResource>(props.uuid)(state.resources);
+        const resource = getResource<TrashableResource>(props.uuid)(state.resources);
         return { date: resource ? resource.trashAt : '' };
     })((props: { date: string }) => renderDate(props.date));
 
 export const ResourceDeleteDate = connect(
     (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<TrashResource>(props.uuid)(state.resources);
+        const resource = getResource<TrashableResource>(props.uuid)(state.resources);
         return { date: resource ? resource.deleteAt : '' };
     })((props: { date: string }) => renderDate(props.date));
 
 export const renderFileSize = (fileSize?: number) =>
-    <Typography noWrap>
+    <Typography noWrap style={{ minWidth: '45px' }}>
         {formatFileSize(fileSize)}
     </Typography>;
 
 export const ResourceFileSize = connect(
     (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
-        return {};
+        const resource = getResourceData(props.uuid)(state.resourcesData);
+        return { fileSize: resource ? resource.fileSize : 0 };
     })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
 
 export const renderOwner = (owner: string) =>
@@ -107,13 +184,17 @@ export const ResourceType = connect(
         return { type: resource ? resource.kind : '' };
     })((props: { type: string }) => renderType(props.type));
 
-export const renderStatus = (item: { status?: string }) =>
-    <Typography noWrap align="center" >
-        {item.status || "-"}
-    </Typography>;
-
-export const ProcessStatus = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const resource = getResource<ProcessResource>(props.uuid)(state.resources);
-        return { status: resource ? resource.state : '-' };
-    })((props: { status: string }) => renderType(props.status));
+export const ProcessStatus = compose(
+    connect((state: RootState, props: { uuid: string }) => {
+        return { process: getProcess(props.uuid)(state.resources) };
+    }),
+    withStyles({}, { withTheme: true }))
+    ((props: { process?: Process, theme: ArvadosTheme }) => {
+        const status = props.process ? getProcessStatus(props.process) : "-";
+        return <Typography
+            noWrap
+            align="center"
+            style={{ color: getProcessStatusColor(status, props.theme) }} >
+            {status}
+        </Typography>;
+    });