-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/annotation log #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XanderVertegaal
wants to merge
7
commits into
develop
Choose a base branch
from
feature/annotation-log
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c1dfcc5
Add AnnotationComments component
XanderVertegaal c6281f1
Do not filter out removed annotations in requested problem
XanderVertegaal 3a0ac2f
Update annotation list styling
XanderVertegaal 2bf0631
Add frontend filter to annotation log
XanderVertegaal 1788516
Fix frontend tests
XanderVertegaal 1705e31
Logic simplifications
XanderVertegaal 5899749
Merge branch 'develop' into feature/annotation-log
XanderVertegaal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 111 additions & 3 deletions
114
frontend/src/app/annotate/annotation-comments/annotation-comments.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,112 @@ | ||
| <ul> | ||
| <li>Annotation history: who did what when?</li> | ||
| <li>Ability to 'gold'/'ungold' sentences</li> | ||
| @let events = filteredEvents(); | ||
|
|
||
| @if (events === null) { | ||
| <p class="text-muted small fst-italic" i18n>Loading…</p> | ||
| } @else { | ||
| <div | ||
| class="d-flex align-items-center justify-content-between mb-2 gap-2 flex-wrap" | ||
| > | ||
| <div class="d-flex gap-2 flex-wrap"> | ||
| <div | ||
| class="btn-group btn-group-sm" | ||
| role="group" | ||
| aria-label="Filter by event kind" | ||
| i18n-aria-label | ||
| > | ||
| <input | ||
| type="checkbox" | ||
| class="btn-check" | ||
| id="filter-added" | ||
| [checked]="showAdded()" | ||
| (change)="showAdded.set(!showAdded())" | ||
| /> | ||
| <label class="btn btn-outline-success" for="filter-added"> | ||
| <fa-icon [icon]="faPlus" class="me-2" /> | ||
| <ng-container i18n>Added</ng-container> | ||
| </label> | ||
| <input | ||
| type="checkbox" | ||
| class="btn-check" | ||
| id="filter-removed" | ||
| [checked]="showRemoved()" | ||
| (change)="showRemoved.set(!showRemoved())" | ||
| /> | ||
| <label class="btn btn-outline-danger" for="filter-removed"> | ||
| <fa-icon [icon]="faMinus" class="me-2" /> | ||
| <ng-container i18n>Removed</ng-container> | ||
| </label> | ||
| </div> | ||
| <div | ||
| class="btn-group btn-group-sm" | ||
| role="group" | ||
| aria-label="Filter by annotation type" | ||
| i18n-aria-label | ||
| > | ||
| <input | ||
| type="checkbox" | ||
| class="btn-check" | ||
| id="filter-labels" | ||
| [checked]="showLabels()" | ||
| (change)="showLabels.set(!showLabels())" | ||
| /> | ||
| <label class="btn btn-outline-secondary" for="filter-labels"> | ||
| <fa-icon [icon]="faTag" class="me-2" /> | ||
| <ng-container i18n>Labels</ng-container> | ||
| </label> | ||
| <input | ||
| type="checkbox" | ||
| class="btn-check" | ||
| id="filter-kb" | ||
| [checked]="showKB()" | ||
| (change)="showKB.set(!showKB())" | ||
| /> | ||
| <label class="btn btn-outline-secondary" for="filter-kb"> | ||
| <fa-icon [icon]="faBook" class="me-2" /> | ||
| <ng-container i18n>KB items</ng-container> | ||
| </label> | ||
| </div> | ||
| </div> | ||
| <span class="text-muted small" i18n> | ||
| Showing {{ events.length }}/{{ totalCount() }} annotations | ||
| </span> | ||
| </div> | ||
| @if (events.length === 0) { | ||
| <p class="text-muted small fst-italic" i18n> | ||
| No annotations match the current filters. | ||
| </p> | ||
| } @else { | ||
| <ul class="list-unstyled d-flex flex-column gap-2 mb-0"> | ||
| @for (event of events; track $index) { | ||
| @let added = event.eventKind === "added"; | ||
| @let isLabel = event.annotationKind === "label"; | ||
| <li> | ||
| <div class="card border-0 shadow-sm overflow-hidden d-flex flex-row"> | ||
| <div | ||
| class="text-white d-flex align-items-center justify-content-center px-2 flex-shrink-0" | ||
| [class]="added ? 'bg-success' : 'bg-danger'" | ||
| > | ||
| <fa-icon [icon]="added ? faPlus : faMinus" /> | ||
| </div> | ||
| <div | ||
| class="card-body py-2 px-3 d-flex align-items-center justify-content-start gap-3" | ||
| > | ||
| <fa-icon [icon]="isLabel ? faTag : faBook" /> | ||
| <span class="flex-grow-1"> | ||
| <strong>{{ event.actor }}</strong> | ||
| {{ event.eventKind }} | ||
| {{ isLabel ? "a label" : "a knowledge base item" }}: | ||
| <span | ||
| [class]="isLabel ? 'label-pill ms-1' : 'font-monospace'" | ||
| > | ||
| {{ event.description }} | ||
| </span> | ||
| </span> | ||
| <span class="text-muted small text-end flex-shrink-0"> | ||
| {{ event.timestamp | date : "medium" }} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </li> | ||
| } | ||
| </ul> | ||
| } } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
119 changes: 118 additions & 1 deletion
119
frontend/src/app/annotate/annotation-comments/annotation-comments.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,139 @@ | ||
| import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
| import { of } from "rxjs"; | ||
|
|
||
| import { ProblemService } from "@/services/problem.service"; | ||
| import { Dataset, EntailmentLabel, KnowledgeBaseAnnotation, KnowledgeBaseRelationship, LabelAnnotation, Problem } from "@/types"; | ||
| import { AnnotationCommentsComponent } from "./annotation-comments.component"; | ||
|
|
||
| const baseAnnotationFields = { | ||
| id: 1, | ||
| session: 1, | ||
| notes: "", | ||
| removable: false, | ||
| removedAt: null, | ||
| removedBy: null, | ||
| }; | ||
|
|
||
| describe("AnnotationCommentsComponent", () => { | ||
| let component: AnnotationCommentsComponent; | ||
| let fixture: ComponentFixture<AnnotationCommentsComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [AnnotationCommentsComponent], | ||
| providers: [ | ||
| { provide: ProblemService, useValue: {} }, | ||
| ], | ||
| }).compileComponents(); | ||
| }); | ||
|
|
||
| // Needed to override the problem$ observable in the providers. | ||
| function recreateComponent(kbAnnotations: KnowledgeBaseAnnotation[] = [], labelAnnotations: LabelAnnotation[] = []) { | ||
| const mockProblem: Problem = { | ||
| id: 1, | ||
| base: null, | ||
| premises: [], | ||
| hypothesis: null, | ||
| entailmentLabel: EntailmentLabel.UNKNOWN, | ||
| dataset: Dataset.USER, | ||
| extraData: null, | ||
| kbAnnotations, | ||
| labelAnnotations, | ||
| }; | ||
|
|
||
| TestBed.overrideProvider(ProblemService, { useValue: { problem$: of(mockProblem) } }); | ||
| fixture = TestBed.createComponent(AnnotationCommentsComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| it("should create", () => { | ||
| recreateComponent(); | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("emits an 'added' event for each annotation", () => { | ||
| recreateComponent( | ||
| [], | ||
| [ | ||
| { | ||
| ...baseAnnotationFields, | ||
| createdAt: "2024-01-01T10:00:00Z", | ||
| createdBy: "Alice", | ||
| label: { id: 1, text: "negation", description: "" }, | ||
| attachedByCurrentUser: false, | ||
| }, | ||
| ] | ||
| ); | ||
|
|
||
| const events = component.filteredEvents()!; | ||
| expect(events.length).toBe(1); | ||
| expect(events[0]).toEqual( | ||
| jasmine.objectContaining({ | ||
| eventKind: "added", | ||
| annotationKind: "label", | ||
| actor: "Alice", | ||
| description: "negation", | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it("emits a 'removed' event when removedAt is set", () => { | ||
| recreateComponent( | ||
| [ | ||
| { | ||
| ...baseAnnotationFields, | ||
| createdAt: "2024-01-01T10:00:00Z", | ||
| createdBy: "Bob", | ||
| removedAt: "2024-01-02T10:00:00Z", | ||
| removedBy: "3", | ||
| entity1: "cat", | ||
| relationship: KnowledgeBaseRelationship.EQUAL, | ||
| entity2: "feline", | ||
| }, | ||
| ], | ||
| [] | ||
| ); | ||
|
|
||
| const events = component.filteredEvents()!; | ||
| expect(events.length).toBe(2); | ||
| const removed = events.find((e) => e.eventKind === "removed"); | ||
| expect(removed).toEqual( | ||
| jasmine.objectContaining({ | ||
| eventKind: "removed", | ||
| annotationKind: "knowledgeBase", | ||
| description: "cat = feline", | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it("sorts events by timestamp descending", () => { | ||
| recreateComponent( | ||
| [], | ||
| [ | ||
| { | ||
| ...baseAnnotationFields, | ||
| id: 1, | ||
| createdAt: "2024-01-01T10:00:00Z", | ||
| createdBy: "Alice", | ||
| label: { id: 1, text: "first", description: "" }, | ||
| attachedByCurrentUser: false, | ||
| }, | ||
| { | ||
| ...baseAnnotationFields, | ||
| id: 2, | ||
| createdAt: "2024-01-03T10:00:00Z", | ||
| createdBy: "Bob", | ||
| label: { id: 2, text: "latest", description: "" }, | ||
| attachedByCurrentUser: false, | ||
| }, | ||
| ] | ||
| ); | ||
|
|
||
| const events = component.filteredEvents()!; | ||
| expect(events[0].description).toBe("latest"); | ||
| expect(events[1].description).toBe("first"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
@forand@letstatements deserve to be at different indentation levels. Maybe keep the@forwith the<ul>above? What do the conventions say?