File tree Expand file tree Collapse file tree 3 files changed +49
-14
lines changed
x-pack/plugins/index_lifecycle_management
public/application/sections/edit_policy Expand file tree Collapse file tree 3 files changed +49
-14
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,34 @@ describe('edit policy', () => {
187187 save ( rendered ) ;
188188 expectedErrorMessages ( rendered , [ policyNameStartsWithUnderscoreErrorMessage ] ) ;
189189 } ) ;
190+ test ( 'should show correct json in policy flyout' , ( ) => {
191+ const rendered = mountWithIntl ( component ) ;
192+ findTestSubject ( rendered , 'requestButton' ) . simulate ( 'click' ) ;
193+ const json = rendered . find ( `code` ) . text ( ) ;
194+ const expected = `PUT _ilm/policy/<policyName>\n${ JSON . stringify (
195+ {
196+ policy : {
197+ phases : {
198+ hot : {
199+ min_age : '0ms' ,
200+ actions : {
201+ rollover : {
202+ max_age : '30d' ,
203+ max_size : '50gb' ,
204+ } ,
205+ set_priority : {
206+ priority : 100 ,
207+ } ,
208+ } ,
209+ } ,
210+ } ,
211+ } ,
212+ } ,
213+ null ,
214+ 2
215+ ) } `;
216+ expect ( json ) . toBe ( expected ) ;
217+ } ) ;
190218 } ) ;
191219 describe ( 'hot phase' , ( ) => {
192220 test ( 'should show errors when trying to save with no max size and no max age' , ( ) => {
Original file line number Diff line number Diff line change @@ -18,29 +18,35 @@ import {
1818 EuiText ,
1919 EuiTitle ,
2020} from '@elastic/eui' ;
21- import { Policy } from '../../../services/policies/types' ;
21+ import { Policy , PolicyFromES } from '../../../services/policies/types' ;
22+ import { serializePolicy } from '../../../services/policies/policy_serialization' ;
2223
2324interface Props {
2425 close : ( ) => void ;
2526 policy : Policy ;
27+ existingPolicy ?: PolicyFromES ;
2628 policyName : string ;
2729}
2830
29- export const PolicyJsonFlyout : React . FunctionComponent < Props > = ( { close, policy, policyName } ) => {
30- const getEsJson = ( { phases } : Policy ) => {
31- return JSON . stringify (
32- {
33- policy : {
34- phases,
35- } ,
31+ export const PolicyJsonFlyout : React . FunctionComponent < Props > = ( {
32+ close,
33+ policy,
34+ policyName,
35+ existingPolicy,
36+ } ) => {
37+ const { phases } = serializePolicy ( policy , existingPolicy ?. policy ) ;
38+ const json = JSON . stringify (
39+ {
40+ policy : {
41+ phases,
3642 } ,
37- null ,
38- 2
39- ) ;
40- } ;
43+ } ,
44+ null ,
45+ 2
46+ ) ;
4147
4248 const endpoint = `PUT _ilm/policy/${ policyName || '<policyName>' } ` ;
43- const request = `${ endpoint } \n${ getEsJson ( policy ) } ` ;
49+ const request = `${ endpoint } \n${ json } ` ;
4450
4551 return (
4652 < EuiFlyout maxWidth = { 480 } onClose = { close } >
Original file line number Diff line number Diff line change @@ -352,7 +352,7 @@ export const EditPolicy: React.FunctionComponent<Props> = ({
352352 </ EuiFlexItem >
353353
354354 < EuiFlexItem grow = { false } >
355- < EuiButtonEmpty onClick = { togglePolicyJsonFlyout } >
355+ < EuiButtonEmpty onClick = { togglePolicyJsonFlyout } data-test-subj = "requestButton" >
356356 { isShowingPolicyJsonFlyout ? (
357357 < FormattedMessage
358358 id = "xpack.indexLifecycleMgmt.editPolicy.hidePolicyJsonButto"
@@ -371,6 +371,7 @@ export const EditPolicy: React.FunctionComponent<Props> = ({
371371 { isShowingPolicyJsonFlyout ? (
372372 < PolicyJsonFlyout
373373 policyName = { policy . name || '' }
374+ existingPolicy = { existingPolicy }
374375 policy = { policy }
375376 close = { ( ) => setIsShowingPolicyJsonFlyout ( false ) }
376377 />
You can’t perform that action at this time.
0 commit comments