Skip to content

Commit

Permalink
[ILM] Fix hiding/disabling searchable snapshot field when rollover is…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
jloleysens and kibanamachine authored Dec 8, 2020
1 parent 3a26307 commit 6ff7199
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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)
Expand All @@ -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 }) => {
Expand Down Expand Up @@ -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.',
}
)}
/>
Expand Down

0 comments on commit 6ff7199

Please sign in to comment.