From: Lucas Di Pentima Date: Thu, 10 Mar 2022 21:57:29 +0000 (-0300) Subject: 16672: Rearranges code related to getting current process' UUID. X-Git-Tag: 2.4.0~2^2~15 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/4aee3fa5225c21771b23666d29be9d796758a65f 16672: Rearranges code related to getting current process' UUID. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/store/process-logs-panel/process-logs-panel-actions.ts b/src/store/process-logs-panel/process-logs-panel-actions.ts index ecbd030b..f0caf052 100644 --- a/src/store/process-logs-panel/process-logs-panel-actions.ts +++ b/src/store/process-logs-panel/process-logs-panel-actions.ts @@ -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) { diff --git a/src/store/process-logs-panel/process-logs-panel.ts b/src/store/process-logs-panel/process-logs-panel.ts index 87b50bd2..74a18041 100644 --- a/src/store/process-logs-panel/process-logs-panel.ts +++ b/src/store/process-logs-panel/process-logs-panel.ts @@ -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; diff --git a/src/store/process-panel/process-panel.ts b/src/store/process-panel/process-panel.ts index 935cfa58..49c2691d 100644 --- a/src/store/process-panel/process-panel.ts +++ b/src/store/process-panel/process-panel.ts @@ -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 diff --git a/src/views/process-log-panel/process-log-panel.tsx b/src/views/process-log-panel/process-log-panel.tsx index 9f61f8b6..b11d1432 100644 --- a/src/views/process-log-panel/process-log-panel.tsx +++ b/src/views/process-log-panel/process-log-panel.tsx @@ -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 }, diff --git a/src/views/process-panel/process-panel.tsx b/src/views/process-panel/process-panel.tsx index 3364a8d6..27acc869 100644 --- a/src/views/process-panel/process-panel.tsx +++ b/src/views/process-panel/process-panel.tsx @@ -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(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);