Skip to content

Commit

Permalink
Merge branch 'staging' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Jan 11, 2023
2 parents 12573fe + 2df373b commit 0b11c5e
Show file tree
Hide file tree
Showing 27 changed files with 336 additions and 155 deletions.
Binary file added src/assets/svg-logo/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion src/components/blocs/evenements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TagList from '../../tag-list';
import useEditMode from '../../../hooks/useEditMode';
import useFetch from '../../../hooks/useFetch';
import useNotice from '../../../hooks/useNotice';
import { getComparableNow } from '../../../utils/dates';

import api from '../../../utils/api';
import { saveError, saveSuccess, deleteError, deleteSuccess } from '../../../utils/notice-contents';
Expand Down Expand Up @@ -64,7 +65,18 @@ export default function AgendaOutlet() {
{data.data.map((event) => (
<TimelineItem date={event.eventDate} key={event.id}>
<Row className="flex--space-between">
<BadgeGroup><Badge text={event.type} /></BadgeGroup>
<BadgeGroup>
<Badge text={event.type} />
{event.eventDate < getComparableNow() ? (
<div className="fr-card__start ">
<Badge text="terminé" colorFamily="brown-opera" />
</div>
) : (
<div>
<Badge text="A venir" type="info" />
</div>
) }
</BadgeGroup>
{editMode && <Button onClick={() => onOpenModalHandler(event)} size="sm" icon="ri-edit-line" title="Editer l'évènement" tertiary borderless rounded />}
</Row>
<Text spacing="mb-1w" size="lead" bold>{event.title}</Text>
Expand Down
16 changes: 12 additions & 4 deletions src/components/blocs/relations-by-group/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useNotice from '../../../hooks/useNotice';
import Map from '../../map/auto-bound-map';
import RelationCard from '../../card/relation-card';
import { deleteError, saveError, saveSuccess, deleteSuccess } from '../../../utils/notice-contents';
import { getComparableNow } from '../../../utils/dates';

export default function RelationsByGroup({ group, reloader }) {
const { id: groupId, name: groupName, accepts: groupAccepts } = group;
Expand Down Expand Up @@ -70,8 +71,15 @@ export default function RelationsByGroup({ group, reloader }) {
// What to do with relatedObject! Shared Model or Card adaptability ?
const renderCards = () => {
if (!data && !data?.data?.length) return null;
const structures = data.data.filter((element) => (element.relatedObject?.collection === 'structures' && element.relatedObject?.currentLocalisation?.geometry?.coordinates));
const markers = structures.map((element) => {
const inactives = data.data.filter((element) => (element.relatedObject?.collection === 'structures'
&& element.relatedObject?.currentLocalisation?.geometry?.coordinates
&& (element?.endDate < getComparableNow() || !element.endDate)));

const actives = data.data.filter((element) => (inactives && (element?.endDate > getComparableNow())));

const orderedList = [...actives, ...inactives];

const markers = orderedList.map((element) => {
const { coordinates } = element.relatedObject.currentLocalisation.geometry;
const markersCoordinates = [...coordinates];
const reversed = markersCoordinates.reverse();
Expand All @@ -83,13 +91,13 @@ export default function RelationsByGroup({ group, reloader }) {
${element.relatedObject.currentLocalisation?.locality}`,
});
});
const list = data.data.map((element) => (
const list = orderedList.map((element) => (
<RelationCard
relation={element}
onEdit={() => onOpenModalHandler(element)}
/>
));
if (structures.length) {
if (orderedList.length) {
return (
<Row gutters>
<Col n="12">
Expand Down
11 changes: 10 additions & 1 deletion src/components/blocs/relations-participations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Bloc, BlocContent, BlocTitle } from '../../bloc';
import useFetch from '../../../hooks/useFetch';
import useUrl from '../../../hooks/useUrl';
import RelationCard from '../../card/relation-card';
import { getComparableNow } from '../../../utils/dates';

export default function RelationsParticipations() {
const { id: resourceId } = useUrl();
Expand All @@ -11,7 +12,15 @@ export default function RelationsParticipations() {

const renderCards = () => {
if (!data && !data?.data?.length) return null;
const list = data.data.map((element) => (
const inactives = data.data.filter((element) => (element.relatedObject?.collection === 'structures'
&& element.relatedObject?.currentLocalisation?.geometry?.coordinates
&& (element?.endDate < getComparableNow() || !element.endDate)));

const actives = data.data.filter((element) => (inactives && (element?.endDate > getComparableNow())));

const orderedList = [...actives, ...inactives];

const list = orderedList.map((element) => (
<RelationCard
relation={element}
onEdit={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function sanitize(form) {
return body;
}

export default function OfficiaTextForm({ id, data, onSave, onDelete }) {
export default function OfficialTextForm({ id, data, onSave, onDelete }) {
const [showErrors, setShowErrors] = useState(false);
const [query, setQuery] = useState('');
const [options, setOptions] = useState('');
Expand Down Expand Up @@ -274,13 +274,13 @@ export default function OfficiaTextForm({ id, data, onSave, onDelete }) {
);
}

OfficiaTextForm.propTypes = {
OfficialTextForm.propTypes = {
id: PropTypes.string,
data: PropTypes.oneOfType([PropTypes.shape, null]),
onSave: PropTypes.func.isRequired,
onDelete: PropTypes.func,
};
OfficiaTextForm.defaultProps = {
OfficialTextForm.defaultProps = {
id: null,
data: { relatedObjects: [] },
onDelete: null,
Expand Down
27 changes: 15 additions & 12 deletions src/components/blocs/wiki/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@ import useUrl from '../../../hooks/useUrl';
import { capitalize } from '../../../utils/strings';

const WIKI_LANG_ORDER = ['frwiki', 'enwiki', 'dewiki', 'itwiki', 'eswiki'];
const WIKI_URL = 'https://www.wikidata.org/w/api.php?format=json&origin=*&action=wbgetentities&ids=';
const getWikipediaUrl = (lang, title) => `https://${lang.slice(0, lang.length - 4)}.wikipedia.org/wiki/${title.replace(' ', '_')}`;
const filterWikipediaSiteLinks = (sitelinks) => [...new Set([...WIKI_LANG_ORDER, ...Object.keys(sitelinks)])]
.filter((lang) => lang !== 'commonswiki')
.filter((lang) => Object.keys(sitelinks).includes(lang))
.map((lang) => ({ lang: lang.slice(0, lang.length - 4).toUpperCase(), link: getWikipediaUrl(lang, sitelinks[lang]?.title) }));
.map((lang) => ({ lang: lang?.slice(0, lang.length - 4).toUpperCase(), link: getWikipediaUrl(lang, sitelinks[lang]?.title) }));

export default function Wiki() {
const { url, apiObject } = useUrl();
const { data: wikidata } = useFetch(`${url}/identifiers?filters[type]=Wikidata`);
const { data: wikidata } = useFetch(`${url}/identifiers?filters[type]=Wikidata&filters`);
const [activity, setActivity] = useState(null);
const [wikis, setWikis] = useState(null);

useEffect(() => {
const getActivity = async (wikiId) => fetch(`https://www.wikidata.org/w/api.php?format=json&origin=*&action=wbgetentities&ids=${wikiId}`)
.then((response) => response.json())
.then((json) => {
setActivity(json?.entities?.[wikiId]?.descriptions?.fr?.value);
const sitelinks = filterWikipediaSiteLinks(json?.entities?.[wikiId]?.sitelinks);
setWikis(sitelinks);
})
.catch(() => null);

const getActivity = async (wikidatas) => {
const allWikis = wikidatas
.filter((w) => w.active)
.map((wiki) => fetch(`${WIKI_URL}${wiki.value}`)
.then((res) => res.json())
.then((doc) => doc.entities[Object.keys(doc.entities)[0]]));
const datas = await Promise.all(allWikis);
setActivity(datas.filter((el) => el)[0]?.descriptions?.fr?.value);
const { sitelinks } = datas.filter((el) => el)[0];
setWikis(filterWikipediaSiteLinks(sitelinks));
};
if (wikidata?.data?.length) {
getActivity(wikidata.data[0]?.value);
getActivity(wikidata.data);
}
}, [wikidata]);
if (activity || wikis?.length > 0) {
Expand Down
35 changes: 21 additions & 14 deletions src/components/card/relation-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Text, Link, TagGroup, Tag, Icon, Badge } from '@dataesr/react-dsfr';
import PropTypes from 'prop-types';
import { Link as RouterLink, useNavigate } from 'react-router-dom';
import useEditMode from '../../hooks/useEditMode';
import { formatDescriptionDates, getComparableNow, toString } from '../../utils/dates';
import { formatDescriptionDatesForMandateAndPrizes, getComparableNow, toString } from '../../utils/dates';
import Button from '../button';
import CopyButton from '../copy/copy-button';
import styles from './styles.module.scss';
Expand All @@ -22,12 +22,13 @@ export default function RelationCard({ relation, inverse, onEdit }) {
const navigate = useNavigate();
const { editMode } = useEditMode();
const toPrintRelation = inverse ? relation.resource : relation.relatedObject;
const isFinished = ((relation.current !== undefined) && !relation.current) || (relation.active === false);
const isComming = ((relation.startDate > getComparableNow()
? formatDescriptionDates(relation.startDate || null, relation.endDate || null)
.replace('depuis le', 'À partir du')
.replace('depuis', 'À partir de')
: formatDescriptionDates(relation.startDate || null, relation.endDate || null)));
const isComming = relation.startDate > getComparableNow();
const interimMandate = relation.mandateTemporary ? ' par intérim ' : '';
const isFinished = ((relation.current !== undefined)
&& !relation.current) || (relation.active === false) || (relation.endDate < getComparableNow());

const renderPriceDate = relation.startDate ? ` obtenu en ${relation.startDate?.split('-')?.[0]}` : ' Date inconnue';

return (
<div className="fr-card fr-card--xs fr-card--grey fr-card--no-border">
<div className={`fr-card__body ${styles['card-body']} ${styles[`${toPrintRelation.collection}-border`]} ${isFinished && 'turngrey'}`}>
Expand All @@ -38,15 +39,16 @@ export default function RelationCard({ relation, inverse, onEdit }) {
{relation.relationType?.[getRelationTypeLabel(relation?.relatedObject?.gender)] || relation.relationType?.name}
</Text>
)}
{relation?.mandatePrecision && ` ${relation?.mandatePrecision}`}
{interimMandate}
{relation?.mandatesPrecision && ` ${relation?.mandatePrecision}`}
{relation?.laureatePrecision && ` ${relation?.laureatePrecision}`}
{' '}
{(relation?.resource.collection === 'prizes' && (relation.startDate || relation.endDate))
? relation.startDate?.split('-')?.[0] || 'Date inconnue'
: isComming}
{(relation?.resource.collection === 'prizes')
? renderPriceDate
: formatDescriptionDatesForMandateAndPrizes(relation) }
</p>
{(relation.otherAssociatedObjects?.length > 0) && (
<div className="fr-card__desc">
{' '}
<Text as="span" size="sm" bold>Structures associées:</Text>
<TagGroup>
{relation.otherAssociatedObjects.map(
Expand All @@ -55,17 +57,22 @@ export default function RelationCard({ relation, inverse, onEdit }) {
</TagGroup>
</div>
)}
{isComming && (
<div className="fr-card__start ">
<Badge type="info" text="A venir" />
</div>
)}
<p className={`fr-card__title ${styles[`${toPrintRelation.collection}-title`]}`}>
<RouterLink className="fr-text--lg" to={toPrintRelation?.href}>
{toPrintRelation?.displayName}
<Icon iconPosition="right" name="ri-arrow-right-line" />
</RouterLink>
</p>
{isFinished ? (
{isFinished && (
<div className={`fr-card__start ${styles['card-end']}`}>
<Badge text="terminé" />
</div>
) : ''}
)}
{(relation.startDateOfficialText?.id || relation.endDateOfficialText?.id) && (
<div className={`fr-card__end ${styles['card-end']}`}>
{relation.startDateOfficialText?.id && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/identifier/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import PaysageBlame from '../../paysage-blame';

const regexpValidateIdentifiers = (type) => {
const validator = {
idRef: [/^\d{8}[\dX]{1}$/, 'Doit contenir 9 caractères'],
idRef: [/^\d{8}[\dX]{1}$/, 'Identifiant incorrect'],
UAI: [/^[0-9]{7}[A-Z]{1}$/, "Doit commencer par 7 chiffres suivis d'une lettre majuscule"],
Wikidata: [/^Q[0-9]+$/, 'Doit commencer par "Q" et être suivi de 7 caractères'],
Siret: [/^[0-9]{14}$/, 'Doit contenir 14 chiffres'],
Expand Down
6 changes: 3 additions & 3 deletions src/components/forms/official-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function sanitize(form) {
return body;
}

export default function OfficiaTextForm({ id, data, onSave, onDelete }) {
export default function OfficialTextForm({ id, data, onSave, onDelete }) {
const [showErrors, setShowErrors] = useState(false);
const [query, setQuery] = useState('');
const [options, setOptions] = useState('');
Expand Down Expand Up @@ -274,13 +274,13 @@ export default function OfficiaTextForm({ id, data, onSave, onDelete }) {
);
}

OfficiaTextForm.propTypes = {
OfficialTextForm.propTypes = {
id: PropTypes.string,
data: PropTypes.oneOfType([PropTypes.shape, null]),
onSave: PropTypes.func.isRequired,
onDelete: PropTypes.func,
};
OfficiaTextForm.defaultProps = {
OfficialTextForm.defaultProps = {
id: null,
data: { relatedObjects: [] },
onDelete: null,
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/social-media/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const regexpValidateSocialMedia = (type) => {
Instagram: [/^(https:\/\/)?(www.)?instagram.com\/[A-Za-z0-9/:%_+.,#?!@&=-]+$/, 'https://www.instagram.com/<compte>/'],
Twitter: [/^(https:\/\/)?(www.)?twitter.com\/[0-9A-Za-z_]{1,15}$/, 'https://twitter.com/<compte>'],
Youtube: [/^(https:\/\/)?(www.)?youtube.com\/[A-Za-z0-9/:%_+.,#?!@&=-]+$/, 'https://www.youtube.com/channel/<chaine>'],
Linkedin: [/^(https:\/\/)?(www.)?(fr.)?linkedin.com\/.+\/[A-Za-z0-9/:%_+.,#?!@&=-]+$/, 'https://www.linkedin.com/<profil>'],
Linkedin: [/^(https:\/\/)?(www.)?(fr.)?linkedin.com\/.+[A-Za-z0-9/:%_+.,#?!@&=-]+$/, 'https://www.linkedin.com/<profil>'],
Twitch: [/^(https:\/\/)?(www.)?twitch\.tv\/([a-z0-9_]+)($|\?)/, 'https://twitch.tv/<chaine>'],
Tiktok: [/^(https:\/\/)?(www.)?tiktok\.com\/([A-Za-z0-9/:%_+.,#?!@&=-]+)($|\?)/, 'https://www.tiktok.com/@<compte>'],
Pinterest: [/^(https:\/\/)?(www.)?pinterest.fr\/[A-Za-z0-9/:%_+.,#?!@&=-]+$/, 'https://www.pinterest.fr/<compte>/'],
Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/weblinks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const regexpValidateWebSite = {
Onisep: /^(https?):\/\/www.onisep.fr\/http\/redirection\/etablissement\/identifiant\/\d+$/,
POpenData: /^(https?):\/\/[A-Za-z0-9/:%+.,#?!@&=-]+$/,
DataGouvFr: /^(https?):\/\/[A-Za-z0-9/:%+.,#?!@&=-]+$/,
mooc: /^(https:\/\/)?(www.)?fun-mooc.fr\/universities\/[A-Za-z0-9/:%+.,#?!@&=-]+\/$/,
mooc: /^(https:\/\/)?(www.)?fun-mooc.fr\/fr?\/(etablissements)?(universities)?\/[A-Za-z0-9:%+.,#?!@&=-]+\/$/,
CanalU: /^(https:\/\/)?(www.)?canal-u.tv\/chaines\/[\w\-_]*(.fr)?$/,
ServicePublic: /^(https:\/\/)?lannuaire.service-public.fr\/(gouvernement|institutions-juridictions|autorites-independantes)\/[A-Za-z0-9/:%+.,#?!@&=-]+$/,
LeMonde: /(^https:\/\/)?(www.)?lemonde.fr\/[a-z]+(-[a-z]+)*\/$/,
Expand All @@ -47,7 +47,7 @@ function validate(body) {
const errorMessage = {};
if (!body?.url) errorMessage.url = "L'url du lien est obligatoire";
if (!body?.type) errorMessage.type = 'Le type de lien est obligatoire';
if (body.type === 'jorfsearch' && !body.url.includes('https://jorfsearch.steinertriples.ch')) {
if (body.type === 'jorfsearch' && !body?.url?.includes('https://jorfsearch.steinertriples.ch')) {
errorMessage.url = 'Veuillez saisir votre URL avec cet exemple : https://jorfsearch.steinertriples.ch/name/<votreNom>';
}
const validationRule = regexpValidateWebSite?.[body.type];
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useEditMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export function EditModeContextProvider({ children }) {
reset();
}, [reset]);

const value = useMemo(() => ({ editMode, reset, toggle, setEditMode }), [editMode, reset, toggle, setEditMode]);
const value = useMemo(
() => ({ editMode, reset, toggle, setEditMode }),
[editMode, reset, toggle, setEditMode],
);

return (
<Context.Provider value={value}>
Expand Down
12 changes: 7 additions & 5 deletions src/layout/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ export default function Header() {
current={pathname === '/'}
/>
<>
<NavItem
title="Je contribue"
asLink={<RouterLink to="/contribuer" />}
current={pathname.startsWith('/contribuer')}
/>
{(viewer.role !== 'reader') && (
<NavItem
title="Je contribue"
asLink={<RouterLink to="/contribuer" />}
current={pathname.startsWith('/contribuer')}
/>
)}
<NavItem
title="Je recherche"
asLink={<RouterLink to="/rechercher?query=&page=1" />}
Expand Down
Loading

0 comments on commit 0b11c5e

Please sign in to comment.