Skip to content

Commit

Permalink
[ML] Update transform cloning to include description and new fields
Browse files Browse the repository at this point in the history
[ML] Clean up console
  • Loading branch information
qn895 committed Sep 23, 2020
1 parent 32abbff commit 3d99c0f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 37 deletions.
81 changes: 44 additions & 37 deletions x-pack/plugins/transform/public/app/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,44 +134,51 @@ export const getCreateTransformRequestBody = (
indexPatternTitle: IndexPattern['title'],
pivotState: StepDefineExposedState,
transformDetailsState: StepDetailsExposedState
): PutTransformsRequestSchema => ({
...getPreviewTransformRequestBody(
indexPatternTitle,
getPivotQuery(pivotState.searchQuery),
dictionaryToArray(pivotState.groupByList),
dictionaryToArray(pivotState.aggList)
),
// conditionally add optional description
...(transformDetailsState.transformDescription !== ''
? { description: transformDetailsState.transformDescription }
: {}),
// conditionally add optional frequency
...(transformDetailsState.transformFrequency !== ''
? { frequency: transformDetailsState.transformFrequency }
: {}),
dest: {
index: transformDetailsState.destinationIndex,
},
// conditionally add continuous mode config
...(transformDetailsState.isContinuousModeEnabled
? {
sync: {
time: {
field: transformDetailsState.continuousModeDateField,
delay: transformDetailsState.continuousModeDelay,
): PutTransformsRequestSchema => {
const tempSettings = {
settings: {} as Record<string, number | null | undefined>,
};
if (transformDetailsState.transformSettingsMaxPageSearchSize) {
tempSettings.settings.max_page_search_size =
transformDetailsState.transformSettingsMaxPageSearchSize;
}
if (transformDetailsState.transformSettingsDocsPerSecond) {
tempSettings.settings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond;
}

return {
...getPreviewTransformRequestBody(
indexPatternTitle,
getPivotQuery(pivotState.searchQuery),
dictionaryToArray(pivotState.groupByList),
dictionaryToArray(pivotState.aggList)
),
// conditionally add optional description
...(transformDetailsState.transformDescription !== ''
? { description: transformDetailsState.transformDescription }
: {}),
// conditionally add optional frequency
...(transformDetailsState.transformFrequency !== ''
? { frequency: transformDetailsState.transformFrequency }
: {}),
dest: {
index: transformDetailsState.destinationIndex,
},
// conditionally add continuous mode config
...(transformDetailsState.isContinuousModeEnabled
? {
sync: {
time: {
field: transformDetailsState.continuousModeDateField,
delay: transformDetailsState.continuousModeDelay,
},
},
},
}
: {}),
// conditionally add additional settings
...(transformDetailsState.transformSettingsMaxPageSearchSize
? {
settings: {
max_page_search_size: transformDetailsState.transformSettingsMaxPageSearchSize,
},
}
: {}),
});
}
: {}),
// conditionally add additional settings
...tempSettings,
};
};

export function isHttpFetchError(error: any): error is HttpFetchError {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface StepDetailsExposedState {
transformDescription: string;
transformFrequency: string;
transformSettingsMaxPageSearchSize: number;
transformSettingsDocsPerSecond?: number;
valid: boolean;
indexPatternTimeField?: string | undefined;
}
Expand Down Expand Up @@ -100,6 +101,20 @@ export function applyTransformConfigToDetailsState(
state.continuousModeDelay = time?.delay ?? defaultContinuousModeDelay;
state.isContinuousModeEnabled = true;
}
if (transformConfig.description !== undefined) {
state.transformDescription = transformConfig.description;
}
if (transformConfig.frequency !== undefined) {
state.transformFrequency = transformConfig.frequency;
}
if (transformConfig.settings) {
if (typeof transformConfig.settings?.max_page_search_size === 'number') {
state.transformSettingsMaxPageSearchSize = transformConfig.settings.max_page_search_size;
}
if (typeof transformConfig.settings?.docs_per_second === 'number') {
state.transformSettingsDocsPerSecond = transformConfig.settings.docs_per_second;
}
}
}
return state;
}
Expand Down Expand Up @@ -275,6 +290,8 @@ export const StepDetailsForm: FC<Props> = React.memo(
const [transformSettingsMaxPageSearchSize, setTransformSettingsMaxPageSearchSize] = useState(
defaults.transformSettingsMaxPageSearchSize
);
const [transformSettingsDocsPerSecond] = useState(defaults.transformSettingsDocsPerSecond);

const isTransformSettingsMaxPageSearchSizeValid = transformSettingsMaxPageSearchSizeValidator(
transformSettingsMaxPageSearchSize
);
Expand All @@ -301,6 +318,7 @@ export const StepDetailsForm: FC<Props> = React.memo(
transformDescription,
transformFrequency,
transformSettingsMaxPageSearchSize,
transformSettingsDocsPerSecond,
destinationIndex,
touched: true,
valid,
Expand Down

0 comments on commit 3d99c0f

Please sign in to comment.