Skip to content

Commit

Permalink
[ML] Fix fi broken if result is an array with only one element
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Nov 2, 2020
1 parent 19ff877 commit 845339e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,20 @@ export const showDataGridColumnChartErrorMessageToast = (
// helper function to transform { [key]: [val] } => { [key]: val }
// for when `fields` is used in es.search since response is always an array of values
// since response always returns an array of values for each field
export const getProcessedFields = (originalObj: object) => {
export const getProcessedFields = (originalObj: object, omitBy?: (key: string) => boolean) => {
const obj: { [key: string]: any } = { ...originalObj };
for (const key of Object.keys(obj)) {
if (Array.isArray(obj[key]) && obj[key].length === 1) {
obj[key] = obj[key][0];
// if no conditional is included, process everything
if (omitBy === undefined) {
if (Array.isArray(obj[key]) && obj[key].length === 1) {
obj[key] = obj[key][0];
}
} else {
// else only process the fields for things users don't want to omit
if (omitBy(key) === false)
if (Array.isArray(obj[key]) && obj[key].length === 1) {
obj[key] = obj[key][0];
}
}
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ export const getIndexData = async (

if (!options.didCancel) {
setRowCount(resp.hits.total.value);
setTableItems(resp.hits.hits.map((d) => getProcessedFields(d.fields)));
setTableItems(
resp.hits.hits.map((d) =>
getProcessedFields(d.fields, (key: string) =>
key.startsWith(`${jobConfig.dest.results_field}.feature_importance`)
)
)
);
setStatus(INDEX_STATUS.LOADED);
}
} catch (e) {
Expand Down

0 comments on commit 845339e

Please sign in to comment.