Skip to content

Commit

Permalink
feat(MAJ prod): lister les documents déployés lors des mises à jours …
Browse files Browse the repository at this point in the history
…de prod et pre-prod
  • Loading branch information
carolineBda committed Oct 6, 2023
1 parent fda61bd commit 718fe68
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 47 deletions.
7 changes: 6 additions & 1 deletion targets/export-elasticsearch/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"extends": ["@shared/eslint-config"]
"extends": [
"@shared/eslint-config"
],
"rules": {
"@typescript-eslint/naming-convention": "warn"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const AlertWarning = ({ repository }: Props): React.ReactElement => {
return <></>;
}

if (alertWarnings?.length ?? 0 > 0) {
if (alertWarnings?.length) {
return (
<>
<Modal
Expand Down Expand Up @@ -80,7 +80,7 @@ export const AlertWarning = ({ repository }: Props): React.ReactElement => {
</TableRow>
</TableHead>
<TableBody>
{alertWarnings?.map((row, index) => {
{alertWarnings.map((row, index) => {
const date = format(
parseISO(row.createdAt),
"dd/MM/yyyy"
Expand Down
20 changes: 16 additions & 4 deletions targets/frontend/src/components/export-es/Status.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Status as StatusType } from "@shared/types";
import { MdTimelapse } from "react-icons/md";
import { Box, Typography } from "@mui/material";
import { theme } from "src/theme";
import { fr } from "@codegouvfr/react-dsfr";

type StatusProps = {
status?: StatusType;
Expand All @@ -18,9 +18,17 @@ export function Status({ status }: StatusProps): JSX.Element {
}
switch (status) {
case StatusType.completed:
return <Typography color={theme.colors.positive}>Succès</Typography>;
return (
<Typography color={fr.colors.decisions.text.default.success.default}>
Succès
</Typography>
);
case StatusType.timeout:
return <Typography color={theme.colors.muted}>Timeout</Typography>;
return (
<Typography color={fr.colors.decisions.text.default.warning.default}>
Timeout
</Typography>
);
case StatusType.running:
return (
<Box sx={{ alignItems: "center", display: "flex" }}>
Expand All @@ -31,7 +39,11 @@ export function Status({ status }: StatusProps): JSX.Element {
</Box>
);
case StatusType.failed:
return <Typography color={theme.colors.critical}>Erreur</Typography>;
return (
<Typography color={fr.colors.decisions.text.default.error.default}>
Erreur
</Typography>
);
default:
return <Typography>{status}</Typography>;
}
Expand Down
2 changes: 1 addition & 1 deletion targets/frontend/src/components/layout/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function Nav() {
</Li>
<Li>
<ActiveLink href="/contenus/fiches-sp" passHref>
fiches service-public
Fiches service-public
</ActiveLink>
</Li>
<Li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Box, Button, Modal, Stack } from "@mui/material";
import { Box, Button, Modal, Stack, Typography } from "@mui/material";
import { styled } from "@mui/system";
import { fr } from "@codegouvfr/react-dsfr";

export type ConfirmModalProps = {
open: boolean;
message: string;
message: JSX.Element | string;
title: string;
onClose: () => void;
onCancel: () => void;
Expand All @@ -20,18 +20,19 @@ export function ConfirmModal({
onValidate,
}: ConfirmModalProps): JSX.Element {
return (
<Modal
open={open}
onClose={onClose}
aria-labelledby={title}
aria-describedby={message}
>
<Modal open={open} onClose={onClose} aria-labelledby={title}>
<StyledBox>
<h2>{title}</h2>
<p>{message}</p>
<Stack direction="row" spacing={2} justifyContent="end">
<Button onClick={onCancel}>Annuler</Button>
<Button onClick={onValidate}>Oui</Button>
<Typography id="modal-modal-title" variant="h4" component="h2" mb={4}>
{title}
</Typography>
{message}
<Stack direction="row" spacing={2} mt={4} justifyContent="end">
<Button variant="outlined" onClick={onCancel}>
Annuler
</Button>
<Button variant="contained" onClick={onValidate}>
Oui
</Button>
</Stack>
</StyledBox>
</Modal>
Expand All @@ -43,9 +44,7 @@ const StyledBox = styled(Box)({
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: 400,
width: 800,
backgroundColor: `${fr.colors.decisions.background.default.grey.default}`,
border: `2px solid ${fr.colors.decisions.border.default.beigeGrisGalet.default}`,
padding: "12px",
borderRadius: "6px",
padding: `${fr.spacing("8v")}`,
});
24 changes: 24 additions & 0 deletions targets/frontend/src/modules/documents/api/documents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ export class DocumentsController {
}
}

public async getUpdatedAfter() {
try {
const client = ApiClient.build(this.req.body.session_variables);
const service = new DocumentsService(
new InformationsRepository(client),
new DocumentsRepository(client)
);

if (!this.req.query.date) {
return this.res.status(400).json({
message: "Date is missing",
});
}
const date = new Date(this.req.query.date as string);
const docs = await service.getUpdatedAfter(date);

this.res.status(201).json(docs);
} catch (error) {
this.res.status(500).json({
message: DEFAULT_ERROR_500_MESSAGE,
});
}
}

checkInputs(): z.infer<typeof actionSchema> {
const inputResult = actionSchema.safeParse(this.req.body);

Expand Down
12 changes: 12 additions & 0 deletions targets/frontend/src/modules/documents/api/documents.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const getDocumentsUpdatedAfterDateQuery = `
query GetDocuments($updated_at: timestamptz!, $sources: [String!]) {
documents(where: {
updated_at: {_gte: $updated_at},
source: {_in: $sources}
},
order_by: {updated_at: desc}) {
title
source
slug
}
}`;
21 changes: 21 additions & 0 deletions targets/frontend/src/modules/documents/api/documents.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ApiClient } from "src/lib/api";
import { documentsPublishMutation } from "./documents.mutation";
import { DocumentRaw } from "../type";
import { getDocumentsUpdatedAfterDateQuery } from "./documents.query";
import { SOURCES } from "@socialgouv/cdtn-sources";

export class DocumentsRepository {
client: ApiClient;
Expand All @@ -26,4 +28,23 @@ export class DocumentsRepository {
throw error;
}
}

async getUpdatedAfter(date: Date): Promise<any[]> {
const { error, data } = await this.client.query<
{ documents: [] },
{ updated_at: Date; sources: string[] }
>(getDocumentsUpdatedAfterDateQuery, {
updated_at: date,
sources: [SOURCES.LETTERS, SOURCES.EDITORIAL_CONTENT],
});

if (error) {
console.log("Error: ", error);
throw error;
}
if (!data || data.documents.length === 0) {
return [];
}
return data.documents;
}
}
13 changes: 10 additions & 3 deletions targets/frontend/src/modules/documents/api/documents.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DocumentsRepository } from "./documents.repository";
import { NotFoundError } from "src/lib/api/ApiErrors";
import { Information, InformationsRepository } from "src/modules/informations";
import { DocumentRaw } from "../type";
import { DocumentRaw, ShortDocument } from "../type";
import { format } from "date-fns";
import { generateIds } from "@shared/id-generator";
import slugify from "@socialgouv/cdtn-slugify";
Expand Down Expand Up @@ -108,7 +108,14 @@ export class DocumentsService {
document = this.mapInformationToDocument(information);
break;
}
const result = await this.documentsRepository.update(document);
return result;
return await this.documentsRepository.update(document);
}

public async getUpdatedAfter(date: Date): Promise<ShortDocument[]> {
const documents = await this.documentsRepository.getUpdatedAfter(date);

return documents.map((doc) => {
return doc;
});
}
}
6 changes: 5 additions & 1 deletion targets/frontend/src/modules/documents/type.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { SourceRoute } from "@socialgouv/cdtn-sources";

export type Document = {
cdtnId: string;
initialId: string;
source: string;
source: SourceRoute;
document: any;
slug: string;
text: string;
title: string;
metaDescription: string;
};

export type ShortDocument = Pick<Document, "source" | "slug" | "title">;

export type DocumentRaw = {
cdtn_id: string;
initial_id: string;
Expand Down
47 changes: 47 additions & 0 deletions targets/frontend/src/modules/export/components/document-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react";
import { Stack } from "src/components/layout/Stack";
import BlockIcon from "@mui/icons-material/Block";
import { CircularProgress as Spinner, Link } from "@mui/material";
import { getRouteBySource } from "@socialgouv/cdtn-sources";
import { ShortDocument } from "../../documents";

type Props = {
docs: ShortDocument[];
isLoadingDocs: boolean;
};
export default function DocumentList({
docs,
isLoadingDocs,
}: Props): JSX.Element {
return (
<>
<strong>Documents inclus dans la mise à jour</strong>

{isLoadingDocs ? (
<Stack mt={2} justifyContent="center">
<Spinner></Spinner>
</Stack>
) : docs.length ? (
<ul>
{docs.map((doc) => (
<li key={doc.slug}>
<Link
href={`https://code-du-travail-numerique-preprod.dev.fabrique.social.gouv.fr/${getRouteBySource(
doc.source
)}/${doc.slug}`}
target="_blank"
sx={{ fontSize: "0.8rem" }}
>
{doc.title}
</Link>
</li>
))}
</ul>
) : (
<Stack mt={2} justifyContent="center">
<BlockIcon></BlockIcon>
</Stack>
)}
</>
);
}
Loading

0 comments on commit 718fe68

Please sign in to comment.