Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mimse committed Oct 24, 2024
1 parent 2fca6d2 commit e9e4b94
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ type Mutation {
}

type NotificationDto {
notificationType: NotificationType!
id: Int!
notificationType: String!
occurredAt: DateTime!
expiresAt: DateTime!
relatedToId: String
Expand Down Expand Up @@ -1311,6 +1311,11 @@ enum MeteringGridImbalanceValuesToInclude {
BOTH
}

enum NotificationType {
BalanceResponsibilityValidationFailed
BalanceResponsibilityActorUnrecognized
}

enum OrganizationAuditedChange {
DOMAIN
NAME
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -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<NotificationDto>
{
protected override void Configure(
IObjectTypeDescriptor<NotificationDto> descriptor)
{
descriptor
.Field(x => x.NotificationType)
.Resolve(context =>
Enum.Parse<NotificationType>(context.Parent<NotificationDto>().NotificationType));
}
}
Original file line number Diff line number Diff line change
@@ -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<NotificationType>
{
protected override void Configure(IEnumTypeDescriptor<NotificationType> descriptor)
{
descriptor.AsIsCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand Down
50 changes: 48 additions & 2 deletions libs/dh/shared/data-access-mocks/src/lib/notifications-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e9e4b94

Please sign in to comment.