From 214db2afd5a46d95d53164d8fae834e265f4fad7 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 17 Feb 2023 17:33:45 +0200 Subject: [PATCH] RED-6170: fix notifications sorting --- .../notifications.component.html | 2 +- .../notifications/notifications.component.ts | 30 +++++++++++++++---- .../src/app/services/notifications.service.ts | 8 +---- apps/red-ui/src/assets/i18n/redact/de.json | 1 + apps/red-ui/src/assets/i18n/redact/en.json | 1 + apps/red-ui/src/assets/i18n/scm/de.json | 1 + apps/red-ui/src/assets/i18n/scm/en.json | 1 + .../lib/notifications/notification.model.ts | 2 +- 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/apps/red-ui/src/app/components/notifications/notifications.component.html b/apps/red-ui/src/app/components/notifications/notifications.component.html index 1ed50b65c..518a46c85 100644 --- a/apps/red-ui/src/app/components/notifications/notifications.component.html +++ b/apps/red-ui/src/app/components/notifications/notifications.component.html @@ -29,7 +29,7 @@
-
{{ notification.time }}
+
{{ notification.creationDate | date : 'exactDate' }}
; readonly groupedNotifications$: Observable; - constructor(private readonly _notificationsService: NotificationsService, private readonly _datePipe: DatePipe) { + constructor( + private readonly _notificationsService: NotificationsService, + private readonly _datePipe: DatePipe, + private readonly _translateService: TranslateService, + ) { this.groupedNotifications$ = this._notificationsService.all$.pipe(map(notifications => this.#groupNotifications(notifications))); this.hasUnreadNotifications$ = this.#hasUnreadNotifications$; } @@ -51,12 +60,21 @@ export class NotificationsComponent { } #groupNotifications(notifications: Notification[]): NotificationsGroup[] { - const grouped = [ - ...notifications.groupBy(n => (isToday(n.creationDate) ? n.creationDate : n.creationDate.split('T')[0])).entries(), - ]; + const todayTranslation = this._translateService.instant('today'); + const groupedMap = notifications.groupBy(n => { + if (isOlderThan(n.creationDate, 2)) { + return dayjs(n.creationDate).year().toString(); + } else if (isOlderThan(n.creationDate, 1)) { + return dayjs(n.creationDate).format('YYYY-MM'); + } + + return n.creationDate.split('T')[0]; + }); + + const grouped = [...groupedMap.entries()]; const sorted = grouped.sort(([aDate], [bDate]) => chronologically(aDate, bDate)); return sorted.map(([date, _notifications]) => ({ - date: this._datePipe.transform(date, 'sophisticatedDate'), + date: isToday(date) ? todayTranslation : this._datePipe.transform(date, 'sophisticatedDate'), notifications: _notifications.sort((a, b) => chronologically(a.creationDate, b.creationDate)), })); } diff --git a/apps/red-ui/src/app/services/notifications.service.ts b/apps/red-ui/src/app/services/notifications.service.ts index 86d468ba5..b4187e969 100644 --- a/apps/red-ui/src/app/services/notifications.service.ts +++ b/apps/red-ui/src/app/services/notifications.service.ts @@ -7,7 +7,6 @@ import { map, switchMap, tap } from 'rxjs/operators'; import { notificationsTranslations } from '@translations/notifications-translations'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { UserService } from '@users/user.service'; -import dayjs from 'dayjs'; import { CHANGED_CHECK_INTERVAL } from '@utils/constants'; import { DossiersCacheService } from './dossiers/dossiers-cache.service'; @@ -71,12 +70,7 @@ export class NotificationsService extends EntitiesService