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

allow loading the app even when plugins fails to load #4769

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Sep 4, 2024

Caveats

  • When python plugins fails to load, workspaces feature will not work as it depends on built-in operators
  • Needs a follow-up to gracefully handle execution of non-existent operations
    • Deferred as the change is bit out of scope of this PR

What changes are proposed in this pull request?

allow loading the app even when plugins fails to load

How is this patch tested? If it is not, please explain why.

By redirecting plugins/operators request to non-existent port in fetch function to prevent loading of python plugins

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

allow loading the app even when plugins fails to load

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Enhanced state management in various components, providing clearer insights into loading and error states.
    • Introduced a notification mechanism for plugin initialization failures, improving user feedback.
    • Added a canInitialize property in the workspace hook to control component rendering based on initialization status.
  • Bug Fixes

    • Improved error handling and visibility for plugin loading processes.
  • Refactor

    • Streamlined control flow in multiple components for better clarity and responsiveness.

@imanjra imanjra requested review from ritch and a team September 4, 2024 13:56
Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes involve modifications to several components and hooks within the application, focusing on enhancing state management and error handling. Key updates include restructuring control flows, improving loading indicators, and refining the handling of initialization states. The adjustments aim to provide clearer feedback on the operational status of various functionalities, including plugins and workspaces, while also simplifying some logic flows.

Changes

Files Change Summary
app/packages/app/src/Sync.tsx Adjusted import statements and removed error handling for the plugins state in the Plugins component, simplifying logic but reducing error visibility.
app/packages/core/src/components/Starter/index.tsx Reorganized import statements and replaced ready with isLoading to improve clarity in loading state management.
app/packages/operators/src/loader.tsx Enhanced state management in useOperators by introducing a string union type for state representation and improved error handling with a more descriptive return value.
app/packages/plugins/src/index.ts Modified loadPlugins and usePlugins functions to standardize string formatting and added user notifications for plugin initialization errors, improving state management with new flags.
app/packages/spaces/src/components/Workspaces/hooks.ts Updated useWorkspaces to depend on operatorsInitializedAtom, ensuring operations only proceed when conditions are met, and enhanced state robustness with default values.
app/packages/spaces/src/components/Workspaces/index.tsx Incorporated canInitialize from useWorkspaces to control workspace loading and prevent rendering when initialization is not permitted.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Workspaces
    participant Hook

    User->>Workspaces: Request to load workspaces
    Workspaces->>Hook: Check if canInitialize
    Hook-->>Workspaces: Return canInitialize status
    alt canInitialize is true
        Workspaces->>Hook: Execute listWorkspace
        Hook-->>Workspaces: Return workspaces data
        Workspaces-->>User: Display workspaces
    else canInitialize is false
        Workspaces-->>User: Render nothing
    end
Loading

🐰 "In the meadow, changes bloom,
With plugins and workspaces, there's more room.
Loading states now shine so bright,
Errors handled, all feels right.
Hopping through code with joy and cheer,
A brighter path for all to steer!" 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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, codebase verification and nitpick comments (1)
app/packages/plugins/src/index.ts (1)

116-116: Nitpick: Standardize string delimiter.

The string delimiter for the cacheKey variable has been updated from single quotes to double quotes. This change does not affect the functionality but standardizes the string formatting.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3ab7f5b and 842c0c4.

Files selected for processing (6)
  • app/packages/app/src/Sync.tsx (2 hunks)
  • app/packages/core/src/components/Starter/index.tsx (3 hunks)
  • app/packages/operators/src/loader.tsx (3 hunks)
  • app/packages/plugins/src/index.ts (3 hunks)
  • app/packages/spaces/src/components/Workspaces/hooks.ts (4 hunks)
  • app/packages/spaces/src/components/Workspaces/index.tsx (2 hunks)
Additional context used
Path-based instructions (6)
app/packages/operators/src/loader.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/spaces/src/components/Workspaces/hooks.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/spaces/src/components/Workspaces/index.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/app/src/Sync.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/Starter/index.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/plugins/src/index.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (17)
app/packages/operators/src/loader.tsx (4)

30-31: LGTM!

The changes enhance the state management by introducing a more granular state representation using a string union type ("loading" | "error" | "ready") and an error state. This provides clearer insights into the function's operational status and allows capturing and managing errors that may occur during the loading of operators.


41-51: LGTM!

The changes to the loadOperators function improve its robustness by:

  • Handling errors using a .catch block, updating the state to "error", and storing the error object. This ensures that errors are properly tracked and can be communicated to the calling components.
  • Updating the state to "ready", triggering a force refresh, and setting operatorsInitialized to true on successful loading of operators.

60-66: LGTM!

The modifications to the return value of the useOperators function provide a more comprehensive interface for consumers of the hook. By returning an object containing multiple properties (ready, hasError, isLoading, error, and state), it allows them to easily determine the current status of the operator loading process.


Line range hint 1-68: Code conforms to best practices!

The code follows best practices in the used technologies:

  • React: It uses React hooks (useEffect, useState) for state management and side effects, and follows the convention of using the use prefix for custom hooks.
  • Recoil: It uses Recoil hooks (useRecoilValue, useSetRecoilState) for accessing and updating Recoil state.
  • TypeScript: It uses TypeScript for type safety, with proper type annotations for function parameters, state variables, and return values.

There are no deviations from best practices in the mentioned technologies.

app/packages/spaces/src/components/Workspaces/hooks.ts (6)

8-8: LGTM!

The code changes are approved.


15-15: LGTM!

The code changes are approved.


18-18: LGTM!

The code changes are approved.


29-29: LGTM!

The code changes are approved.


41-41: LGTM!

The code changes are approved.


64-64: LGTM!

The code changes are approved.

app/packages/spaces/src/components/Workspaces/index.tsx (2)

28-34: LGTM!

The destructuring of the new canInitialize variable from the useWorkspaces hook looks good. The variable name is descriptive and follows the camelCase convention, which is a best practice in Typescript.


53-58: Great job with the useEffect hook changes!

The updates to the useEffect hook are excellent:

  • Checking both initialized and canInitialize before calling listWorkspace ensures that the workspace is only loaded if the component is both initialized and allowed to initialize, which is a best practice.
  • Returning null if canInitialize is false prevents the component from rendering when initialization is not permitted, which is also a good practice and improves the component's responsiveness to its initialization state.
  • Adding canInitialize to the useEffect hook's dependency array ensures that the effect is re-run when canInitialize changes, avoiding potential stale state issues.

These changes enhance the component's overall logic and performance. Well done!

app/packages/app/src/Sync.tsx (1)

32-32: LGTM!

The import statement for IndexPageQuery has been added back correctly.

app/packages/core/src/components/Starter/index.tsx (3)

8-8: LGTM!

The change is a minor refactor that improves code organization.


33-33: LGTM!

The change improves the clarity of the component's state management by using a more descriptive variable name and focusing on the loading state.


38-38: LGTM!

The change is consistent with the previous change and improves the responsiveness of the component to loading conditions.

app/packages/plugins/src/index.ts (1)

160-175: LGTM!

The changes to the usePlugins function enhance the error handling and state management:

  • The introduction of the notify function allows alerting users when the initialization of Python plugins fails.
  • The state management is updated to include operatorHasError and operatorIsLoading flags from the useOperators hook.
  • The return object is adjusted to incorporate the new loading and error states from the operators.

These changes improve the user experience by providing more granular feedback on the plugin loading process.

Also applies to: 184-185

@imanjra imanjra merged commit 960cf9b into develop Sep 17, 2024
11 checks passed
@imanjra imanjra deleted the bugfix/pluginless-load branch September 17, 2024 15:31
@coderabbitai coderabbitai bot mentioned this pull request Sep 18, 2024
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.

2 participants