16672: Rearranges code related to getting current process' UUID.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 10 Mar 2022 21:57:29 +0000 (18:57 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 25 Mar 2022 20:59:23 +0000 (17:59 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/store/process-logs-panel/process-logs-panel-actions.ts
src/store/process-logs-panel/process-logs-panel.ts
src/store/process-panel/process-panel.ts
src/views/process-log-panel/process-log-panel.tsx
src/views/process-panel/process-panel.tsx

index ecbd030b1c27d62d505aab7d37d779d33b80c5e6..f0caf0522f164388682f9ddb93ae276945d56d2c 100644 (file)
@@ -45,7 +45,7 @@ export const initProcessLogsPanel = (processUuid: string) =>
 export const addProcessLogsPanelItem = (message: ResourceEventMessage<{ text: string }>) =>
     async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => {
         if (PROCESS_PANEL_LOG_EVENT_TYPES.indexOf(message.eventType) > -1) {
-            const uuid = getProcessLogsPanelCurrentUuid(getState());
+            const uuid = getProcessLogsPanelCurrentUuid(getState().router);
             if (uuid) {
                 const process = getProcess(uuid)(getState().resources);
                 if (process) {
index 87b50bd2f97ff89f1a7d057e580aa3093a13bf80..74a18041bcc9e07f9f28000c8ab10588f6be0e50 100644 (file)
@@ -2,8 +2,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { RootState } from '../store';
 import { matchProcessLogRoute, matchProcessRoute } from 'routes/routes';
+import { RouterState } from 'react-router-redux';
 
 export interface ProcessLogsPanel {
     filters: string[];
@@ -19,7 +19,7 @@ export const getProcessPanelLogs = ({ selectedFilter, logs }: ProcessLogsPanel)
     return logs[selectedFilter];
 };
 
-export const getProcessLogsPanelCurrentUuid = ({ router }: RootState) => {
+export const getProcessLogsPanelCurrentUuid = (router: RouterState) => {
     const pathname = router.location ? router.location.pathname : '';
     const match = matchProcessLogRoute(pathname) || matchProcessRoute(pathname);
     return match ? match.params.id : undefined;
index 935cfa58b4bf6929a1ed6c3e27428fd4b258a79d..49c2691d9d4c21c3fdd2ee48eea60a74f2db31c6 100644 (file)
@@ -2,7 +2,16 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { RouterState } from "react-router-redux";
+import { matchProcessRoute } from "routes/routes";
+
 export interface ProcessPanel {
     containerRequestUuid: string;
     filters: { [status: string]: boolean };
 }
+
+export const getProcessPanelCurrentUuid = (router: RouterState) => {
+    const pathname = router.location ? router.location.pathname : '';
+    const match = matchProcessRoute(pathname);
+    return match ? match.params.id : undefined;
+};
\ No newline at end of file
index 9f61f8b6c607f790208b859296c99028ba161458..b11d1432c14125db016545734b844f7d94a8dcd6 100644 (file)
@@ -25,9 +25,8 @@ export interface FilterOption {
     value: string;
 }
 
-const mapStateToProps = (state: RootState): ProcessLogPanelRootDataProps => {
-    const { resources, processLogsPanel } = state;
-    const uuid = getProcessLogsPanelCurrentUuid(state) || '';
+const mapStateToProps = ({resources, processLogsPanel, router}: RootState): ProcessLogPanelRootDataProps => {
+    const uuid = getProcessLogsPanelCurrentUuid(router) || '';
     return {
         process: getProcess(uuid)(resources),
         selectedFilter: { label: processLogsPanel.selectedFilter, value: processLogsPanel.selectedFilter },
index 3364a8d63043c78fcbb7ed130226ae524d5e2471..27acc8690efe77959a5c7ed87fe8cbb68ac5cb48 100644 (file)
@@ -7,18 +7,26 @@ 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 {
+    ProcessPanelRootDataProps,
+    ProcessPanelRootActionProps,
+    ProcessPanelRoot
+} from './process-panel-root';
+import {
+    getProcessPanelCurrentUuid,
+    ProcessPanel as ProcessPanelState
+} from 'store/process-panel/process-panel';
 import { groupBy } from 'lodash';
-import { toggleProcessPanelFilter, navigateToOutput, openWorkflow } from 'store/process-panel/process-panel-actions';
+import {
+    toggleProcessPanelFilter,
+    navigateToOutput,
+    openWorkflow
+} from 'store/process-panel/process-panel-actions';
 import { openProcessInputDialog } from 'store/processes/process-input-actions';
 import { cancelRunningWorkflow } from 'store/processes/processes-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 uuid = getProcessPanelCurrentUuid(router) || '';
     const subprocesses = getSubprocesses(uuid)(resources);
     return {
         process: getProcess(uuid)(resources),
@@ -40,9 +48,7 @@ const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps =>
     cancelProcess: (uuid) => dispatch<any>(cancelRunningWorkflow(uuid))
 });
 
-export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);
-
-export const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
+const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
     const grouppedProcesses = groupBy(processes, getProcessStatus);
     return Object
         .keys(processPanel.filters)
@@ -52,4 +58,6 @@ export const getFilters = (processPanel: ProcessPanelState, processes: Process[]
             checked: processPanel.filters[filter],
             key: filter,
         }));
-    };
\ No newline at end of file
+    };
+
+export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);