[8.6] [Enterprise Search] Add copy button for pipelines (#147712) (#147771)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Enterprise Search] Add copy button for pipelines
(#147712)](https://github.com/elastic/kibana/pull/147712)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sander
Philipse","email":"94373878+sphilipse@users.noreply.github.com"},"sourceCommit":{"committedDate":"2022-12-19T14:24:26Z","message":"[Enterprise
Search] Add copy button for pipelines (#147712)\n\nThis ensures the copy
button shows up for curl requests on the\r\nconnectors pipeline
page.","sha":"32de227cd1350dceffeae8b1093f4a81ad7103e9","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:EnterpriseSearch","v8.6.0","v8.7.0"],"number":147712,"url":"https://github.com/elastic/kibana/pull/147712","mergeCommit":{"message":"[Enterprise
Search] Add copy button for pipelines (#147712)\n\nThis ensures the copy
button shows up for curl requests on the\r\nconnectors pipeline
page.","sha":"32de227cd1350dceffeae8b1093f4a81ad7103e9"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/147712","number":147712,"mergeCommit":{"message":"[Enterprise
Search] Add copy button for pipelines (#147712)\n\nThis ensures the copy
button shows up for curl requests on the\r\nconnectors pipeline
page.","sha":"32de227cd1350dceffeae8b1093f4a81ad7103e9"}}]}] BACKPORT-->

Co-authored-by: Sander Philipse <94373878+sphilipse@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2022-12-19 11:36:29 -05:00 committed by GitHub
parent 6686c00b45
commit 3d1a52e139
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import React from 'react';
import React, { useEffect, useState } from 'react';
import {
EuiAccordion,
@ -32,6 +32,19 @@ export const DefaultPipelineItem: React.FC<{
pipelineName: string;
pipelineState: IngestPipelineParams;
}> = ({ index, indexName, ingestionMethod, openModal, pipelineName, pipelineState }) => {
/**
* If we don't open the accordion on load, the curl code never shows the copy button
* Because if the accordion is closed, the code block is not present in the DOM
* And EuiCodeBlock doesn't show the copy button if it's virtualized (ie not present in DOM)
* It doesn't re-evaluate whether it's present in DOM if the inner text doesn't change
* Opening and closing makes sure it's present in DOM on initial load, so the copy button shows
* We use setImmediate to then close it on the next javascript loop
*/
const [accordionOpen, setAccordionOpen] = useState<boolean>(true);
useEffect(() => {
setImmediate(() => setAccordionOpen(false));
}, []);
return (
<EuiFlexGroup direction="column" gutterSize="xs">
<EuiFlexItem>
@ -65,6 +78,8 @@ export const DefaultPipelineItem: React.FC<{
{ defaultMessage: 'Ingest a document using cURL' }
)}
id="ingestPipelinesCurlAccordion"
forceState={accordionOpen ? 'open' : 'closed'}
onClick={() => setAccordionOpen(!accordionOpen)}
>
<CurlRequest
document={{ body: 'body', title: 'Title' }}