From 0b469f5b3f121be0b945389ec385e54ea15f77eb Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Thu, 7 Nov 2024 14:36:30 -0500 Subject: [PATCH] feat(web): enhance notifications indicator in UPC (#950) * feat(web): scaffold ui for notifications indicator * refactor(web): poll for notification overview instead of subscription * test: rm failing notifications.resolver test stub * feat(web): pulse indicator when new notifications are received --- api/src/graphql/generated/client/gql.ts | 1 + .../graphql/generated/client/validators.ts | 1 + .../notifications.resolver.spec.ts | 18 ---- .../notifications/notifications.resolver.ts | 3 +- .../graph/resolvers/resolvers.module.ts | 2 +- web/components/Notifications/Indicator.vue | 98 +++++++++++++++++++ web/components/Notifications/Sidebar.vue | 3 +- .../graphql/notification.query.ts | 24 +++++ web/composables/gql/fragment-masking.ts | 26 ++++- web/composables/gql/gql.ts | 11 +++ web/composables/gql/graphql.ts | 11 ++- web/package-lock.json | 65 ++++++------ 12 files changed, 208 insertions(+), 55 deletions(-) delete mode 100644 api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.spec.ts create mode 100644 web/components/Notifications/Indicator.vue diff --git a/api/src/graphql/generated/client/gql.ts b/api/src/graphql/generated/client/gql.ts index b6b97e517..7ff96c0d5 100644 --- a/api/src/graphql/generated/client/gql.ts +++ b/api/src/graphql/generated/client/gql.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import * as types from './graphql.js'; import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; diff --git a/api/src/graphql/generated/client/validators.ts b/api/src/graphql/generated/client/validators.ts index c38bc5588..4bb0c65ba 100644 --- a/api/src/graphql/generated/client/validators.ts +++ b/api/src/graphql/generated/client/validators.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ import { z } from 'zod' import { AccessUrlInput, ArrayCapacityBytesInput, ArrayCapacityInput, ClientType, ConfigErrorState, DashboardAppsInput, DashboardArrayInput, DashboardCaseInput, DashboardConfigInput, DashboardDisplayInput, DashboardInput, DashboardOsInput, DashboardServiceInput, DashboardServiceUptimeInput, DashboardTwoFactorInput, DashboardTwoFactorLocalInput, DashboardTwoFactorRemoteInput, DashboardVarsInput, DashboardVersionsInput, DashboardVmsInput, EventType, Importance, NetworkInput, NotificationInput, NotificationStatus, PingEventSource, RegistrationState, RemoteAccessEventActionType, RemoteAccessInput, RemoteGraphQLClientInput, RemoteGraphQLEventType, RemoteGraphQLServerInput, ServerStatus, URL_TYPE, UpdateType } from '@app/graphql/generated/client/graphql' diff --git a/api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.spec.ts b/api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.spec.ts deleted file mode 100644 index d64e56a75..000000000 --- a/api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, type TestingModule } from '@nestjs/testing'; -import { NotificationsResolver } from './notifications.resolver'; - -describe('NotificationsResolver', () => { - let resolver: NotificationsResolver; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [NotificationsResolver], - }).compile(); - - resolver = module.get(NotificationsResolver); - }); - - it('should be defined', () => { - expect(resolver).toBeDefined(); - }); -}); diff --git a/api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts b/api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts index d20f65d05..76bf7c111 100644 --- a/api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts +++ b/api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts @@ -11,10 +11,11 @@ import { NotificationsService } from './notifications.service'; import { Importance } from '@app/graphql/generated/client/graphql'; import { AppError } from '@app/core/errors/app-error'; import { formatTimestamp } from '@app/utils'; +import {Inject} from "@nestjs/common"; @Resolver('Notifications') export class NotificationsResolver { - constructor(readonly notificationsService: NotificationsService) {} + constructor(@Inject('NOTIFICATIONS_SERVICE') readonly notificationsService: NotificationsService) {} /**============================================ * Queries diff --git a/api/src/unraid-api/graph/resolvers/resolvers.module.ts b/api/src/unraid-api/graph/resolvers/resolvers.module.ts index 6d7eec31f..f3651fd07 100644 --- a/api/src/unraid-api/graph/resolvers/resolvers.module.ts +++ b/api/src/unraid-api/graph/resolvers/resolvers.module.ts @@ -33,7 +33,7 @@ import { NotificationsService } from './notifications/notifications.service'; ServerResolver, VarsResolver, VmsResolver, - NotificationsService, + { provide: 'NOTIFICATIONS_SERVICE', useClass: NotificationsService }, ], }) export class ResolversModule {} diff --git a/web/components/Notifications/Indicator.vue b/web/components/Notifications/Indicator.vue new file mode 100644 index 000000000..8178f567a --- /dev/null +++ b/web/components/Notifications/Indicator.vue @@ -0,0 +1,98 @@ + + + diff --git a/web/components/Notifications/Sidebar.vue b/web/components/Notifications/Sidebar.vue index 6a044270b..08aed5af2 100644 --- a/web/components/Notifications/Sidebar.vue +++ b/web/components/Notifications/Sidebar.vue @@ -1,5 +1,4 @@