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: update readonly props without strict mode #679

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keiya01
Copy link
Member

@keiya01 keiya01 commented Oct 16, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced storybook stories for the ImageryLayer component with selectable imagery providers ("arcgis" and "cesium").
    • Introduced a new story, Strict, for additional rendering options.
  • Bug Fixes

    • Improved handling of synchronous and asynchronous imagery providers in the ImageryLayer component.
  • Refactor

    • Updated logic for managing the imagery layer waiting list for better clarity.

Copy link

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces enhancements to the ImageryLayer component and its associated stories in Storybook. The ImageLayer.stories.tsx file now includes a new Strict story and improved argTypes for selecting imagery providers. The ImageryLayer.ts file updates the imageryProvider type to accommodate both synchronous and asynchronous providers and modifies the logic for managing the imagery layer waiting list. Additionally, the useCesiumComponent hook's useEffect is adjusted to refine the timing of property updates during the unmounting process.

Changes

File Change Summary
src/ImageryLayer/ImageLayer.stories.tsx Enhanced storybook stories with new Strict story, updated argTypes for tile selection, and modified render function for both Basic and Strict.
src/ImageryLayer/ImageryLayer.ts Updated imageryProvider type to handle both synchronous and asynchronous providers; changed logic for imageryLayerWaitingList management.
src/core/hooks.ts Adjusted useEffect in useCesiumComponent for better timing of property updates during unmounting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Storybook
    participant ImageryLayer

    User->>Storybook: Select tile ("arcgis" or "cesium")
    Storybook->>ImageryLayer: Render with selected imageryProvider
    ImageryLayer->>ImageryLayer: Update imageryProvider
    ImageryLayer-->>User: Display selected imagery
Loading

🐇 "In the world of layers, we now can see,
With choices of tiles, oh so fancy!
From arcgis to cesium, pick your delight,
Our stories now sparkle, oh what a sight!
With hooks that adjust and types that expand,
Imagery's magic is now at hand!" 🖼️✨


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

@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)
src/ImageryLayer/ImageLayer.stories.tsx (3)

17-30: LGTM: Enhanced story interactivity with tile selection.

The changes to the Basic story improve its functionality by allowing users to select between different imagery providers. The conditional logic in the render function correctly implements this feature.

Consider extracting the URL for the ArcGIS imagery provider into a constant at the top of the file for better maintainability:

const ARCGIS_WORLD_STREET_MAP_URL = "https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";

Then use this constant in the render function:

ArcGisMapServerImageryProvider.fromUrl(ARCGIS_WORLD_STREET_MAP_URL)

37-58: LGTM: Added Strict story for StrictMode testing.

The addition of the Strict story is a good practice, allowing the component to be tested under React's StrictMode. The implementation correctly replicates the functionality of the Basic story within a StrictMode wrapper.

To reduce code duplication between the Basic and Strict stories, consider extracting the common logic into a separate function:

const createStoryRender = (Wrapper = React.Fragment) => ({ tile, ...args }: any) => (
  <Wrapper>
    <Viewer full>
      <ImageryLayer
        {...args}
        imageryProvider={
          tile === "arcgis"
            ? ArcGisMapServerImageryProvider.fromUrl(ARCGIS_WORLD_STREET_MAP_URL)
            : IonImageryProvider.fromAssetId(IonWorldImageryStyle.AERIAL)
        }
      />
      <ImageryLayer alpha={0.5} imageryProvider={IonImageryProvider.fromAssetId(3812, {})} />
    </Viewer>
  </Wrapper>
);

export const Basic: Story = {
  argTypes: {
    tile: { options: ["arcgis", "cesium"], control: { type: "select" } },
  } as any,
  render: createStoryRender(),
};

export const Strict: Story = {
  argTypes: {
    tile: { options: ["arcgis", "cesium"], control: { type: "select" } },
  } as any,
  render: createStoryRender(StrictMode),
};

This approach would make the code more DRY and easier to maintain.


Line range hint 1-58: Overall, great improvements to the ImageryLayer stories!

The changes in this file enhance both the functionality and testability of the ImageryLayer component in Storybook. The addition of tile selection options and the new Strict story provide more comprehensive testing scenarios. These modifications align well with the PR objectives and improve the overall quality of the component's stories.

Consider implementing a custom hook or utility function for creating imagery providers based on the tile selection. This could be reused across different components and stories, promoting code reuse and maintainability:

const useImageryProvider = (tile: string) => {
  return useMemo(() => {
    if (tile === "arcgis") {
      return ArcGisMapServerImageryProvider.fromUrl(ARCGIS_WORLD_STREET_MAP_URL);
    }
    return IonImageryProvider.fromAssetId(IonWorldImageryStyle.AERIAL);
  }, [tile]);
};

This approach would centralize the logic for creating imagery providers and make it easier to add new provider types in the future.

src/ImageryLayer/ImageryLayer.ts (1)

111-112: Approved: Improved waiting list management

The new implementation for removing awaited imagery providers from the waiting list is more efficient and clearer than the previous filter method. It directly modifies the array using splice, which is a good practice.

However, we can further optimize this code by combining the indexOf and splice operations:

context.__$internal.imageryLayerWaitingList.splice(
  context.__$internal.imageryLayerWaitingList.indexOf(imageryProvider),
  1
);

This change would slightly improve performance by avoiding the creation of an intermediate variable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0a11635 and 5af270b.

📒 Files selected for processing (3)
  • src/ImageryLayer/ImageLayer.stories.tsx (2 hunks)
  • src/ImageryLayer/ImageryLayer.ts (2 hunks)
  • src/core/hooks.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
src/ImageryLayer/ImageLayer.stories.tsx (1)

2-2: LGTM: Import statement updated correctly.

The addition of IonWorldImageryStyle import from the cesium library is consistent with its usage in the updated render functions for both stories.

src/ImageryLayer/ImageryLayer.ts (2)

58-58: LGTM: Improved type definition for ImageryLayerProps

The updated type definition for ImageryLayerProps correctly combines ImageryLayerCesiumProps and ImageryLayerCesiumReadonlyProps. This change enhances type safety and allows the component to handle both synchronous and asynchronous imagery providers, which aligns with the PR objectives.


Line range hint 1-138: Overall assessment: Improvements to ImageryLayer component

The changes in this file successfully address the PR objectives by updating the ImageryLayer component to handle both synchronous and asynchronous imagery providers. The type definitions have been improved, and the waiting list management has been optimized. These changes enhance the component's flexibility and performance.

To ensure the changes are working as expected, consider adding or updating unit tests to cover the new functionality, particularly the handling of asynchronous imagery providers and the updated waiting list management logic.

To verify the changes, run the following script:

src/core/hooks.ts (1)

290-291: Approve: Improved lifecycle management

This change enhances the robustness of the useCesiumComponent hook by ensuring that any ongoing unmount process is completed before updating properties. It prevents potential race conditions between unmounting and updating, which could lead to errors or unexpected behavior.

The addition of:

if (unmountReadyRef.current) {
  await unmountReadyRef.current;
}

is a necessary improvement that aligns with the existing pattern of managing asynchronous operations in the component lifecycle.

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

Successfully merging this pull request may close these issues.

1 participant