From aece0a95124b9c83ced17c978b77badd7e42b56d Mon Sep 17 00:00:00 2001 From: Giuseppe Steduto Date: Thu, 21 Sep 2023 17:52:56 +0200 Subject: [PATCH] wf-details: do not change chosen log tab automatically Changes the JobLogs component so that instead of constantly updating the logs to show the last "failed" or "running" step, the step is changed only on page load, or when the list of logs change from being empty to having at least one entry. Closes #351. --- CHANGES.rst | 1 + .../components/WorkflowLogs.js | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 854e4447..1af86db7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,7 @@ Version 0.9.1 (UNRELEASED) - Changes the workflow progress bar to always display it as full for finished workflows. - Changes the interactive session notification by adding a message stating that the session will be closed after a specified number of days inactivity. - Changes the workflow-details page to make it possible to scroll through the list of workflow steps in the job logs section. +- Changes the workflow-details page to not automatically refresh the selected job when viewing the related logs, but keeping the user-selected one active. Version 0.9.0 (2023-01-19) -------------------------- diff --git a/reana-ui/src/pages/workflowDetails/components/WorkflowLogs.js b/reana-ui/src/pages/workflowDetails/components/WorkflowLogs.js index 63d83253..c1525a9d 100644 --- a/reana-ui/src/pages/workflowDetails/components/WorkflowLogs.js +++ b/reana-ui/src/pages/workflowDetails/components/WorkflowLogs.js @@ -47,18 +47,27 @@ EngineLogs.propTypes = { }; function JobLogs({ logs }) { - const [selectedStep, setSelectedStep] = useState(); - - useEffect(() => { + function chooseLastStepID(logs) { const failedStepId = findKey(logs, (log) => log.status === "failed"); - if (failedStepId) return setSelectedStep(failedStepId); + if (failedStepId) return failedStepId; const runningStepId = findKey(logs, (log) => log.status === "running"); - if (runningStepId) return setSelectedStep(runningStepId); + if (runningStepId) return runningStepId; + + // Return the last step id if there are no failed or running steps. + return Object.keys(logs).pop(); + } - const logKeys = Object.keys(logs); - setSelectedStep(logKeys[logKeys.length - 1]); - }, [logs]); + const lastStepID = chooseLastStepID(logs); + const [selectedStep, setSelectedStep] = useState(lastStepID); + + useEffect(() => { + // Only update the shown step logs if there was no log displayed before + // and there is one ready to be displayed now + if (lastStepID && !selectedStep) { + setSelectedStep(lastStepID); + } + }, [logs, lastStepID, selectedStep]); const steps = Object.entries(logs).map(([id, log]) => ({ key: id,