From a5ee6bbb65d7c169d3616878e54e5cb22b13862a Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Wed, 22 Jan 2025 12:18:15 +0100 Subject: [PATCH 1/3] Chain editor: hide "Submit only analysis step data to RStudio" when there are no analysis records --- webapp/store/ui/chain/index.js | 2 +- .../views/Analysis/Chain/ChainBasicProps.js | 3 +- .../Analysis/Chain/ChainRStudioFieldset.js | 30 +++++++++++-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/webapp/store/ui/chain/index.js b/webapp/store/ui/chain/index.js index 02b2b6834c..9f37463afe 100644 --- a/webapp/store/ui/chain/index.js +++ b/webapp/store/ui/chain/index.js @@ -1,5 +1,5 @@ export { ChainActions } from './actions' -export { useChain } from './hooks' +export { useChain, useChainRecordsCountByStep } from './hooks' export { ChainReducer } from './reducer' diff --git a/webapp/views/App/views/Analysis/Chain/ChainBasicProps.js b/webapp/views/App/views/Analysis/Chain/ChainBasicProps.js index b9ebf22a90..ea066f6883 100644 --- a/webapp/views/App/views/Analysis/Chain/ChainBasicProps.js +++ b/webapp/views/App/views/Analysis/Chain/ChainBasicProps.js @@ -8,8 +8,7 @@ import * as Chain from '@common/analysis/chain' import { useI18n } from '@webapp/store/system' import { useSurvey } from '@webapp/store/survey' -import { useChain } from '@webapp/store/ui/chain' -import { useChainRecordsCountByStep } from '@webapp/store/ui/chain/hooks' +import { useChain, useChainRecordsCountByStep } from '@webapp/store/ui/chain' import * as API from '@webapp/service/api' diff --git a/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js b/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js index dec8602ec0..431b714ea3 100644 --- a/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js +++ b/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js @@ -3,10 +3,11 @@ import { useDispatch } from 'react-redux' import PropTypes from 'prop-types' import * as Record from '@core/record/record' +import * as RecordStep from '@core/record/recordStep' import * as Validation from '@core/validation/validation' import * as Chain from '@common/analysis/chain' -import { ChainActions, useChain } from '@webapp/store/ui/chain' +import { ChainActions, useChain, useChainRecordsCountByStep } from '@webapp/store/ui/chain' import { Checkbox } from '@webapp/components/form' import ButtonRStudio from '@webapp/components/ButtonRStudio' import RecordsDropdown from './RecordsDropdown' @@ -18,25 +19,28 @@ export const ChainRStudioFieldset = (props) => { const chain = useChain() const validation = Chain.getValidation(chain) - const openRStudio = useCallback(() => { - dispatch(ChainActions.openRStudio()) - }, [dispatch]) + const recordsCountByStep = useChainRecordsCountByStep() + const analysisRecordsAvailable = + Number(recordsCountByStep[RecordStep.getStepIdByName(RecordStep.stepNames.analysis)]) > 0 - const openRStudioLocal = useCallback(() => { - dispatch(ChainActions.openRStudio({ isLocal: true })) - }, [dispatch]) + const _openRStudio = useCallback(({ isLocal = false }) => dispatch(ChainActions.openRStudio({ isLocal })), [dispatch]) + + const openRStudio = useCallback(() => _openRStudio(), [_openRStudio]) + const openRStudioLocal = useCallback(() => _openRStudio({ isLocal: true }), [_openRStudio]) return (
RStudio
- updateChain(Chain.assocSubmitOnlyAnalysisStepDataIntoR(value)(chain))} - /> + {analysisRecordsAvailable && ( + updateChain(Chain.assocSubmitOnlyAnalysisStepDataIntoR(value)(chain))} + /> + )} Date: Wed, 22 Jan 2025 13:47:51 +0100 Subject: [PATCH 2/3] code cleanup --- webapp/store/ui/chain/state.js | 2 +- webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/webapp/store/ui/chain/state.js b/webapp/store/ui/chain/state.js index 2a44860bda..6528bfb5ed 100644 --- a/webapp/store/ui/chain/state.js +++ b/webapp/store/ui/chain/state.js @@ -18,7 +18,7 @@ const hasRecordsToProcess = (state) => { const chain = getChain(state) const recordsCountByStep = getRecordsCountByStep(state) const totalRecords = Chain.isSubmitOnlyAnalysisStepDataIntoR(chain) - ? Number(recordsCountByStep[RecordStep.getStepIdByName(RecordStep.stepNames.analysis)]) || 0 + ? Number(recordsCountByStep[RecordStep.analysisCode]) || 0 : RecordStep.steps.reduce((acc, step) => acc + Number(recordsCountByStep[step.id]) || 0, 0) return totalRecords > 0 } diff --git a/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js b/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js index 431b714ea3..3939f59a63 100644 --- a/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js +++ b/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js @@ -20,8 +20,7 @@ export const ChainRStudioFieldset = (props) => { const validation = Chain.getValidation(chain) const recordsCountByStep = useChainRecordsCountByStep() - const analysisRecordsAvailable = - Number(recordsCountByStep[RecordStep.getStepIdByName(RecordStep.stepNames.analysis)]) > 0 + const analysisRecordsAvailable = Number(recordsCountByStep[RecordStep.analysisCode]) > 0 const _openRStudio = useCallback(({ isLocal = false }) => dispatch(ChainActions.openRStudio({ isLocal })), [dispatch]) From c39c9e266b4c941dafd7727dfcd94d1c29a2f8b6 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Wed, 22 Jan 2025 13:58:06 +0100 Subject: [PATCH 3/3] code cleanup --- .../views/App/views/Analysis/Chain/ChainRStudioFieldset.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js b/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js index 3939f59a63..481959c3ce 100644 --- a/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js +++ b/webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js @@ -22,7 +22,10 @@ export const ChainRStudioFieldset = (props) => { const recordsCountByStep = useChainRecordsCountByStep() const analysisRecordsAvailable = Number(recordsCountByStep[RecordStep.analysisCode]) > 0 - const _openRStudio = useCallback(({ isLocal = false }) => dispatch(ChainActions.openRStudio({ isLocal })), [dispatch]) + const _openRStudio = useCallback( + ({ isLocal = false } = {}) => dispatch(ChainActions.openRStudio({ isLocal })), + [dispatch] + ) const openRStudio = useCallback(() => _openRStudio(), [_openRStudio]) const openRStudioLocal = useCallback(() => _openRStudio({ isLocal: true }), [_openRStudio])