Skip to content

Commit

Permalink
[In App] Do not displaying broken notifications (#7310)
Browse files Browse the repository at this point in the history
* handle gracefully broken notificaionts by not displaying them

* fix the translation and displya of the space type

* codegen with latest fields

---------

Co-authored-by: Svetoslav <[email protected]>
  • Loading branch information
bobbykolev and hero101 authored Dec 12, 2024
1 parent 25f79db commit 395768d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/core/apollo/generated/apollo-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,7 @@ export type InAppNotificationCommunityNewMemberFieldPolicy = {
export type InAppNotificationUserMentionedKeySpecifier = (
| 'category'
| 'comment'
| 'commentOriginName'
| 'commentUrl'
| 'contributorType'
| 'id'
Expand All @@ -1570,6 +1571,7 @@ export type InAppNotificationUserMentionedKeySpecifier = (
export type InAppNotificationUserMentionedFieldPolicy = {
category?: FieldPolicy<any> | FieldReadFunction<any>;
comment?: FieldPolicy<any> | FieldReadFunction<any>;
commentOriginName?: FieldPolicy<any> | FieldReadFunction<any>;
commentUrl?: FieldPolicy<any> | FieldReadFunction<any>;
contributorType?: FieldPolicy<any> | FieldReadFunction<any>;
id?: FieldPolicy<any> | FieldReadFunction<any>;
Expand Down
1 change: 1 addition & 0 deletions src/core/apollo/generated/apollo-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,7 @@ export const InAppNotificationUserMentionedFragmentDoc = gql`
}
commentUrl
comment
commentOriginName
contributorType
}
${VisualUriFragmentDoc}
Expand Down
4 changes: 4 additions & 0 deletions src/core/apollo/generated/graphql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,8 @@ export type InAppNotificationUserMentioned = InAppNotification & {
category: InAppNotificationCategory;
/** The comment that the contributor was mentioned in. */
comment: Scalars['String'];
/** The display name of the resource where the comment was created. */
commentOriginName: Scalars['String'];
/** The url of the resource where the comment was created. */
commentUrl: Scalars['String'];
/** The type of the Contributor that joined. */
Expand Down Expand Up @@ -28000,6 +28002,7 @@ export type InAppNotificationsQuery = {
triggeredAt: Date;
commentUrl: string;
comment: string;
commentOriginName: string;
contributorType: CommunityContributorType;
triggeredBy:
| {
Expand Down Expand Up @@ -28210,6 +28213,7 @@ export type InAppNotificationUserMentionedFragment = {
__typename?: 'InAppNotificationUserMentioned';
commentUrl: string;
comment: string;
commentOriginName: string;
contributorType: CommunityContributorType;
triggeredBy:
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ fragment InAppNotificationUserMentioned on InAppNotificationUserMentioned {
}
commentUrl
comment
commentOriginName
contributorType
}
1 change: 1 addition & 0 deletions src/main/inAppNotifications/useInAppNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface InAppNotificationProps {
};
comment?: string;
commentUrl?: string;
commentOriginName?: string;
}

export const useInAppNotifications = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useTranslation } from 'react-i18next';
import { InAppNotificationProps } from '../useInAppNotifications';
import { InAppNotificationBaseView, InAppNotificationBaseViewProps } from './InAppNotificationBaseView';
import { useMemo } from 'react';
import { getChildJourneyTypeName } from '@/domain/shared/utils/spaceLevel';
import { SpaceLevel } from '@/core/apollo/generated/graphql-schema';

export const CollaborationCalloutPublishedView = ({
id,
Expand All @@ -24,7 +26,7 @@ export const CollaborationCalloutPublishedView = ({
const notificationTextValues = {
defaultValue: '',
spaceName: space?.profile?.displayName,
spaceType: space?.level,
spaceType: t(`common.${getChildJourneyTypeName({ level: space?.level ?? SpaceLevel.Space })}`),
calloutName: callout?.framing?.profile?.displayName,
calloutType: calloutType,
contributorName: triggeredBy?.profile?.displayName,
Expand All @@ -48,5 +50,15 @@ export const CollaborationCalloutPublishedView = ({
};
}, [id, state, space, callout, triggeredBy, triggeredAt, t]);

// do not display notification if these are missing
if (
!callout ||
!callout.framing?.profile?.displayName ||
!callout?.framing?.profile?.url ||
!triggeredBy?.profile?.displayName
) {
return null;
}

return <InAppNotificationBaseView {...notification} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ export const CommunicationUserMentionView = ({
type,
state,
space,
callout,
triggeredBy,
triggeredAt,
comment,
commentUrl,
commentOriginName,
}: InAppNotificationProps) => {
const notification: InAppNotificationBaseViewProps = useMemo(() => {
const notificationTextValues = {
defaultValue: '',
commenterName: triggeredBy?.profile?.displayName,
calloutName: callout?.framing?.profile?.displayName,
calloutName: commentOriginName,
comment,
};

Expand All @@ -37,7 +37,12 @@ export const CommunicationUserMentionView = ({
triggeredAt: triggeredAt,
values: notificationTextValues,
};
}, [id, state, space, triggeredBy, callout, triggeredAt, comment, commentUrl]);
}, [id, state, space, triggeredBy, commentOriginName, triggeredAt, comment, commentUrl]);

// do not display notification if these are missing
if (!commentOriginName || !commentUrl || !triggeredBy?.profile?.displayName) {
return null;
}

return <InAppNotificationBaseView {...notification} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ export const CommunityNewMemberAdminView = ({ id, state, space, triggeredAt, act
};
}, [id, state, space, triggeredAt, actor]);

// do not display notification if these are missing
if (!actor?.profile?.displayName || !space?.profile?.displayName) {
return null;
}

return <InAppNotificationBaseView {...notification} />;
};
5 changes: 5 additions & 0 deletions src/main/inAppNotifications/views/CommunityNewMemberView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ export const CommunityNewMemberView = ({ id, type, state, space, triggeredAt }:
};
}, [id, state, space, triggeredAt]);

// do not display notification if these are missing
if (!space?.profile?.displayName) {
return null;
}

return <InAppNotificationBaseView {...notification} />;
};

0 comments on commit 395768d

Please sign in to comment.