-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
|
@@ -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 | ||
title="La fiche n'existe pas" | ||
aria-label="La fiche n'existe pas" | ||
/> | ||
</Text> | ||
); | ||
} | ||
return ( | ||
<Text sx={{ color: "muted" }}> | ||
bientôt disponible{" "} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, |
||
<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", | ||
}), | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW IF EXISTS "v1"."fiches_sp"; |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgotten console.log ? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment.
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:
I suggest to remove the
IoMdInformationCircleOutline
and directly writeLa fiche n'existe pas
in place offiche non trouvée