Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layout persistence when switching between orthogonal, flight, and oblique mode #8177

Merged
merged 6 commits into from
Nov 11, 2024

Conversation

daniel-wer
Copy link
Member

@daniel-wer daniel-wer commented Nov 7, 2024

On master, switching between the modes reliably leads to empty viewports, because the wrong layout is chosen (e.g. the orthogonal layout, although flight mode is active)

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • Confirm that you can trigger the bug on master. Open a dataset and switch to flight mode, back to orthogonal and then back to flight mode. For me, the orthogonal layout is displayed then and the viewports are empty. Can only be fixed by resetting the layout .
    • This should no longer happen on this branch.
  • Test other layout related functionality: Collapse left and right tabs, maximize viewports, reorder and resize tabs, reload the page.

(Please delete unneeded items, merge only when none are left open)

Summary by CodeRabbit

Release Notes

  • New Features

    • Added metadata support for annotations on Trees and Segments.
    • Introduced a summary row in the time tracking overview.
    • Enhanced slider functionality for value changes and resets.
    • Expanded search functionality to include unnamed segments.
    • Support for remote OME-Zarr NGFF version 0.5 datasets.
    • Superusers can now delete workflow reports.
  • Improvements

    • Admins can view and cancel all jobs, with job ownership displayed.
    • Dataset thumbnails now reflect selected mappings from view configurations.
    • Enhanced user feedback during page refreshes with structured loading messages.
    • Improved control flow for layout updates and border toggling.
  • Bug Fixes

    • Resolved issues with dataset uploads and sharing tokens.
    • Fixed layout persistence bugs affecting viewport switching.

@daniel-wer daniel-wer added the bug label Nov 7, 2024
@daniel-wer daniel-wer self-assigned this Nov 7, 2024
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The pull request introduces several enhancements and fixes to the WEBKNOSSOS platform. Key features include the addition of metadata to annotations for Trees and Segments, improved slider functionality, and expanded search capabilities for unnamed segments. The changelog has been updated to reflect these changes, along with bug fixes related to dataset uploads and sharing tokens. Additionally, modifications have been made to the FlexLayoutWrapper and TracingLayoutView components to improve layout management and user experience during state updates.

Changes

File Path Change Summary
CHANGELOG.unreleased.md Updated to include new features, changes, and bug fixes related to annotations and layout.
frontend/javascripts/oxalis/view/layouting/flex_layout_wrapper.tsx Modified rebuildLayout and onLayoutChange methods for improved state management. Updated toggleBorder method for clarity.
frontend/javascripts/oxalis/view/layouting/tracing_layout_view.tsx Updated onLayoutChange for better state handling and improved user feedback during refresh. Added setControllerStatus method.

Possibly related PRs

Suggested labels

frontend

Suggested reviewers

  • normanrz

Poem

🐇 In the meadow where changes bloom,
New features sprout, dispelling gloom.
Annotations dance with metadata bright,
Layouts refresh, a joyous sight!
Bugs are chased away with glee,
Hopping forward, we’re wild and free! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
frontend/javascripts/oxalis/view/layouting/tracing_layout_view.tsx (1)

Line range hint 1-450: Consider architectural improvements for layout management.

While the immediate issue is fixed, consider the following improvements to make the layout management more robust and maintainable:

  1. Extract layout persistence logic into a dedicated service/hook to reduce complexity in the component
  2. Create a utility function for layout type determination to avoid repetition
  3. Add error handling for layout persistence failures

Example structure:

// useLayoutManager.ts
export function useLayoutManager(commandType, viewMode, is2d) {
  const layoutType = determineLayout(commandType, viewMode, is2d);
  
  const saveLayout = async (model, layoutName) => {
    try {
      await storeLayoutConfig(model, layoutType, layoutName);
    } catch (error) {
      // Handle persistence failure
    }
  };
  
  return {
    layoutType,
    saveLayout,
    // ... other layout management methods
  };
}
frontend/javascripts/oxalis/view/layouting/flex_layout_wrapper.tsx (3)

210-215: LGTM! This change fixes the layout persistence issue.

The use of setState callback ensures that onLayoutChange is called only after the model state has been fully updated. This fixes the timing issue that was causing empty viewports when switching between orthogonal, flight, and oblique modes.

This pattern is particularly important for layout updates where the order of operations is critical. Consider documenting this requirement in a code comment to prevent future regressions.


Line range hint 401-404: Consider addressing TypeScript type issues.

The code uses @ts-ignore to suppress TypeScript errors. While this works, it would be better to properly type these instances.

For example, replace:

// @ts-ignore Typescript doesn't infer the type of side to "left" | "right" but only string, instead
([side, isOpen]: [BorderOpenStatusKeys, boolean])

with:

([side, isOpen]: [keyof BorderOpenStatus, boolean])

Line range hint 279-282: Add error handling for missing viewport IDs.

The error case for unknown viewport IDs only logs to console. Consider adding proper error handling or fallback behavior.

 default: {
-  console.error(`The settings tab with id ${id} is unknown.`);
-  return null;
+  console.error(`Unknown viewport ID: ${id}`);
+  return <div className="error-viewport">Invalid Viewport Configuration</div>;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 41f3d9e and b0abc05.

📒 Files selected for processing (3)
  • CHANGELOG.unreleased.md (1 hunks)
  • frontend/javascripts/oxalis/view/layouting/flex_layout_wrapper.tsx (1 hunks)
  • frontend/javascripts/oxalis/view/layouting/tracing_layout_view.tsx (1 hunks)
🔇 Additional comments (4)
CHANGELOG.unreleased.md (1)

44-44: LGTM! Well-documented changelog entry.

The changelog entry accurately describes the bug fix, follows the proper format, and aligns with the PR objectives. The description clearly communicates both the issue and the conditions that trigger it.

frontend/javascripts/oxalis/view/layouting/tracing_layout_view.tsx (2)

197-206: LGTM! Fixed layout persistence issue.

The change correctly addresses the layout persistence bug by ensuring saveCurrentLayout is called only after the state update is complete. This fixes the issue where switching between viewing modes (orthogonal, flight, oblique) resulted in empty viewports.

Previously, saveCurrentLayout accessed stale state since it was called before the state update was processed. The new implementation using setState callback guarantees that the latest layout is saved.


197-206: Verify layout persistence implementation.

Let's verify that the layout persistence implementation is complete and consistent across the codebase.

✅ Verification successful

Based on the shell script results, I can now provide a final response:

Layout persistence implementation verified successfully

The implementation shows consistent patterns across the codebase:

  • Layout saving is properly handled through saveCurrentLayout with correct state management
  • determineLayout is consistently used to determine layout types based on command type, view mode, and dimensionality
  • The setState callback ensuring layout persistence after state update is correctly implemented
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify layout persistence implementation

# Test 1: Check for other instances where layouts might be saved without proper state handling
echo "Checking for potential layout persistence issues..."
rg -A 2 "saveCurrentLayout|storeLayoutConfig" --type ts

# Test 2: Verify layout type determination consistency
echo "Checking layout type determination usage..."
ast-grep --pattern 'determineLayout($_, $_, $_)'

# Test 3: Check for proper setState usage with callbacks
echo "Checking setState usage patterns..."
ast-grep --pattern 'setState($_, $_)'

Length of output: 5435

frontend/javascripts/oxalis/view/layouting/flex_layout_wrapper.tsx (1)

210-215: Verify similar setState patterns in related layout components.

Let's check if other layout-related components follow the same pattern for state updates.

✅ Verification successful

The setState pattern with onLayoutChange callback is consistent with the codebase

The verification shows that:

  • The setState pattern in flex_layout_wrapper.tsx is properly integrated with the layout system
  • The onLayoutChange callback is consistently used across layout components
  • The change is part of a well-structured layout persistence mechanism where:
    • TracingLayoutView manages the high-level layout state
    • FlexLayoutWrapper handles layout model updates with proper state management
    • Changes are properly propagated through the component hierarchy
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for setState calls in layout-related files to ensure consistent patterns
echo "Searching for setState patterns in layout files..."
rg -l 'setState.*=>' frontend/javascripts/oxalis/view/layouting/

Length of output: 177


Script:

#!/bin/bash
# Let's try a more comprehensive search for setState patterns
# First, let's see what files exist in the layouting directory
echo "Files in layouting directory:"
fd . frontend/javascripts/oxalis/view/layouting/

echo -e "\nSearching for setState patterns:"
# Search for setState with context to see the actual usage
rg "setState" frontend/javascripts/oxalis/view/layouting/ -A 3 -B 1

echo -e "\nSearching for onLayoutChange patterns:"
# Also search for onLayoutChange since it's related to the layout update
rg "onLayoutChange" frontend/javascripts/oxalis/view/layouting/ -A 2 -B 2

Length of output: 8921

Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

Nice, thanks for also fixing this bug 👍

I only noticed that the formating could be improved. I tried to ensure that my suggestions are prettier / biome compliant.
Feel free to decide whether to adapt this or not :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants