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

[CORL-3070]: filter out rejected and deleted comments from notifications #4526

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { Localized } from "@fluent/react/compat";
import React, { FunctionComponent, useCallback, useState } from "react";
import React, {
FunctionComponent,
useCallback,
useMemo,
useState,
} from "react";
import { graphql, RelayPaginationProp } from "react-relay";

import {
useLocal,
useRefetch,
withPaginationContainer,
} from "coral-framework/lib/relay";
import {
GQLCOMMENT_STATUS,
GQLNOTIFICATION_TYPE,
} from "coral-framework/schema";
import CLASSES from "coral-stream/classes";
import Spinner from "coral-stream/common/Spinner";
import { Flex } from "coral-ui/components/v2";
Expand Down Expand Up @@ -71,6 +80,23 @@ const NotificationsPaginator: FunctionComponent<Props> = (props) => {
);
}, [props.relay]);

const notificationsToShow = useMemo(() => {
return props.query.notifications.edges.filter((n) => {
if (
n.node.type !==
(GQLNOTIFICATION_TYPE.REPLY || GQLNOTIFICATION_TYPE.REPLY_STAFF)
) {
return true;
} else {
// filter out Rejected comments and deleted comments
return (
n.node.commentReply?.status !== GQLCOMMENT_STATUS.REJECTED &&
!n.node.commentReply?.deleted
);
}
});
}, [props.query.notifications.edges]);

if (!props.query || !props.query.viewer) {
return null;
}
Expand Down Expand Up @@ -169,7 +195,7 @@ const NotificationsPaginator: FunctionComponent<Props> = (props) => {
</Flex>
</Localized>
<div>
{props.query.notifications.edges.map(({ node }) => {
{notificationsToShow.map(({ node }) => {
return (
<NotificationContainer
key={node.id}
Expand Down Expand Up @@ -233,6 +259,11 @@ const enhanced = withPaginationContainer<
edges {
node {
id
type
commentReply {
status
deleted
}
...NotificationContainer_notification
}
}
Expand Down
Loading