Skip to content

Commit

Permalink
Merge pull request #1287 from AletheiaFact/create-verification-reques…
Browse files Browse the repository at this point in the history
…t-page

Create verification request page
  • Loading branch information
thesocialdev authored Jul 18, 2024
2 parents 6c18460 + 24f52e9 commit 6641cf0
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 60 deletions.
6 changes: 6 additions & 0 deletions cypress/e2e/tests/header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe("Test the header menus", () => {
cy.url().should("contains", "source");
});

it("Open side bar and click source", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testVerificationRequestItem]").click();
cy.url().should("contains", "verification-request");
});

it("Open side bar and click about", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testAboutItem]").click();
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"kanbanItem": "Kanban",
"nameSpaceItem": "Namespace",
"supportiveMaterials": "Supportive Materials",
"sourcesItem": "Sources"
"sourcesItem": "Sources",
"verificationRequestItem": "Verification Requests"
}
4 changes: 3 additions & 1 deletion public/locales/en/seo.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"claimListTitle": "Claims",
"claimListDescription": "See claims on AletheiaFact.org",
"createSourceTitle": "Create source",
"createSourceDescription": "Create sources to AletheiaFact.org"
"createSourceDescription": "Create sources to AletheiaFact.org",
"verificationRequestTitle": "Verification Requests",
"verificationRequestDescription": "See verification requests on AletheiaFact.org"
}
4 changes: 3 additions & 1 deletion public/locales/en/verificationRequest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"verificationRequestListHeader": "Verification Requests",
"verificationRequestTitle": "Verification Request",
"manageVerificationRequests": "Manage selected verification requests",
"createClaimFromVerificationRequest": "No claim was created with this verification request",
"openVerificationRequestClaimLabel": "A claim created was related to this verification request",
"openVerificationRequestClaimButton": "Open claim",
"agroupVerificationRequest": "Related verification requests"
"agroupVerificationRequest": "Related verification requests",
"openVerificationRequest": "Open"
}
3 changes: 2 additions & 1 deletion public/locales/pt/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"kanbanItem": "Meu Trabalho",
"nameSpaceItem": "Namespace",
"supportiveMaterials": "Materiais de Apoio",
"sourcesItem": "Fontes"
"sourcesItem": "Fontes",
"verificationRequestItem": "Denúncias"
}
4 changes: 3 additions & 1 deletion public/locales/pt/seo.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"claimListTitle": "Declarações",
"claimListDescription": "Veja declarações na AletheiaFact.org",
"createSourceTitle": "Adicione uma fonte",
"createSourceDescription": "Adiciona uma fonte na AletheiaFact.org"
"createSourceDescription": "Adiciona uma fonte na AletheiaFact.org",
"verificationRequestTitle": "Denúncias",
"verificationRequestDescription": "Veja as denúncias na AletheiaFact.org"
}
4 changes: 3 additions & 1 deletion public/locales/pt/verificationRequest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"verificationRequestListHeader": "Denúncias",
"verificationRequestTitle": "Denúncia",
"manageVerificationRequests": "Gerenciar denúncias selecionadas",
"createClaimFromVerificationRequest": "Nenhuma afirmação foi criada com esta denúncia",
"openVerificationRequestClaimLabel": "Uma afirmação criada foi relacionada com essa denúncia",
"openVerificationRequestClaimButton": "Abrir afirmação",
"agroupVerificationRequest": "Denúncias relacionadas"
"agroupVerificationRequest": "Denúncias relacionadas",
"openVerificationRequest": "Abrir"
}
48 changes: 46 additions & 2 deletions server/verification-request/verification-request.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { Response } from "express";
import { ReviewTaskService } from "../review-task/review-task.service";
import { CreateVerificationRequestDTO } from "./dto/create-verification-request-dto";
import { UpdateVerificationRequestDTO } from "./dto/update-verification-request.dto";
import { IsPublic } from "../auth/decorators/is-public.decorator";

@Controller(":namespace?")
export class VerificationRequestController {
Expand All @@ -33,6 +34,28 @@ export class VerificationRequestController {
@ApiTags("verification-request")
@Get("api/verification-request")
@Header("Cache-Control", "max-age=60, must-revalidate")
public async listAll(@Query() getVerificationRequest) {
const { pageSize, page } = getVerificationRequest;

return Promise.all([
this.verificationRequestService.listAll(getVerificationRequest),
this.verificationRequestService.count({}),
]).then(([verificationRequests, totalVerificationRequests]) => {
const totalPages = Math.ceil(totalVerificationRequests / pageSize);

return {
verificationRequests,
totalVerificationRequests,
totalPages,
page: page,
pageSize: pageSize,
};
});
}

@ApiTags("verification-request")
@Get("api/verification-request/search")
@Header("Cache-Control", "max-age=60, must-revalidate")
public async getAll(@Query() getVerificationRequest) {
return this.verificationRequestService.findAll(getVerificationRequest);
}
Expand Down Expand Up @@ -74,7 +97,28 @@ export class VerificationRequestController {
);
}

@ApiTags("verification-request")
@IsPublic()
@ApiTags("pages")
@Get("verification-request")
@Header("Cache-Control", "max-age=60, must-revalidate")
public async verificationRequestPage(
@Req() req: BaseRequest,
@Res() res: Response
) {
const parsedUrl = parse(req.url, true);

await this.viewService.getNextServer().render(
req,
res,
"/verification-request-page",
Object.assign(parsedUrl.query, {
nameSpace: req.params.namespace,
})
);
}

@IsPublic()
@ApiTags("pages")
@Get("verification-request/:dataHash")
@Header("Cache-Control", "max-age=60, must-revalidate")
public async verificationRequestReviewPage(
Expand All @@ -95,7 +139,7 @@ export class VerificationRequestController {
await this.viewService.getNextServer().render(
req,
res,
"/verification-request-page",
"/verification-request-review-page",
Object.assign(parsedUrl.query, {
reviewTask,
sitekey: this.configService.get<string>("recaptcha_sitekey"),
Expand Down
12 changes: 12 additions & 0 deletions server/verification-request/verification-request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export class VerificationRequestService {
private groupService: GroupService
) {}

async listAll({ page, pageSize, order }): Promise<VerificationRequest[]> {
return this.VerificationRequestModel.find({})
.skip(page * parseInt(pageSize, 10))
.limit(parseInt(pageSize, 10))
.sort({ _id: order })
.lean();
}

/**
* Find all verification requests that query matches
* @param verifiedRequestQuery query parameter
Expand Down Expand Up @@ -270,4 +278,8 @@ export class VerificationRequestService {

return groupId;
}

count(query) {
return this.VerificationRequestModel.countDocuments().where(query);
}
}
32 changes: 31 additions & 1 deletion src/api/verificationRequestApi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import axios from "axios";
import { NameSpaceEnum } from "../types/Namespace";

const request = axios.create({
withCredentials: true,
baseURL: `/api/verification-request`,
});

const getVerificationRequests = (params) => {
const get = (options) => {
const params = {
page: options.page ? options.page - 1 : 0,
order: options.order || "asc",
pageSize: options.pageSize ? options.pageSize : 10,
nameSpace: options?.nameSpace || NameSpaceEnum.Main,
};

return request
.get(`/`, { params })
.then((response) => {
const {
verificationRequests,
totalPages,
totalVerificationRequests,
} = response.data;

return {
data: verificationRequests,
total: totalVerificationRequests,
totalPages,
};
})
.catch((err) => {
console.log(err);
});
};

const getVerificationRequests = (params) => {
return request
.get(`/search`, { params })
.then((response) => {
return response?.data;
})
Expand Down Expand Up @@ -50,6 +79,7 @@ const removeVerificationRequestFromGroup = (id, params) => {
};

const verificationRequestApi = {
get,
getVerificationRequests,
getById,
updateVerificationRequest,
Expand Down
12 changes: 12 additions & 0 deletions src/components/AletheiaMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ const AletheiaMenu = () => {
{t("menu:sourcesItem")}
</Menu.Item>

<Menu.Item
key={
nameSpace !== NameSpaceEnum.Main
? `/${nameSpace}/verification-request`
: "/verification-request"
}
onClick={handleClick}
data-cy={"testVerificationRequestItem"}
>
{t("menu:verificationRequestItem")}
</Menu.Item>

{role !== Roles.Regular && (
<Menu.Item
key={
Expand Down
21 changes: 17 additions & 4 deletions src/components/VerificationRequest/VerificationRequestCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Typography } from "antd";
import { Col, Typography } from "antd";
import React from "react";
import colors from "../../styles/colors";
import CardBase from "../CardBase";

const VerificationRequestCard = ({ content, actions = [] }) => {
const VerificationRequestCard = ({
content,
actions = [],
expandable = true,
}) => {
return (
<CardBase style={{ padding: 32 }}>
<Typography.Paragraph
Expand All @@ -13,12 +17,21 @@ const VerificationRequestCard = ({ content, actions = [] }) => {
margin: 0,
lineHeight: 1.6,
}}
ellipsis={{ rows: 4, expandable: true }}
ellipsis={{ rows: 4, expandable }}
>
{content}
</Typography.Paragraph>

{actions ? actions.map((action) => action) : <></>}
<Col
style={{
marginTop: 32,
display: "flex",
justifyContent: "flex-end",
width: "100%",
}}
>
{actions ? actions.map((action) => action) : <></>}
</Col>
</CardBase>
);
};
Expand Down
52 changes: 52 additions & 0 deletions src/components/VerificationRequest/VerificationRequestList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react";
import BaseList from "../List/BaseList";
import { Col, Row } from "antd";
import { useTranslation } from "next-i18next";
import { useAtom } from "jotai";
import { currentNameSpace } from "../../atoms/namespace";
import verificationRequestApi from "../../api/verificationRequestApi";
import VerificationRequestCard from "./VerificationRequestCard";
import AletheiaButton from "../Button";

const VerificationRequestList = () => {
const { t } = useTranslation();
const [nameSpace] = useAtom(currentNameSpace);

return (
<Row justify="center">
<Col span={18}>
<BaseList
apiCall={verificationRequestApi.get}
filter={{ nameSpace }}
title={t(
"verificationRequest:verificationRequestListHeader"
)}
renderItem={({ content, data_hash }, index) => (
<VerificationRequestCard
key={index}
content={content}
expandable={false}
actions={[
<AletheiaButton
href={`/verification-request/${data_hash}`}
>
{t(
"verificationRequest:openVerificationRequest"
)}
</AletheiaButton>,
]}
/>
)}
grid={{
gutter: 20,
md: 2,
lg: 2,
xl: 2,
xxl: 2,
}}
/>
</Col>
</Row>
);
};
export default VerificationRequestList;
Loading

0 comments on commit 6641cf0

Please sign in to comment.