From 10e30dd8a5e2d489eea85da10a1ffe59af6555b8 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 28 Sep 2020 17:48:36 -0500 Subject: [PATCH] [ML] Refactor to getCreateTransformSettingsRequestBody --- .../transform/public/app/common/request.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/transform/public/app/common/request.ts b/x-pack/plugins/transform/public/app/common/request.ts index 5c78e119f1979..8c70b5df260f7 100644 --- a/x-pack/plugins/transform/public/app/common/request.ts +++ b/x-pack/plugins/transform/public/app/common/request.ts @@ -130,22 +130,27 @@ export function getPreviewTransformRequestBody( return request; } -export const getCreateTransformRequestBody = ( - indexPatternTitle: IndexPattern['title'], - pivotState: StepDefineExposedState, +export const getCreateTransformSettingsRequestBody = ( transformDetailsState: StepDetailsExposedState -): PutTransformsRequestSchema => { - const tempSettings = { - settings: {} as Record, - }; +): { settings: PutTransformsRequestSchema['settings'] } => { + // have to use Record<> here because typeof schema is readonly + const tempSettings = {} as Record; + if (transformDetailsState.transformSettingsMaxPageSearchSize) { - tempSettings.settings.max_page_search_size = - transformDetailsState.transformSettingsMaxPageSearchSize; + tempSettings.max_page_search_size = transformDetailsState.transformSettingsMaxPageSearchSize; } if (transformDetailsState.transformSettingsDocsPerSecond) { - tempSettings.settings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond; + tempSettings.docs_per_second = transformDetailsState.transformSettingsDocsPerSecond; } + return { settings: tempSettings }; +}; + +export const getCreateTransformRequestBody = ( + indexPatternTitle: IndexPattern['title'], + pivotState: StepDefineExposedState, + transformDetailsState: StepDetailsExposedState +): PutTransformsRequestSchema => { return { ...getPreviewTransformRequestBody( indexPatternTitle, @@ -176,7 +181,7 @@ export const getCreateTransformRequestBody = ( } : {}), // conditionally add additional settings - ...tempSettings, + ...getCreateTransformSettingsRequestBody(transformDetailsState), }; };