Skip to content

Conversation

@adambasha0
Copy link
Contributor

@adambasha0 adambasha0 commented Sep 5, 2025

PR: Preferred Thumbnail Selection for ImageModal:

1. Problem Description

  • Users could not select or display a preferred thumbnail for analysis-related attachments (samples, reactions, devices, research plans, cell lines).
  • The UI did not provide feedback while loading images, leading to a poor user experience.

2. Solution

  • Enable selection and display of a preferred thumbnail for analysis items.
  • Add a loading spinner to indicate image fetch progress.
  • Ensure all relevant parent components can pass and update preferred thumbnail information.
  • Expose preferred_thumbnail in the container API metadata.

3. Implementation

  • Refactored ImageModal to:

    • Accept preferredThumbnail and onChangePreferredThumbnail props.
    • Show a loading spinner while fetching images.
    • Highlight and allow selection of the preferred thumbnail.
    • Use robust integer comparison for thumbnail IDs.
    • Clean up and optimize state handling.
    • Updated all analysis-related parent components (sample, reaction, device, research plan, cell line) to:
    • Pass new props to ImageModal.
    • Handle preferred thumbnail changes and propagate them as needed.
  • Backend: Updated container entity to expose preferred_thumbnail in API responses.

  • To be discussed:

    • It is not clear yet whether the inside genericContainer need to be updated as well.

  • rather 1-story 1-commit than sub-atomic commits

  • commit title is meaningful => git history search

  • commit description is helpful => helps the reviewer to understand the changes

  • code is up-to-date with the latest developments of the target branch (rebased to it or whatever) => ⏩-merge for linear history is favoured

  • added code is linted

  • tests are passing (at least locally): we still have some random test failure on CI. thinking of asking spec/examples.txt to be commited

  • in case the changes are visible to the end-user,  video or screenshots should be added to the PR => helps with user testing

  • testing coverage improvement is improved.

  • CHANGELOG :  add a bullet point on top (optional: reference to github issue/PR )

  • parallele PR for documentation  on docusaurus  if the feature/fix is tagged for a release

@adambasha0 adambasha0 added this to the v3.0 milestone Sep 5, 2025
@adambasha0 adambasha0 self-assigned this Sep 5, 2025
@github-actions
Copy link

github-actions bot commented Sep 5, 2025

LCOV of commit 68046fd during Continuous Integration #5990

Summary coverage rate:
  lines......: 66.5% (16252 of 24447 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate: n/a

@adambasha0
Copy link
Contributor Author

Chemotion.dev.37.webm

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables users to select and display a preferred thumbnail for analysis-related attachments across samples, reactions, devices, research plans, and cell lines. It adds thumbnail selection functionality with visual feedback including loading spinners and highlighted preferred thumbnails.

  • Refactored ImageModal component to support preferred thumbnail selection and display loading states
  • Updated all analysis-related parent components to pass preferred thumbnail props to ImageModal
  • Added backend support to expose preferred_thumbnail in container API metadata

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
app/javascript/src/utilities/imageHelper.js Added debug logging for preferred attachment ID tracking
app/javascript/src/fetchers/AttachmentFetcher.js Added debug logging for attachment fetcher parameters
app/javascript/src/components/common/ImageModal.js Major refactor to support preferred thumbnail selection, loading states, and thumbnail pagination
app/javascript/src/apps/mydb/elements/details/samples/analysesTab/SampleDetailsContainersDnd.js Added updateContainerPreferredThumbnail prop to ContainerRow
app/javascript/src/apps/mydb/elements/details/samples/analysesTab/SampleDetailsContainersCom.js Added updateContainerPreferredThumbnail prop to ReactionsDisplay
app/javascript/src/apps/mydb/elements/details/samples/analysesTab/SampleDetailsContainersAux.js Updated AnalysesHeader to handle preferred thumbnail changes
app/javascript/src/apps/mydb/elements/details/samples/analysesTab/SampleDetailsContainers.js Added updateContainerPreferredThumbnail method and prop passing
app/javascript/src/apps/mydb/elements/details/researchPlans/analysesTab/ResearchPlanDetailsContainers.js Added preferred thumbnail handling to research plan containers
app/javascript/src/apps/mydb/elements/details/deviceDescriptions/analysesTab/AnalysisHeader.js Added preferred thumbnail handling to device description analysis
app/javascript/src/apps/mydb/elements/details/cellLines/analysesTab/Header.js Added preferred thumbnail handling to cell line analysis
app/api/entities/container_entity.rb Exposed preferred_thumbnail field in container API metadata

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

* @returns {Promise<string>} A promise that resolves to a base64 image source string or a fallback SVG path.
*/
const fetchImageSrcByAttachmentId = async (id) => {
console.log('preferred-attachment-id', id);
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug console.log statement before merging to production. Debug logging should not be left in production code.

Suggested change
console.log('preferred-attachment-id', id);

Copilot uses AI. Check for mistakes.
.filter((key) => key !== 'id')
.map((key) => [key, params[key]])
);
console.log(params, urlParams);
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug console.log statement before merging to production. Debug logging should not be left in production code.

Suggested change
console.log(params, urlParams);

Copilot uses AI. Check for mistakes.
}

buildImageSrcArrayFromThumbnails(thumbnails) {
console.log(thumbnails);
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug console.log statement before merging to production. Debug logging should not be left in production code.

Suggested change
console.log(thumbnails);

Copilot uses AI. Check for mistakes.

fetchThumbnails() {
const { ChildrenAttachmentsIds } = this.props;
console.log('ChildrenAttachmentsIds', ChildrenAttachmentsIds);
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug console.log statement before merging to production. Debug logging should not be left in production code.

Suggested change
console.log('ChildrenAttachmentsIds', ChildrenAttachmentsIds);

Copilot uses AI. Check for mistakes.
Comment on lines 217 to 243
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
this.handleSetPreferred(thumb);
}
}}
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extract this keyboard event handler to a separate method to improve readability and reduce inline complexity.

Copilot uses AI. Check for mistakes.
const onChangePreferredThumbnail = (currentPreferredThumbnail) => {
// Handle the change of preferred thumbnail
if (currentPreferredThumbnail !== preferredThumbnail) {
// Handle the change of preferred thumbnail
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove duplicate comment. Both lines say 'Handle the change of preferred thumbnail'.

Suggested change
// Handle the change of preferred thumbnail

Copilot uses AI. Check for mistakes.
const onChangePreferredThumbnail = (currentPreferredThumbnail) => {
// Handle the change of preferred thumbnail
if (currentPreferredThumbnail !== preferredThumbnail) {
// Handle the change of preferred thumbnail
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove duplicate comment. Both lines say 'Handle the change of preferred thumbnail'.

Suggested change
// Handle the change of preferred thumbnail

Copilot uses AI. Check for mistakes.
const onChangePreferredThumbnail = (currentPreferredThumbnail) => {
// Handle the change of preferred thumbnail
if (currentPreferredThumbnail !== preferredThumbnail) {
// Handle the change of preferred thumbnail
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove duplicate comment. Both lines say 'Handle the change of preferred thumbnail'.

Suggested change
// Handle the change of preferred thumbnail

Copilot uses AI. Check for mistakes.
const onChangePreferredThumbnail = (currentPreferredThumbnail) => {
// Handle the change of preferred thumbnail
if (currentPreferredThumbnail !== preferredThumbnail) {
// Handle the change of preferred thumbnail
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove duplicate comment. Both lines say 'Handle the change of preferred thumbnail'.

Suggested change
// Handle the change of preferred thumbnail

Copilot uses AI. Check for mistakes.
@PiTrem PiTrem changed the title Option to set thumbnail as preview in analysis tab for many model elements feat: set which thumbnail to show as preview in analysis tab Sep 9, 2025
@PiTrem PiTrem changed the title feat: set which thumbnail to show as preview in analysis tab feat: set image thumbnail to show as preview in analysis tab Sep 9, 2025
@PiTrem PiTrem linked an issue Sep 23, 2025 that may be closed by this pull request
@alizaib1217
Copy link
Contributor

alizaib1217 commented Sep 26, 2025

Hi @adambasha0! Great feature implementation overall. Here are the key issues and suggestions I found during review:

🐛 Functional Issues

  1. Default Preferred Thumbnail Not Displayed: On first load, no thumbnail is highlighted as preferred in the thumbnail grid, even if one exists.
image
  1. Preview Not Updated When Thumbnail Selected: Clicking a thumbnail in the grid marks it as preferred but doesn't update the main preview image above (i.e., in the modal).
image
  1. Thumbnail Navigation Arrows Not Working: The left/right arrow buttons for paginating through thumbnails are non-functional.

  2. Preferred Thumbnail Not Persisted in Modal View: After selecting a preferred thumbnail, it does not appear in the main view, even after closing and reopening the modal doesn't show the preferred thumbnail in the main preview area(i.e., in the modal).

🔧 Code Quality Issues

  1. Debug Console Statements: Remove production console.log statements from:

    • imageHelper.js:61
    • AttachmentFetcher.js:26
    • ImageModal.js:112, 124
  2. Duplicate Comments: Clean up repeated "Handle the change of preferred thumbnail" comments in parent components.

  3. Missing Error Handling: Add try-catch blocks for thumbnail fetch failures.
    a. fetchThumbnails() method - Lines 125-128
    b. fetchImageThumbnail() - Line 141, we are not resetting the loading state when fetchImageSrcByAttachmentId fails

  4. Inline Event Handler: Extract keyboard handler (lines 217-222) to a separate method for better readability.

Copy link
Contributor

@alizaib1217 alizaib1217 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes in above comment.

- Add preferred thumbnail functionality to ImageModal component
- Enable thumbnail selection interface with pagination and visual feedback
- Pass preferred thumbnail and children attachment IDs to ImageModal
- Add thumbnail fetching capabilities via AttachmentFetcher
- Implement thumbnail grid display with current selection highlighting
- Add navigation controls for multi-page thumbnail viewing
- Update analysis headers to support preferred thumbnail display
- Include console logging for debugging preferred thumbnail functionality
- Add preferred thumbnail functionality to ImageModal component
- Enable thumbnail selection interface with pagination and visual feedback
- Pass preferred thumbnail and children attachment IDs to ImageModal
- Add thumbnail fetching capabilities via AttachmentFetcher
- Implement thumbnail grid display with current selection highlighting
- Add navigation controls for multi-page thumbnail viewing
- Update analysis headers to support preferred thumbnail display
- Include console logging for debugging preferred thumbnail functionality
Major refactor of ImageModal:
- Added support for preferredThumbnail and onChangePreferredThumbnail props.
- Added loading spinner UI while fetching images.
- Improved preferred thumbnail highlighting and selection logic.
- Fixed integer comparison for thumbnail IDs.
- Cleaned up and optimized state handling.
Updated usage of ImageModal in:
- Sample analysis, reaction analysis, device description, cell line, and researchplan analysis modals/components
- Changes done to pass new props and handle preferred thumbnail changes.
Ensured all parent components propagate preferredThumbnail, ChildrenAttachmentsIds, and onChangePreferredThumbnail as needed.
- Container API: Exposed preferred_thumbnail in container entity metadata.
…umbnail fetch error handling- remove debug logs
@adambasha0
Copy link
Contributor Author

adambasha0 commented Oct 13, 2025

Hi @alizaib1217, Thanks for the review. I fixed Code Quality issues.
Regarding:

  • Default Preferred Thumbnail Not Displayed/Preferred Thumbnail Not Persisted in Modal View: It should be only set by the user, not automatically.
  • I do not think the feature should handle Preview Not Updated When Thumbnail Selected as it is only about setting/updating the thumbnail, not the preview
  • Thumbnail Navigation Arrows are working

@adambasha0 adambasha0 force-pushed the option-to-set-thumbnail-as-preview-in-analysis-tab branch from 68046fd to cf7d5e4 Compare October 13, 2025 13:47
@github-actions
Copy link

LCOV of commit cf7d5e4 during CI - Ruby Lint, RSpec, and code coverage #19

Summary coverage rate:
  lines......: 66.3% (16339 of 24655 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate: n/a

@alizaib1217
Copy link
Contributor

Hi @alizaib1217, Thanks for the review. I fixed Code Quality issues. Regarding:

  • Default Preferred Thumbnail Not Displayed/Preferred Thumbnail Not Persisted in Modal View: It should be only set by the user, not automatically.
  • I do not think the feature should handle Preview Not Updated When Thumbnail Selected as it is only about setting/updating the thumbnail, not the preview
  • Thumbnail Navigation Arrows are working

Hi, Thanks for the quick response.

@adambasha0 Can you share a small video of thumbnail arrow working for more than 2 images? I have three images in dataset, and it seems disabled in the modal view. I am clicking the button, but nothing happens.

@adambasha0
Copy link
Contributor Author

Hi @alizaib1217, Thanks for the review. I fixed Code Quality issues. Regarding:

  • Default Preferred Thumbnail Not Displayed/Preferred Thumbnail Not Persisted in Modal View: It should be only set by the user, not automatically.
  • I do not think the feature should handle Preview Not Updated When Thumbnail Selected as it is only about setting/updating the thumbnail, not the preview
  • Thumbnail Navigation Arrows are working

Hi, Thanks for the quick response.

@adambasha0 Can you share a small video of thumbnail arrow working for more than 2 images? I have three images in dataset, and it seems disabled in the modal view. I am clicking the button, but nothing happens.

The current thumbnailsPerPage is 6. this means you have to upload at least 7 images for arrows to start working. Less than this you would only have 1 page and the arrows will be disabled

@alizaib1217 alizaib1217 self-requested a review October 24, 2025 13:31
Copy link
Contributor

@alizaib1217 alizaib1217 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, looks good. Thanks for the update.

@PiTrem PiTrem linked an issue Oct 30, 2025 that may be closed by this pull request
@PiTrem PiTrem marked this pull request as draft October 30, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

analyses - switch images data analysis preview changes while upload from ELN to Repo

2 participants