diff --git a/src/plugins/discover/public/application/angular/doc_table/components/table_row/_cell.scss b/src/plugins/discover/public/application/angular/doc_table/components/table_row/_cell.scss index 22b6e0f29268b..e175a2f3383e2 100644 --- a/src/plugins/discover/public/application/angular/doc_table/components/table_row/_cell.scss +++ b/src/plugins/discover/public/application/angular/doc_table/components/table_row/_cell.scss @@ -1,3 +1,7 @@ +.kbnDocTableCell__dataField { + white-space: pre-wrap; +} + .kbnDocTableCell__toggleDetails { padding: $euiSizeXS 0 0 0!important; } diff --git a/test/functional/apps/discover/_doc_table_newline.ts b/test/functional/apps/discover/_doc_table_newline.ts new file mode 100644 index 0000000000000..cdb1496413484 --- /dev/null +++ b/test/functional/apps/discover/_doc_table_newline.ts @@ -0,0 +1,49 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); + const kibanaServer = getService('kibanaServer'); + const PageObjects = getPageObjects(['common', 'discover']); + const find = getService('find'); + const log = getService('log'); + const retry = getService('retry'); + const security = getService('security'); + + describe('discover doc table newline handling', function describeIndexTests() { + before(async function () { + await security.testUser.setRoles(['kibana_admin', 'kibana_message_with_newline']); + await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/message_with_newline'); + await kibanaServer.uiSettings.replace({ + defaultIndex: 'newline-test', + 'doc_table:legacy': true, + }); + await PageObjects.common.navigateToApp('discover'); + }); + after(async () => { + await security.testUser.restoreDefaults(); + esArchiver.unload('test/functional/fixtures/es_archiver/message_with_newline'); + await kibanaServer.uiSettings.unset('defaultIndex'); + await kibanaServer.uiSettings.unset('doc_table:legacy'); + }); + + it('should break text on newlines', async function () { + await PageObjects.discover.clickFieldListItemToggle('message'); + const dscTableRows = await find.allByCssSelector('.kbnDocTable__row'); + + await retry.waitFor('height of multi-line content > single-line content', async () => { + const heightWithoutNewline = await dscTableRows[0].getAttribute('clientHeight'); + const heightWithNewline = await dscTableRows[1].getAttribute('clientHeight'); + log.debug(`Without newlines: ${heightWithoutNewline}, With newlines: ${heightWithNewline}`); + return Number(heightWithNewline) > Number(heightWithoutNewline); + }); + }); + }); +} diff --git a/test/functional/apps/discover/index.ts b/test/functional/apps/discover/index.ts index 869fb625e8796..b396f172f6961 100644 --- a/test/functional/apps/discover/index.ts +++ b/test/functional/apps/discover/index.ts @@ -27,6 +27,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./_discover')); loadTestFile(require.resolve('./_discover_histogram')); loadTestFile(require.resolve('./_doc_table')); + loadTestFile(require.resolve('./_doc_table_newline')); loadTestFile(require.resolve('./_filter_editor')); loadTestFile(require.resolve('./_errors')); loadTestFile(require.resolve('./_field_data')); diff --git a/test/functional/config.js b/test/functional/config.js index 670488003e56c..c2c856517c58e 100644 --- a/test/functional/config.js +++ b/test/functional/config.js @@ -247,6 +247,20 @@ export default async function ({ readConfigFile }) { }, kibana: [], }, + kibana_message_with_newline: { + elasticsearch: { + cluster: [], + indices: [ + { + names: ['message_with_newline'], + privileges: ['read', 'view_index_metadata'], + field_security: { grant: ['*'], except: [] }, + }, + ], + run_as: [], + }, + kibana: [], + }, kibana_timefield: { elasticsearch: { diff --git a/test/functional/fixtures/es_archiver/message_with_newline/data.json b/test/functional/fixtures/es_archiver/message_with_newline/data.json new file mode 100644 index 0000000000000..3611f2d3878a4 --- /dev/null +++ b/test/functional/fixtures/es_archiver/message_with_newline/data.json @@ -0,0 +1,36 @@ +{ + "type": "doc", + "value": { + "id": "index-pattern:newline-test", + "index": ".kibana", + "source": { + "index-pattern": { + "fields": "[]", + "title": "newline-test" + }, + "type": "index-pattern" + } + } +} + +{ + "type": "doc", + "value": { + "id": "1", + "index": "newline-test", + "source": { + "message" : "no new line" + } + } +} + +{ + "type": "doc", + "value": { + "id": "2", + "index": "newline-test", + "source": { + "message" : "two\nnew\nlines" + } + } +} diff --git a/test/functional/fixtures/es_archiver/message_with_newline/mappings.json b/test/functional/fixtures/es_archiver/message_with_newline/mappings.json new file mode 100644 index 0000000000000..3e2db145e7e3b --- /dev/null +++ b/test/functional/fixtures/es_archiver/message_with_newline/mappings.json @@ -0,0 +1,12 @@ +{ + "type": "index", + "value": { + "index": "newline-test", + "settings": { + "index": { + "number_of_replicas": "0", + "number_of_shards": "1" + } + } + } +}