Skip to content

Commit 3121977

Browse files
committed
fix media selection
Signed-off-by: Colorado, Camilo <[email protected]>
1 parent c2ee3b0 commit 3121977

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

application/ui/src/components/virtualizer-grid-layout/virtualizer-grid-layout.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
img {
3535
box-sizing: border-box;
36-
object-fit: contain;
36+
object-fit: cover;
3737
width: 100%;
3838
height: 100%;
3939
}

application/ui/src/features/inspect/dataset/media-preview/inference-result/inference-result.component.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

33
import { SchemaPredictionResponse } from '@geti-inspect/api/spec';
44
import { DimensionValue, Responsive, View } from '@geti/ui';
@@ -21,15 +21,27 @@ interface InferenceResultProps {
2121
const labelHeight: Responsive<DimensionValue> = 'size-350';
2222

2323
export const InferenceResult = ({ selectedMediaItem, inferenceResult }: InferenceResultProps) => {
24+
const imageRef = useRef(null);
2425
const { inferenceOpacity } = useInference();
2526
const [imageDimensions, setImageDimensions] = useState({ width: 0, height: 0, left: 0, top: 0 });
2627

2728
const handleImageLoaded = (imageElement: HTMLImageElement) => {
2829
setImageDimensions(getImageDimensions(imageElement));
2930
};
3031

32+
useEffect(() => {
33+
if (!imageRef.current) return;
34+
35+
const observer = new ResizeObserver(([entry]) => {
36+
handleImageLoaded(entry.target as HTMLImageElement);
37+
});
38+
39+
observer.observe(imageRef.current);
40+
return () => observer.disconnect();
41+
}, []);
42+
3143
return (
32-
<>
44+
<View height={'100%'} paddingTop={labelHeight}>
3345
{inferenceResult && (
3446
<View
3547
height={labelHeight}
@@ -42,8 +54,9 @@ export const InferenceResult = ({ selectedMediaItem, inferenceResult }: Inferenc
4254
</View>
4355
)}
4456

45-
<View width={'100%'} height={'100%'} position={'relative'} marginTop={labelHeight}>
57+
<View width={'100%'} height={'100%'} position={'relative'}>
4658
<img
59+
ref={imageRef}
4760
alt={selectedMediaItem.filename}
4861
className={clsx(classes.img)}
4962
src={`/api/projects/${selectedMediaItem.project_id}/images/${selectedMediaItem.id}/full`}
@@ -54,16 +67,16 @@ export const InferenceResult = ({ selectedMediaItem, inferenceResult }: Inferenc
5467
{isNonEmptyString(inferenceResult?.anomaly_map) && (
5568
<motion.img
5669
exit={{ opacity: 0 }}
57-
style={imageDimensions}
5870
initial={{ opacity: 0 }}
5971
animate={{ opacity: inferenceOpacity }}
6072
className={clsx(classes.inferenceImage)}
73+
style={{ ...imageDimensions }}
6174
src={`data:image/png;base64,${inferenceResult.anomaly_map}`}
6275
alt={`${selectedMediaItem.filename} inference`}
6376
/>
6477
)}
6578
</AnimatePresence>
6679
</View>
67-
</>
80+
</View>
6881
);
6982
};

application/ui/src/features/inspect/dataset/media-preview/inference-result/inference-result.module.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.img {
22
width: 100%;
33
height: 100%;
4-
margin: auto;
5-
display: block;
64
object-fit: contain;
75
}
86

application/ui/src/features/inspect/dataset/media-preview/inference-result/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const getImageDimensions = (img: HTMLImageElement) => {
1313
const naturalWidth = img.naturalWidth;
1414
const naturalHeight = img.naturalHeight;
1515

16+
if (naturalHeight === 0 || containerHeight === 0) {
17+
return { top: 0, left: 0, width: 0, height: 0 };
18+
}
19+
1620
const imageRatio = naturalWidth / naturalHeight;
1721
const containerRatio = containerWidth / containerHeight;
1822

application/ui/src/features/inspect/dataset/media-preview/sidebar-items/sidebar-items.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Selection, View } from '@geti/ui';
22
import { GridLayoutOptions } from 'react-aria-components';
3-
import { getThumbnailUrl } from 'src/features/inspect/utils';
3+
import { getThumbnailUrl, isNonEmptyString } from 'src/features/inspect/utils';
44

55
import { GridMediaItem } from '../../../../..//components/virtualizer-grid-layout/grid-media-item/grid-media-item.component';
66
import { MediaThumbnail } from '../../../../../components/media-thumbnail/media-thumbnail.component';
@@ -35,7 +35,7 @@ export const SidebarItems = ({
3535
const firstKey = updatedSelectedKeys.values().next().value;
3636
const mediaItem = mediaItems.find((item) => item.id === firstKey);
3737

38-
onSelectedMediaItem(mediaItem?.id ?? null);
38+
isNonEmptyString(mediaItem?.id) && onSelectedMediaItem(mediaItem.id);
3939
};
4040

4141
const handleDeletedItem = (deletedIds: string[]) => {

0 commit comments

Comments
 (0)