X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ae9841925d717e97a74f3ae17c414c638c56e496..1e6d5bc0ce92a7575030b299193b99cbad50e810:/src/views/process-panel/process-panel.tsx

diff --git a/src/views/process-panel/process-panel.tsx b/src/views/process-panel/process-panel.tsx
index d7a9305261..348222f6d7 100644
--- a/src/views/process-panel/process-panel.tsx
+++ b/src/views/process-panel/process-panel.tsx
@@ -2,142 +2,71 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
+import { RootState } from 'store/store';
+import { connect } from 'react-redux';
+import { getProcess, getSubprocesses, Process, getProcessStatus } from 'store/processes/process';
+import { Dispatch } from 'redux';
+import { openProcessContextMenu } from 'store/context-menu/context-menu-actions';
 import {
-    StyleRulesCallback, WithStyles, withStyles, Card,
-    CardHeader, IconButton, CardContent, Grid, Chip
-} from '@material-ui/core';
-import { ArvadosTheme } from '~/common/custom-theme';
-import { ProcessResource } from '~/models/process';
-import { DispatchProp, connect } from 'react-redux';
-import { RouteComponentProps } from 'react-router';
-import { MoreOptionsIcon, ProcessIcon } from '~/components/icon/icon';
-import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
-import { RootState } from '~/store/store';
-import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
-import { openContextMenu } from '~/store/context-menu/context-menu-actions';
-import { SubprocessesCard } from '~/views/process-panel/subprocesses-card';
+    ProcessPanelRootDataProps,
+    ProcessPanelRootActionProps,
+    ProcessPanelRoot
+} from './process-panel-root';
+import {
+    getProcessPanelCurrentUuid,
+    ProcessPanel as ProcessPanelState
+} from 'store/process-panel/process-panel';
+import { groupBy } from 'lodash';
+import {
+    loadOutputs,
+    toggleProcessPanelFilter,
+} from 'store/process-panel/process-panel-actions';
+import { cancelRunningWorkflow } from 'store/processes/processes-actions';
+import { navigateToLogCollection, setProcessLogsPanelFilter } from 'store/process-logs-panel/process-logs-panel-actions';
+import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
 
-type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'content' | 'chip' | 'headerText' | 'link';
+const mapStateToProps = ({ router, auth, resources, processPanel, processLogsPanel }: RootState): ProcessPanelRootDataProps => {
+    const uuid = getProcessPanelCurrentUuid(router) || '';
+    const subprocesses = getSubprocesses(uuid)(resources);
+    return {
+        process: getProcess(uuid)(resources),
+        subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
+        filters: getFilters(processPanel, subprocesses),
+        processLogsPanel: processLogsPanel,
+        auth: auth,
+    };
+};
 
-const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    card: {
-        marginBottom: theme.spacing.unit * 2,
-        width: '60%'
-    },
-    iconHeader: {
-        fontSize: '1.875rem',
-        color: theme.customs.colors.green700
-    },
-    label: {
-        fontSize: '0.875rem',
-    },
-    value: {
-        textTransform: 'none',
-        fontSize: '0.875rem'
+const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
+    onLogCopyToClipboard: (message: string) => {
+        dispatch<any>(snackbarActions.OPEN_SNACKBAR({
+            message,
+            hideDuration: 2000,
+            kind: SnackbarKind.SUCCESS,
+        }));
     },
-    content: {
-        display: 'flex',
-        paddingBottom: '0px ',
-        paddingTop: '0px',
-        '&:last-child': {
-            paddingBottom: '0px ',
-        }
+    onContextMenu: (event, process) => {
+        dispatch<any>(openProcessContextMenu(event, process));
     },
-    link: {
-        fontSize: '0.875rem',
-        '&:hover': {
-            color: theme.palette.primary.main,
-            cursor: 'pointer'
-        }
+    onToggle: status => {
+        dispatch<any>(toggleProcessPanelFilter(status));
     },
-    chip: {
-        height: theme.spacing.unit * 2.5,
-        width: theme.spacing.unit * 12,
-        backgroundColor: theme.customs.colors.green700,
-        color: theme.palette.common.white,
-        fontSize: '0.875rem',
-        borderRadius: theme.spacing.unit * 0.625
-    },
-    headerText: {
-        fontSize: '0.875rem',
-        display: 'flex',
-        position: 'relative',
-        justifyContent: 'flex-start',
-        top: -theme.spacing.unit * 4.5,
-        left: theme.spacing.unit * 3,
-    }
+    cancelProcess: (uuid) => dispatch<any>(cancelRunningWorkflow(uuid)),
+    onLogFilterChange: (filter) => dispatch(setProcessLogsPanelFilter(filter.value)),
+    navigateToLog: (uuid) => dispatch<any>(navigateToLogCollection(uuid)),
+    fetchOutputs: (uuid, setOutputs) => dispatch<any>(loadOutputs(uuid, setOutputs)),
 });
 
-interface ProcessPanelDataProps {
-    item: ProcessResource;
-}
-
-interface ProcessPanelActionProps {
-    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProcessResource) => void;
-}
-
-type ProcessPanelProps = ProcessPanelDataProps & ProcessPanelActionProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
-
-export const ProcessPanel = withStyles(styles)(
-    connect((state: RootState) => ({
-        item: state.collectionPanel.item,
-        tags: state.collectionPanel.tags
-    }))(
-        class extends React.Component<ProcessPanelProps> {
-            render() {
-                const { classes } = this.props;
-
-                return <div>
-                    <Card className={classes.card}>
-                        <CardHeader
-                            avatar={<ProcessIcon className={classes.iconHeader} />}
-                            action={
-                                <IconButton
-                                    aria-label="More options"
-                                    onClick={this.handleContextMenu}>
-                                    <MoreOptionsIcon />
-                                </IconButton>
-                            }
-                            title="Pipeline template that generates a config file from a template" />
-                        <CardContent className={classes.content}>
-                            <Grid container direction="column">
-                                <Grid item xs={8}>
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Status' value={<Chip label="Complete" className={classes.chip} />} />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Started at' value="1:25 PM 3/23/2018" />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Finished at' value='1:25 PM 3/23/2018' />
-                                </Grid>
-                            </Grid>
-                            <Grid container direction="column">
-                                <Grid item xs={8}>
-                                    <DetailsAttribute classLabel={classes.link} classValue={classes.value}
-                                        label='Container output' />
-                                    <DetailsAttribute classLabel={classes.link} classValue={classes.value}
-                                        label='Show inputs' />
-                                    <DetailsAttribute classLabel={classes.link} classValue={classes.value}
-                                        label='Show command' />
-                                </Grid>
-                            </Grid>
-                        </CardContent>
-                        <span className={classes.headerText}>This container request was created from the workflow FastQC MultiQC</span>
-                    </Card>
-                    <SubprocessesCard />
-                </div>;
-            }
+const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
+    const grouppedProcesses = groupBy(processes, getProcessStatus);
+    return Object
+        .keys(processPanel.filters)
+        .map(filter => ({
+            label: filter,
+            value: (grouppedProcesses[filter] || []).length,
+            checked: processPanel.filters[filter],
+            key: filter,
+        }));
+    };
 
-            handleContextMenu = (event: React.MouseEvent<any>) => {
-                // const { uuid, name, description } = this.props.item;
-                const resource = {
-                    uuid: '',
-                    name: '',
-                    description: '',
-                    kind: ContextMenuKind.PROCESS
-                };
-                this.props.dispatch<any>(openContextMenu(event, resource));
-            }
-        }
-    )
-);
\ No newline at end of file
+export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);
