Skip to content

Commit

Permalink
[ML] Refactor to getCreateTransformSettingsRequestBody
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Sep 28, 2020
1 parent 7b9c151 commit 10e30dd
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions x-pack/plugins/transform/public/app/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number | null | undefined>,
};
): { settings: PutTransformsRequestSchema['settings'] } => {
// have to use Record<> here because typeof schema is readonly
const tempSettings = {} as Record<string, number | null | undefined>;

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,
Expand Down Expand Up @@ -176,7 +181,7 @@ export const getCreateTransformRequestBody = (
}
: {}),
// conditionally add additional settings
...tempSettings,
...getCreateTransformSettingsRequestBody(transformDetailsState),
};
};

Expand Down

0 comments on commit 10e30dd

Please sign in to comment.