Skip to content

Commit

Permalink
default searchable snapshot to enabled on cloud when creating a new p…
Browse files Browse the repository at this point in the history
…olicy
  • Loading branch information
jloleysens committed Jan 18, 2021
1 parent f7fdda5 commit 9c2956a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,28 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ 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`;

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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const EditPolicyContextProvider = ({
return <EditPolicyContext.Provider value={value}>{children}</EditPolicyContext.Provider>;
};

export const useEditPolicyContext = () => {
export const useEditPolicyContext = (): EditPolicyContextValue => {
const ctx = useContext(EditPolicyContext);
if (!ctx) {
throw new Error('useEditPolicyContext can only be called inside of EditPolicyContext!');
Expand Down

0 comments on commit 9c2956a

Please sign in to comment.