Skip to content

Commit

Permalink
[Enhancement #461] Do no create term occurrence when only approving e…
Browse files Browse the repository at this point in the history
…xisting suggested occurrence.

It already exists in the repository.
  • Loading branch information
ledsoft committed May 20, 2024
1 parent 8a2c226 commit cd43910
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/action/AsyncAnnotatorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function loadTermByIri(termIri: string) {
export function saveOccurrence(occurrence: TermOccurrence) {
const action = { type: ActionType.CREATE_TERM_OCCURRENCE };
return (dispatch: ThunkDispatch) => {
dispatch(asyncActionRequest(action, true));
return Ajax.put(
`${Constants.API_PREFIX}/occurrence`,
content(occurrence.toJsonLd())
Expand Down
4 changes: 2 additions & 2 deletions src/action/AsyncTermActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function removeOccurrence(
type: ActionType.REMOVE_TERM_OCCURRENCE,
};
return (dispatch: ThunkDispatch) => {
dispatch(asyncActionRequest(action));
dispatch(asyncActionRequest(action, true));
const OccurrenceIri = VocabularyUtils.create(occurrence.iri!);
return Ajax.delete(
Constants.API_PREFIX + "/occurrence/" + OccurrenceIri.fragment,
Expand Down Expand Up @@ -267,7 +267,7 @@ export function approveOccurrence(
type: ActionType.APPROVE_TERM_OCCURRENCE,
};
return (dispatch: ThunkDispatch) => {
dispatch(asyncActionRequest(action));
dispatch(asyncActionRequest(action, true));
const OccurrenceIri = VocabularyUtils.create(occurrence.iri!);
return Ajax.put(
Constants.API_PREFIX + "/occurrence/" + OccurrenceIri.fragment,
Expand Down
15 changes: 11 additions & 4 deletions src/component/annotator/Annotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ export class Annotator extends React.Component<AnnotatorProps, AnnotatorState> {
} else {
delete ann.attribs.resource;
}
delete ann.attribs.score;
let shouldUpdate = true;
if (term !== null) {
shouldUpdate = this.createOccurrence(annotationSpan, ann, term);
this.approveOccurrence(annotationSpan);
}
delete ann.attribs.score;
if (shouldUpdate) {
this.updateInternalHtml(dom);
}
Expand Down Expand Up @@ -294,9 +294,16 @@ export class Annotator extends React.Component<AnnotatorProps, AnnotatorState> {
});
return false;
} else {
const to = createTermOccurrence(term, annotationElem, this.props.fileIri);
to.types = [VocabularyUtils.TERM_FILE_OCCURRENCE];
this.props.saveTermOccurrence(to);
if (!annotationNode.score) {
// Create occurrence only if we are not just approving an existing one
const to = createTermOccurrence(
term,
annotationElem,
this.props.fileIri
);
to.types = [VocabularyUtils.TERM_FILE_OCCURRENCE];
this.props.saveTermOccurrence(to);
}
return true;
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/component/annotator/__tests__/Annotator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1087,5 +1087,23 @@ describe("Annotator", () => {
wrapper.instance().onAnnotationTermSelected(annotation, term);
expect(mockedCallbackProps.onUpdate).not.toHaveBeenCalled();
});

it("does not create term occurrence when user approves existing annotation", () => {
const wrapper = shallow<Annotator>(
<Annotator
fileIri={fileIri}
vocabularyIri={vocabularyIri}
{...mockedCallbackProps}
{...stateProps}
initialHtml={generalHtmlContent}
{...intlFunctions()}
/>
);
const term = Generator.generateTerm();
annotation.resource = term.iri;
annotation.score = "1.0";
wrapper.instance().onAnnotationTermSelected(annotation, term);
expect(mockedCallbackProps.saveTermOccurrence).not.toHaveBeenCalled();
});
});
});

0 comments on commit cd43910

Please sign in to comment.