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): add ref to relevant content #340

Merged
merged 4 commits into from
Feb 26, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 38 additions & 4 deletions targets/frontend/src/pages/alerts/[[...params]].js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @jsxImportSource theme-ui */
import { Accordion } from "@reach/accordion";
import slugify from "@socialgouv/cdtn-slugify";
import { getRouteBySource } from "@socialgouv/cdtn-sources";
Expand All @@ -9,10 +10,11 @@ import { DiffChange } from "src/components/changes";
import { ChangesGroup } from "src/components/changes/ChangeGroup";
import { Layout } from "src/components/layout/auth.layout";
import { Stack } from "src/components/layout/Stack";
import { Li } from "src/components/list";
import { Pagination } from "src/components/pagination";
import { withCustomUrqlClient } from "src/hoc/CustomUrqlClient";
import { withUserProvider } from "src/hoc/UserProvider";
import { Card, Container, Divider, Message } from "theme-ui";
import { Box, Card, Container, Divider, Message, NavLink } from "theme-ui";
import { useQuery } from "urql";

const getAlertQuery = `
Expand Down Expand Up @@ -157,21 +159,41 @@ export function AlertPage() {
<ChangesGroup
changes={alert.changes.documents}
label="Contenus liés"
renderChange={(item, i) => {
renderChange={(item) => {
const [title, anchor] = item.document.title.split("#");

return (
<li key={`${alert.id}-documents-${i}`}>
<li
sx={{ lineHeight: 1.4, paddingBottom: "xxsmall" }}
key={`${alert.id}-documents-${item.document.id}`}
>
<a
target="_blank"
rel="noopener noreferrer"
key={item.document.id}
href={`https://code.travail.gouv.fr/${getRouteBySource(
item.document.source
)}/${slugify(title)}${anchor ? `#${anchor}` : ``}`}
>
{title}
</a>
<Box>
{jsxJoin(
item.references.map((node) => (
<NavLink
sx={{
fontSize: "xsmall",
color: "muted",
lineHeight: 1,
}}
href={node.url}
key={node.dila_cid}
>
{node.title}
</NavLink>
)),
", "
)}
</Box>
</li>
);
}}
Expand Down Expand Up @@ -202,3 +224,15 @@ export function AlertPage() {
// };

export default withCustomUrqlClient(withUserProvider(AlertPage));

function jsxJoin(array, str) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure I get what is this for ? Where is the comma in the end ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is Array.join() but work for array containing jsx

return array.length > 0
? array.reduce((result, item) => (
<>
{result}
{str}
{item}
</>
))
: null;
}