Skip to content

Commit

Permalink
[ILM] Fix bug when clearing priority field (#70154)
Browse files Browse the repository at this point in the history
# Conflicts:
#	x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts
#	x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx
#	x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts
#	x-pack/plugins/index_lifecycle_management/public/application/store/selectors/policies.js
  • Loading branch information
alisonelizabeth committed Jun 30, 2020
1 parent 0f68376 commit 165f8dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ import {
defaultEmptyHotPhase,
} from '../defaults';

export const getPolicies = (state) => state.policies.policies;
export const getPolicies = state => state.policies.policies;
export const getPolicyByName = (state, name) =>
getPolicies(state).find((policy) => policy.name === name) || {};
export const getIsNewPolicy = (state) => state.policies.selectedPolicy.isNew;
export const getSelectedPolicy = (state) => state.policies.selectedPolicy;
export const getIsSelectedPolicySet = (state) => state.policies.selectedPolicySet;
export const getSelectedOriginalPolicyName = (state) => state.policies.originalPolicyName;
export const getPolicyFilter = (state) => state.policies.filter;
export const getPolicySort = (state) => state.policies.sort;
export const getPolicyCurrentPage = (state) => state.policies.currentPage;
export const getPolicyPageSize = (state) => state.policies.pageSize;
export const isPolicyListLoaded = (state) => state.policies.isLoaded;
getPolicies(state).find(policy => policy.name === name) || {};
export const getIsNewPolicy = state => state.policies.selectedPolicy.isNew;
export const getSelectedPolicy = state => state.policies.selectedPolicy;
export const getIsSelectedPolicySet = state => state.policies.selectedPolicySet;
export const getSelectedOriginalPolicyName = state => state.policies.originalPolicyName;
export const getPolicyFilter = state => state.policies.filter;
export const getPolicySort = state => state.policies.sort;
export const getPolicyCurrentPage = state => state.policies.currentPage;
export const getPolicyPageSize = state => state.policies.pageSize;
export const isPolicyListLoaded = state => state.policies.isLoaded;

const getFilteredPolicies = createSelector(getPolicies, getPolicyFilter, (policies, filter) => {
return filterItems(['name'], filter, policies);
});
export const getTotalPolicies = createSelector(getFilteredPolicies, (filteredPolicies) => {
export const getTotalPolicies = createSelector(getFilteredPolicies, filteredPolicies => {
return filteredPolicies.length;
});
export const getPolicyPager = createSelector(
Expand All @@ -80,16 +80,16 @@ export const getPageOfPolicies = createSelector(
return pagedPolicies;
}
);
export const getSaveAsNewPolicy = (state) => state.policies.selectedPolicy.saveAsNew;
export const getSaveAsNewPolicy = state => state.policies.selectedPolicy.saveAsNew;

export const getSelectedPolicyName = (state) => {
export const getSelectedPolicyName = state => {
if (!getSaveAsNewPolicy(state)) {
return getSelectedOriginalPolicyName(state);
}
return state.policies.selectedPolicy.name;
};

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

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

Expand All @@ -100,7 +100,7 @@ export const getPhaseData = (state, phase, key) => {
return getPhase(state, phase)[key];
};

export const splitSizeAndUnits = (field) => {
export const splitSizeAndUnits = field => {
let size;
let units;

Expand All @@ -116,8 +116,8 @@ export const splitSizeAndUnits = (field) => {
};
};

export const isNumber = (value) => typeof value === 'number';
export const isEmptyObject = (obj) => {
export const isNumber = value => typeof value === 'number';
export const isEmptyObject = obj => {
return !obj || (Object.entries(obj).length === 0 && obj.constructor === Object);
};

Expand Down Expand Up @@ -166,7 +166,7 @@ const phaseFromES = (phase, phaseName, defaultEmptyPolicy) => {
if (actions.allocate) {
const allocate = actions.allocate;
if (allocate.require) {
Object.entries(allocate.require).forEach((entry) => {
Object.entries(allocate.require).forEach(entry => {
policy[PHASE_NODE_ATTRS] = entry.join(':');
});
// checking for null or undefined here
Expand All @@ -192,13 +192,15 @@ const phaseFromES = (phase, phaseName, defaultEmptyPolicy) => {
}

if (actions.set_priority) {
policy[PHASE_INDEX_PRIORITY] = actions.set_priority.priority;
const { priority } = actions.set_priority;

policy[PHASE_INDEX_PRIORITY] = priority ?? '';
}
}
return policy;
};

export const policyFromES = (policy) => {
export const policyFromES = policy => {
const {
name,
policy: { phases },
Expand Down Expand Up @@ -307,6 +309,10 @@ export const phaseToES = (phase, originalEsPhase) => {
esPhase.actions.set_priority = {
priority: phase[PHASE_INDEX_PRIORITY],
};
} else if (phase[PHASE_INDEX_PRIORITY] === '') {
esPhase.actions.set_priority = {
priority: null,
};
}
return esPhase;
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const minAgeSchema = schema.maybe(schema.string());

const setPrioritySchema = schema.maybe(
schema.object({
priority: schema.number(),
priority: schema.nullable(schema.number()),
})
);

Expand Down

0 comments on commit 165f8dd

Please sign in to comment.