X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/4476731a9ec985c5abd97da453978af0dfa4406b..fa9e1f065eefa7265879869e4b45eb76be64b4ce:/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 1ae87470..8108cd1e 100644
--- a/src/views/process-panel/process-panel.tsx
+++ b/src/views/process-panel/process-panel.tsx
@@ -2,127 +2,51 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-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';
-
-type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'content' | 'chip' | 'headerText';
-
-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'
+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 { matchProcessRoute } from '~/routes/routes';
+import { ProcessPanelRootDataProps, ProcessPanelRootActionProps, ProcessPanelRoot } from './process-panel-root';
+import { ProcessPanel as ProcessPanelState} from '~/store/process-panel/process-panel';
+import { groupBy } from 'lodash';
+import { toggleProcessPanelFilter } from '~/store/process-panel/process-panel-actions';
+import { openProcessInputDialog } from '~/store/processes/process-input-actions';
+
+const mapStateToProps = ({ router, resources, processPanel }: RootState): ProcessPanelRootDataProps => {
+    const pathname = router.location ? router.location.pathname : '';
+    const match = matchProcessRoute(pathname);
+    const uuid = match ? match.params.id : '';
+    const subprocesses = getSubprocesses(uuid)(resources);
+    return {
+        process: getProcess(uuid)(resources),
+        subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
+        filters: getFilters(processPanel, subprocesses),
+        totalSubprocessesLength: subprocesses.length,
+    };
+};
+
+const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
+    onContextMenu: (event, process) => {
+        dispatch<any>(openProcessContextMenu(event, process));
     },
-    content: {
-        display: 'flex',
-        paddingBottom: '0px ',
-        paddingTop: '0px',
-        '&:last-child': {
-            paddingBottom: '0px ',
-        }
+    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-end',
-        top: -theme.spacing.unit * 4.5,
-        right: theme.spacing.unit * 2,
-    }
+    openProcessInputDialog: (uuid) => dispatch<any>(openProcessInputDialog(uuid))
 });
 
-interface ProcessPanelDataProps {
-    item: ProcessResource;
-}
-
-interface ProcessPanelActionProps {
-    onItemRouteChange: (processId: string) => void;
-    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, onContextMenu, item } = this.props;
-
-                return <div>
-                    <Card className={classes.card}>
-                        <CardHeader
-                            avatar={<ProcessIcon className={classes.iconHeader} />}
-                            action={
-                                <IconButton
-                                    aria-label="More options"
-                                    onClick={event => onContextMenu(event, item)}>
-                                    <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.label} classValue={classes.value}
-                                        label='Container output' />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Show inputs' />
-                                    <DetailsAttribute classLabel={classes.label} 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>
-                </div>;
-            }
-            componentWillReceiveProps({ match, item, onItemRouteChange }: ProcessPanelProps) {
-                if (!item || match.params.id !== item.uuid) {
-                    onItemRouteChange(match.params.id);
-                }
-            }
-        }
-    )
-);
\ No newline at end of file
+export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);
+
+export 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,
+        }));
+    };
\ No newline at end of file
