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(frontend): update fiches service-public view #361

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion targets/frontend/src/components/fiches-sp/addFicheForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function AddFicheSpForm({ onAdd }) {
<Button
size="small"
variant="secondary"
outline
type="button"
sx={{ flex: "0 0 auto", ml: "xxlarge" }}
onClick={() => append({ id: "" })}
Expand All @@ -108,7 +109,7 @@ export function AddFicheSpForm({ onAdd }) {
})}
<Box>
<Button
variant="secondary"
variant="primary"
disabled={Object.keys(errors).length > 0 || !isDirty}
>
{isDirty && Object.keys(errors).length === 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export function FichesServicePublicContainer() {

const getFicheServicePublicId = `
query getServicePublicId($offset: Int = 0, $limit: Int = 50) {
ficheIds: service_public_contents( offset: $offset, limit: $limit, order_by: [{status: desc, id: asc}]) {
id, status
ficheIds: v1_fiches_sp( offset: $offset, limit: $limit) {
id, cdtn_id, status, is_available, is_published
}
aggs:service_public_contents_aggregate {
aggs:v1_fiches_sp_aggregate {
aggregate{
count
}
Expand Down
142 changes: 126 additions & 16 deletions targets/frontend/src/components/fiches-sp/list.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
/** @jsxImportSource theme-ui */

import PropTypes from "prop-types";
import { useContext } from "react";
import {
IoMdCheckmarkCircleOutline,
IoMdInformationCircleOutline,
} from "react-icons/io";
import { SelectionContext } from "src/pages/contenus/fiches-sp";
import { Label } from "theme-ui";

import { Li, List } from "../list";
import { css, Label, Text } from "theme-ui";

export function ServicPublicList({ items }) {
return (
<List>
<Table>
<thead>
<tr>
<Th sx={{ width: "2.5rem" }} />
<Th align="left">id</Th>
<Th align="left">status</Th>
</tr>
</thead>
{items.map((item) => (
<Li key={item.id}>
<ServicePublicItem item={item} />
</Li>
<ServicePublicItemRow key={item.id} item={item} />
))}
</List>
</Table>
);
}

function ServicePublicItem({ item }) {
function ServicePublicItemRow({ item }) {
const [selectedItems, setSelectedItems] = useContext(SelectionContext);

function updateSelection(event) {
Expand All @@ -27,13 +37,113 @@ function ServicePublicItem({ item }) {
}
}
return (
<Label>
<input
type="checkbox"
defaultChecked={selectedItems.includes(item.id)}
onChange={updateSelection}
<Tr>
<Td>
<input
type="checkbox"
defaultChecked={selectedItems.includes(item.id)}
onChange={updateSelection}
id={`row-${item.id}`}
/>
</Td>
<Td>
<Label htmlFor={`row-${item.id}`} sx={{ cursor: "pointer" }}>
{item.id}
</Label>
</Td>
<Td>{getStatus(item)}</Td>
</Tr>
);
}

function getStatus({ status, cdtn_id, is_available, is_published }) {
if (status === "unknow") {
return <Text sx={{ color: "danger" }}>fiche inconnue</Text>;
}
if (cdtn_id === null) {
if (status === "unknown") {
return (
<Text sx={{ color: "critical" }}>
fiche non trouvée{" "}
<IoMdInformationCircleOutline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you add a tip here to say the same thing:

fiche non trouvée <->La fiche n'existe pas

I suggest to remove the IoMdInformationCircleOutline and directly write La fiche n'existe pas in place of fiche non trouvée

title="La fiche n'existe pas"
aria-label="La fiche n'existe pas"
/>
</Text>
);
}
return (
<Text sx={{ color: "muted" }}>
bientôt disponible{" "}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, bientôt disponible is wrong because an error can happen. I suggest to remove the tip and directly write En attente de traitement.

<IoMdInformationCircleOutline
title="La fiche n'a pas encore été importée"
aria-label="La fiche n'a pas encore été importée"
/>
</Text>
);
}
if (is_available) {
if (is_published) {
return (
<Text sx={{ color: "positive" }}>
<IoMdCheckmarkCircleOutline
aria-label="la fiche est disponible"
title="La fiche est disponible"
/>
</Text>
);
}
return <Text sx={{ color: "muted" }}>dépubliée</Text>;
}
return (
<Text sx={{ color: "critical" }}>
supprimée{" "}
<IoMdInformationCircleOutline
title="La fiche n'existe plus."
aria-label="La fiche n'existe plus"
/>
{item.id} ({item.status})
</Label>
</Text>
);
}

const Table = (props) => <table css={styles.table} {...props} />;
const Tr = (props) => <tr css={styles.tr} {...props} />;
const cellPropTypes = {
align: PropTypes.oneOf(["left", "right", "center"]),
};
const Th = ({ align = "left", ...props }) => (
<th css={styles.th} sx={{ textAlign: align }} {...props} />
);
Th.propTypes = cellPropTypes;
const Td = ({ align = "left", ...props }) => (
<td css={styles.td} {...props} sx={{ textAlign: align }} />
);
Td.propTypes = cellPropTypes;

const styles = {
table: css({
borderCollapse: "collapse",
borderRadius: "small",
overflow: "hidden",
width: "100%",
}),
td: css({
fontWeight: 300,
px: "xsmall",
py: "xxsmall",
"tr:nth-of-type(even) &": {
bg: "highlight",
},
}),
th: css({
borderBottom: "1px solid",
fontSize: "medium",
// bg: "info",
// color: "white",
fontWeight: "semibold",

px: "xsmall",

py: "xsmall",
}),
};
3 changes: 3 additions & 0 deletions targets/hasura/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@
- created_at
filter: {}
check: {}
- table:
schema: v1
name: fiches_sp
- table:
schema: v1
name: fiches_travail_data_alerts
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP VIEW IF EXISTS "v1"."fiches_sp";
11 changes: 11 additions & 0 deletions targets/hasura/migrations/1616080671217_create_fichesp_view/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE OR REPLACE VIEW"v1"."fiches_sp" AS
SELECT
fichesp.id,
fichesp.status,
COALESCE(documents.is_published AND documents.is_available, false) as online_status,
documents.cdtn_id,
documents.is_published,
documents.is_available
FROM service_public_contents as "fichesp"
LEFT JOIN documents on fichesp.id = documents.initial_id
ORDER BY online_status ASC, TRIM(leading 'F' FROM id)::INTEGER ASC;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top 👍

Empty file removed targets/ingester/data/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions targets/ingester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"build": "ncc build ./src/cli.js -o ./dist -s",
"cli": "node --enable-source-maps --unhandled-rejections=strict dist/index.js",
"cli:dev": "HASURA_GRAPHQL_ENDPOINT=http://localhost:8080/v1/graphql HASURA_GRAPHQL_ADMIN_SECRET=admin1 node -r esm src/cli.js",
"cli:prod": "HASURA_GRAPHQL_ENDPOINT=http://localhost:8080/v1/graphql HASURA_GRAPHQL_ADMIN_SECRET=admin1 node --enable-source-maps --unhandled-rejections=strict dist/index.js",
"lint": "eslint src/**/*.js",
"types": "tsc",
"test": "jest --passWithNoTests"
Expand Down
12 changes: 3 additions & 9 deletions targets/ingester/src/transform/fichesServicePublic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,18 @@ export default async function getFichesServicePublic(pkgName) {
throw new Error(`error while retrieving ingester packages version`);
}

const includeFicheId = results.data?.ficheIds.map(({ id }) => id) || [];

const includeFicheId =
(results.data || { ficheIds: [] }).ficheIds.map(({ id }) => id) || [];
const listFicheVdd = filter(includeFicheId, ficheVddIndex);

const unknonwFiches = includeFicheId.filter((id) =>
listFicheVdd.every((fiche) => fiche.id !== id)
);
console.log({ unknonwFiches });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgotten console.log ? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

await client
.mutation(updateStatusMutation, { ids: unknonwFiches, status: "unknown" })
.toPromise();

const knonwFiches = includeFicheId.filter((id) =>
listFicheVdd.some((fiche) => fiche.id === id)
);
await client
.mutation(updateStatusMutation, { ids: knonwFiches, status: "done" })
.toPromise();

const fichesIdFromContrib = contributions.flatMap(({ answers }) => {
const url = extractMdxContentUrl(answers.generic.markdown);
if (url) {
Expand Down