Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add support for different link types in feature announcements #4620

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import type {
ImageFields,
TypeFeatureAnnouncement,
} from '../types/feature-announcement/type-feature-announcement';
import type { TypeExtensionLinkFields } 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';
Expand Down Expand Up @@ -55,8 +60,13 @@ const fetchFeatureAnnouncementNotifications = async (
}

const findIncludedItem = (sysId: string) => {
const typedData: EntryCollection<ImageFields | TypeExtensionLinkFields> =
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);
Expand All @@ -71,11 +81,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,
Expand All @@ -91,10 +116,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,
},
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -12,23 +17,29 @@ export type FeatureAnnouncementRawNotificationData = Omit<
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
extensionLink?: {
extensionLinkText: string;
extensionLinkRoute: string;
};

// Mobile Link
mobileLink?: {
mobileLinkText: string;
mobileLinkUrl: string;
};
};

export type FeatureAnnouncementRawNotification = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Entry, EntryFieldTypes } from 'contentful';

import type {
TypeExternalLinkFields,
TypeExtensionLinkFields,
TypeLinkFields,
TypeActionFields,
TypePortfolioLinkFields,
TypeMobileLinkFields,
} from './type-links';

export type ImageFields = {
Expand Down Expand Up @@ -35,12 +36,15 @@ export type TypeFeatureAnnouncementFields = {
image: EntryFieldTypes.EntryLink<ImageFields>;
longDescription: EntryFieldTypes.RichText;

// Portfolio Links - TODO, cleanup portfolio links
link?: EntryFieldTypes.EntryLink<TypeLinkFields>;
action?: EntryFieldTypes.EntryLink<TypeActionFields>;

// External Link
externalLink?: EntryFieldTypes.EntryLink<TypeExternalLinkFields>;
// Portfolio Link
portfolioLink?: EntryFieldTypes.EntryLink<TypePortfolioLinkFields>;
// Extension Link
extensionLink?: EntryFieldTypes.EntryLink<TypeExtensionLinkFields>;
// Mobile Link
mobileLink?: EntryFieldTypes.EntryLink<TypeMobileLinkFields>;

clients?: EntryFieldTypes.Text<'extension' | 'mobile' | 'portfolio'>;
};
contentTypeId: 'productAnnouncement';
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Loading