From 9c2956a899f33ed132f3378c471596cf3308932c Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 18 Jan 2021 10:23:17 +0100 Subject: [PATCH] default searchable snapshot to enabled on cloud when creating a new policy --- .../searchable_snapshot_field.tsx | 13 +++++++++---- .../sections/edit_policy/edit_policy_context.tsx | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/searchable_snapshot_field/searchable_snapshot_field.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/searchable_snapshot_field/searchable_snapshot_field.tsx index 3157c0a51accf..5fa192158fb3b 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/searchable_snapshot_field/searchable_snapshot_field.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/searchable_snapshot_field/searchable_snapshot_field.tsx @@ -51,7 +51,7 @@ export const SearchableSnapshotField: FunctionComponent = ({ phase }) => const { services: { cloud }, } = useKibana(); - const { getUrlForApp, policy, license } = useEditPolicyContext(); + const { getUrlForApp, policy, license, isNewPolicy } = useEditPolicyContext(); const { isUsingSearchableSnapshotInHotPhase, isUsingRollover } = useConfigurationIssues(); const searchableSnapshotPath = `phases.${phase}.actions.searchable_snapshot.snapshot_repository`; @@ -59,15 +59,20 @@ export const SearchableSnapshotField: FunctionComponent = ({ phase }) => const [formData] = useFormData({ watch: searchableSnapshotPath }); const searchableSnapshotRepo = get(formData, searchableSnapshotPath); + const isColdPhase = phase === 'cold'; const isDisabledDueToLicense = !license.canUseSearchableSnapshot(); - const isDisabledInColdDueToHotPhase = phase === 'cold' && isUsingSearchableSnapshotInHotPhase; - const isDisabledInColdDueToRollover = phase === 'cold' && !isUsingRollover; + const isDisabledInColdDueToHotPhase = isColdPhase && isUsingSearchableSnapshotInHotPhase; + const isDisabledInColdDueToRollover = isColdPhase && !isUsingRollover; const isDisabled = isDisabledDueToLicense || isDisabledInColdDueToHotPhase || isDisabledInColdDueToRollover; const [isFieldToggleChecked, setIsFieldToggleChecked] = useState(() => - Boolean(policy.phases[phase]?.actions?.searchable_snapshot?.snapshot_repository) + Boolean( + // New policy on cloud should have searchable snapshot on in cold phase + (isColdPhase && isNewPolicy && cloud?.isCloudEnabled) || + policy.phases[phase]?.actions?.searchable_snapshot?.snapshot_repository + ) ); useEffect(() => { diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy_context.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy_context.tsx index f7b9b1af1ee3a..3f6eac9b7a8af 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy_context.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy_context.tsx @@ -32,7 +32,7 @@ export const EditPolicyContextProvider = ({ return {children}; }; -export const useEditPolicyContext = () => { +export const useEditPolicyContext = (): EditPolicyContextValue => { const ctx = useContext(EditPolicyContext); if (!ctx) { throw new Error('useEditPolicyContext can only be called inside of EditPolicyContext!');