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

fix: Correctly filter CollectorProfileUpdatePromptNotificationItem in Activity rail #11501

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/app/Scenes/Activity/ActivityList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const ActivityList: React.FC<ActivityListProps> = ({ viewer, type }) => {

const notificationsNodes = extractNodes(data?.notificationsConnection)

const notifications = notificationsNodes.filter(shouldDisplayNotification)
const notifications = notificationsNodes.filter((notification) =>
shouldDisplayNotification(notification, "list")
)

const handleLoadMore = () => {
if (!hasNext || isLoadingNext) {
Expand Down Expand Up @@ -127,6 +129,8 @@ const notificationsConnectionFragment = graphql`
totalCount
}
item {
__typename

... on ViewingRoomPublishedNotificationItem {
viewingRoomsConnection(first: 1) {
totalCount
Expand All @@ -138,7 +142,11 @@ const notificationsConnectionFragment = graphql`
internalID
}
}
... on CollectorProfileUpdatePromptNotificationItem {
__typename
}
}

...ActivityItem_notification
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ describe("shouldDisplayNotification", () => {
const result4 = shouldDisplayNotification({
notificationType: "VIEWING_ROOM_PUBLISHED",
artworks: undefined,
item: { viewingRoomsConnection: { totalCount: 1 } },
item: {
viewingRoomsConnection: { totalCount: 1 },
__typename: "ViewingRoomPublishedNotificationItem",
},
})
expect(result4).toEqual(true)

// editorial notification has article
const result5 = shouldDisplayNotification({
notificationType: "ARTICLE_FEATURED_ARTIST",
artworks: undefined,
item: { article: { internalID: "1" } },
item: { article: { internalID: "1" }, __typename: "ArticleFeaturedArtistNotificationItem" },
})
expect(result5).toEqual(true)
})
Expand Down Expand Up @@ -68,15 +71,21 @@ describe("shouldDisplayNotification", () => {
const result4 = shouldDisplayNotification({
notificationType: "VIEWING_ROOM_PUBLISHED",
artworks: undefined,
item: { viewingRoomsConnection: { totalCount: 0 } },
item: {
viewingRoomsConnection: { totalCount: 0 },
__typename: "ViewingRoomPublishedNotificationItem",
},
})
expect(result4).toEqual(false)

// editorial notification has no article
const result5 = shouldDisplayNotification({
notificationType: "ARTICLE_FEATURED_ARTIST",
artworks: undefined,
item: {},
item: {
article: null,
__typename: "ArticleFeaturedArtistNotificationItem",
},
})
expect(result5).toEqual(false)
})
Expand Down
22 changes: 16 additions & 6 deletions src/app/Scenes/Activity/utils/shouldDisplayNotification.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { ActivityList_viewer$data } from "__generated__/ActivityList_viewer.graphql"
import { ActivityRail_viewer$data } from "__generated__/ActivityRail_viewer.graphql"
import { isArtworksBasedNotification } from "app/Scenes/Activity/utils/isArtworksBasedNotification"
import { ExtractNodeType } from "app/utils/relayHelpers"

export type NotificationNode = NonNullable<
NonNullable<NonNullable<ActivityList_viewer$data["notificationsConnection"]>["edges"]>[0]
>["node"]
export type NotificationNode =
| ExtractNodeType<ActivityList_viewer$data["notificationsConnection"]>
| ExtractNodeType<ActivityRail_viewer$data["notificationsConnection"]>

export const shouldDisplayNotification = (
notification:
| Pick<NonNullable<NotificationNode>, "notificationType" | "artworks" | "item">
| null
| undefined
| undefined,
mode: "rail" | "list" = "list"
) => {
if (!notification) {
return false
Expand All @@ -20,14 +23,21 @@ export const shouldDisplayNotification = (
return artworksCount > 0
}

if (notification.notificationType === "VIEWING_ROOM_PUBLISHED") {
if (notification.item?.__typename === "ViewingRoomPublishedNotificationItem") {
const viewingRoomsCount = notification.item?.viewingRoomsConnection?.totalCount ?? 0
return viewingRoomsCount > 0
}

if (notification.notificationType === "ARTICLE_FEATURED_ARTIST") {
if (notification.item?.__typename === "ArticleFeaturedArtistNotificationItem") {
return !!notification.item?.article?.internalID
}

if (
mode === "rail" &&
notification.item?.__typename === "CollectorProfileUpdatePromptNotificationItem"
) {
return false
}

return true
}
12 changes: 10 additions & 2 deletions src/app/Scenes/HomeView/Components/ActivityRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export const ActivityRail: React.FC<ActivityRailProps> = ({ title, viewer }) =>

const notificationsNodes = extractNodes(data?.notificationsConnection)

const notifications = notificationsNodes.filter(shouldDisplayNotification)

const notifications = notificationsNodes.filter((notification) =>
shouldDisplayNotification(notification, "rail")
)
if (notifications.length === 0) {
return null
}
Expand Down Expand Up @@ -79,18 +80,25 @@ const notificationsConnectionFragment = graphql`
totalCount
}
item {
__typename

... on ViewingRoomPublishedNotificationItem {
viewingRoomsConnection(first: 1) {
totalCount
}
}

... on CollectorProfileUpdatePromptNotificationItem {
__typename
}

... on ArticleFeaturedArtistNotificationItem {
article {
internalID
}
}
}

...ActivityRailItem_item
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const HomeViewSectionActivity: React.FC<HomeViewSectionActivityProps> = (
const tracking = useHomeViewTracking()

const section = useFragment(sectionFragment, sectionProp)
const notifications = extractNodes(section.notificationsConnection).filter(
shouldDisplayNotification
const notifications = extractNodes(section.notificationsConnection).filter((notification) =>
shouldDisplayNotification(notification, "rail")
)
const viewAll = section.component?.behaviors?.viewAll

Expand Down Expand Up @@ -134,6 +134,8 @@ const sectionFragment = graphql`
}
targetHref
item {
__typename

... on ViewingRoomPublishedNotificationItem {
viewingRoomsConnection(first: 1) {
totalCount
Expand Down