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), }; };