From 6da544ac0cb8967490f00286a8bd2934e653cbbc Mon Sep 17 00:00:00 2001 From: Henry Taeschner Date: Sat, 26 Oct 2024 18:11:51 +0200 Subject: [PATCH] fix: moved convertLineBreaks to utils --- .../announcement-banner/announcement-banner.component.ts | 7 ++----- .../announcement-list-active.component.ts | 8 ++------ src/app/shared/utils.spec.ts | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/app/remotes/announcement-banner/announcement-banner.component.ts b/src/app/remotes/announcement-banner/announcement-banner.component.ts index 549377a..fbac202 100644 --- a/src/app/remotes/announcement-banner/announcement-banner.component.ts +++ b/src/app/remotes/announcement-banner/announcement-banner.component.ts @@ -27,6 +27,7 @@ import { Configuration } from 'src/app/shared/generated' import { SharedModule } from 'src/app/shared/shared.module' +import { convertLineBreaks } from 'src/app/shared/utils' import { environment } from 'src/environments/environment' @Component({ @@ -58,6 +59,7 @@ export class OneCXAnnouncementBannerComponent implements ocxRemoteComponent, ocx private currentDate = new Date().toISOString() private announcementsSubject = new BehaviorSubject([]) public announcements$: Observable = this.announcementsSubject.asObservable() + convertLineBreaks = convertLineBreaks constructor( @Inject(BASE_URL) private readonly baseUrl: ReplaySubject, @@ -141,9 +143,4 @@ export class OneCXAnnouncementBannerComponent implements ocxRemoteComponent, ocx return [] } } - - // display simple formatted text - public convertLineBreaks(text?: string) { - return text?.replace(/(?:\r\n|\r|\n)/g, '
') ?? '' - } } diff --git a/src/app/remotes/announcement-list-active/announcement-list-active.component.ts b/src/app/remotes/announcement-list-active/announcement-list-active.component.ts index ea718f6..2dbadd2 100644 --- a/src/app/remotes/announcement-list-active/announcement-list-active.component.ts +++ b/src/app/remotes/announcement-list-active/announcement-list-active.component.ts @@ -22,7 +22,7 @@ import { } from '@onecx/portal-integration-angular' import { SharedModule } from 'src/app/shared/shared.module' -import { copyToClipboard } from 'src/app/shared/utils' +import { convertLineBreaks, copyToClipboard } from 'src/app/shared/utils' import { AnnouncementAbstract, AnnouncementInternalAPIService, Configuration } from 'src/app/shared/generated' import { environment } from 'src/environments/environment' @@ -53,6 +53,7 @@ export class OneCXAnnouncementListActiveComponent implements ocxRemoteComponent, public announcements$: Observable = this.announcementsSubject.asObservable() public displayDetailDialog = false copyToClipboard = copyToClipboard + convertLineBreaks = convertLineBreaks constructor( @Inject(BASE_URL) private readonly baseUrl: ReplaySubject, @@ -107,9 +108,4 @@ export class OneCXAnnouncementListActiveComponent implements ocxRemoteComponent, }) ) } - - // display simple formatted text - public convertLineBreaks(text?: string) { - return text?.replace(/(?:\r\n|\r|\n)/g, '
') ?? '' - } } diff --git a/src/app/shared/utils.spec.ts b/src/app/shared/utils.spec.ts index 2e26de4..8b5d9cc 100644 --- a/src/app/shared/utils.spec.ts +++ b/src/app/shared/utils.spec.ts @@ -108,7 +108,7 @@ describe('util functions', () => { }) }) - describe('sortByLocale', () => { + describe('convertLineBreaks', () => { it('should convert line breaks to br', () => { const text = '123\r456'