diff --git a/apps/dh/api-dh/source/DataHub.WebApi.Tests/Snapshots/SchemaTests.ChangeTest.verified.graphql b/apps/dh/api-dh/source/DataHub.WebApi.Tests/Snapshots/SchemaTests.ChangeTest.verified.graphql index c99e47c9da..a3b71e756f 100644 --- a/apps/dh/api-dh/source/DataHub.WebApi.Tests/Snapshots/SchemaTests.ChangeTest.verified.graphql +++ b/apps/dh/api-dh/source/DataHub.WebApi.Tests/Snapshots/SchemaTests.ChangeTest.verified.graphql @@ -448,8 +448,8 @@ type Mutation { } type NotificationDto { + notificationType: NotificationType! id: Int! - notificationType: String! occurredAt: DateTime! expiresAt: DateTime! relatedToId: String @@ -1311,6 +1311,11 @@ enum MeteringGridImbalanceValuesToInclude { BOTH } +enum NotificationType { + BalanceResponsibilityValidationFailed + BalanceResponsibilityActorUnrecognized +} + enum OrganizationAuditedChange { DOMAIN NAME diff --git a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Enums/NotificationType.cs b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Enums/NotificationType.cs new file mode 100644 index 0000000000..63a3883476 --- /dev/null +++ b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Enums/NotificationType.cs @@ -0,0 +1,21 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Energinet.DataHub.WebApi.GraphQL.Enums; + +public enum NotificationType +{ + BalanceResponsibilityValidationFailed = 1, + BalanceResponsibilityActorUnrecognized = 2, +} diff --git a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Notification/NotificationDtoType.cs b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Notification/NotificationDtoType.cs new file mode 100644 index 0000000000..65784ee1ca --- /dev/null +++ b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Notification/NotificationDtoType.cs @@ -0,0 +1,30 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Energinet.DataHub.WebApi.Clients.Notifications.Dto; +using Energinet.DataHub.WebApi.GraphQL.Enums; + +namespace Energinet.DataHub.WebApi.GraphQL.Types.Notification; + +public class NotificationDtoType : ObjectType +{ + protected override void Configure( + IObjectTypeDescriptor descriptor) + { + descriptor + .Field(x => x.NotificationType) + .Resolve(context => + Enum.Parse(context.Parent().NotificationType)); + } +} diff --git a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Notification/NotificationEnumType.cs b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Notification/NotificationEnumType.cs new file mode 100644 index 0000000000..ead81366a8 --- /dev/null +++ b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Notification/NotificationEnumType.cs @@ -0,0 +1,26 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Energinet.DataHub.WebApi.GraphQL.Enums; +using Energinet.DataHub.WebApi.GraphQL.Extensions; + +namespace Energinet.DataHub.WebApi.GraphQL.Types.Notification; + +public class NotificationEnumType : EnumType +{ + protected override void Configure(IEnumTypeDescriptor descriptor) + { + descriptor.AsIsCase(); + } +} diff --git a/libs/dh/core/feature-notifications/src/lib/dh-notifications-center.component.ts b/libs/dh/core/feature-notifications/src/lib/dh-notifications-center.component.ts index 6945a42947..9a843dc4f4 100644 --- a/libs/dh/core/feature-notifications/src/lib/dh-notifications-center.component.ts +++ b/libs/dh/core/feature-notifications/src/lib/dh-notifications-center.component.ts @@ -143,7 +143,11 @@ export class DhNotificationsCenterComponent { isOpen = false; - notifications = computed(() => this.getNotificationsQuery.data()?.notifications ?? []); + notifications = computed(() => { + const notifications = structuredClone(this.getNotificationsQuery.data()?.notifications ?? []); + notifications.sort((a, b) => b.id - a.id); + return notifications; + }); constructor() { this.getNotificationsQuery.subscribeToMore({ @@ -156,9 +160,9 @@ export class DhNotificationsCenterComponent { this.bannerService.showBanner(incomingNotification); } - const notifications = [...pref.notifications, incomingNotification].filter( - (value, index, self) => self.findIndex((n) => n.id === value.id) === index - ); + const notifications = [...pref.notifications, incomingNotification] + .filter((value, index, self) => self.findIndex((n) => n.id === value.id) === index) + .sort((a, b) => b.id - a.id); return { ...pref, diff --git a/libs/dh/shared/data-access-mocks/src/lib/notifications-mocks.ts b/libs/dh/shared/data-access-mocks/src/lib/notifications-mocks.ts index 9716410c07..35dbc6864d 100644 --- a/libs/dh/shared/data-access-mocks/src/lib/notifications-mocks.ts +++ b/libs/dh/shared/data-access-mocks/src/lib/notifications-mocks.ts @@ -16,11 +16,57 @@ */ import { HttpResponse, delay } from 'msw'; -import { mockDismissNotificationMutation } from '@energinet-datahub/dh/shared/domain/graphql'; +import { + mockDismissNotificationMutation, + mockGetNotificationsQuery, + NotificationType, +} from '@energinet-datahub/dh/shared/domain/graphql'; import { mswConfig } from '@energinet-datahub/gf/util-msw'; export function notificationsMocks() { - return [dismissNotification()]; + return [dismissNotification(), getNotifications()]; +} + +function getNotifications() { + return mockGetNotificationsQuery(async () => { + await delay(mswConfig.delay); + + return HttpResponse.json({ + data: { + __typename: 'Query', + notifications: [ + { + __typename: 'NotificationDto', + id: 1, + notificationType: NotificationType.BalanceResponsibilityValidationFailed, + relatedToId: '1', + occurredAt: new Date(), + }, + { + __typename: 'NotificationDto', + id: 4, + notificationType: NotificationType.BalanceResponsibilityValidationFailed, + relatedToId: '4', + occurredAt: new Date(), + }, + { + __typename: 'NotificationDto', + id: 3, + notificationType: NotificationType.BalanceResponsibilityValidationFailed, + relatedToId: '3', + occurredAt: new Date(), + }, + { + __typename: 'NotificationDto', + id: 6, + notificationType: NotificationType.BalanceResponsibilityValidationFailed, + relatedToId: '6', + occurredAt: new Date(), + }, + ], + }, + }); + }); } function dismissNotification() {