Skip to content

Commit

Permalink
fix(mentions): Fix undo button for multiples corrections, close #79
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 4, 2024
1 parent a825aea commit 58b43a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
42 changes: 27 additions & 15 deletions client/src/pages/mentions.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-param-reassign */
import {
Badge,
Button,
Col,
Container,
Expand All @@ -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';

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -242,6 +238,22 @@ export default function Mentions() {
style={{ color: rowData.mention_context.used ? '#8dc572' : '#be6464' }}
/>
);
const hasCorrectionTemplate = (rowData) => (rowData?.hasCorrection ? (
<>
<Badge variant={correction.corrected.badgeType}>
{correction.corrected.label}
</Badge>
<Button
icon="arrow-go-back-line"
onClick={() => undo2(rowData.id)}
size="sm"
title="Undo changes"
variant="info"
/>
</>
) : (
''
));

// Events
const onPage = (event) => {
Expand Down

0 comments on commit 58b43a2

Please sign in to comment.