This repository was archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathLabel.js
More file actions
146 lines (130 loc) · 4.09 KB
/
Label.js
File metadata and controls
146 lines (130 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { inject } from "mobx-react";
import { observer } from "mobx-react-lite";
import React, { useCallback, useEffect, useMemo, useRef } from "react";
import { FaCaretDown, FaChevronLeft, FaColumns } from "react-icons/fa";
import { Block, Elem } from "../../utils/bem";
import { FF_DEV_1170, isFF } from "../../utils/feature-flags";
import { Button } from "../Common/Button/Button";
import { FieldsButton } from "../Common/FieldsButton";
import { Icon } from "../Common/Icon/Icon";
import { Resizer } from "../Common/Resizer/Resizer";
import { Space } from "../Common/Space/Space";
import { DataView } from "../MainView";
import "./Label.styl";
import { ImageProvider } from "../../providers/ImageProvider";
const LabelingHeader = ({ SDK, onClick, isExplorerMode }) => {
return (
<Elem name="header" mod={{ labelStream: !isExplorerMode }}>
<Space size="large">
{SDK.interfaceEnabled("backButton") && (
<Button
icon={<FaChevronLeft style={{ marginRight: 4, fontSize: 16 }} />}
type="link"
onClick={onClick}
style={{ fontSize: 18, padding: 0, color: "black" }}
>
Back
</Button>
)}
{isExplorerMode ? (
<FieldsButton
wrapper={FieldsButton.Checkbox}
icon={<Icon icon={FaColumns} />}
trailingIcon={<Icon icon={FaCaretDown} />}
title={"Fields"}
/>
) : null}
</Space>
</Elem>
);
};
const injector = inject(({ store }) => {
return {
store,
loading: store?.loadingData,
};
});
/**
* @param {{store: import("../../stores/AppStore").AppStore}} param1
*/
export const Labeling = injector(observer(({
store,
loading,
}) => {
const lsfRef = useRef();
const SDK = store?.SDK;
const view = store?.currentView;
const { isExplorerMode } = store;
const isLabelStream = useMemo(() => {
return SDK.mode === 'labelstream';
}, []);
const closeLabeling = useCallback(() => {
store.closeLabeling();
}, [store]);
const initLabeling = useCallback(() => {
if (!SDK.lsf) SDK.initLSF(lsfRef.current);
SDK.startLabeling();
}, []);
useEffect(() => {
if (!isLabelStream) SDK.on("taskSelected", initLabeling);
return () => {
if (!isLabelStream) SDK.off("taskSelected", initLabeling);
};
}, []);
useEffect(() => {
if (!SDK.lsf && store.dataStore.selected || isLabelStream) {
initLabeling();
}
}, []);
useEffect(() => {
return () => SDK.destroyLSF();
}, []);
const onResize = useCallback((width) => {
view.setLabelingTableWidth(width);
// trigger resize events inside LSF
window.dispatchEvent(new Event("resize"));
}, []);
const outlinerEnabled = isFF(FF_DEV_1170);
return (
<ImageProvider key="app-image-provider">
<Block name="label-view" mod={{ loading }}>
{SDK.interfaceEnabled("labelingHeader") && (
<LabelingHeader
SDK={SDK}
onClick={closeLabeling}
isExplorerMode={isExplorerMode}
/>
)}
<Elem name="content">
{isExplorerMode && (
<Elem name="table">
<Elem
tag={Resizer}
name="dataview"
minWidth={200}
showResizerLine={false}
type={'quickview'}
maxWidth={window.innerWidth * 0.35}
initialWidth={view.labelingTableWidth} // hardcoded as in main-menu-trigger
onResizeFinished={onResize}
style={{ display: "flex", flex: 1, width: '100%' }}
>
<DataView />
</Elem>
</Elem>
)}
<Elem name="lsf-wrapper" mod={{ mode: isExplorerMode ? "explorer" : "labeling" }}>
{loading && <Elem name="waiting" mod={{ animated: true }}/>}
<Elem
ref={lsfRef}
id="label-studio-dm"
name="lsf-container"
key="label-studio"
mod={{ outliner: outlinerEnabled }}
/>
</Elem>
</Elem>
</Block>
</ImageProvider>
);
}));