Skip to content

Commit

Permalink
more custom logic for analysis methods and plans
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian committed Jan 22, 2025
1 parent 9dde1af commit e04c7f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion services/ui-src/src/components/fields/DynamicField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions services/ui-src/src/components/reports/DrawerReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -305,7 +317,7 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
<Text>{entity.custom_analysis_method_description}</Text>
)}
{entity.analysis_method_frequency &&
entity.analysis_method_applicable_plans && (
entity.analysis_method_applicable_plans?.length > 0 && (
<Text>
{entity.analysis_method_frequency[0].value}:&nbsp;
{entity.analysis_method_applicable_plans
Expand All @@ -321,7 +333,7 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
)}
<Box sx={buttonBoxStyling(canAddEntities)}>
{enterButton(entity, isEntityCompleted)}
{canAddEntities && !entity.isRequired && (
{hasPlans && canAddEntities && !entity.isRequired && (
<Button
sx={sx.deleteButton}
data-testid="delete-entity"
Expand Down

0 comments on commit e04c7f3

Please sign in to comment.