Skip to content

Commit

Permalink
[ILM] Surface shrink action in edit form if it's already been set on …
Browse files Browse the repository at this point in the history
…the policy (#35987) (#35992)

* Set PHASE_SHRINK_ENABLED to true if the action has been specified on the phase.
  • Loading branch information
cjcenizal authored May 3, 2019
1 parent 670e98b commit 126367d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/




import { connect } from 'react-redux';
import { WarmPhase as PresentationComponent } from './warm_phase';

import {
getPhase,
} from '../../../../store/selectors';
import { setPhaseData } from '../../../../store/actions';
import { PHASE_WARM, PHASE_HOT, PHASE_ROLLOVER_ENABLED } from '../../../../constants';
import { WarmPhase as PresentationComponent } from './warm_phase';

export const WarmPhase = connect(
state => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WarmPhaseUi extends PureComponent {
isShowingErrors: PropTypes.bool.isRequired,
errors: PropTypes.object.isRequired,
};

render() {
const {
setPhaseData,
Expand All @@ -50,18 +51,22 @@ class WarmPhaseUi extends PureComponent {
hotPhaseRolloverEnabled,
intl,
} = this.props;

const shrinkLabel = intl.formatMessage({
id: 'xpack.indexLifecycleMgmt.warmPhase.shrinkIndexLabel',
defaultMessage: 'Shrink index',
});

const moveToWarmPhaseOnRolloverLabel = intl.formatMessage({
id: 'xpack.indexLifecycleMgmt.warmPhase.moveToWarmPhaseOnRolloverLabel',
defaultMessage: 'Move to warm phase on rollover',
});

const forcemergeLabel = intl.formatMessage({
id: 'xpack.indexLifecycleMgmt.warmPhase.forceMergeDataLabel',
defaultMessage: 'Force merge data',
});

return (
<div id="warmPhaseContent" aria-live="polite" role="region" aria-relevant="additions">
<EuiDescribedFormGroup
Expand Down Expand Up @@ -221,6 +226,7 @@ class WarmPhaseUi extends PureComponent {
aria-label={shrinkLabel}
aria-controls="shrinkContent"
/>

<div id="shrinkContent" aria-live="polite" role="region">
{phaseData[PHASE_SHRINK_ENABLED] ? (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { connect } from 'react-redux';
import { EditPolicy as PresentationComponent } from './edit_policy';

import {
getSaveAsNewPolicy,
getSelectedPolicy,
Expand All @@ -16,14 +16,17 @@ import {
getIsNewPolicy,
getSelectedOriginalPolicyName
} from '../../store/selectors';

import {
setSelectedPolicy,
setSelectedPolicyName,
setSaveAsNewPolicy,
saveLifecyclePolicy,
fetchPolicies,
} from '../../store/actions';

import { findFirstError } from '../../services/find_errors';
import { EditPolicy as PresentationComponent } from './edit_policy';

export const EditPolicy = connect(
state => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { toastNotifications } from 'ui/notify';
import { goToPolicyList } from '../../services/navigation';
import { FormattedMessage, injectI18n } from '@kbn/i18n/react';

import {
EuiPage,
EuiPageBody,
Expand All @@ -26,22 +26,26 @@ import {
EuiFlexItem,
EuiDescribedFormGroup,
} from '@elastic/eui';
import { HotPhase } from './components/hot_phase';
import { WarmPhase } from './components/warm_phase';
import { DeletePhase } from './components/delete_phase';
import { ColdPhase } from './components/cold_phase';

import {
PHASE_HOT,
PHASE_COLD,
PHASE_DELETE,
PHASE_WARM,
STRUCTURE_POLICY_NAME,
} from '../../constants';

import { goToPolicyList } from '../../services/navigation';
import { findFirstError } from '../../services/find_errors';
import { LearnMoreLink } from '../components';
import { NodeAttrsDetails } from './components/node_attrs_details';
import { PolicyJsonFlyout } from './components/policy_json_flyout';
import { ErrableFormRow } from './form_errors';
import { LearnMoreLink } from '../components';
import { HotPhase } from './components/hot_phase';
import { WarmPhase } from './components/warm_phase';
import { DeletePhase } from './components/delete_phase';
import { ColdPhase } from './components/cold_phase';

class EditPolicyUi extends Component {
static propTypes = {
selectedPolicy: PropTypes.object.isRequired,
Expand All @@ -57,24 +61,30 @@ class EditPolicyUi extends Component {
isShowingPolicyJsonFlyout: false,
};
}

selectPolicy = policyName => {
const { setSelectedPolicy, policies } = this.props;

const selectedPolicy = policies.find(policy => {
return policy.name === policyName;
});

if (selectedPolicy) {
setSelectedPolicy(selectedPolicy);
}
};

componentDidMount() {
window.scrollTo(0, 0);

const {
isPolicyListLoaded,
fetchPolicies,
match: {
params: { policyName },
} = { params: {} },
} = this.props;

if (policyName) {
const decodedPolicyName = decodeURIComponent(policyName);
if (isPolicyListLoaded) {
Expand All @@ -88,10 +98,12 @@ class EditPolicyUi extends Component {
this.props.setSelectedPolicy(null);
}
}

backToPolicyList = () => {
this.props.setSelectedPolicy(null);
goToPolicyList();
};

submit = async () => {
const { intl } = this.props;
this.setState({ isShowingErrors: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/




export const getBootstrapEnabled = state => state.general.bootstrapEnabled;
export const getIndexName = state => state.general.indexName;
export const getAliasName = state => state.general.aliasName;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

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

import {
PHASE_HOT,
PHASE_WARM,
Expand All @@ -26,6 +28,7 @@ import {
PHASE_INDEX_PRIORITY,
PHASE_ROLLOVER_MAX_DOCUMENTS
} from '../../constants';

import {
getPhase,
getPhases,
Expand All @@ -36,28 +39,36 @@ import {
getSelectedOriginalPolicyName,
getPolicies
} from '.';

import { getPolicyByName } from './policies';

export const numberRequiredMessage = i18n.translate('xpack.indexLifecycleMgmt.editPolicy.numberRequiredError', {
defaultMessage: 'A number is required.'
});

export const positiveNumberRequiredMessage = i18n.translate('xpack.indexLifecycleMgmt.editPolicy.positiveNumberRequiredError', {
defaultMessage: 'Only positive numbers are allowed.'
});

export const maximumAgeRequiredMessage = i18n.translate('xpack.indexLifecycleMgmt.editPolicy.maximumAgeMissingError', {
defaultMessage: 'A maximum age is required.'
});

export const maximumSizeRequiredMessage =
i18n.translate('xpack.indexLifecycleMgmt.editPolicy.maximumIndexSizeMissingError', {
defaultMessage: 'A maximum index size is required.'
});

export const maximumDocumentsRequiredMessage =
i18n.translate('xpack.indexLifecycleMgmt.editPolicy.maximumDocumentsMissingError', {
defaultMessage: 'Maximum documents is required.'
});

export const positiveNumbersAboveZeroErrorMessage =
i18n.translate('xpack.indexLifecycleMgmt.editPolicy.positiveNumberAboveZeroRequiredError', {
defaultMessage: 'Only numbers above 0 are allowed.'
});

export const validatePhase = (type, phase, errors) => {
const phaseErrors = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { createSelector } from 'reselect';

export const getNodes = state => state.nodes.nodes;

export const getNodeOptions = createSelector(
[state => getNodes(state)],
nodes => {
Expand All @@ -30,9 +31,12 @@ export const getNodeOptions = createSelector(

export const getSelectedPrimaryShardCount = state =>
state.nodes.selectedPrimaryShardCount;

export const getSelectedReplicaCount = state =>
state.nodes.selectedReplicaCount !== undefined ? state.nodes.selectedReplicaCount : 1;

export const getSelectedNodeAttrs = state => state.nodes.selectedNodeAttrs;

export const getNodesFromSelectedNodeAttrs = state => {
const nodes = getNodes(state)[getSelectedNodeAttrs(state)];
if (nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/



import { createSelector } from 'reselect';
import { Pager } from '@elastic/eui';

import {
PHASE_HOT,
PHASE_WARM,
Expand All @@ -33,14 +32,15 @@ import {
PHASE_INDEX_PRIORITY,
PHASE_ROLLOVER_MAX_DOCUMENTS
} from '../../constants';

import { filterItems, sortTable } from '../../services';

import {
defaultEmptyDeletePhase,
defaultEmptyColdPhase,
defaultEmptyWarmPhase,
defaultEmptyHotPhase
} from '../defaults';
import { filterItems, sortTable } from '../../services';


export const getPolicies = state => state.policies.policies;
export const getPolicyByName = (state, name) => getPolicies(state).find((policy) => policy.name === name) || {};
Expand Down Expand Up @@ -97,8 +97,10 @@ export const getSelectedPolicyName = state => {
};

export const getPhases = state => state.policies.selectedPolicy.phases;

export const getPhase = (state, phase) =>
getPhases(state)[phase];

export const getPhaseData = (state, phase, key) => {
if (PHASE_ATTRIBUTES_THAT_ARE_NUMBERS.includes(key)) {
return parseInt(getPhase(state, phase)[key]);
Expand Down Expand Up @@ -127,7 +129,7 @@ export const isEmptyObject = (obj) => {
return !obj || (Object.entries(obj).length === 0 && obj.constructor === Object);
};

export const phaseFromES = (phase, phaseName, defaultEmptyPolicy) => {
const phaseFromES = (phase, phaseName, defaultEmptyPolicy) => {
const policy = { ...defaultEmptyPolicy };
if (!phase) {
return policy;
Expand Down Expand Up @@ -196,11 +198,14 @@ export const phaseFromES = (phase, phaseName, defaultEmptyPolicy) => {
}

if (actions.shrink) {
policy[PHASE_SHRINK_ENABLED] = true;
policy[PHASE_PRIMARY_SHARD_COUNT] = actions.shrink.number_of_shards;
}

if (actions.freeze) {
policy[PHASE_FREEZE_ENABLED] = true;
}

if (actions.set_priority) {
policy[PHASE_INDEX_PRIORITY] = actions.set_priority.priority;
}
Expand All @@ -210,6 +215,7 @@ export const phaseFromES = (phase, phaseName, defaultEmptyPolicy) => {

export const policyFromES = (policy) => {
const { name, policy: { phases } } = policy;

return {
name,
phases: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
indexLifecycleManagement
} from './reducers/';


export const indexLifecycleManagementStore = (initialState = {}) => {
const enhancers = [applyMiddleware(thunk)];

Expand Down

0 comments on commit 126367d

Please sign in to comment.