Skip to content

Commit 3c6c267

Browse files
authored
Merge pull request #4434 from coralproject/feat/dsa-related-reports-section
[CORL-2970]: DSA - Display related reports on single report screen
2 parents d117cbb + 98e0407 commit 3c6c267

File tree

9 files changed

+174
-1
lines changed

9 files changed

+174
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.label {
2+
font-size: var(--font-size-1);
3+
text-transform: uppercase;
4+
}
5+
6+
.button {
7+
background-color: var(--palette-grey-200);
8+
color: var(--palette-grey-500);
9+
text-align: left;
10+
}
11+
12+
.reportIDLabel {
13+
text-transform: uppercase;
14+
}
15+
16+
.referenceID {
17+
margin-left: var(--spacing-2);
18+
text-decoration: underline;
19+
}
20+
21+
.arrowIcon {
22+
margin-left: auto;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { Localized } from "@fluent/react/compat";
2+
import React, { FunctionComponent } from "react";
3+
import { graphql } from "react-relay";
4+
5+
import { withFragmentContainer } from "coral-framework/lib/relay";
6+
import { ArrowRightIcon, SvgIcon } from "coral-ui/components/icons";
7+
import { Flex } from "coral-ui/components/v2";
8+
import { Button } from "coral-ui/components/v3";
9+
10+
import { RelatedReports_dsaReport } from "coral-admin/__generated__/RelatedReports_dsaReport.graphql";
11+
12+
import styles from "./RelatedReports.css";
13+
14+
interface Props {
15+
dsaReport: RelatedReports_dsaReport;
16+
}
17+
18+
const RelatedReports: FunctionComponent<Props> = ({ dsaReport }) => {
19+
const relatedReports = dsaReport.relatedReports.edges.map(
20+
(edge) => edge.node
21+
);
22+
23+
if (relatedReports.length === 0) {
24+
return null;
25+
}
26+
27+
return (
28+
<Flex direction="column">
29+
<Localized id="reports-relatedReports-label">
30+
<div className={styles.label}>Related Reports</div>
31+
</Localized>
32+
{relatedReports.map((report) => {
33+
return (
34+
<Flex marginTop={2} key={report.id}>
35+
<Button
36+
className={styles.button}
37+
fullWidth
38+
color="none"
39+
variant="flat"
40+
href={`/admin/reports/report/${report.id}`}
41+
>
42+
<Flex>
43+
<Flex>
44+
<Localized id="reports-relatedReports-reportIDLabel">
45+
<span className={styles.reportIDLabel}>Report ID</span>
46+
</Localized>
47+
<span className={styles.referenceID}>
48+
{report.referenceID}
49+
</span>
50+
</Flex>
51+
<Flex className={styles.arrowIcon}>
52+
<SvgIcon Icon={ArrowRightIcon} />
53+
</Flex>
54+
</Flex>
55+
</Button>
56+
</Flex>
57+
);
58+
})}
59+
</Flex>
60+
);
61+
};
62+
63+
const enhanced = withFragmentContainer<Props>({
64+
dsaReport: graphql`
65+
fragment RelatedReports_dsaReport on DSAReport
66+
@argumentDefinitions(
67+
count: { type: "Int", defaultValue: 10 }
68+
cursor: { type: "Cursor" }
69+
orderBy: { type: "REPORT_SORT", defaultValue: CREATED_AT_DESC }
70+
) {
71+
id
72+
relatedReports(first: $count, after: $cursor, orderBy: $orderBy)
73+
@connection(key: "RelatedReports_relatedReports") {
74+
edges {
75+
node {
76+
id
77+
referenceID
78+
}
79+
}
80+
}
81+
}
82+
`,
83+
})(RelatedReports);
84+
85+
export default enhanced;

Diff for: client/src/core/client/admin/routes/Reports/SingleReportRoute.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import styles from "./SingleReportRoute.css";
3636

3737
import NotFound from "../NotFound";
3838
import ChangeStatusModal from "./ChangeStatusModal";
39+
import RelatedReports from "./RelatedReports";
3940
import ReportedComment from "./ReportedComment";
4041
import ReportHistory from "./ReportHistory";
4142
import ReportMakeDecisionModal from "./ReportMakeDecisionModal";
@@ -235,6 +236,7 @@ const SingleReportRoute: FunctionComponent<Props> & {
235236
dsaReport={dsaReport}
236237
onShowUserDrawer={onShowUserDrawer}
237238
/>
239+
<RelatedReports dsaReport={dsaReport} />
238240
{dsaReport.decision && (
239241
<>
240242
<Divider />
@@ -381,6 +383,7 @@ SingleReportRoute.routeConfig = createRouteConfig<
381383
...ReportShareButton_dsaReport
382384
...ReportMakeDecisionModal_dsaReport
383385
...ReportedComment_dsaReport
386+
...RelatedReports_dsaReport
384387
}
385388
}
386389
`,

Diff for: client/src/core/client/admin/test/fixtures.ts

+2
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ export const dsaReports = createFixtures<GQLDSAReport>([
851851
additionalInformation:
852852
"The additional information supporting why that law is alleged to have been broken",
853853
history: [],
854+
relatedReports: { edges: [], pageInfo: { hasNextPage: false } },
854855
},
855856
{
856857
id: "dsa-report-2",
@@ -869,6 +870,7 @@ export const dsaReports = createFixtures<GQLDSAReport>([
869870
"A detailed explanation of why it is a violation of Law number 2",
870871
},
871872
history: [],
873+
relatedReports: { edges: [], pageInfo: { hasNextPage: false } },
872874
},
873875
]);
874876

Diff for: locales/en-US/admin.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,9 @@ reports-decisionModal-detailedExplanationLabel = Detailed explanation
19111911
reports-decisionModal-detailedExplanationTextarea =
19121912
.placeholder = Add explanation...
19131913
1914+
reports-relatedReports-label = Related reports
1915+
reports-relatedReports-reportIDLabel = Report ID
1916+
19141917
# Control panel
19151918

19161919
controlPanel-redis-redis = Redis

Diff for: server/src/core/server/graph/loaders/DSAReports.ts

+18
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import {
55
DSAReportConnectionInput,
66
find,
77
retrieveDSAReportConnection,
8+
retrieveDSAReportRelatedReportsConnection,
89
} from "coral-server/models/dsaReport";
910

1011
import GraphContext from "../context";
1112
import { createManyBatchLoadFn } from "./util";
1213

1314
import {
15+
DSAReportToRelatedReportsArgs,
1416
GQLDSAREPORT_STATUS_FILTER,
1517
GQLREPORT_SORT,
1618
QueryToDsaReportsArgs,
@@ -53,4 +55,20 @@ export default (ctx: GraphContext) => ({
5355
cache: !ctx.disableCaching,
5456
}
5557
),
58+
relatedReports: (
59+
submissionID: string,
60+
id: string,
61+
{ first, orderBy, after }: DSAReportToRelatedReportsArgs
62+
) =>
63+
retrieveDSAReportRelatedReportsConnection(
64+
ctx.mongo,
65+
ctx.tenant.id,
66+
submissionID,
67+
id,
68+
{
69+
first: defaultTo(first, 10),
70+
orderBy: defaultTo(orderBy, GQLREPORT_SORT.CREATED_AT_DESC),
71+
after,
72+
}
73+
),
5674
});

Diff for: server/src/core/server/graph/resolvers/DSAReport.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import { defaultTo } from "lodash";
2+
13
import * as dsaReport from "coral-server/models/dsaReport";
24

3-
import { GQLDSAReportTypeResolver } from "coral-server/graph/schema/__generated__/types";
5+
import {
6+
GQLDSAReportTypeResolver,
7+
GQLREPORT_SORT,
8+
} from "coral-server/graph/schema/__generated__/types";
49

510
export const DSAReport: GQLDSAReportTypeResolver<dsaReport.DSAReport> = {
611
reporter: (report, args, ctx) => {
@@ -33,4 +38,11 @@ export const DSAReport: GQLDSAReportTypeResolver<dsaReport.DSAReport> = {
3338
return null;
3439
}
3540
},
41+
relatedReports: ({ submissionID, id }, { first, after, orderBy }, ctx) => {
42+
return ctx.loaders.DSAReports.relatedReports(submissionID, id, {
43+
first: defaultTo(first, 10),
44+
after,
45+
orderBy: defaultTo(orderBy, GQLREPORT_SORT.CREATED_AT_DESC),
46+
});
47+
},
3648
};

Diff for: server/src/core/server/graph/schema/schema.graphql

+10
Original file line numberDiff line numberDiff line change
@@ -3661,6 +3661,16 @@ type DSAReport {
36613661
such as a note added, status changed, or decision made
36623662
"""
36633663
lastUpdated: Time
3664+
3665+
"""
3666+
relatedReports are DSAReports that share a submissionID and were submitted at the same time
3667+
in one illegal content report
3668+
"""
3669+
relatedReports(
3670+
first: Int = 10 @constraint(max: 50)
3671+
orderBy: REPORT_SORT = CREATED_AT_DESC
3672+
after: Cursor
3673+
): DSAReportsConnection!
36643674
}
36653675

36663676
type CommentRevisionPerspectiveMetadata {

Diff for: server/src/core/server/models/dsaReport/report.ts

+17
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ export async function retrieveDSAReportConnection(
167167
return retrieveConnection(input, query);
168168
}
169169

170+
export async function retrieveDSAReportRelatedReportsConnection(
171+
mongo: MongoContext,
172+
tenantID: string,
173+
submissionID: string,
174+
id: string,
175+
input: DSAReportConnectionInput
176+
): Promise<Readonly<Connection<Readonly<DSAReport>>>> {
177+
// Create the query.
178+
const query = new Query(mongo.dsaReports()).where({
179+
tenantID,
180+
submissionID,
181+
id: { $ne: id },
182+
});
183+
184+
return retrieveConnection(input, query);
185+
}
186+
170187
export async function retrieveDSAReport(
171188
mongo: MongoContext,
172189
tenantID: string,

0 commit comments

Comments
 (0)