Skip to content

Commit

Permalink
[ILM] Delete phase redesign (rework) (elastic#90291)
Browse files Browse the repository at this point in the history
* Phases redesign

* Fixed scss file

* Fixed errors

* Added changes for phase blocks

* Added styles adjustments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
yuliacech and kibanamachine committed Feb 9, 2021
1 parent 735d9a9 commit 5badc31
Show file tree
Hide file tree
Showing 34 changed files with 672 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,27 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
};
};

const createToggleDeletePhaseActions = () => {
const enablePhase = async () => {
await act(async () => {
find('enableDeletePhaseButton').simulate('click');
});
component.update();
};

const disablePhase = async () => {
await act(async () => {
find('disableDeletePhaseButton').simulate('click');
});
component.update();
};

return {
enablePhase,
disablePhase,
};
};

return {
...testBed,
actions: {
Expand Down Expand Up @@ -303,7 +324,7 @@ export const setup = async (arg?: { appServicesContext: Partial<AppServicesConte
...createSearchableSnapshotActions('cold'),
},
delete: {
enable: enable('delete'),
...createToggleDeletePhaseActions(),
setMinAgeValue: setMinAgeValue('delete'),
setMinAgeUnits: setMinAgeUnits('delete'),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('<EditPolicy />', () => {
// Set max docs to test whether we keep the unknown fields in that object after serializing
await actions.hot.setMaxDocs('1000');
// Remove the delete phase to ensure that we also correctly remove data
await actions.delete.enable(false);
await actions.delete.disablePhase();
await actions.savePolicy();

const latestRequest = server.requests[server.requests.length - 1];
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('<EditPolicy />', () => {
unknown_setting: true,
},
},
min_age: '0ms',
min_age: '0d',
},
},
});
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('<EditPolicy />', () => {
"priority": 50,
},
},
"min_age": "0ms",
"min_age": "0d",
}
`);
});
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('<EditPolicy />', () => {
"number_of_shards": 123,
},
},
"min_age": "0ms",
"min_age": "0d",
},
},
}
Expand Down Expand Up @@ -839,7 +839,7 @@ describe('<EditPolicy />', () => {
expect(actions.timeline.hasColdPhase()).toBe(true);
expect(actions.timeline.hasDeletePhase()).toBe(false);

await actions.delete.enable(true);
await actions.delete.enablePhase();
expect(actions.timeline.hasHotPhase()).toBe(true);
expect(actions.timeline.hasWarmPhase()).toBe(true);
expect(actions.timeline.hasColdPhase()).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ const activatePhase = async (rendered: ReactWrapper, phase: string) => {
});
rendered.update();
};
const activateDeletePhase = async (rendered: ReactWrapper) => {
const testSubject = `enableDeletePhaseButton`;
await act(async () => {
await findTestSubject(rendered, testSubject).simulate('click');
});
rendered.update();
};
const openNodeAttributesSection = async (rendered: ReactWrapper, phase: string) => {
const getControls = () => findTestSubject(rendered, `${phase}-dataTierAllocationControls`);
await act(async () => {
Expand Down Expand Up @@ -454,6 +461,11 @@ describe('edit policy', () => {
waitForFormLibValidation(rendered);
expectedErrorMessages(rendered, [i18nTexts.editPolicy.errors.nonNegativeNumberRequired]);
});

test("doesn't show min age input", async () => {
const rendered = mountWithIntl(component);
expect(findTestSubject(rendered, 'hot-selectedMinimumAge').exists()).toBeFalsy();
});
});
describe('warm phase', () => {
beforeEach(() => {
Expand Down Expand Up @@ -670,6 +682,13 @@ describe('edit policy', () => {
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeFalsy();
});

test('shows min age input only when enabled', async () => {
const rendered = mountWithIntl(component);
expect(findTestSubject(rendered, 'warm-selectedMinimumAge').exists()).toBeFalsy();
await activatePhase(rendered, 'warm');
expect(findTestSubject(rendered, 'warm-selectedMinimumAge').exists()).toBeTruthy();
});
});
describe('cold phase', () => {
beforeEach(() => {
Expand Down Expand Up @@ -807,13 +826,20 @@ describe('edit policy', () => {
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeFalsy();
});

test('shows min age input only when enabled', async () => {
const rendered = mountWithIntl(component);
expect(findTestSubject(rendered, 'cold-selectedMinimumAge').exists()).toBeFalsy();
await activatePhase(rendered, 'cold');
expect(findTestSubject(rendered, 'cold-selectedMinimumAge').exists()).toBeTruthy();
});
});
describe('delete phase', () => {
test('should allow 0 for phase timing', async () => {
const rendered = mountWithIntl(component);
await noRollover(rendered);
await setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'delete');
await activateDeletePhase(rendered);
await setPhaseAfter(rendered, 'delete', '0');
waitForFormLibValidation(rendered);
expectedErrorMessages(rendered, []);
Expand All @@ -822,11 +848,18 @@ describe('edit policy', () => {
const rendered = mountWithIntl(component);
await noRollover(rendered);
await setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'delete');
await activateDeletePhase(rendered);
await setPhaseAfter(rendered, 'delete', '-1');
waitForFormLibValidation(rendered);
expectedErrorMessages(rendered, [i18nTexts.editPolicy.errors.nonNegativeNumberRequired]);
});

test('is hidden when disabled', async () => {
const rendered = mountWithIntl(component);
expect(findTestSubject(rendered, 'delete-phaseContent').exists()).toBeFalsy();
await activateDeletePhase(rendered);
expect(findTestSubject(rendered, 'delete-phaseContent').exists()).toBeTruthy();
});
});
describe('not on cloud', () => {
beforeEach(() => {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* 2.0.
*/

export { ActiveBadge } from './active_badge';
export { LearnMoreLink } from './learn_more_link';
export { OptionalLabel } from './optional_label';
export { PolicyJsonFlyout } from './policy_json_flyout';
export { DescribedFormRow, ToggleFieldWithDescribedFormRow } from './described_form_row';
export { FieldLoadingError } from './field_loading_error';
export { ActiveHighlight } from './active_highlight';
export { Timeline } from './timeline';
export { FormErrorsCallout } from './form_errors_callout';

export { PhaseFooter } from './phase_footer';
export * from './phases';
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export { ActiveHighlight } from './active_highlight';
export { InfinityIcon } from './infinity_icon';
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
*/

import React, { FunctionComponent } from 'react';
import { EuiIcon, EuiIconProps } from '@elastic/eui';
import { InfinityIconSvg } from './infinity_icon.svg';

import './active_highlight.scss';

interface Props {
phase: 'hot' | 'warm' | 'cold';
enabled: boolean;
}
export const ActiveHighlight: FunctionComponent<Props> = ({ phase, enabled }) => {
return <div className={`ilmActivePhaseHighlight ${phase}Phase ${enabled ? 'active' : ''} `} />;
};
export const InfinityIcon: FunctionComponent<Omit<EuiIconProps, 'type'>> = (props) => (
<EuiIcon type={InfinityIconSvg} {...props} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { PhaseFooter } from './phase_footer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { FunctionComponent } from 'react';

import { i18n } from '@kbn/i18n';

import { EuiText, EuiButtonGroup, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

import { PhasesExceptDelete } from '../../../../../../common/types';

import { usePhaseTimings } from '../../form';

import { InfinityIconSvg } from '../infinity_icon/infinity_icon.svg';

interface Props {
phase: PhasesExceptDelete;
}

export const PhaseFooter: FunctionComponent<Props> = ({ phase }) => {
const {
isDeletePhaseEnabled,
setDeletePhaseEnabled: setValue,
[phase]: phaseConfiguration,
} = usePhaseTimings();

if (!phaseConfiguration.isFinalDataPhase) {
return null;
}

const phaseDescription = isDeletePhaseEnabled
? i18n.translate('xpack.indexLifecycleMgmt.editPolicy.phaseTiming.beforeDeleteDescription', {
defaultMessage: 'Data will be deleted after this phase',
})
: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.phaseTiming.foreverTimingDescription', {
defaultMessage: 'Data will remain in this phase forever',
});

const selectedButton = isDeletePhaseEnabled
? 'ilmEnableDeletePhaseButton'
: 'ilmDisableDeletePhaseButton';

const buttons = [
{
id: `ilmDisableDeletePhaseButton`,
label: i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.deletePhase.disablePhaseButtonLabel',
{
defaultMessage: 'Keep data in this phase forever',
}
),
iconType: InfinityIconSvg,
},
{
id: `ilmEnableDeletePhaseButton`,
label: i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.deletePhase.enablePhaseButtonLabel',
{
defaultMessage: 'Delete data after this phase',
}
),
iconType: 'trash',
'data-test-subj': 'enableDeletePhaseButton',
},
];

return (
<EuiFlexGroup alignItems="center" gutterSize="s" wrap>
<EuiFlexItem grow={false}>
<EuiText size="s" color="subdued">
{phaseDescription}
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonGroup
legend={i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.deletePhase.buttonGroupLegend',
{ defaultMessage: 'Enable or disable delete phase' }
)}
options={buttons}
idSelected={selectedButton}
onChange={(id) => {
setValue(id === 'ilmEnableDeletePhaseButton');
}}
isIconOnly={true}
/>
</EuiFlexItem>
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { PhaseIcon } from './phase_icon';
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.ilmPhaseIcon {
width: $euiSizeXL;
height: $euiSizeXL;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
background-color: $euiColorLightestShade;
&--disabled {
margin-top: $euiSizeS;
width: $euiSize;
height: $euiSize;
}
&--delete {
background-color: $euiColorLightShade;
}
&__inner--hot {
fill: $euiColorVis9_behindText;
}
&__inner--warm {
fill: $euiColorVis5_behindText;
}
&__inner--cold {
fill: $euiColorVis1_behindText;
}
&__inner--delete {
fill: $euiColorDarkShade;
}

&__inner--disabled {
fill: $euiColorMediumShade;
}
}
Loading

0 comments on commit 5badc31

Please sign in to comment.