1
|
import { Col, Container, Row, Stack } from 'react-bootstrap';
|
2
|
import { Occurrence, Tag } from '../types/tag';
|
3
|
import { ChangeEvent, useContext, useState } from 'react';
|
4
|
|
5
|
import 'antd/dist/antd.css';
|
6
|
import { Button, Input } from 'antd';
|
7
|
import {
|
8
|
PlusOutlined,
|
9
|
EyeOutlined,
|
10
|
DownOutlined,
|
11
|
DeleteOutlined,
|
12
|
} from '@ant-design/icons';
|
13
|
import { AnnotationContext } from '../../contexts/AnnotationContext';
|
14
|
|
15
|
export function AnnotationItem(props: { tag: Tag }) {
|
16
|
const [visibleProperties, setVisibleProperties] = useState(false);
|
17
|
const {
|
18
|
addOccurrence,
|
19
|
deleteOccurrence,
|
20
|
changeVisibility,
|
21
|
changePosition,
|
22
|
changeLength,
|
23
|
} = useContext(AnnotationContext);
|
24
|
|
25
|
const onAddOccurrence = () => {
|
26
|
addOccurrence(props.tag);
|
27
|
};
|
28
|
|
29
|
const onDeleteOccurrence = (occurrence: Occurrence) => (e: any) => {
|
30
|
deleteOccurrence(occurrence);
|
31
|
};
|
32
|
|
33
|
const onChangeVisibility = () => {
|
34
|
changeVisibility(props.tag);
|
35
|
};
|
36
|
|
37
|
const onChangePosition =
|
38
|
(occurrence: Occurrence) => (e: ChangeEvent<HTMLInputElement>) => {
|
39
|
changePosition(occurrence, Number(e.currentTarget.value));
|
40
|
};
|
41
|
|
42
|
const onChangeLength =
|
43
|
(occurrence: Occurrence) => (e: ChangeEvent<HTMLInputElement>) => {
|
44
|
changeLength(occurrence, Number(e.currentTarget.value));
|
45
|
};
|
46
|
|
47
|
const changePropertiesVisibility = () => {
|
48
|
setVisibleProperties(!visibleProperties);
|
49
|
};
|
50
|
|
51
|
return (
|
52
|
<Container>
|
53
|
<Row>
|
54
|
<Col className="d-flex align-items-center">{props.tag.name}</Col>
|
55
|
<Col sm="auto">
|
56
|
<Button
|
57
|
type="text"
|
58
|
shape="circle"
|
59
|
icon={<PlusOutlined />}
|
60
|
onClick={onAddOccurrence}
|
61
|
/>
|
62
|
<Button
|
63
|
type="text"
|
64
|
shape="circle"
|
65
|
icon={<EyeOutlined />}
|
66
|
onClick={onChangeVisibility}
|
67
|
/>
|
68
|
<Button
|
69
|
type="text"
|
70
|
shape="circle"
|
71
|
icon={<DownOutlined />}
|
72
|
onClick={changePropertiesVisibility}
|
73
|
/>
|
74
|
</Col>
|
75
|
</Row>
|
76
|
{visibleProperties && (
|
77
|
<Stack>
|
78
|
<div>Kategorie: {props.tag.category}</div>
|
79
|
<div>Výskyty:</div>
|
80
|
{props.tag.occurrences.map((occurrence, index) => {
|
81
|
return (
|
82
|
<div key={index} id={props.tag.name + index}>
|
83
|
<Container>
|
84
|
<Row>
|
85
|
<Col>
|
86
|
<Row>
|
87
|
<Col className="d-flex align-items-center">
|
88
|
Pozice:
|
89
|
</Col>
|
90
|
<Col sm="auto">
|
91
|
<Input
|
92
|
value={occurrence.position}
|
93
|
onChange={onChangePosition(
|
94
|
occurrence
|
95
|
)}
|
96
|
/>
|
97
|
</Col>
|
98
|
</Row>
|
99
|
<Row>
|
100
|
<Col className="d-flex align-items-center">
|
101
|
Délka:
|
102
|
</Col>
|
103
|
<Col sm="auto">
|
104
|
<Input
|
105
|
value={occurrence.length}
|
106
|
onChange={onChangeLength(
|
107
|
occurrence
|
108
|
)}
|
109
|
/>
|
110
|
</Col>
|
111
|
</Row>
|
112
|
</Col>
|
113
|
<Col
|
114
|
sm="auto"
|
115
|
className="d-flex align-items-center"
|
116
|
>
|
117
|
<Button
|
118
|
icon={<DeleteOutlined />}
|
119
|
onClick={onDeleteOccurrence(occurrence)}
|
120
|
></Button>
|
121
|
</Col>
|
122
|
</Row>
|
123
|
</Container>
|
124
|
</div>
|
125
|
);
|
126
|
})}
|
127
|
</Stack>
|
128
|
)}
|
129
|
</Container>
|
130
|
);
|
131
|
}
|