X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f53d651573ef8c358cbdf38c7a56c6aed8178b61..4b8cc1acf54add3e4337b27a7e957a84dc9c07b4:/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 2c8db994..4f283a6c 100644
--- a/src/views/process-panel/process-panel.tsx
+++ b/src/views/process-panel/process-panel.tsx
@@ -2,69 +2,49 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { Grid } from '@material-ui/core';
-import { ProcessInformationCard } from '~/views-components/process-information-card/process-information-card';
-import { SubprocessesCard } from '~/views/process-panel/subprocesses-card';
-import { SubprocessFilterDataProps } from '~/components/subprocess-filter/subprocess-filter';
+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 { 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';
 
-export class ProcessPanel extends React.Component {
-    state = {
-        filters: [
-            {
-                key: 'queued',
-                value: 1,
-                label: 'Queued',
-                checked: true
-            }, {
-                key: 'active',
-                value: 2,
-                label: 'Active',
-                checked: true
-            },
-            {
-                key: 'completed',
-                value: 2,
-                label: 'Completed',
-                checked: true
-            },
-            {
-                key: 'failed',
-                value: 2,
-                label: 'Failed',
-                checked: true
-            }
-        ]
+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,
     };
+};
 
-    onToggle = (filter: SubprocessFilterDataProps) => {
-        this.setState((prev: { filters: any[] }) => {
-            return {
-                filters: prev.filters.map((f: SubprocessFilterDataProps) => {
-                    if(f.key === filter.key) {
-                        return {
-                            ...filter,
-                            checked: !filter.checked
-                        };
-                    }
-                    return f;
-                })
-            };
-        });
+const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
+    onContextMenu: (event, process) => {
+        dispatch<any>(openProcessContextMenu(event, process));
+    },
+    onToggle: status => {
+        dispatch<any>(toggleProcessPanelFilter(status));
     }
+});
 
-    render() {
-        return <Grid container spacing={16}>
-            <Grid item xs={7}>
-                <ProcessInformationCard />
-            </Grid>
-            <Grid item xs={5}>
-                <SubprocessesCard 
-                    subprocesses={4}
-                    filters={this.state.filters}
-                    onToggle={this.onToggle}
-                />
-            </Grid>
-        </Grid>;
-    }
-}
+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
