Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain editor: hide "Submit only analysis step data to RStudio" when there are no analysis records #3712

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion webapp/store/ui/chain/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { ChainActions } from './actions'

export { useChain } from './hooks'
export { useChain, useChainRecordsCountByStep } from './hooks'

export { ChainReducer } from './reducer'
2 changes: 1 addition & 1 deletion webapp/store/ui/chain/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions webapp/views/App/views/Analysis/Chain/ChainBasicProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
32 changes: 19 additions & 13 deletions webapp/views/App/views/Analysis/Chain/ChainRStudioFieldset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -18,25 +19,30 @@ 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.analysisCode]) > 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 (
<fieldset className="rstudio-fieldset">
<legend>RStudio</legend>
<div className="content">
<div>
<Checkbox
label="chainView.submitOnlyAnalysisStepDataIntoR"
checked={Chain.isSubmitOnlyAnalysisStepDataIntoR(chain)}
validation={Validation.getFieldValidation(Chain.keysProps.submitOnlyAnalysisStepDataIntoR)(validation)}
onChange={(value) => updateChain(Chain.assocSubmitOnlyAnalysisStepDataIntoR(value)(chain))}
/>
{analysisRecordsAvailable && (
<Checkbox
label="chainView.submitOnlyAnalysisStepDataIntoR"
checked={Chain.isSubmitOnlyAnalysisStepDataIntoR(chain)}
validation={Validation.getFieldValidation(Chain.keysProps.submitOnlyAnalysisStepDataIntoR)(validation)}
onChange={(value) => updateChain(Chain.assocSubmitOnlyAnalysisStepDataIntoR(value)(chain))}
/>
)}
<Checkbox
label="chainView.submitOnlySelectedRecordsIntoR"
checked={Chain.isSubmitOnlySelectedRecordsIntoR(chain)}
Expand Down
Loading