Skip to content

Commit 67fcc9a

Browse files
Get frontend working again
1 parent 8d1c187 commit 67fcc9a

7 files changed

Lines changed: 76 additions & 71 deletions

File tree

frontend/src/app/annotate/annotation-input/annotation-input.component.html

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
<a
2323
class="btn btn-secondary d-flex align-items-center justify-content-center"
2424
[routerLink]="['/', 'annotate', 'new']"
25-
[queryParams]="{base: form.getRawValue().id }"
26-
25+
[queryParams]="{ base: form.getRawValue().id }"
2726
>
2827
<fa-icon
2928
[icon]="faCopy"
@@ -60,43 +59,37 @@
6059
</div>
6160
</div>
6261

63-
@if (modified) {
64-
<!-- TODO: does the design make sense? -->
65-
<div class="alert alert-warning d-flex justify-content-between">
66-
<span i18n>Annotation modified</span>
67-
<div>
68-
<button
69-
type="button"
70-
class="btn btn-light me-3"
71-
(click)="saveChanges()"
72-
>
73-
<fa-icon
74-
[icon]="faFloppyDisk"
75-
class="fa-sm"
76-
aria-hidden="true"
77-
></fa-icon>
78-
<span class="ms-2" i18n>Save</span>
79-
</button>
80-
<button
81-
type="button"
82-
class="btn btn-light"
83-
(click)="revertChanges()"
84-
>
85-
<fa-icon
86-
[icon]="faRotateLeft"
87-
class="fa-sm"
88-
aria-hidden="true"
89-
></fa-icon>
90-
<span class="ms-2" i18n>Revert</span>
91-
</button>
92-
</div>
93-
</div>
94-
}
95-
}
96-
@else {
62+
@if (modified) {
63+
<!-- TODO: does the design make sense? -->
64+
<div class="alert alert-warning d-flex justify-content-between">
65+
<span i18n>Annotation modified</span>
66+
<div>
67+
<button
68+
type="button"
69+
class="btn btn-light me-3"
70+
(click)="saveProblem()"
71+
>
72+
<fa-icon
73+
[icon]="faFloppyDisk"
74+
class="fa-sm"
75+
aria-hidden="true"
76+
></fa-icon>
77+
<span class="ms-2" i18n>Save</span>
78+
</button>
79+
<button type="button" class="btn btn-light">
80+
<fa-icon
81+
[icon]="faRotateLeft"
82+
class="fa-sm"
83+
aria-hidden="true"
84+
></fa-icon>
85+
<span class="ms-2" i18n>Revert</span>
86+
</button>
87+
</div>
88+
</div>
89+
} } @else {
9790
<div class="h-100 d-flex align-items-center justify-content-center text-muted">
9891
<fa-icon [icon]="faExclamationCircle"></fa-icon>
99-
<h2 class="h4 mb-0 ms-2">
92+
<h2 class="h4 mb-0 ms-2" i18n>
10093
There are no problems matching your search criteria.
10194
</h2>
10295
</div>

frontend/src/app/annotate/annotation-input/annotation-input.component.spec.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,25 @@ describe("AnnotationInputComponent", () => {
5353
premises: ["First premise", "Second premise"],
5454
hypothesis: "Test hypothesis",
5555
entailmentLabel: EntailmentLabel.ENTAILMENT,
56-
kbItems: [
57-
{
58-
id: 456,
59-
entity1: "cat",
60-
entity2: "animal",
61-
relationship: KnowledgeBaseRelationship.SUBSET
62-
},
63-
{
64-
id: 789,
65-
entity1: "dog",
66-
entity2: "pet",
67-
relationship: KnowledgeBaseRelationship.EQUAL
68-
}
69-
],
56+
annotation: {
57+
id: 1,
58+
entailmentLabel: EntailmentLabel.ENTAILMENT,
59+
createdAt: "2025-01-01T00:00:00Z",
60+
kbItems: [
61+
{
62+
id: 456,
63+
entity1: "cat",
64+
entity2: "animal",
65+
relationship: KnowledgeBaseRelationship.SUBSET
66+
},
67+
{
68+
id: 789,
69+
entity1: "dog",
70+
entity2: "pet",
71+
relationship: KnowledgeBaseRelationship.EQUAL
72+
}
73+
]
74+
},
7075
dataset: Dataset.USER,
7176
extraData: null
7277
};
@@ -109,7 +114,7 @@ describe("AnnotationInputComponent", () => {
109114
premises: [],
110115
hypothesis: "Empty test hypothesis",
111116
entailmentLabel: EntailmentLabel.NEUTRAL,
112-
kbItems: [],
117+
annotation: null,
113118
dataset: Dataset.USER,
114119
extraData: null
115120
};
@@ -133,7 +138,7 @@ describe("AnnotationInputComponent", () => {
133138
premises: ["Test premise"],
134139
hypothesis: "Test hypothesis",
135140
entailmentLabel: EntailmentLabel.CONTRADICTION,
136-
kbItems: [],
141+
annotation: null,
137142
dataset: Dataset.USER,
138143
extraData: null
139144
};
@@ -155,7 +160,7 @@ describe("AnnotationInputComponent", () => {
155160
premises: [],
156161
hypothesis: "",
157162
entailmentLabel: EntailmentLabel.UNKNOWN,
158-
kbItems: [],
163+
annotation: null,
159164
dataset: Dataset.USER,
160165
extraData: null
161166
};
@@ -175,7 +180,7 @@ describe("AnnotationInputComponent", () => {
175180
premises: [],
176181
hypothesis: "",
177182
entailmentLabel: EntailmentLabel.UNKNOWN,
178-
kbItems: [],
183+
annotation: null,
179184
dataset: Dataset.USER,
180185
extraData: null
181186
};

frontend/src/app/annotate/annotation-input/annotation-input.component.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
import { PremisesFormComponent } from "./premises-form/premises-form.component";
1212
import { KnowledgeBaseFormComponent } from "./knowledge-base-form/knowledge-base-form.component";
1313
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
14-
import { Dataset, KnowledgeBaseRelationship, Problem } from "../../types";
15-
import { faCheck, faCopy, faExclamationCircle, faFloppyDisk, faTrash, faTree, faWrench } from "@fortawesome/free-solid-svg-icons";
14+
import { Dataset, KnowledgeBaseItem, KnowledgeBaseRelationship, Problem } from "../../types";
15+
import { faCheck, faCopy, faExclamationCircle, faFloppyDisk, faRotateLeft, faTrash, faTree, faWrench } from "@fortawesome/free-solid-svg-icons";
1616
import { ProblemDetailsComponent } from "./problem-details/problem-details.component";
1717
import { map, Subject } from "rxjs";
1818
import { ActivatedRoute, Router, RouterLinkWithHref } from "@angular/router";
@@ -79,9 +79,6 @@ export function kbForm(entity1: string, entity2: string, relationship: Knowledge
7979
styleUrl: "./annotation-input.component.scss",
8080
})
8181
export class AnnotationInputComponent implements OnInit {
82-
public faFloppyDisk = faFloppyDisk;
83-
public faRotateLeft = faRotateLeft;
84-
8582
private route = inject(ActivatedRoute);
8683
private router = inject(Router);
8784
private destroyRef = inject(DestroyRef);
@@ -100,6 +97,7 @@ export class AnnotationInputComponent implements OnInit {
10097
public faCheck = faCheck;
10198
public faTree = faTree;
10299
public faFloppyDisk = faFloppyDisk;
100+
public faRotateLeft = faRotateLeft;
103101
public faExclamationCircle = faExclamationCircle;
104102
public faTrash = faTrash;
105103
public faWrench = faWrench;
@@ -131,7 +129,7 @@ export class AnnotationInputComponent implements OnInit {
131129
this.form?.valueChanges.subscribe(
132130
data => {
133131
// TODO: replace with more reasonable object compare
134-
this.modified = JSON.stringify(this.formValue) != JSON.stringify(data)
132+
this.modified = JSON.stringify(this.formValue) != JSON.stringify(data);
135133
}
136134
);
137135
});
@@ -197,7 +195,7 @@ export class AnnotationInputComponent implements OnInit {
197195
}
198196

199197
private buildForm(problem: Problem): ParseInputForm {
200-
const kbItems = this.buildKbForms(problem.kbItems);
198+
const kbItems = this.buildKbForms(problem.annotation?.kbAnnotations ?? []);
201199

202200
return new FormGroup({
203201
id: new FormControl<number | null>(problem.id, {
@@ -222,7 +220,8 @@ export class AnnotationInputComponent implements OnInit {
222220
kbItems: new FormArray<KnowledgeBaseItemsForm>(kbItems),
223221
});
224222
}
225-
private buildKbForms(inputKbItems: Problem['kbItems']): KnowledgeBaseItemsForm[] {
223+
224+
private buildKbForms(inputKbItems: KnowledgeBaseItem[]): KnowledgeBaseItemsForm[] {
226225
return inputKbItems.map(item => new FormGroup({
227226
id: new FormControl<number | null>(item.id, {
228227
nonNullable: true

frontend/src/app/annotate/annotation-input/problem-details/problem-details.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const createMockProblem = (
1616
entailmentLabel,
1717
premises: ["premise"],
1818
hypothesis: "hypothesis",
19-
kbItems: [],
19+
annotation: null,
2020
extraData,
2121
});
2222

frontend/src/app/services/problem.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe("ProblemService", () => {
5454
premises: ["a"],
5555
hypothesis: "b",
5656
entailmentLabel: EntailmentLabel.ENTAILMENT,
57-
kbItems: [],
57+
annotation: null,
5858
extraData: {
5959
pairId: 1,
6060
relatednessScore: 4.5

frontend/src/app/services/problem.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ export class ProblemService {
109109
premises: existingProblem?.premises ?? [],
110110
entailmentLabel: EntailmentLabel.UNKNOWN,
111111
extraData: null,
112-
kbItems: existingProblem?.kbItems.map(kbItem => ({
113-
...kbItem,
114-
id: null,
115-
})) ?? []
112+
annotation: existingProblem?.annotation ? {
113+
...existingProblem.annotation,
114+
kbAnnotations: existingProblem.annotation.kbAnnotations.map(kbItem => ({
115+
...kbItem,
116+
id: null,
117+
}))
118+
} : null
116119
}
117120

118121
};

frontend/src/app/types.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@ export enum KnowledgeBaseRelationship {
3030
SUPERSET = "superset",
3131
}
3232

33-
interface KnowledgeBaseItem {
33+
export interface KnowledgeBaseItem {
3434
id: number | null;
3535
entity1: string;
3636
relationship: KnowledgeBaseRelationship;
3737
entity2: string;
3838
}
3939

40+
export interface Annotation {
41+
kbAnnotations: KnowledgeBaseItem[];
42+
problemAnnotations: unknown;
43+
}
44+
4045
interface ProblemBase {
4146
id: number | null;
4247
base: number | null;
4348
premises: string[];
4449
hypothesis: string | null;
4550
entailmentLabel: EntailmentLabel;
46-
kbItems: KnowledgeBaseItem[];
51+
annotation: Annotation | null;
4752
}
4853

4954
interface SickProblem extends ProblemBase {

0 commit comments

Comments
 (0)