Skip to content

Commit

Permalink
fix(mentions): Complete corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Oct 31, 2024
1 parent e0a0613 commit 8a35f35
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 48 deletions.
50 changes: 12 additions & 38 deletions client/src/pages/mentions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -513,7 +481,10 @@ export default function Mentions() {
</Button>
</ModalContent>
<ModalFooter>
<Button onClick={addCorrections} title="Validate modifications">
<Button
onClick={addCorrections}
title={`Validate modification${corrections.length > 1 ? 's' : ''}`}
>
{`Validate modification${corrections.length > 1 ? 's' : ''}`}
</Button>
</ModalFooter>
Expand Down Expand Up @@ -560,8 +531,11 @@ export default function Mentions() {
</Select>
</ModalContent>
<ModalFooter>
<Button onClick={switchType} title="Validate modifications">
Validate modifications
<Button
onClick={switchType}
title={`Validate modification${corrections.length > 1 ? 's' : ''}`}
>
{`Validate modification${corrections.length > 1 ? 's' : ''}`}
</Button>
</ModalFooter>
</Modal>
Expand Down
56 changes: 50 additions & 6 deletions client/src/utils/curations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
8 changes: 4 additions & 4 deletions server/src/utils/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit 8a35f35

Please sign in to comment.