Skip to content

Commit

Permalink
only licensing can disable searchable snapshot field
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Feb 25, 2021
1 parent 0b48847 commit 08a4742
Showing 1 changed file with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>

const isColdPhase = phase === 'cold';
const isDisabledDueToLicense = !license.canUseSearchableSnapshot();
const isDisabledInColdDueToHotPhase = isColdPhase && isUsingSearchableSnapshotInHotPhase;

const isDisabled = isDisabledDueToLicense || isDisabledInColdDueToHotPhase;

const [isFieldToggleChecked, setIsFieldToggleChecked] = useState(() =>
Boolean(
Expand All @@ -74,10 +71,10 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
);

useEffect(() => {
if (isDisabled) {
if (isDisabledDueToLicense) {
setIsFieldToggleChecked(false);
}
}, [isDisabled]);
}, [isDisabledDueToLicense]);

const renderField = () => (
<SearchableSnapshotDataProvider>
Expand Down Expand Up @@ -278,20 +275,6 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
)}
</EuiCallOut>
);
} else if (isDisabledInColdDueToHotPhase) {
infoCallout = (
<EuiCallOut
size="s"
data-test-subj="searchableSnapshotFieldsEnabledInHotCallout"
title={i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotDisabledCalloutBody',
{
defaultMessage:
'Cannot create a searchable snapshot in cold when it is configured in hot phase.',
}
)}
/>
);
}

return infoCallout ? (
Expand All @@ -308,7 +291,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
data-test-subj={`searchableSnapshotField-${phase}`}
switchProps={{
checked: isFieldToggleChecked,
disabled: isDisabled,
disabled: isDisabledDueToLicense,
onChange: setIsFieldToggleChecked,
'data-test-subj': 'searchableSnapshotToggle',
label: i18n.translate(
Expand Down Expand Up @@ -339,7 +322,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
fieldNotices={renderInfoCallout()}
fullWidth
>
{isDisabled ? <div /> : renderField}
{isDisabledDueToLicense ? <div /> : renderField}
</DescribedFormRow>
);
};

0 comments on commit 08a4742

Please sign in to comment.