diff --git a/services/ui-src/src/components/fields/DynamicField.tsx b/services/ui-src/src/components/fields/DynamicField.tsx index 0cca559d4..a4e815a01 100644 --- a/services/ui-src/src/components/fields/DynamicField.tsx +++ b/services/ui-src/src/components/fields/DynamicField.tsx @@ -144,7 +144,7 @@ export const DynamicField = ({ name, label, ...props }: Props) => { // filter analysis methods to remove deleted plans const filteredAnalysisMethods = report?.fieldData?.analysisMethods?.map( (method: EntityShape) => { - if (method.analysis_method_applicable_plans?.length) { + if (method?.analysis_method_applicable_plans?.length) { method.analysis_method_applicable_plans = method.analysis_method_applicable_plans.filter( (plan: AnyObject) => plan.key !== selectedRecord.id diff --git a/services/ui-src/src/components/reports/DrawerReportPage.tsx b/services/ui-src/src/components/reports/DrawerReportPage.tsx index 6bbfab752..bf716e55f 100644 --- a/services/ui-src/src/components/reports/DrawerReportPage.tsx +++ b/services/ui-src/src/components/reports/DrawerReportPage.tsx @@ -257,6 +257,18 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => { const isCustomEntity = canAddEntities && !getDefaultAnalysisMethodIds().includes(entity.id); const calculateEntityCompletion = () => { + // logic to ensure analysis methods always have a plan selected + if ( + isAnalysisMethodsPage && + !entity?.analysis_method_applicable_plans?.length + ) { + if (isCustomEntity) { + return false; + } else if (entity?.analysis_applicable?.[0]?.value === "Yes") { + return false; + } + } + let formFields = form.fields; if (isCustomEntity) { formFields = addEntityForm.fields; @@ -305,7 +317,7 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => { {entity.custom_analysis_method_description} )} {entity.analysis_method_frequency && - entity.analysis_method_applicable_plans && ( + entity.analysis_method_applicable_plans?.length > 0 && ( {entity.analysis_method_frequency[0].value}:  {entity.analysis_method_applicable_plans @@ -321,7 +333,7 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => { )} {enterButton(entity, isEntityCompleted)} - {canAddEntities && !entity.isRequired && ( + {hasPlans && canAddEntities && !entity.isRequired && (