[ILM] Show forcemerge in hot when rollover is searchable snapshot is enabled (#85292)
* pivot to different rollover validation mechanism * implement stakeholder feedback to show forcemerge in hot * replace ternary with if..else statements * make rollover validation test more comprehensive
This commit is contained in:
parent
ec0bfe9f14
commit
7fc7fe325c
|
@ -324,7 +324,7 @@ describe('edit policy', () => {
|
|||
});
|
||||
});
|
||||
describe('hot phase', () => {
|
||||
test('should show errors when trying to save with no max size and no max age', async () => {
|
||||
test('should show errors when trying to save with no max size, no max age and no max docs', async () => {
|
||||
const rendered = mountWithIntl(component);
|
||||
expect(findTestSubject(rendered, 'rolloverSettingsRequired').exists()).toBeFalsy();
|
||||
await setPolicyName(rendered, 'mypolicy');
|
||||
|
@ -338,6 +338,11 @@ describe('edit policy', () => {
|
|||
maxAgeInput.simulate('change', { target: { value: '' } });
|
||||
});
|
||||
waitForFormLibValidation(rendered);
|
||||
const maxDocsInput = findTestSubject(rendered, 'hot-selectedMaxDocuments');
|
||||
await act(async () => {
|
||||
maxDocsInput.simulate('change', { target: { value: '' } });
|
||||
});
|
||||
waitForFormLibValidation(rendered);
|
||||
await save(rendered);
|
||||
expect(findTestSubject(rendered, 'rolloverSettingsRequired').exists()).toBeTruthy();
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ import { useFormData, UseField, SelectField, NumericField } from '../../../../..
|
|||
|
||||
import { i18nTexts } from '../../../i18n_texts';
|
||||
|
||||
import { ROLLOVER_EMPTY_VALIDATION, useConfigurationIssues } from '../../../form';
|
||||
import { ROLLOVER_EMPTY_VALIDATION } from '../../../form';
|
||||
|
||||
import { useEditPolicyContext } from '../../../edit_policy_context';
|
||||
|
||||
|
@ -51,8 +51,6 @@ export const HotPhase: FunctionComponent = () => {
|
|||
const isRolloverEnabled = get(formData, useRolloverPath);
|
||||
const [showEmptyRolloverFieldsError, setShowEmptyRolloverFieldsError] = useState(false);
|
||||
|
||||
const { isUsingSearchableSnapshotInHotPhase } = useConfigurationIssues();
|
||||
|
||||
return (
|
||||
<>
|
||||
<EuiDescribedFormGroup
|
||||
|
@ -143,7 +141,7 @@ export const HotPhase: FunctionComponent = () => {
|
|||
<UseField path={ROLLOVER_FORM_PATHS.maxSize}>
|
||||
{(field) => {
|
||||
const showErrorCallout = field.errors.some(
|
||||
(e) => e.validationType === ROLLOVER_EMPTY_VALIDATION
|
||||
(e) => e.code === ROLLOVER_EMPTY_VALIDATION
|
||||
);
|
||||
if (showErrorCallout !== showEmptyRolloverFieldsError) {
|
||||
setShowEmptyRolloverFieldsError(showErrorCallout);
|
||||
|
@ -236,8 +234,8 @@ export const HotPhase: FunctionComponent = () => {
|
|||
</ToggleFieldWithDescribedFormRow>
|
||||
{isRolloverEnabled && (
|
||||
<>
|
||||
{<ForcemergeField phase="hot" />}
|
||||
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
|
||||
{!isUsingSearchableSnapshotInHotPhase && <ForcemergeField phase="hot" />}
|
||||
</>
|
||||
)}
|
||||
<SetPriorityInputField phase={hotProperty} />
|
||||
|
|
|
@ -8,6 +8,9 @@ import { i18n } from '@kbn/i18n';
|
|||
|
||||
import { FormSchema, fieldValidators } from '../../../../shared_imports';
|
||||
import { defaultSetPriority, defaultPhaseIndexPriority } from '../../../constants';
|
||||
import { ROLLOVER_FORM_PATHS } from '../constants';
|
||||
|
||||
const rolloverFormPaths = Object.values(ROLLOVER_FORM_PATHS);
|
||||
|
||||
import { FormInternal } from '../types';
|
||||
|
||||
|
@ -127,6 +130,7 @@ export const schema: FormSchema<FormInternal> = {
|
|||
validator: ifExistsNumberGreaterThanZero,
|
||||
},
|
||||
],
|
||||
fieldsToValidateOnChange: rolloverFormPaths,
|
||||
},
|
||||
max_docs: {
|
||||
label: i18n.translate('xpack.indexLifecycleMgmt.hotPhase.maximumDocumentsLabel', {
|
||||
|
@ -141,6 +145,7 @@ export const schema: FormSchema<FormInternal> = {
|
|||
},
|
||||
],
|
||||
serializer: serializers.stringToNumber,
|
||||
fieldsToValidateOnChange: rolloverFormPaths,
|
||||
},
|
||||
max_size: {
|
||||
label: i18n.translate('xpack.indexLifecycleMgmt.hotPhase.maximumIndexSizeLabel', {
|
||||
|
@ -154,6 +159,7 @@ export const schema: FormSchema<FormInternal> = {
|
|||
validator: ifExistsNumberGreaterThanZero,
|
||||
},
|
||||
],
|
||||
fieldsToValidateOnChange: rolloverFormPaths,
|
||||
},
|
||||
},
|
||||
forcemerge: {
|
||||
|
|
|
@ -56,33 +56,31 @@ export const ROLLOVER_EMPTY_VALIDATION = 'ROLLOVER_EMPTY_VALIDATION';
|
|||
* This validator checks that and updates form values by setting errors states imperatively to
|
||||
* indicate this error state.
|
||||
*/
|
||||
export const rolloverThresholdsValidator: ValidationFunc = ({ form }) => {
|
||||
export const rolloverThresholdsValidator: ValidationFunc = ({ form, path }) => {
|
||||
const fields = form.getFields();
|
||||
if (
|
||||
!(
|
||||
fields[ROLLOVER_FORM_PATHS.maxAge].value ||
|
||||
fields[ROLLOVER_FORM_PATHS.maxDocs].value ||
|
||||
fields[ROLLOVER_FORM_PATHS.maxSize].value
|
||||
fields[ROLLOVER_FORM_PATHS.maxAge]?.value ||
|
||||
fields[ROLLOVER_FORM_PATHS.maxDocs]?.value ||
|
||||
fields[ROLLOVER_FORM_PATHS.maxSize]?.value
|
||||
)
|
||||
) {
|
||||
fields[ROLLOVER_FORM_PATHS.maxAge].setErrors([
|
||||
{
|
||||
validationType: ROLLOVER_EMPTY_VALIDATION,
|
||||
if (path === ROLLOVER_FORM_PATHS.maxAge) {
|
||||
return {
|
||||
code: ROLLOVER_EMPTY_VALIDATION,
|
||||
message: i18nTexts.editPolicy.errors.maximumAgeRequiredMessage,
|
||||
},
|
||||
]);
|
||||
fields[ROLLOVER_FORM_PATHS.maxDocs].setErrors([
|
||||
{
|
||||
validationType: ROLLOVER_EMPTY_VALIDATION,
|
||||
};
|
||||
} else if (path === ROLLOVER_FORM_PATHS.maxDocs) {
|
||||
return {
|
||||
code: ROLLOVER_EMPTY_VALIDATION,
|
||||
message: i18nTexts.editPolicy.errors.maximumDocumentsRequiredMessage,
|
||||
},
|
||||
]);
|
||||
fields[ROLLOVER_FORM_PATHS.maxSize].setErrors([
|
||||
{
|
||||
validationType: ROLLOVER_EMPTY_VALIDATION,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: ROLLOVER_EMPTY_VALIDATION,
|
||||
message: i18nTexts.editPolicy.errors.maximumSizeRequiredMessage,
|
||||
},
|
||||
]);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
fields[ROLLOVER_FORM_PATHS.maxAge].clearErrors(ROLLOVER_EMPTY_VALIDATION);
|
||||
fields[ROLLOVER_FORM_PATHS.maxDocs].clearErrors(ROLLOVER_EMPTY_VALIDATION);
|
||||
|
|
Loading…
Reference in a new issue