Skip to content

Commit d8ab8d2

Browse files
authored
Show endpoint in JSON preview of index lifecycle policy editor. (#42791) (#42896)
* Reduce tabs from 4 to 2. * Increase flyout width to 480px and remove overlay. * Show line numbers. * Use EuiCopy component. * Add description text. * Update title and endpoint when there is no name specified.
1 parent 624165d commit d8ab8d2

File tree

4 files changed

+65
-33
lines changed

4 files changed

+65
-33
lines changed

x-pack/legacy/plugins/index_lifecycle_management/public/sections/edit_policy/components/policy_json_flyout.js

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ import { i18n } from '@kbn/i18n';
99
import { FormattedMessage } from '@kbn/i18n/react';
1010
import PropTypes from 'prop-types';
1111
import { toastNotifications } from 'ui/notify';
12-
import copy from 'copy-to-clipboard';
1312

1413
import {
1514
EuiButton,
16-
EuiCodeBlock,
15+
EuiCodeEditor,
16+
EuiCopy,
17+
EuiFlyout,
1718
EuiFlyoutBody,
1819
EuiFlyoutFooter,
19-
EuiFlyout,
2020
EuiFlyoutHeader,
2121
EuiPortal,
22+
EuiSpacer,
23+
EuiText,
2224
EuiTitle,
2325
} from '@elastic/eui';
2426

@@ -27,55 +29,87 @@ export class PolicyJsonFlyout extends PureComponent {
2729
close: PropTypes.func.isRequired,
2830
lifecycle: PropTypes.object.isRequired,
2931
};
32+
3033
getEsJson({ phases }) {
3134
return JSON.stringify({
3235
policy: {
3336
phases
3437
}
35-
}, null, 4);
36-
}
37-
copyToClipboard(lifecycle) {
38-
copy(this.getEsJson(lifecycle));
39-
toastNotifications.add(i18n.translate(
40-
'xpack.indexLifecycleMgmt.editPolicy.policyJsonFlyout.copiedToClipboardMessage',
41-
{
42-
defaultMessage: 'JSON copied to clipboard'
43-
}
44-
));
38+
}, null, 2);
4539
}
40+
4641
render() {
4742
const { lifecycle, close, policyName } = this.props;
43+
const endpoint = `PUT _ilm/policy/${policyName || '{policyName}'}\n`;
44+
const request = `${endpoint}${this.getEsJson(lifecycle)}`;
4845

4946
return (
5047
<EuiPortal>
51-
<EuiFlyout maxWidth={400} ownFocus onClose={close}>
48+
<EuiFlyout maxWidth={480} onClose={close}>
5249
<EuiFlyoutHeader>
5350
<EuiTitle>
5451
<h2>
55-
<FormattedMessage
56-
id="xpack.indexLifecycleMgmt.policyJsonFlyout.title"
57-
defaultMessage="JSON for index lifecycle policy {policyName}"
58-
values={{ policyName }}
59-
/>
52+
{policyName ? (
53+
<FormattedMessage
54+
id="xpack.indexLifecycleMgmt.policyJsonFlyout.namedTitle"
55+
defaultMessage="Request for {policyName}"
56+
values={{ policyName }}
57+
/>
58+
) : (
59+
<FormattedMessage
60+
id="xpack.indexLifecycleMgmt.policyJsonFlyout.unnamedTitle"
61+
defaultMessage="Request"
62+
/>
63+
)}
6064
</h2>
6165
</EuiTitle>
6266
</EuiFlyoutHeader>
6367

6468
<EuiFlyoutBody>
65-
<EuiCodeBlock
66-
language="json"
67-
>
68-
{this.getEsJson(lifecycle)}
69-
</EuiCodeBlock>
69+
<EuiText>
70+
<p>
71+
<FormattedMessage
72+
id="xpack.indexLifecycleMgmt.policyJsonFlyout.descriptionText"
73+
defaultMessage="This is the underlying request to Elasticsearch that will create or update this index lifecycle policy."
74+
/>
75+
</p>
76+
</EuiText>
77+
78+
<EuiSpacer />
79+
80+
<EuiCodeEditor
81+
mode="json"
82+
theme="textmate"
83+
isReadOnly
84+
setOptions={{ maxLines: Infinity, useWorker: false }}
85+
value={request}
86+
editorProps={{
87+
$blockScrolling: Infinity
88+
}}
89+
/>
7090
</EuiFlyoutBody>
7191

7292
<EuiFlyoutFooter>
73-
<EuiButton onClick={() => this.copyToClipboard(lifecycle)}>
74-
<FormattedMessage
75-
id="xpack.indexLifecycleMgmt.policyJsonFlyout.copyToClipboardButton"
76-
defaultMessage="Copy to clipboard"
77-
/>
78-
</EuiButton>
93+
<EuiCopy textToCopy={request}>
94+
{copy => (
95+
<EuiButton
96+
onClick={() => {
97+
copy();
98+
toastNotifications.add(i18n.translate(
99+
'xpack.indexLifecycleMgmt.editPolicy.policyJsonFlyout.copiedToClipboardMessage',
100+
{
101+
defaultMessage: 'Request copied to clipboard'
102+
}
103+
));
104+
}}
105+
>
106+
<FormattedMessage
107+
id="xpack.indexLifecycleMgmt.policyJsonFlyout.copyToClipboardButton"
108+
defaultMessage="Copy to clipboard"
109+
/>
110+
</EuiButton>
111+
)}
112+
</EuiCopy>
79113
</EuiFlyoutFooter>
80114
</EuiFlyout>
81115
</EuiPortal>

x-pack/legacy/plugins/index_lifecycle_management/public/sections/edit_policy/edit_policy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export class EditPolicy extends Component {
336336
<EuiButtonEmpty onClick={this.showPolicyJsonFlyout}>
337337
<FormattedMessage
338338
id="xpack.indexLifecycleMgmt.editPolicy.showPolicyJsonButton"
339-
defaultMessage="Show JSON"
339+
defaultMessage="Show request"
340340
/>
341341
</EuiButtonEmpty>
342342
</EuiFlexItem>

x-pack/plugins/translations/translations/ja-JP.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4994,7 +4994,6 @@
49944994
"xpack.indexLifecycleMgmt.noMatch.noPolicicesDescription": "表示するポリシーがありません",
49954995
"xpack.indexLifecycleMgmt.optionalMessage": " (オプション)",
49964996
"xpack.indexLifecycleMgmt.policyJsonFlyout.copyToClipboardButton": "クリップボードにコピー",
4997-
"xpack.indexLifecycleMgmt.policyJsonFlyout.title": "インデックスライフサイクルポリシー {policyName} の JSON",
49984997
"xpack.indexLifecycleMgmt.policyTable.actionsButtonText": "アクション",
49994998
"xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.cancelButton": "キャンセル",
50004999
"xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.chooseTemplateLabel": "インデックステンプレート",

x-pack/plugins/translations/translations/zh-CN.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5137,7 +5137,6 @@
51375137
"xpack.indexLifecycleMgmt.noMatch.noPolicicesDescription": "没有要显示的策略",
51385138
"xpack.indexLifecycleMgmt.optionalMessage": " (可选)",
51395139
"xpack.indexLifecycleMgmt.policyJsonFlyout.copyToClipboardButton": "复制到剪贴板",
5140-
"xpack.indexLifecycleMgmt.policyJsonFlyout.title": "索引生命周期策略 “{policyName}” 的 JSON",
51415140
"xpack.indexLifecycleMgmt.policyTable.actionsButtonText": "操作",
51425141
"xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.cancelButton": "取消",
51435142
"xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.chooseTemplateLabel": "索引模板",

0 commit comments

Comments
 (0)