Skip to content

Commit

Permalink
add destIndex specific fields when using sourceIndex for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Mar 31, 2020
1 parent b05bda3 commit 49dd643
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ export function getFlattenedFields(obj: EsDocSource, resultsField: string): EsFi

export const getDefaultFieldsFromJobCaps = (
fields: Field[],
jobConfig: DataFrameAnalyticsConfig
jobConfig: DataFrameAnalyticsConfig,
needsDestIndexFields: boolean
): { selectedFields: Field[]; docFields: Field[]; depVarType?: ES_FIELD_TYPES } => {
const fieldsObj = { selectedFields: [], docFields: [] };
if (fields.length === 0) {
Expand All @@ -260,16 +261,22 @@ export const getDefaultFieldsFromJobCaps = (
const predictedField = `${resultsField}.${
predictionFieldName ? predictionFieldName : defaultPredictionField
}`;

const allFields: any = [
{
id: `${resultsField}.is_training`,
name: `${resultsField}.is_training`,
type: ES_FIELD_TYPES.BOOLEAN,
},
{ id: predictedField, name: predictedField, type },
...fields,
].sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig));
// Only need to add these first two fields if we didn't use dest index pattern to get the fields
const allFields: any =
needsDestIndexFields === true
? [
{
id: `${resultsField}.is_training`,
name: `${resultsField}.is_training`,
type: ES_FIELD_TYPES.BOOLEAN,
},
{ id: predictedField, name: predictedField, type },
]
: [];

allFields.push(...fields);
// @ts-ignore
allFields.sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig));

let selectedFields = allFields
.slice(0, DEFAULT_REGRESSION_COLUMNS * 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,23 @@ export const ResultsTable: FC<Props> = React.memo(
}
}

const needsDestIndexFields = indexPattern && indexPattern.title === jobConfig.source.index[0];

const {
errorMessage,
loadExploreData,
sortField,
sortDirection,
status,
tableItems,
} = useExploreData(jobConfig, selectedFields, setSelectedFields, setDocFields, setDepVarType);
} = useExploreData(
jobConfig,
needsDestIndexFields,
selectedFields,
setSelectedFields,
setDocFields,
setDepVarType
);

const columns: Array<ColumnType<TableItem>> = selectedFields
.sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface UseExploreDataReturnType {

export const useExploreData = (
jobConfig: DataFrameAnalyticsConfig | undefined,
needsDestIndexFields: boolean,
selectedFields: Field[],
setSelectedFields: React.Dispatch<React.SetStateAction<Field[]>>,
setDocFields: React.Dispatch<React.SetStateAction<Field[]>>,
Expand All @@ -70,7 +71,7 @@ export const useExploreData = (
selectedFields: defaultSelected,
docFields,
depVarType,
} = getDefaultFieldsFromJobCaps(fields, jobConfig);
} = getDefaultFieldsFromJobCaps(fields, jobConfig, needsDestIndexFields);

setDepVarType(depVarType);
setSelectedFields(defaultSelected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,23 @@ export const ResultsTable: FC<Props> = React.memo(
}
}

const needsDestIndexFields = indexPattern && indexPattern.title === jobConfig.source.index[0];

const {
errorMessage,
loadExploreData,
sortField,
sortDirection,
status,
tableItems,
} = useExploreData(jobConfig, selectedFields, setSelectedFields, setDocFields, setDepVarType);
} = useExploreData(
jobConfig,
needsDestIndexFields,
selectedFields,
setSelectedFields,
setDocFields,
setDepVarType
);

const columns: Array<ColumnType<TableItem>> = selectedFields
.sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface UseExploreDataReturnType {

export const useExploreData = (
jobConfig: DataFrameAnalyticsConfig | undefined,
needsDestIndexFields: boolean,
selectedFields: Field[],
setSelectedFields: React.Dispatch<React.SetStateAction<Field[]>>,
setDocFields: React.Dispatch<React.SetStateAction<Field[]>>,
Expand All @@ -65,7 +66,7 @@ export const useExploreData = (
selectedFields: defaultSelected,
docFields,
depVarType,
} = getDefaultFieldsFromJobCaps(fields, jobConfig);
} = getDefaultFieldsFromJobCaps(fields, jobConfig, needsDestIndexFields);

setDepVarType(depVarType);
setSelectedFields(defaultSelected);
Expand Down

0 comments on commit 49dd643

Please sign in to comment.