From 58b43a21d6546e8945c09560c4fb7c7dd51a7d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Mon, 4 Nov 2024 16:08:39 +0100 Subject: [PATCH] fix(mentions): Fix undo button for multiples corrections, close #79 --- README.md | 4 +++- client/src/pages/mentions.jsx | 42 ++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f6146d81..acfbf915 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ [![Discord Follow](https://dcbadge.vercel.app/api/server/TudsqDqTqb?style=flat)](https://discord.gg/TudsqDqTqb) ![license](https://img.shields.io/github/license/dataesr/works-magnet) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/dataesr/works-magnet) -[![Production deployment](https://github.com/dataesr/works-magnet/actions/workflows/production.yml/badge.svg)](https://github.com/dataesr/works-magnet/actions/workflows/production.yml) +[![deployment](https://github.com/dataesr/works-magnet/actions/workflows/production.yml/badge.svg)](https://github.com/dataesr/works-magnet/actions/workflows/production.yml) +![website](https://img.shields.io/website?url=https%3A%2F%2Fworks-magnet.esr.gouv.fr) +[![SWH](https://archive.softwareheritage.org/badge/origin/https://github.com/dataesr/works-magnet)](https://archive.softwareheritage.org/browse/origin/?origin_url=https://github.com/dataesr/works-magnet) Retrieve the scholarly works of your institution. diff --git a/client/src/pages/mentions.jsx b/client/src/pages/mentions.jsx index 1fd4fee6..b07a02a0 100644 --- a/client/src/pages/mentions.jsx +++ b/client/src/pages/mentions.jsx @@ -1,5 +1,6 @@ /* eslint-disable no-param-reassign */ import { + Badge, Button, Col, Container, @@ -21,13 +22,13 @@ import { useEffect, useState } from 'react'; import { useSearchParams } from 'react-router-dom'; import useWebSocket from 'react-use-websocket'; +import { correction } from '../config'; import useToast from '../hooks/useToast'; import { getMentionsCorrections } from '../utils/curations'; import { affiliations2Template, authorsTemplate, doiTemplate, - hasCorrectionTemplate, } from '../utils/templates'; import { capitalize, getMentions } from '../utils/works'; @@ -146,23 +147,18 @@ export default function Mentions() { switchSendModal(); } }; - const undo = (_mentions, _mention) => { - const mentionTmp = _mentions.map((mention) => { - if (mention.id === _mention.id) { - return { - ...mention, - hasCorrection: false, - hasCorrectionType: false, - mention_context: JSON.parse( - JSON.stringify(_mention.mention_context_original), - ), - type: _mention.type_original, - }; + const undo = (id) => { + const mentionsTmp = mentions.map((mention) => { + if (mention.id === id) { + mention.hasCorrection = false; + mention.hasCorrectionType = false; + mention.mention_context = JSON.parse(JSON.stringify(mention.mention_context_original)), + mention.type = mention.type_original; } return mention; }); - setMentions(mentionTmp); - setCorrections(getMentionsCorrections(mentionTmp)); + setMentions(mentionsTmp); + setCorrections(getMentionsCorrections(mentionsTmp)); }; const switchType = () => { const selectedMentionsIds = selectedMentions.map( @@ -242,6 +238,22 @@ export default function Mentions() { style={{ color: rowData.mention_context.used ? '#8dc572' : '#be6464' }} /> ); + const hasCorrectionTemplate = (rowData) => (rowData?.hasCorrection ? ( + <> + + {correction.corrected.label} + +