Skip to content

Commit

Permalink
[ML] Fix color coding for outlier detection. Fix nested fields for da…
Browse files Browse the repository at this point in the history
…ta gird. (#80467) (#80493)

- Fix for color coding for outlier detection due to updated feature influence format.
- Fix for displaying cell values for nested fields.
  • Loading branch information
walterra committed Oct 14, 2020
1 parent 679e712 commit 72b9219
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,24 @@ export const useRenderCellValue = (
return results[cId.replace(`${resultsField}.`, '')];
}

return tableItems.hasOwnProperty(adjustedRowIndex)
? getNestedProperty(tableItems[adjustedRowIndex], cId, null)
: null;
if (tableItems.hasOwnProperty(adjustedRowIndex)) {
const item = tableItems[adjustedRowIndex];

// Try if the field name is available as is.
if (item.hasOwnProperty(cId)) {
return item[cId];
}

// Try if the field name is available as a nested field.
return getNestedProperty(tableItems[adjustedRowIndex], cId, null);
}

return null;
}

const cellValue = getCellValue(columnId);

// React by default doesn't all us to use a hook in a callback.
// React by default doesn't allow us to use a hook in a callback.
// However, this one will be passed on to EuiDataGrid and its docs
// recommend wrapping `setCellProps` in a `useEffect()` hook
// so we're ignoring the linting rule here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export const getFeatureCount = (resultsField: string, tableItems: DataGridItem[]
return 0;
}

return Object.keys(tableItems[0]).filter((key) =>
key.includes(`${resultsField}.${FEATURE_INFLUENCE}.`)
).length;
const fullItem = tableItems[0];

if (
fullItem[resultsField] !== undefined &&
Array.isArray(fullItem[resultsField][FEATURE_INFLUENCE])
) {
return fullItem[resultsField][FEATURE_INFLUENCE].length;
}

return 0;
};

0 comments on commit 72b9219

Please sign in to comment.