From ef4eae65201be653996d91e339e70375b9fcb601 Mon Sep 17 00:00:00 2001 From: alex <48489896+devnaumov@users.noreply.github.com> Date: Wed, 15 Feb 2023 09:11:58 +0100 Subject: [PATCH] CB-3111 preserve leading spaces (#1458) --- webapp/packages/core-utils/src/index.ts | 3 ++- .../core-utils/src/removeLineBreak.test.ts | 17 +++++++++++++++++ .../packages/core-utils/src/removeLineBreak.ts | 11 +++++++++++ .../src/styles/base.scss | 2 +- .../Actions/ResultSet/ResultSetFormatAction.ts | 11 ++++++----- 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 webapp/packages/core-utils/src/removeLineBreak.test.ts create mode 100644 webapp/packages/core-utils/src/removeLineBreak.ts diff --git a/webapp/packages/core-utils/src/index.ts b/webapp/packages/core-utils/src/index.ts index 6963d638b3..12c1aece5b 100644 --- a/webapp/packages/core-utils/src/index.ts +++ b/webapp/packages/core-utils/src/index.ts @@ -51,4 +51,5 @@ export * from './svgToDataUri'; export * from './uriToBlob'; export * from './utf8ToBase64'; export * from './createLastPromiseGetter'; -export * from './removeMetadataFromBase64'; \ No newline at end of file +export * from './removeMetadataFromBase64'; +export * from './removeLineBreak'; \ No newline at end of file diff --git a/webapp/packages/core-utils/src/removeLineBreak.test.ts b/webapp/packages/core-utils/src/removeLineBreak.test.ts new file mode 100644 index 0000000000..52c0512a0b --- /dev/null +++ b/webapp/packages/core-utils/src/removeLineBreak.test.ts @@ -0,0 +1,17 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2022 DBeaver Corp and others + * + * Licensed under the Apache License, Version 2.0. + * you may not use this file except in compliance with the License. + */ + +import { removeLineBreak } from './removeLineBreak'; + +describe('removeLineBreak', () => { + it('should remove line break characters from a string', () => { + const input = 'This is a\r\ntest string\nwith line breaks\r.'; + const expectedOutput = 'This is atest stringwith line breaks.'; + expect(removeLineBreak(input)).toEqual(expectedOutput); + }); +}); \ No newline at end of file diff --git a/webapp/packages/core-utils/src/removeLineBreak.ts b/webapp/packages/core-utils/src/removeLineBreak.ts new file mode 100644 index 0000000000..8f346b8e78 --- /dev/null +++ b/webapp/packages/core-utils/src/removeLineBreak.ts @@ -0,0 +1,11 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2022 DBeaver Corp and others + * + * Licensed under the Apache License, Version 2.0. + * you may not use this file except in compliance with the License. + */ + +export function removeLineBreak(value: string) { + return value.replace(/\r?\n|\r/g, ''); +} \ No newline at end of file diff --git a/webapp/packages/plugin-data-spreadsheet-new/src/styles/base.scss b/webapp/packages/plugin-data-spreadsheet-new/src/styles/base.scss index ac0764ccf3..3e9f1c3316 100644 --- a/webapp/packages/plugin-data-spreadsheet-new/src/styles/base.scss +++ b/webapp/packages/plugin-data-spreadsheet-new/src/styles/base.scss @@ -44,7 +44,7 @@ .text-formatter__value { overflow: hidden; - white-space: nowrap; + white-space: pre; text-overflow: ellipsis; } diff --git a/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction.ts b/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction.ts index 43da51673d..8d581beb92 100644 --- a/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction.ts +++ b/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction.ts @@ -7,6 +7,7 @@ */ import { ResultDataFormat } from '@cloudbeaver/core-sdk'; +import { removeLineBreak } from '@cloudbeaver/core-utils'; import { DatabaseDataAction } from '../../DatabaseDataAction'; import type { IDatabaseDataSource } from '../../IDatabaseDataSource'; @@ -130,14 +131,14 @@ export class ResultSetFormatAction extends DatabaseDataAction 1000) { - return value.split('').map(v => (v.charCodeAt(0) < 32 ? ' ' : v)).join(''); - } - if (value === null) { return '[null]'; } - return String(value); + if (typeof value === 'string' && value.length > 1000) { + return removeLineBreak(value.split('').map(v => (v.charCodeAt(0) < 32 ? ' ' : v)).join('')); + } + + return removeLineBreak(String(value)); } }