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 pathImageCell.js
More file actions
62 lines (56 loc) · 1.6 KB
/
ImageCell.js
File metadata and controls
62 lines (56 loc) · 1.6 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
import { getRoot } from "mobx-state-tree";
import { FF_LSDV_4711, isFF } from "../../utils/feature-flags";
import { AnnotationPreview } from "../Common/AnnotationPreview/AnnotationPreview";
import { useRef } from "react";
import { useImageProvider } from "../../providers/ImageProvider";
const imgDefaultProps = {};
if (isFF(FF_LSDV_4711)) imgDefaultProps.crossOrigin = 'anonymous';
export const ImageCell = (column) => {
const {
original,
value,
column: { alias },
} = column;
const root = getRoot(original);
const imgRef = useRef();
const { getImage } = useImageProvider();
const renderImagePreview = original.total_annotations === 0 || !root.showPreviews;
const imgSrc = Array.isArray(value) ? value[0] : value;
if (!imgSrc) return null;
getImage(imgSrc).then((loadedImage) => {
if (imgRef.current && loadedImage.loaded && loadedImage.url) {
imgRef.current.setAttribute("src", loadedImage.url);
imgRef.current.style.display = "";
}
});
return renderImagePreview ? (
<img
{...imgDefaultProps}
ref={imgRef}
key={imgSrc}
alt="Data"
style={{
maxHeight: "100%",
maxWidth: "100px",
objectFit: "contain",
borderRadius: 3,
display: "none",
}}
/>
) : (
<AnnotationPreview
task={original}
annotation={original.annotations[0]}
config={getRoot(original).SDK}
name={alias}
variant="120x120"
fallbackImage={value}
style={{
maxHeight: "100%",
maxWidth: "100px",
objectFit: "contain",
borderRadius: 3,
}}
/>
);
};