[ML] Fix Transform runtime mapping editor so mappings can be removed (#95108)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
f3908f7754
commit
07a041ab3a
|
@ -44,8 +44,11 @@ export const AdvancedRuntimeMappingsEditor: FC<StepDefineFormHook['runtimeMappin
|
|||
// Try to parse the string passed on from the editor.
|
||||
// If parsing fails, the "Apply"-Button will be disabled
|
||||
try {
|
||||
const parsedJson = JSON.parse(convertToJson(d));
|
||||
setRuntimeMappingsEditorApplyButtonEnabled(isRuntimeMappings(parsedJson));
|
||||
// if the user deletes the json in the editor
|
||||
// they should still be able to apply changes
|
||||
const isEmptyStr = d === '';
|
||||
const parsedJson = isEmptyStr ? {} : JSON.parse(convertToJson(d));
|
||||
setRuntimeMappingsEditorApplyButtonEnabled(isEmptyStr || isRuntimeMappings(parsedJson));
|
||||
} catch (e) {
|
||||
setRuntimeMappingsEditorApplyButtonEnabled(false);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,8 @@ export const AdvancedRuntimeMappingsSettings: FC<StepDefineFormHook> = (props) =
|
|||
} = props.pivotConfig;
|
||||
|
||||
const applyChanges = () => {
|
||||
const nextConfig = JSON.parse(advancedRuntimeMappingsConfig);
|
||||
const nextConfig =
|
||||
advancedRuntimeMappingsConfig === '' ? {} : JSON.parse(advancedRuntimeMappingsConfig);
|
||||
const previousConfig = runtimeMappings;
|
||||
|
||||
applyRuntimeMappingsEditorChanges();
|
||||
|
|
|
@ -52,7 +52,8 @@ export const useAdvancedRuntimeMappingsEditor = (defaults: StepDefineExposedStat
|
|||
} = useXJsonMode(stringifiedRuntimeMappings ?? '');
|
||||
|
||||
const applyRuntimeMappingsEditorChanges = () => {
|
||||
const parsedRuntimeMappings = JSON.parse(advancedRuntimeMappingsConfig);
|
||||
const parsedRuntimeMappings =
|
||||
advancedRuntimeMappingsConfig === '' ? {} : JSON.parse(advancedRuntimeMappingsConfig);
|
||||
const prettySourceConfig = JSON.stringify(parsedRuntimeMappings, null, 2);
|
||||
setRuntimeMappingsUpdated(true);
|
||||
setRuntimeMappings(parsedRuntimeMappings);
|
||||
|
|
Loading…
Reference in a new issue