From 37117599ac7d29eb06d533987ab880e7bba1dffe Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Mon, 19 Aug 2024 14:32:35 +0200 Subject: [PATCH 1/3] feat: :sparkles: add support for different link types in feature announcements --- .../services/feature-announcements.ts | 33 +++++++++++++++- .../feature-announcement.ts | 26 ++++++++----- .../type-feature-announcement.ts | 16 +++++--- .../types/feature-announcement/type-links.ts | 38 ++++++++++++------- 4 files changed, 82 insertions(+), 31 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts b/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts index 957ea79848..125969eb73 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts @@ -8,7 +8,11 @@ import type { ImageFields, TypeFeatureAnnouncement, } from '../types/feature-announcement/type-feature-announcement'; +import type { TypeExternalLinkFields } from '../types/feature-announcement/type-links'; +import type { TypePortfolioLinkFields } from '../types/feature-announcement/type-links'; import type { TypeExtensionLinkFields } from '../types/feature-announcement/type-links'; +import type { TypeMobileLinkFields } from '../types/feature-announcement/type-links'; + import type { INotification } from '../types/notification/notification'; const DEFAULT_SPACE_ID = ':space_id'; @@ -55,7 +59,7 @@ const fetchFeatureAnnouncementNotifications = async ( } const findIncludedItem = (sysId: string) => { - const typedData: EntryCollection = + const typedData: EntryCollection = data; const item = typedData?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) || @@ -71,11 +75,26 @@ const fetchFeatureAnnouncementNotifications = async ( ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields']) : undefined; + const externalLinkFields = fields.externalLink + ? (findIncludedItem( + fields.externalLink.sys.id, + ) as TypeExternalLinkFields['fields']) + : undefined; + const portfolioLinkFields = fields.portfolioLink + ? (findIncludedItem( + fields.portfolioLink.sys.id, + ) as TypePortfolioLinkFields['fields']) + : undefined; const extensionLinkFields = fields.extensionLink ? (findIncludedItem( fields.extensionLink.sys.id, ) as TypeExtensionLinkFields['fields']) : undefined; + const mobileLinkFields = fields.mobileLink + ? (findIncludedItem( + fields.mobileLink.sys.id, + ) as TypeMobileLinkFields['fields']) + : undefined; const notification: FeatureAnnouncementRawNotification = { type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT, @@ -91,10 +110,22 @@ const fetchFeatureAnnouncementNotifications = async ( description: imageFields?.description, url: imageFields?.file?.url ?? '', }, + externalLink: externalLinkFields && { + externalLinkText: externalLinkFields?.externalLinkText, + externalLinkUrl: externalLinkFields?.externalLinkUrl, + }, + portfolioLink: portfolioLinkFields && { + portfolioLinkText: portfolioLinkFields?.portfolioLinkText, + portfolioLinkUrl: portfolioLinkFields?.portfolioLinkUrl, + }, extensionLink: extensionLinkFields && { extensionLinkText: extensionLinkFields?.extensionLinkText, extensionLinkRoute: extensionLinkFields?.extensionLinkRoute, }, + mobileLink: mobileLinkFields && { + mobileLinkText: mobileLinkFields?.mobileLinkText, + mobileLinkUrl: mobileLinkFields?.mobileLinkUrl, + }, }, }; diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts index 65076340bb..0a17f3817d 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts @@ -11,17 +11,17 @@ export type FeatureAnnouncementRawNotificationData = Omit< description?: string; url: string; }; - - // Portfolio Links - link?: { - linkText: string; - linkUrl: string; - isExternal: boolean; + + // External Link + externalLink?: { + externalLinkText: string; + externalLinkUrl: string; }; - action?: { - actionText: string; - actionUrl: string; - isExternal: boolean; + + // Portfolio Link + portfolioLink?: { + portfolioLinkText: string; + portfolioLinkUrl: string; }; // Extension Link @@ -29,6 +29,12 @@ export type FeatureAnnouncementRawNotificationData = Omit< extensionLinkText: string; extensionLinkRoute: string; }; + + // Mobile Link + mobileLink?: { + mobileLinkText: string; + mobileLinkUrl: string; + }; }; export type FeatureAnnouncementRawNotification = { diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-feature-announcement.ts b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-feature-announcement.ts index 5378005e61..e4bd1839c3 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-feature-announcement.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-feature-announcement.ts @@ -1,9 +1,10 @@ import type { Entry, EntryFieldTypes } from 'contentful'; import type { + TypeExternalLinkFields, TypeExtensionLinkFields, - TypeLinkFields, - TypeActionFields, + TypePortfolioLinkFields, + TypeMobileLinkFields, } from './type-links'; export type ImageFields = { @@ -35,12 +36,15 @@ export type TypeFeatureAnnouncementFields = { image: EntryFieldTypes.EntryLink; longDescription: EntryFieldTypes.RichText; - // Portfolio Links - TODO, cleanup portfolio links - link?: EntryFieldTypes.EntryLink; - action?: EntryFieldTypes.EntryLink; - + // External Link + externalLink?: EntryFieldTypes.EntryLink; + // Portfolio Link + portfolioLink?: EntryFieldTypes.EntryLink; // Extension Link extensionLink?: EntryFieldTypes.EntryLink; + // Mobile Link + mobileLink?: EntryFieldTypes.EntryLink; + clients?: EntryFieldTypes.Text<'extension' | 'mobile' | 'portfolio'>; }; contentTypeId: 'productAnnouncement'; diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-links.ts b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-links.ts index 24569f32f4..5153c48112 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-links.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/type-links.ts @@ -1,4 +1,15 @@ -// Extension Links +// Generic External Link +// We use this to show a link than will open an external web page +export type TypeExternalLinkFields = { + fields: { + externalLinkText: string; + externalLinkUrl: string; + }; + contentTypeId: 'externalLink'; +}; + +// Extension Link +// We use this to show a link than will open an extension tab export type TypeExtensionLinkFields = { fields: { extensionLinkText: string; @@ -7,23 +18,22 @@ export type TypeExtensionLinkFields = { contentTypeId: 'extensionLink'; }; -// Portfolio Links - TODO clean up portfolio links (we don't need 2 different versions) -export type TypeLinkFields = { +// Portfolio Link +// We use this to show a link than will open a portfolio page +export type TypePortfolioLinkFields = { fields: { - linkText: string; - linkUrl: string; - isExternal: boolean; + portfolioLinkText: string; + portfolioLinkUrl: string; }; - contentTypeId: 'link'; + contentTypeId: 'portfolioLink'; }; -export type TypeActionFields = { +// Mobile Link +// We use this to show a link than will open an application page +export type TypeMobileLinkFields = { fields: { - actionText: string; - actionUrl: string; - isExternal: boolean; + mobileLinkText: string; + mobileLinkUrl: string; }; - contentTypeId: 'action'; + contentTypeId: 'mobileLink'; }; - -// Mobile Links - TODO unsupported From 59c38ff6256daa884118591772e2e0db43f509c5 Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Wed, 21 Aug 2024 14:29:45 +0200 Subject: [PATCH 2/3] fix: :rotating_light: fix lint errors --- .../services/feature-announcements.ts | 20 ++++++++++++------- .../feature-announcement.ts | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts b/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts index 125969eb73..fdfa40a824 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts @@ -8,11 +8,12 @@ import type { ImageFields, TypeFeatureAnnouncement, } from '../types/feature-announcement/type-feature-announcement'; -import type { TypeExternalLinkFields } from '../types/feature-announcement/type-links'; -import type { TypePortfolioLinkFields } from '../types/feature-announcement/type-links'; -import type { TypeExtensionLinkFields } from '../types/feature-announcement/type-links'; -import type { TypeMobileLinkFields } from '../types/feature-announcement/type-links'; - +import type { + TypeExternalLinkFields, + TypePortfolioLinkFields, + TypeExtensionLinkFields, + TypeMobileLinkFields, +} from '../types/feature-announcement/type-links'; import type { INotification } from '../types/notification/notification'; const DEFAULT_SPACE_ID = ':space_id'; @@ -59,8 +60,13 @@ const fetchFeatureAnnouncementNotifications = async ( } const findIncludedItem = (sysId: string) => { - const typedData: EntryCollection = - data; + const typedData: EntryCollection< + | ImageFields + | TypeExtensionLinkFields + | TypePortfolioLinkFields + | TypeMobileLinkFields + | TypeExternalLinkFields + > = data; const item = typedData?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) || typedData?.includes?.Asset?.find((i: Asset) => i?.sys?.id === sysId); diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts index 0a17f3817d..465d96eba1 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts @@ -11,7 +11,7 @@ export type FeatureAnnouncementRawNotificationData = Omit< description?: string; url: string; }; - + // External Link externalLink?: { externalLinkText: string; From babdf9660e3dd7f22479ac8da1807961348a2548 Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Fri, 23 Aug 2024 08:34:58 +0200 Subject: [PATCH 3/3] fix: :bug: fix ts error --- .../types/feature-announcement/feature-announcement.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts index 465d96eba1..a1d6acb019 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts @@ -3,7 +3,12 @@ import type { TypeFeatureAnnouncement } from './type-feature-announcement'; export type FeatureAnnouncementRawNotificationData = Omit< TypeFeatureAnnouncement['fields'], - 'image' | 'longDescription' | 'extensionLink' | 'link' | 'action' + | 'image' + | 'longDescription' + | 'extensionLink' + | 'portfolioLink' + | 'externalLink' + | 'mobileLink' > & { longDescription: string; image: {