Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Update transform cloning to include description and new fields #78364

Merged
merged 11 commits into from
Oct 1, 2020
Merged
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;
}
walterra marked this conversation as resolved.
Show resolved Hide resolved

return {
walterra marked this conversation as resolved.
Show resolved Hide resolved
...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