Skip to content

Commit

Permalink
[Ingest Pipelines] Replace newline character to make flyout details m…
Browse files Browse the repository at this point in the history
…ore readable (#182640)
  • Loading branch information
sabarasaba authored May 13, 2024
1 parent a7423bb commit 781b5ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ export type PipelineListTestSubjects =
| 'emptyList.title'
| 'sectionLoading'
| 'pipelineLoadError'
| 'jsonCodeBlock'
| 'reloadButton';
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ describe('<PipelinesList />', () => {
const pipeline3 = {
name: 'test_pipeline3',
description: 'test_pipeline3 description',
processors: [],
processors: [
{
script: {
lang: 'painless',
source: `String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);\nArrayList tags = new ArrayList();\ntags.add(envSplit[params['position']].trim());\nctx['tags'] = tags;`,
params: {
delimiter: '-',
position: 1,
},
},
},
],
deprecated: true,
};

Expand Down Expand Up @@ -123,6 +134,14 @@ describe('<PipelinesList />', () => {
expect(find('pipelineDetails.title').text()).toBe(pipeline1.name);
});

test('Replaces newline characters for spaces in flyout for json blocks', async () => {
const { find, actions } = testBed;

await actions.clickPipelineAt(1);

expect(find('jsonCodeBlock').text()).not.toContain(`\n`);
});

test('should delete a pipeline', async () => {
const { actions, component } = testBed;
const { name: pipelineName } = pipeline1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ export const PipelineDetailsJsonBlock: FunctionComponent<Props> = ({ json }) =>
const uuid = useRef(0);
uuid.current++;

// Convert JSON object to string
const jsonString = JSON.stringify(json, null, 2);
// Replace all newline characters with empty spaces
const formattedString = jsonString.replace(/\\n/g, ' ');

return (
<EuiCodeBlock
paddingSize="s"
language="json"
overflowHeight={json.length > 0 ? 300 : undefined}
isCopyable
key={uuid.current}
data-test-subj="jsonCodeBlock"
>
{JSON.stringify(json, null, 2)}
{formattedString}
</EuiCodeBlock>
);
};

0 comments on commit 781b5ee

Please sign in to comment.