1 |
4e91ed40
|
Dominik Poch
|
import { Col, Container, Row, Stack } from 'react-bootstrap';
|
2 |
76242338
|
Dominik Poch
|
import { Tag } from '../types/tag';
|
3 |
c73aecde
|
Dominik Poch
|
import { ChangeEvent, useContext, useState } from 'react';
|
4 |
967f45fc
|
Dominik Poch
|
import 'antd/dist/antd.css';
|
5 |
bcbaa7d3
|
Dominik Poch
|
import { Button, Input, Select } from 'antd';
|
6 |
967f45fc
|
Dominik Poch
|
import {
|
7 |
|
|
PlusOutlined,
|
8 |
|
|
DownOutlined,
|
9 |
|
|
DeleteOutlined,
|
10 |
76242338
|
Dominik Poch
|
TagOutlined,
|
11 |
967f45fc
|
Dominik Poch
|
} from '@ant-design/icons';
|
12 |
c73aecde
|
Dominik Poch
|
import { AnnotationContext } from '../../contexts/AnnotationContext';
|
13 |
bcbaa7d3
|
Dominik Poch
|
import { ETagSentiment, TagInstanceInfo } from '../../api';
|
14 |
|
|
|
15 |
|
|
const { Option } = Select;
|
16 |
967f45fc
|
Dominik Poch
|
|
17 |
acb8a961
|
Dominik Poch
|
/**
|
18 |
|
|
* Creates a single item in an annotation panel.
|
19 |
|
|
* @param props Properties should contain a tag that will be shown in this annotation.
|
20 |
|
|
* @returns The item that represents an annotation.
|
21 |
|
|
*/
|
22 |
c73aecde
|
Dominik Poch
|
export function AnnotationItem(props: { tag: Tag }) {
|
23 |
4bc99591
|
Lukáš Vlček
|
const { markSelectedText } = useContext(AnnotationContext);
|
24 |
|
|
|
25 |
acb8a961
|
Dominik Poch
|
/**
|
26 |
|
|
* Should properties of this annotation be visible?
|
27 |
|
|
*/
|
28 |
967f45fc
|
Dominik Poch
|
const [visibleProperties, setVisibleProperties] = useState(false);
|
29 |
acb8a961
|
Dominik Poch
|
|
30 |
|
|
/**
|
31 |
|
|
* Context that manages annotations.
|
32 |
|
|
*/
|
33 |
c73aecde
|
Dominik Poch
|
const {
|
34 |
|
|
addOccurrence,
|
35 |
|
|
deleteOccurrence,
|
36 |
|
|
changePosition,
|
37 |
812ee966
|
Dominik Poch
|
changeNote,
|
38 |
bcbaa7d3
|
Dominik Poch
|
changeSentiment,
|
39 |
c73aecde
|
Dominik Poch
|
changeLength,
|
40 |
|
|
} = useContext(AnnotationContext);
|
41 |
967f45fc
|
Dominik Poch
|
|
42 |
acb8a961
|
Dominik Poch
|
/**
|
43 |
|
|
* Adds new occurrence of this annotation to the context.
|
44 |
|
|
*/
|
45 |
c73aecde
|
Dominik Poch
|
const onAddOccurrence = () => {
|
46 |
|
|
addOccurrence(props.tag);
|
47 |
4e91ed40
|
Dominik Poch
|
};
|
48 |
967f45fc
|
Dominik Poch
|
|
49 |
acb8a961
|
Dominik Poch
|
/**
|
50 |
|
|
* Removes an occurrence of this annotation from the context.
|
51 |
|
|
* @param occurrence The occurrence that should be removed.
|
52 |
|
|
*/
|
53 |
76242338
|
Dominik Poch
|
const onDeleteOccurrence = (occurrence: TagInstanceInfo) => (e: any) => {
|
54 |
c73aecde
|
Dominik Poch
|
deleteOccurrence(occurrence);
|
55 |
4e91ed40
|
Dominik Poch
|
};
|
56 |
967f45fc
|
Dominik Poch
|
|
57 |
acb8a961
|
Dominik Poch
|
/**
|
58 |
|
|
* Changes a position of an occurrence of this annotation in the context.
|
59 |
|
|
* @param occurrence The occurrence that should be changed.
|
60 |
|
|
*/
|
61 |
c73aecde
|
Dominik Poch
|
const onChangePosition =
|
62 |
76242338
|
Dominik Poch
|
(occurrence: TagInstanceInfo) => (e: ChangeEvent<HTMLInputElement>) => {
|
63 |
c73aecde
|
Dominik Poch
|
changePosition(occurrence, Number(e.currentTarget.value));
|
64 |
4e91ed40
|
Dominik Poch
|
};
|
65 |
|
|
|
66 |
acb8a961
|
Dominik Poch
|
/**
|
67 |
|
|
* Changes a length of an occurrence of this annotation in the context.
|
68 |
|
|
* @param occurrence The occurrence that should be changed.
|
69 |
|
|
*/
|
70 |
c73aecde
|
Dominik Poch
|
const onChangeLength =
|
71 |
76242338
|
Dominik Poch
|
(occurrence: TagInstanceInfo) => (e: ChangeEvent<HTMLInputElement>) => {
|
72 |
c73aecde
|
Dominik Poch
|
changeLength(occurrence, Number(e.currentTarget.value));
|
73 |
4e91ed40
|
Dominik Poch
|
};
|
74 |
|
|
|
75 |
bcbaa7d3
|
Dominik Poch
|
const onChangeSentiment = (occurrence: TagInstanceInfo) => (val: ETagSentiment) => {
|
76 |
|
|
changeSentiment(occurrence, val);
|
77 |
|
|
};
|
78 |
|
|
|
79 |
812ee966
|
Dominik Poch
|
const onChangeNote =
|
80 |
|
|
(occurrence: TagInstanceInfo) => (e: ChangeEvent<HTMLTextAreaElement>) => {
|
81 |
|
|
changeNote(occurrence, e.currentTarget.value);
|
82 |
|
|
};
|
83 |
|
|
|
84 |
acb8a961
|
Dominik Poch
|
/**
|
85 |
|
|
* Changes visibility of properties of this annotation.
|
86 |
|
|
*/
|
87 |
c73aecde
|
Dominik Poch
|
const changePropertiesVisibility = () => {
|
88 |
|
|
setVisibleProperties(!visibleProperties);
|
89 |
|
|
};
|
90 |
|
|
|
91 |
967f45fc
|
Dominik Poch
|
return (
|
92 |
c73aecde
|
Dominik Poch
|
<Container>
|
93 |
76242338
|
Dominik Poch
|
<Row className="border rounded">
|
94 |
|
|
<Col sm="auto" className="d-flex align-items-center">
|
95 |
|
|
<TagOutlined />
|
96 |
|
|
</Col>
|
97 |
4bc99591
|
Lukáš Vlček
|
<Col className="d-flex align-items-center">
|
98 |
|
|
{props.tag.tagName}
|
99 |
|
|
{props.tag.subtagName ? ' (' + props.tag.subtagName + ')' : ''}
|
100 |
|
|
</Col>
|
101 |
4e91ed40
|
Dominik Poch
|
<Col sm="auto">
|
102 |
|
|
<Button
|
103 |
|
|
type="text"
|
104 |
|
|
shape="circle"
|
105 |
|
|
icon={<PlusOutlined />}
|
106 |
c73aecde
|
Dominik Poch
|
onClick={onAddOccurrence}
|
107 |
4e91ed40
|
Dominik Poch
|
/>
|
108 |
|
|
<Button
|
109 |
|
|
type="text"
|
110 |
|
|
shape="circle"
|
111 |
|
|
icon={<DownOutlined />}
|
112 |
|
|
onClick={changePropertiesVisibility}
|
113 |
|
|
/>
|
114 |
|
|
</Col>
|
115 |
967f45fc
|
Dominik Poch
|
</Row>
|
116 |
|
|
{visibleProperties && (
|
117 |
76242338
|
Dominik Poch
|
<Stack gap={1} className="mb-2">
|
118 |
4e91ed40
|
Dominik Poch
|
<div>Kategorie: {props.tag.category}</div>
|
119 |
|
|
<div>Výskyty:</div>
|
120 |
|
|
{props.tag.occurrences.map((occurrence, index) => {
|
121 |
967f45fc
|
Dominik Poch
|
return (
|
122 |
bcbaa7d3
|
Dominik Poch
|
<Container key={index} className="shadow-sm pb-1 pt-1">
|
123 |
|
|
<Row>
|
124 |
76242338
|
Dominik Poch
|
<Col>
|
125 |
|
|
<Row>
|
126 |
812ee966
|
Dominik Poch
|
<Col>Pozice: {occurrence.position}</Col>
|
127 |
|
|
</Row>
|
128 |
|
|
<Row>
|
129 |
|
|
<Col>Délka: {occurrence.length}</Col>
|
130 |
76242338
|
Dominik Poch
|
</Row>
|
131 |
|
|
<Row>
|
132 |
bcbaa7d3
|
Dominik Poch
|
<Col
|
133 |
|
|
className="d-flex align-items-center"
|
134 |
|
|
sm="4"
|
135 |
|
|
>
|
136 |
812ee966
|
Dominik Poch
|
Poznámka:
|
137 |
76242338
|
Dominik Poch
|
</Col>
|
138 |
bcbaa7d3
|
Dominik Poch
|
<Col>
|
139 |
812ee966
|
Dominik Poch
|
<Input.TextArea
|
140 |
|
|
defaultValue={occurrence.note ?? ''}
|
141 |
89154cb1
|
Dominik Poch
|
onBlur={onChangeNote(occurrence)}
|
142 |
76242338
|
Dominik Poch
|
/>
|
143 |
|
|
</Col>
|
144 |
|
|
</Row>
|
145 |
bcbaa7d3
|
Dominik Poch
|
{occurrence.sentiment && (
|
146 |
|
|
<Row>
|
147 |
|
|
<Col
|
148 |
|
|
className="d-flex align-items-center"
|
149 |
|
|
sm="4"
|
150 |
|
|
>
|
151 |
|
|
Sentiment:
|
152 |
|
|
</Col>
|
153 |
|
|
<Col>
|
154 |
|
|
<Select
|
155 |
812ee966
|
Dominik Poch
|
defaultValue={
|
156 |
|
|
occurrence.sentiment
|
157 |
|
|
}
|
158 |
bcbaa7d3
|
Dominik Poch
|
style={{ width: '100%' }}
|
159 |
|
|
onChange={onChangeSentiment(
|
160 |
|
|
occurrence
|
161 |
|
|
)}
|
162 |
|
|
>
|
163 |
|
|
<Option
|
164 |
|
|
value={ETagSentiment.Positive}
|
165 |
|
|
>
|
166 |
|
|
Pozitivní
|
167 |
|
|
</Option>
|
168 |
|
|
<Option
|
169 |
|
|
value={ETagSentiment.Neutral}
|
170 |
|
|
>
|
171 |
|
|
Neutrální
|
172 |
|
|
</Option>
|
173 |
|
|
<Option
|
174 |
|
|
value={ETagSentiment.Negative}
|
175 |
|
|
>
|
176 |
|
|
Negativní
|
177 |
|
|
</Option>
|
178 |
|
|
</Select>
|
179 |
|
|
</Col>
|
180 |
|
|
</Row>
|
181 |
|
|
)}
|
182 |
76242338
|
Dominik Poch
|
</Col>
|
183 |
|
|
<Col sm="auto" className="d-flex align-items-center">
|
184 |
|
|
<Button
|
185 |
|
|
icon={<DeleteOutlined />}
|
186 |
|
|
onClick={onDeleteOccurrence(occurrence)}
|
187 |
|
|
danger
|
188 |
|
|
></Button>
|
189 |
|
|
</Col>
|
190 |
|
|
</Row>
|
191 |
|
|
</Container>
|
192 |
967f45fc
|
Dominik Poch
|
);
|
193 |
|
|
})}
|
194 |
4e91ed40
|
Dominik Poch
|
</Stack>
|
195 |
967f45fc
|
Dominik Poch
|
)}
|
196 |
c73aecde
|
Dominik Poch
|
</Container>
|
197 |
967f45fc
|
Dominik Poch
|
);
|
198 |
|
|
}
|