From 1570b17bb8579de89f7fd7f012ac1e00304d04a5 Mon Sep 17 00:00:00 2001 From: tongy-msft <91754176+tongyu-microsoft@users.noreply.github.com> Date: Mon, 20 May 2024 23:47:51 -0700 Subject: [PATCH] Fix robot page exception on TypeError: Cannot read properties of undefined (reading 'cohort') (#2540) * fix robot page exception on TypeError: Cannot read properties of undefined (reading 'cohort') in .filter * Update ChartConfigurationFlyout.tsx * Update ModelAssessmentDashboard.tsx --- .../Controls/ModelOverview/ChartConfigurationFlyout.tsx | 4 ++-- .../Controls/ModelOverview/ModelOverviewChartPivot.tsx | 4 ++-- .../lib/ModelAssessmentDashboard/ModelAssessmentDashboard.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ChartConfigurationFlyout.tsx b/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ChartConfigurationFlyout.tsx index 33184db25d..68d8af7e7b 100644 --- a/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ChartConfigurationFlyout.tsx +++ b/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ChartConfigurationFlyout.tsx @@ -68,9 +68,9 @@ export class ChartConfigurationFlyout extends React.Component< // maximum which indicates that new cohorts were created. newCohorts = this.props.datasetCohorts .filter( - (errorCohort) => errorCohort.cohort.getCohortID() > prevMaxCohortID + (errorCohort) => errorCohort?.cohort?.getCohortID() > prevMaxCohortID ) - .map((errorCohort) => errorCohort.cohort.getCohortID()); + .map((errorCohort) => errorCohort?.cohort?.getCohortID()); } // reset feature-based cohort selection if the underlying feature-based cohorts changed diff --git a/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ModelOverviewChartPivot.tsx b/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ModelOverviewChartPivot.tsx index 3e57a02eb5..847621f5b6 100644 --- a/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ModelOverviewChartPivot.tsx +++ b/libs/model-assessment/src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ModelOverviewChartPivot.tsx @@ -83,12 +83,12 @@ export class ModelOverviewChartPivot extends React.Component< // only keep selected stats and cohorts based on cohort ID labeledStatistics = this.props.labeledStatistics.filter((_, i) => this.props.selectedChartCohorts.includes( - chartCohorts[i].cohort.getCohortID() + chartCohorts[i]?.cohort.getCohortID() ) ); chartCohorts = chartCohorts.filter((errorCohort) => this.props.selectedChartCohorts.includes( - errorCohort.cohort.getCohortID() + errorCohort?.cohort.getCohortID() ) ); } else { diff --git a/libs/model-assessment/src/lib/ModelAssessmentDashboard/ModelAssessmentDashboard.tsx b/libs/model-assessment/src/lib/ModelAssessmentDashboard/ModelAssessmentDashboard.tsx index bda8052184..d34a079dd0 100644 --- a/libs/model-assessment/src/lib/ModelAssessmentDashboard/ModelAssessmentDashboard.tsx +++ b/libs/model-assessment/src/lib/ModelAssessmentDashboard/ModelAssessmentDashboard.tsx @@ -369,7 +369,7 @@ export class ModelAssessmentDashboard extends CohortBasedComponent< return; } const newCohorts = [...this.state.cohorts].filter( - (t) => t.cohort.name !== cohort.cohort.name + (t) => t?.cohort?.name !== cohort?.cohort?.name ); this.setState({ cohorts: newCohorts