Skip to content

Commit

Permalink
[ILM] Fix json in request flyout (#75971)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
yuliacech and elasticmachine authored Aug 27, 2020
1 parent ec15160 commit b802af8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,34 @@ describe('edit policy', () => {
save(rendered);
expectedErrorMessages(rendered, [policyNameStartsWithUnderscoreErrorMessage]);
});
test('should show correct json in policy flyout', () => {
const rendered = mountWithIntl(component);
findTestSubject(rendered, 'requestButton').simulate('click');
const json = rendered.find(`code`).text();
const expected = `PUT _ilm/policy/<policyName>\n${JSON.stringify(
{
policy: {
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_age: '30d',
max_size: '50gb',
},
set_priority: {
priority: 100,
},
},
},
},
},
},
null,
2
)}`;
expect(json).toBe(expected);
});
});
describe('hot phase', () => {
test('should show errors when trying to save with no max size and no max age', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,35 @@ import {
EuiText,
EuiTitle,
} from '@elastic/eui';
import { Policy } from '../../../services/policies/types';
import { Policy, PolicyFromES } from '../../../services/policies/types';
import { serializePolicy } from '../../../services/policies/policy_serialization';

interface Props {
close: () => void;
policy: Policy;
existingPolicy?: PolicyFromES;
policyName: string;
}

export const PolicyJsonFlyout: React.FunctionComponent<Props> = ({ close, policy, policyName }) => {
const getEsJson = ({ phases }: Policy) => {
return JSON.stringify(
{
policy: {
phases,
},
export const PolicyJsonFlyout: React.FunctionComponent<Props> = ({
close,
policy,
policyName,
existingPolicy,
}) => {
const { phases } = serializePolicy(policy, existingPolicy?.policy);
const json = JSON.stringify(
{
policy: {
phases,
},
null,
2
);
};
},
null,
2
);

const endpoint = `PUT _ilm/policy/${policyName || '<policyName>'}`;
const request = `${endpoint}\n${getEsJson(policy)}`;
const request = `${endpoint}\n${json}`;

return (
<EuiFlyout maxWidth={480} onClose={close}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export const EditPolicy: React.FunctionComponent<Props> = ({
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiButtonEmpty onClick={togglePolicyJsonFlyout}>
<EuiButtonEmpty onClick={togglePolicyJsonFlyout} data-test-subj="requestButton">
{isShowingPolicyJsonFlyout ? (
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.hidePolicyJsonButto"
Expand All @@ -371,6 +371,7 @@ export const EditPolicy: React.FunctionComponent<Props> = ({
{isShowingPolicyJsonFlyout ? (
<PolicyJsonFlyout
policyName={policy.name || ''}
existingPolicy={existingPolicy}
policy={policy}
close={() => setIsShowingPolicyJsonFlyout(false)}
/>
Expand Down

0 comments on commit b802af8

Please sign in to comment.