diff --git a/frontend/src/components/ResultGrid.tsx b/frontend/src/components/ResultGrid.tsx index 64760ae..809460a 100644 --- a/frontend/src/components/ResultGrid.tsx +++ b/frontend/src/components/ResultGrid.tsx @@ -1,6 +1,9 @@ +// TypeScript (ResultGrid.tsx snippet) import React, { useEffect, useState } from 'react'; import { DataGrid, GridColDef } from '@mui/x-data-grid'; import { OpenAPI, SamplesService } from '../../openapi'; +import './Sampleimage.css'; + interface ImageInfo { id: number; @@ -22,14 +25,10 @@ interface ResultGridProps { const ResultGrid: React.FC = ({ activePgroup }) => { const [rows, setRows] = useState([]); - const [basePath, setBasePath] = React.useState(""); - const [hoveredImageUrl, setHoveredImageUrl] = useState(null); + const [basePath, setBasePath] = useState(''); useEffect(() => { - // Detect the current environment const mode = import.meta.env.MODE; - - // Dynamic resolution for OpenAPI.BASE OpenAPI.BASE = mode === 'test' ? import.meta.env.VITE_OPENAPI_BASE_TEST @@ -45,7 +44,7 @@ const ResultGrid: React.FC = ({ activePgroup }) => { console.log('Environment Mode:', mode); console.log('Resolved OpenAPI.BASE:', OpenAPI.BASE); - // Set the base path for images dynamically + // Update the base path for images setBasePath(`${OpenAPI.BASE}/`); }, []); @@ -62,111 +61,82 @@ const ResultGrid: React.FC = ({ activePgroup }) => { }, [activePgroup]); const columns: GridColDef[] = [ - { field: 'sample_id', headerName: 'ID', width: 70 }, - { field: 'sample_name', headerName: 'Sample Name', width: 150 }, - { field: 'puck_name', headerName: 'Puck Name', width: 150 }, - { field: 'dewar_name', headerName: 'Dewar Name', width: 150 }, - { - field: 'images', - headerName: 'Images', - width: 300, - renderCell: (params) => { - const imageList: ImageInfo[] = params.value; - if (imageList && imageList.length) { - const primaryImage = imageList[0]; - // Define the base path to your backend images directory + { field: 'sample_id', headerName: 'ID', width: 70 }, + { field: 'sample_name', headerName: 'Sample Name', width: 150 }, + { field: 'puck_name', headerName: 'Puck Name', width: 150 }, + { field: 'dewar_name', headerName: 'Dewar Name', width: 150 }, + { + field: 'images', + headerName: 'Images', + width: 300, + renderCell: (params) => { + const imageList: ImageInfo[] = params.value; + if (imageList && imageList.length) { + const primaryImage = imageList[0]; + const imageUrl = basePath + primaryImage.filepath; - const imageUrl = basePath + primaryImage.filepath; + return ( +
+ sample + {imageList.length > 1 && ( +
+ +{imageList.length - 1} +
+ {imageList.slice(1).map((img) => { + const url = basePath + img.filepath; + return ( + {img.comment + ); + })} - console.log("Local relative path:", imageUrl); - - console.log("Updated image URL:", imageUrl); - - return ( -
- sample { - console.log("Mouse entered image"); - setHoveredImageUrl(imageUrl); - }} - onMouseLeave={() => { - console.log("Mouse left image"); - setHoveredImageUrl(null); - }} - /> - - {imageList.length > 1 && ( -
- +{imageList.length - 1} -
- {imageList.slice(1).map((img) => { - const tooltipImageUrl = basePath + img.filepath; - return ( - sample - ); - })} +
-
- )} -
- ); - } - return null; + )} +
+ ); + } + return null; + }, }, - }, - ]; - - - // Map each row so that DataGrid can use a unique "id" prop; here we use sample_id. - const gridRows = rows.map((row) => ({ ...row, id: row.sample_id })); + ]; return ( -
-
- -
- {hoveredImageUrl && ( -
- large preview -
- )} -
+ row.sample_id} + sx={{ + '& .MuiDataGrid-cell': { + overflow: 'visible', + }, + }} + /> + ); }; - - -export default ResultGrid; +export default ResultGrid; \ No newline at end of file diff --git a/frontend/src/components/SampleImage.css b/frontend/src/components/SampleImage.css new file mode 100644 index 0000000..bd6f9b9 --- /dev/null +++ b/frontend/src/components/SampleImage.css @@ -0,0 +1,13 @@ +.zoom-image { + transition: transform 0.3s ease; + cursor: pointer; +} + +.zoom-image:hover { + transform: scale(10); /* Adjust the scale value as needed */ + z-index: 10; /* Bring it to front if overlapping */ +} + +.tooltip:hover .tooltip-content { + display: block !important; +}