Add row-specific styling and improve image rendering
Introduced row-specific CSS classes for better UI distinction, highlighting rows based on run type and processing results. Enhanced image rendering logic with consistent styling, hover effects, and a smaller image size for better visual clarity.
This commit is contained in:
parent
266c8a81ac
commit
6bd4843d38
15
frontend/src/components/ResultGrid.css
Normal file
15
frontend/src/components/ResultGrid.css
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/* Light yellow for rows with runs */
|
||||||
|
.row-light-yellow {
|
||||||
|
background-color: #fff9c4; /* Light yellow color */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Light green for rows with processing results */
|
||||||
|
.row-light-green {
|
||||||
|
background-color: #dcedc8 !important; /* Light green color */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optional: Add hover effect */
|
||||||
|
.row-light-yellow:hover,
|
||||||
|
.row-light-green:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
@ -2,8 +2,10 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { DataGridPremium, GridColDef } from '@mui/x-data-grid-premium';
|
import { DataGridPremium, GridColDef } from '@mui/x-data-grid-premium';
|
||||||
import RunDetails from './RunDetails';
|
import RunDetails from './RunDetails';
|
||||||
import './SampleImage.css';
|
import './SampleImage.css';
|
||||||
|
import './ResultGrid.css';
|
||||||
import { OpenAPI, SamplesService } from '../../openapi';
|
import { OpenAPI, SamplesService } from '../../openapi';
|
||||||
|
|
||||||
|
|
||||||
// Extend your image info interface if needed.
|
// Extend your image info interface if needed.
|
||||||
interface ImageInfo {
|
interface ImageInfo {
|
||||||
id: number;
|
id: number;
|
||||||
@ -100,6 +102,11 @@ interface ResultGridProps {
|
|||||||
const ResultGrid: React.FC<ResultGridProps> = ({ activePgroup }) => {
|
const ResultGrid: React.FC<ResultGridProps> = ({ activePgroup }) => {
|
||||||
const [rows, setRows] = useState<TreeRow[]>([]);
|
const [rows, setRows] = useState<TreeRow[]>([]);
|
||||||
const [basePath, setBasePath] = useState('');
|
const [basePath, setBasePath] = useState('');
|
||||||
|
const hasProcessingResults = (row: TreeRow): boolean => {
|
||||||
|
// You can later replace this placeholder with actual logic.
|
||||||
|
// Mocking the logic by returning `true` for demonstration.
|
||||||
|
return row.type === 'run' && !!row.beamline_parameters?.detector;
|
||||||
|
};
|
||||||
|
|
||||||
// Helper function to safely get the number of images.
|
// Helper function to safely get the number of images.
|
||||||
const getNumberOfImages = (run: ExperimentParameters): number => {
|
const getNumberOfImages = (run: ExperimentParameters): number => {
|
||||||
@ -112,6 +119,23 @@ const ResultGrid: React.FC<ResultGridProps> = ({ activePgroup }) => {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getRowClassName = (params: { row: TreeRow }) => {
|
||||||
|
const { row } = params;
|
||||||
|
|
||||||
|
// Light green if the run contains processing results
|
||||||
|
if (hasProcessingResults(row)) {
|
||||||
|
return 'row-light-green';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Light yellow if the row type is 'run'
|
||||||
|
if (row.type === 'run') {
|
||||||
|
return 'row-light-yellow';
|
||||||
|
}
|
||||||
|
|
||||||
|
// No special styling
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
// Helper function to determine the experiment type.
|
// Helper function to determine the experiment type.
|
||||||
const getExperimentType = (run: ExperimentParameters): string => {
|
const getExperimentType = (run: ExperimentParameters): string => {
|
||||||
const params = run.beamline_parameters;
|
const params = run.beamline_parameters;
|
||||||
@ -229,27 +253,31 @@ const ResultGrid: React.FC<ResultGridProps> = ({ activePgroup }) => {
|
|||||||
headerName: 'Images',
|
headerName: 'Images',
|
||||||
width: 300,
|
width: 300,
|
||||||
renderCell: (params) => {
|
renderCell: (params) => {
|
||||||
const images = params.row.images;
|
const imageList: ImageInfo[] = params.row.images;
|
||||||
if (images && images.length) {
|
if (!imageList || imageList.length === 0) return null;
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', gap: '8px' }}>
|
return (
|
||||||
{images.map((image: ImageInfo) => (
|
<div style={{ display: 'flex', gap: '10px' }}>
|
||||||
<img
|
{imageList.map((img) => {
|
||||||
key={image.id}
|
const url = `${basePath}${img.filepath}`;
|
||||||
src={`${basePath}${image.filepath}`}
|
return (
|
||||||
alt={image.comment || `Image ${image.id}`}
|
<div key={img.id} style={{ position: 'relative' }}>
|
||||||
style={{
|
<img
|
||||||
height: 50,
|
src={url}
|
||||||
width: 50,
|
alt={img.comment || 'sample'}
|
||||||
objectFit: 'cover',
|
className="zoom-image"
|
||||||
borderRadius: '4px',
|
style={{
|
||||||
}}
|
width: 40,
|
||||||
/>
|
height: 40,
|
||||||
))}
|
borderRadius: 4,
|
||||||
</div>
|
cursor: 'pointer',
|
||||||
);
|
}}
|
||||||
}
|
/>
|
||||||
return null;
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -274,6 +302,7 @@ const ResultGrid: React.FC<ResultGridProps> = ({ activePgroup }) => {
|
|||||||
getRowId={(row) => row.id}
|
getRowId={(row) => row.id}
|
||||||
autoHeight
|
autoHeight
|
||||||
treeData
|
treeData
|
||||||
|
getRowClassName={getRowClassName}
|
||||||
getTreeDataPath={(row: TreeRow) => {
|
getTreeDataPath={(row: TreeRow) => {
|
||||||
if (row.type === 'run') {
|
if (row.type === 'run') {
|
||||||
// Include sample_id to make the path globally unique
|
// Include sample_id to make the path globally unique
|
||||||
|
Loading…
x
Reference in New Issue
Block a user