From 8a35f353eea51047458ed824054da52c65d10207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Thu, 31 Oct 2024 18:59:15 +0100 Subject: [PATCH] fix(mentions): Complete corrections --- client/src/pages/mentions.jsx | 50 ++++++++---------------------- client/src/utils/curations.jsx | 56 ++++++++++++++++++++++++++++++---- server/src/utils/github.js | 8 ++--- 3 files changed, 66 insertions(+), 48 deletions(-) diff --git a/client/src/pages/mentions.jsx b/client/src/pages/mentions.jsx index 94faa22..dc1887d 100644 --- a/client/src/pages/mentions.jsx +++ b/client/src/pages/mentions.jsx @@ -114,43 +114,11 @@ export default function Mentions() { return mention; }), ); - const correctedMentions = mentions - .filter((correctedMention) => correctedMention.hasCorrection) - .map((correctedMention) => ({ - id: correctedMention.id, - doi: correctedMention.doi, - texts: [ - { - text: correctedMention.context, - class_attributes: { - classification: { - used: { - previousValue: correctedMention.mention_context_original.used, - score: 1.0, - value: correctedMention.mention_context.used, - }, - created: { - previousValue: - correctedMention.mention_context_original.created, - score: 1.0, - value: correctedMention.mention_context.created, - }, - shared: { - previousValue: - correctedMention.mention_context_original.shared, - score: 1.0, - value: correctedMention.mention_context.shared, - }, - }, - }, - }, - ], - })); - setCorrections(correctedMentions); - setSelectedMentions([]); + setCorrections(getMentionsCorrections(mentions)); setCorrectionsUsed(DEFAULT_CORRECTION); setCorrectionsCreated(DEFAULT_CORRECTION); setCorrectionsShared(DEFAULT_CORRECTION); + setSelectedMentions([]); switchCharacterizationsModal(); }; const feedback = async () => { @@ -179,7 +147,7 @@ export default function Mentions() { } }; const undo = (_mentions, _mention) => { - const mentionTmp = mentions.map((mention) => { + const mentionTmp = _mentions.map((mention) => { if (mention.id === _mention.id) { return { ...mention, @@ -513,7 +481,10 @@ export default function Mentions() { - @@ -560,8 +531,11 @@ export default function Mentions() { - diff --git a/client/src/utils/curations.jsx b/client/src/utils/curations.jsx index a0ba121..c242523 100644 --- a/client/src/utils/curations.jsx +++ b/client/src/utils/curations.jsx @@ -11,11 +11,55 @@ const getAffiliationsCorrections = (affiliations) => affiliations const getMentionsCorrections = (mentions) => mentions .filter((mention) => mention.hasCorrection) - .map((mention) => ({ - id: mention.id, - doi: mention.doi, - type: mention.type, - previousType: mention.type_original, - })); + .map((mention) => { + const corrections = []; + if (mention.type !== mention.type_original) { + corrections.push({ + id: mention.id, + doi: mention.doi, + type: mention.type, + previousType: mention.type_original, + }); + } + if ( + mention.mention_context.used + !== mention.mention_context_original.used + || mention.mention_context.created + !== mention.mention_context_original.created + || mention.mention_context.shared + !== mention.mention_context_original.shared + ) { + corrections.push({ + id: mention.id, + doi: mention.doi, + texts: [ + { + text: mention.context, + class_attributes: { + classification: { + used: { + previousValue: mention.mention_context_original.used, + score: 1.0, + value: mention.mention_context.used, + }, + created: { + previousValue: mention.mention_context_original.created, + score: 1.0, + value: mention.mention_context.created, + }, + shared: { + previousValue: mention.mention_context_original.shared, + score: 1.0, + value: mention.mention_context.shared, + }, + }, + }, + }, + ], + }); + } + return corrections; + }) + .flat(); export { getAffiliationsCorrections, getMentionsCorrections }; diff --git a/server/src/utils/github.js b/server/src/utils/github.js index 1a15ba7..ba572f5 100644 --- a/server/src/utils/github.js +++ b/server/src/utils/github.js @@ -93,11 +93,11 @@ const createIssue = ({ email, issue, type }) => { case 'openalex-affiliations': return createIssueOpenAlexAffiliations({ email, issue }); default: - console.error(`Error wile creating Github issue as "type" should be one of ["mentions-characterizations", "openalex-affiliations"] instead of "${type}".`); + console.error( + `Error wile creating Github issue as "type" should be one of ["mentions-characterizations", "openalex-affiliations"] instead of "${type}".`, + ); return false; } }; -export { - createIssue, -}; +export { createIssue };