X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/605e792e4854c7aad2f08e08fa7a8d9eba9d64a1..465a61ffcf1a815bf68daeb7bcbf31dd9721cdf4:/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 dff1437bd0..6e2d75c6cb 100644
--- a/src/views/process-panel/process-panel.tsx
+++ b/src/views/process-panel/process-panel.tsx
@@ -2,94 +2,82 @@
 //
 // 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
-} 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';
+    ProcessPanelRootDataProps,
+    ProcessPanelRootActionProps,
+    ProcessPanelRoot
+} from './process-panel-root';
+import {
+    getProcessPanelCurrentUuid,
+    ProcessPanel as ProcessPanelState
+} from 'store/process-panel/process-panel';
+import { groupBy } from 'lodash';
+import {
+    loadInputs,
+    loadOutputDefinitions,
+    loadOutputs,
+    toggleProcessPanelFilter,
+    updateOutputParams,
+} 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';
+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,
+        inputRaw: processPanel.inputRaw,
+        inputParams: processPanel.inputParams,
+        outputRaw: processPanel.outputRaw,
+        outputDefinitions: processPanel.outputDefinitions,
+        outputParams: processPanel.outputParams,
+    };
+};
 
-const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    card: {
-        marginBottom: theme.spacing.unit * 2
+const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
+    onCopyToClipboard: (message: string) => {
+        dispatch<any>(snackbarActions.OPEN_SNACKBAR({
+            message,
+            hideDuration: 2000,
+            kind: SnackbarKind.SUCCESS,
+        }));
     },
-    iconHeader: {
-        fontSize: '1.875rem',
-        color: theme.customs.colors.green700
+    onContextMenu: (event, process) => {
+        dispatch<any>(openProcessContextMenu(event, process));
     },
-    label: {
-        fontSize: '0.875rem'
+    onToggle: status => {
+        dispatch<any>(toggleProcessPanelFilter(status));
     },
-    value: {
-        textTransform: 'none',
-        fontSize: '0.875rem'
-    }
+    cancelProcess: (uuid) => dispatch<any>(cancelRunningWorkflow(uuid)),
+    onLogFilterChange: (filter) => dispatch(setProcessLogsPanelFilter(filter.value)),
+    navigateToLog: (uuid) => dispatch<any>(navigateToLogCollection(uuid)),
+    loadInputs: (containerRequest) => dispatch<any>(loadInputs(containerRequest)),
+    loadOutputs: (containerRequest) => dispatch<any>(loadOutputs(containerRequest)),
+    loadOutputDefinitions: (containerRequest) => dispatch<any>(loadOutputDefinitions(containerRequest)),
+    updateOutputParams: () => dispatch<any>(updateOutputParams())
 });
 
-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;
+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,
+        }));
+    };
 
-                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"
-                            subheader="(no description)"
-                        />
-                        <CardContent>
-                            <Grid container direction="column">
-                                <Grid item xs={6}>
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Collection UUID' value="uuid" />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Number of files' value='14' />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Content size' value='54 MB' />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Owner' value="ownerUuid" />
-                                </Grid>
-                            </Grid>
-                        </CardContent>
-                    </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);
