From b24ee4b3ff5c3e1b3347169559dbe02f065a54b5 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Thu, 10 Dec 2020 17:53:01 +0100 Subject: [PATCH] fix serialization of rollover (#85582) --- .../form/deserializer_and_serializer.test.ts | 12 ++++++++++++ .../edit_policy/form/serializer/serializer.ts | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/deserializer_and_serializer.test.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/deserializer_and_serializer.test.ts index 9891921b271e..518a205b1230 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/deserializer_and_serializer.test.ts +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/deserializer_and_serializer.test.ts @@ -300,4 +300,16 @@ describe('deserializer and serializer', () => { expect(result.phases.hot!.actions.shrink).toBeUndefined(); expect(result.phases.warm!.actions.shrink).toBeUndefined(); }); + + it('removes rollover action fields', () => { + formInternal.phases.hot!.actions.rollover!.max_size = ''; + formInternal.phases.hot!.actions.rollover!.max_age = ''; + formInternal.phases.hot!.actions.rollover!.max_docs = '' as any; + + const result = serializer(formInternal); + + expect(result.phases.hot!.actions.rollover!.max_age).toBeUndefined(); + expect(result.phases.hot!.actions.rollover!.max_docs).toBeUndefined(); + expect(result.phases.hot!.actions.rollover!.max_size).toBeUndefined(); + }); }); diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/serializer/serializer.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/serializer/serializer.ts index aaf996303730..91e175d49de2 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/serializer/serializer.ts +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/serializer/serializer.ts @@ -43,12 +43,20 @@ export const createSerializer = (originalPolicy?: SerializedPolicy) => ( if (draft.phases.hot?.actions) { const hotPhaseActions = draft.phases.hot.actions; if (hotPhaseActions.rollover && _meta.hot.useRollover) { - if (hotPhaseActions.rollover.max_age) { + if (updatedPolicy.phases.hot!.actions.rollover?.max_age) { hotPhaseActions.rollover.max_age = `${hotPhaseActions.rollover.max_age}${_meta.hot.maxAgeUnit}`; + } else { + delete hotPhaseActions.rollover.max_age; } - if (hotPhaseActions.rollover.max_size) { + if (typeof updatedPolicy.phases.hot!.actions.rollover?.max_docs !== 'number') { + delete hotPhaseActions.rollover.max_docs; + } + + if (updatedPolicy.phases.hot!.actions.rollover?.max_size) { hotPhaseActions.rollover.max_size = `${hotPhaseActions.rollover.max_size}${_meta.hot.maxStorageSizeUnit}`; + } else { + delete hotPhaseActions.rollover.max_size; } if (!updatedPolicy.phases.hot!.actions?.forcemerge) {