Skip to content

Commit

Permalink
Merge pull request #2659 from Inist-CNRS/2525-annotation-on-modified-…
Browse files Browse the repository at this point in the history
…value

2525 annotation on modified value
  • Loading branch information
jonathanarnault authored Mar 4, 2025
2 parents 440c747 + 39d5d70 commit 21a78a1
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 42 deletions.
5 changes: 3 additions & 2 deletions src/app/custom/translations.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,8 @@
"annotation_status_parking" "Parking" "Parking"
"annotation_correct_value" Correct "%{value}" Corriger "%{value}"
"annotation_remove_value" Remove "%{value}" Retirer "%{value}"
"annotation_remove_content" Remove content from "%{value}" Retirer du contenu de "%{value}"
"annotation_remove_content" Remove content Retirer du contenu
"annotation_remove_content_from" Remove content from "%{value}" Retirer du contenu de "%{value}"
"annotation_add_value" "Add Value" "Ajouter une valeur"
"annotation_general_comment" "General commentary" "Commentaire général"
"annotation_choose_value" "Choose value to annotate" "Choisir la valeur à annoter"
Expand All @@ -1305,7 +1306,7 @@
"annotations_import_success" "%{filename} file have been imported successfully." "Le fichier %{filename} a été importé avec succès."
"annotations_import_failed_imports" "%{smart_count} annotation failed to be imported: %{filename}. |||| %{smart_count} annotations failed to be imported: %{filename}." "%{smart_count} annotation n'a pas pu être importée : %{filename} |||| %{smart_count} annotations n'ont pas pu être importées : %{filename}."
"annotations_import_error" "An error occured while importing annotations, please try again later." "Une erreur est survenue lors de l'import des annotations, merci de réessayer ultérieurement."
"annotation_remove_content" "Remove some content" "Retirer du contenu"
"annotation_remove_content_choice" "Remove some content" "Retirer du contenu"
"annotation_correct_content" "Correct some content" "Corriger du contenu"
"annotation_add_content" "Add some content" "Ajouter du contenu"
"annotation_annotate_field_choice" "Annotate the field" "Annoter le champ"
Expand Down
157 changes: 131 additions & 26 deletions src/app/js/annotation/AnnotationCommentStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,35 @@ import { useStore } from '@tanstack/react-form';
import PropTypes from 'prop-types';
import {
ANNOTATION_KIND_ADDITION,
ANNOTATION_KIND_COMMENT,
ANNOTATION_KIND_CORRECTION,
ANNOTATION_KIND_REMOVAL,
} from '../../../common/validator/annotation.validator';
import { useTranslate } from '../i18n/I18NContext';
import { CommentField } from './fields/CommentField';
import { ProposedValueField } from './fields/ProposedValueField';
import { getIsFieldValueAnUrl } from '../formats';

export function AnnotationCommentStep({ field, form, initialValue }) {
export const CommentDescription = ({
kind,
isFieldAnUrl,
annotationInitialValue,
fieldInitialValue,
}) => {
const { translate } = useTranslate();
const annotationInitialValue = useStore(form.store, (state) => {
return state.values.initialValue?.replace(/<[^>]*>/g, '');
});

const kind = useStore(form.store, (state) => {
return state.values.kind;
});

return (
<>
<Stack direction="row" gap={1} alignItems="center">
switch (kind) {
case ANNOTATION_KIND_CORRECTION: {
return isFieldAnUrl ? (
<Typography
sx={{
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
{translate('annotation_correct_content')}
</Typography>
) : (
<Tooltip title={annotationInitialValue}>
<Typography
sx={{
Expand All @@ -33,24 +43,119 @@ export function AnnotationCommentStep({ field, form, initialValue }) {
overflow: 'hidden',
}}
>
{kind === 'removal' &&
(Array.isArray(initialValue)
? translate('annotation_remove_value', {
value: annotationInitialValue,
})
: translate('annotation_remove_content', {
value: annotationInitialValue,
}))}
{kind === ANNOTATION_KIND_CORRECTION &&
translate('annotation_correct_value', {
{translate('annotation_correct_value', {
value: annotationInitialValue,
})}
</Typography>
</Tooltip>
);
}
case ANNOTATION_KIND_ADDITION: {
return (
<Typography
sx={{
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
{translate('annotation_add_value')}
</Typography>
);
}
case ANNOTATION_KIND_COMMENT: {
return (
<Typography
sx={{
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
{translate('annotation_general_comment')}
</Typography>
);
}
case ANNOTATION_KIND_REMOVAL: {
if (isFieldAnUrl) {
return (
<Typography
sx={{
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
{translate('annotation_remove_content')}
</Typography>
);
}

if (Array.isArray(fieldInitialValue)) {
return (
<Tooltip title={annotationInitialValue}>
<Typography
sx={{
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
{translate('annotation_remove_value', {
value: annotationInitialValue,
})}
{kind === 'addition' &&
translate('annotation_add_value')}
{kind === 'comment' &&
translate('annotation_general_comment')}
</Typography>
</Tooltip>
);
}

return (
<Tooltip title={annotationInitialValue}>
<Typography
sx={{
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
{translate('annotation_remove_content_from', {
value: annotationInitialValue,
})}
</Typography>
</Tooltip>
);
}
}
};

CommentDescription.propTypes = {
isFieldAnUrl: PropTypes.bool.isRequired,
kind: PropTypes.string.isRequired,
annotationInitialValue: PropTypes.string,
fieldInitialValue: PropTypes.any,
};

export function AnnotationCommentStep({ field, form, initialValue }) {
const { translate } = useTranslate();
const isFieldAnUrl = getIsFieldValueAnUrl(field.format?.name);

const annotationInitialValue = useStore(form.store, (state) => {
return state.values.initialValue?.replace(/<[^>]*>/g, '');
});

const kind = useStore(form.store, (state) => {
return state.values.kind;
});

return (
<>
<Stack direction="row" gap={1} alignItems="center">
<CommentDescription
annotationInitialValue={annotationInitialValue}
fieldInitialValue={initialValue}
isFieldAnUrl={isFieldAnUrl}
kind={kind}
/>
<Tooltip title={translate('public_annotation')}>
<HelpIcon fontSize="1.125rem" />
</Tooltip>
Expand Down
Loading

0 comments on commit 21a78a1

Please sign in to comment.