[ILM] Fix hiding/disabling searchable snapshot field when rollover is disabled (#85169)

* fix hiding/disabling searchable snapshot field when rollover is disabled

* added test

* fix i18n

* for now, we hide the forcemerge field in hot

* implement copy updates

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2020-12-08 16:21:10 +01:00 committed by GitHub
parent 3a26307079
commit 6ff71992a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 10 deletions

View file

@ -200,11 +200,14 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
const createSearchableSnapshotActions = (phase: Phases) => {
const fieldSelector = `searchableSnapshotField-${phase}`;
const licenseCalloutSelector = `${fieldSelector}.searchableSnapshotDisabledDueToLicense`;
const rolloverCalloutSelector = `${fieldSelector}.searchableSnapshotFieldsNoRolloverCallout`;
const toggleSelector = `${fieldSelector}.searchableSnapshotToggle`;
const toggleSearchableSnapshot = createFormToggleAction(toggleSelector);
return {
searchableSnapshotDisabled: () => exists(licenseCalloutSelector),
searchableSnapshotDisabledDueToRollover: () => exists(rolloverCalloutSelector),
searchableSnapshotDisabled: () =>
exists(licenseCalloutSelector) && find(licenseCalloutSelector).props().disabled === true,
searchableSnapshotsExists: () => exists(fieldSelector),
findSearchableSnapshotToggle: () => find(toggleSelector),
searchableSnapshotDisabledDueToLicense: () =>

View file

@ -745,4 +745,34 @@ describe('<EditPolicy />', () => {
});
});
});
describe('without rollover', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]);
httpRequestsMockHelpers.setListNodes({
isUsingDeprecatedDataRoleConfig: false,
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['123'] },
});
httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] });
await act(async () => {
testBed = await setup({
appServicesContext: {
license: licensingMock.createLicense({ license: { type: 'basic' } }),
},
});
});
const { component } = testBed;
component.update();
});
test('hiding and disabling searchable snapshot field', async () => {
const { actions } = testBed;
await actions.hot.toggleRollover(false);
await actions.cold.enable(true);
expect(actions.hot.searchableSnapshotsExists()).toBeFalsy();
expect(actions.cold.searchableSnapshotDisabledDueToLicense()).toBeTruthy();
});
});
});

View file

@ -234,9 +234,11 @@ export const HotPhase: FunctionComponent = () => {
</>
)}
</ToggleFieldWithDescribedFormRow>
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
{isRolloverEnabled && !isUsingSearchableSnapshotInHotPhase && (
<ForcemergeField phase="hot" />
{isRolloverEnabled && (
<>
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
{!isUsingSearchableSnapshotInHotPhase && <ForcemergeField phase="hot" />}
</>
)}
<SetPriorityInputField phase={hotProperty} />
</EuiAccordion>

View file

@ -29,7 +29,9 @@ import { useConfigurationIssues } from '../../../../form';
import { i18nTexts } from '../../../../i18n_texts';
import { FieldLoadingError, DescribedFormRow, LearnMoreLink } from '../../../index';
import { useRolloverPath } from '../../../../constants';
import { FieldLoadingError, DescribedFormRow, LearnMoreLink } from '../../../';
import { SearchableSnapshotDataProvider } from './searchable_snapshot_data_provider';
@ -53,12 +55,19 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
} = useKibana();
const { getUrlForApp, policy, license } = useEditPolicyContext();
const { isUsingSearchableSnapshotInHotPhase } = useConfigurationIssues();
const searchableSnapshotPath = `phases.${phase}.actions.searchable_snapshot.snapshot_repository`;
const [formData] = useFormData({ watch: [searchableSnapshotPath, useRolloverPath] });
const isRolloverEnabled = get(formData, useRolloverPath);
const searchableSnapshotRepo = get(formData, searchableSnapshotPath);
const isDisabledDueToLicense = !license.canUseSearchableSnapshot();
const isDisabledInColdDueToHotPhase = phase === 'cold' && isUsingSearchableSnapshotInHotPhase;
const isDisabledInColdDueToRollover = phase === 'cold' && !isRolloverEnabled;
const isDisabled = isDisabledDueToLicense || isDisabledInColdDueToHotPhase;
const isDisabled =
isDisabledDueToLicense || isDisabledInColdDueToHotPhase || isDisabledInColdDueToRollover;
const [isFieldToggleChecked, setIsFieldToggleChecked] = useState(() =>
Boolean(policy.phases[phase]?.actions?.searchable_snapshot?.snapshot_repository)
@ -70,9 +79,6 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
}
}, [isDisabled]);
const [formData] = useFormData({ watch: searchableSnapshotPath });
const searchableSnapshotRepo = get(formData, searchableSnapshotPath);
const renderField = () => (
<SearchableSnapshotDataProvider>
{({ error, isLoading, resendRequest, data }) => {
@ -280,7 +286,21 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({ phase }) =>
'xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotDisabledCalloutBody',
{
defaultMessage:
'Cannot perform searchable snapshot in cold when it is configured in hot phase.',
'Cannot create a searchable snapshot in cold when it is configured in hot phase.',
}
)}
/>
);
} else if (isDisabledInColdDueToRollover) {
infoCallout = (
<EuiCallOut
size="s"
data-test-subj="searchableSnapshotFieldsNoRolloverCallout"
title={i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.searchableSnapshotNoRolloverCalloutBody',
{
defaultMessage:
'Cannot create a searchable snapshot when rollover is disabled in the hot phase.',
}
)}
/>