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

post merge fixes and spaces tweaks #4475

Merged
merged 4 commits into from
Jun 11, 2024

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Jun 10, 2024

  • Fix executeOperator third param to be options
  • Scrollable add panel popover for when you have many panels
  • Fix python panels not loading correctly on app reload
  • Improve ButtonView and IconButtonView and add href to btn util

Summary by CodeRabbit

  • New Features

    • Added support for popoutProps in the Popout component for enhanced customization.
    • Introduced conditional color settings for buttons based on the variant prop.
  • Enhancements

    • Updated executeOperator function to support additional options and improved parameter handling.
    • Enhanced AddPanelButton with better styling and scrolling capabilities.
    • Improved ButtonView and IconButtonView components with new variant properties for more flexible UI design.
  • Bug Fixes

    • Corrected type definitions for various properties in CustomPanelProps to ensure accurate functionality.

Copy link
Contributor

coderabbitai bot commented Jun 10, 2024

Walkthrough

The recent changes encompass updates to component properties, function parameters, and type definitions across various files. Key modifications include the addition of new properties to the Popout component, parameter updates in the executeOperator function, and type changes in the CustomPanelProps interface. Additionally, button components now support conditional styling based on the variant prop, and the btn function in Python has new parameters for enhanced functionality.

Changes

File Path Change Summary
app/packages/components/src/components/Popout/index.tsx Added popoutProps to PopoutProps and included it in the Popout function.
app/packages/operators/src/operators.ts Updated executeOperator parameters: p: any to params: unknown, added options?: OperatorExecutorOptions, renamed params to computedParams, and included options in InvocationRequest.
app/packages/operators/src/useCustomPanelHooks.ts Changed CustomPanelProps properties from Function to string, modified executeOperator function call to include a callback object.
app/packages/operators/src/usePanelEvent.ts Updated executeOperator function call to pass options.callback as an object parameter.
app/packages/spaces/src/components/AddPanelButton.tsx Updated Popout component's style to include maxHeight, overflow, and popoutProps properties.
app/packages/core/src/plugins/SchemaIO/components/Button.tsx Added conditional color setting based on variant prop in the Button component.
app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx Added variant property in BaseButtonView function and updated import statements.
app/packages/core/src/plugins/SchemaIO/components/IconButtonView.tsx Introduced handling for different variant values, added Button component, and adjusted rendering logic.
fiftyone/operators/types.py Updated btn function to include href parameter, expanded variant options, and removed icon_variant parameter.

Poem

In code's vast field, changes bloom,
🌸 New props and types, dispelling gloom.
Buttons now with colors bright,
Variants guide with shining light.
Operators fine-tuned with care,
Enhancing functions everywhere.
A rabbit hops with joy so clear,
For in this code, improvements near. 🐇


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@imanjra imanjra force-pushed the bugfix/python-panels-im-x1 branch from 3e81fc8 to 6f2ffe9 Compare June 10, 2024 23:23
@imanjra imanjra marked this pull request as ready for review June 10, 2024 23:23
@imanjra imanjra requested a review from ritch June 10, 2024 23:23
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: 1

Outside diff range and nitpick comments (5)
app/packages/operators/src/operators.ts (5)

Line range hint 91-91: ### Default Parameter Order Issue
The default parameters in the constructors of InvocationRequest, Executor, and ExecutionContext are incorrectly placed before required parameters. This can lead to issues where the default parameters cannot be omitted at the call site without specifying all subsequent parameters, which is counterintuitive.

Consider rearranging the parameters so that all default parameters follow the required ones. This change will make the function signatures clearer and more predictable.

- constructor(public operatorURI: string, public params: unknown = {}, public options?: OperatorExecutorOptions)
+ constructor(public operatorURI: string, public options?: OperatorExecutorOptions, public params: unknown = {})

- constructor(public params: object = {}, public _currentContext: RawContext, public hooks: object = {}, public executor: Executor = null)
+ constructor(public _currentContext: RawContext, public hooks: object = {}, public executor: Executor = null, public params: object = {})

Also applies to: 155-155, 156-156, 759-759


Line range hint 213-213: ### Simplify Boolean Expressions
The use of ternary operators for boolean values in the OperatorConfig constructor is unnecessary. You can simplify the code by directly assigning the boolean values without using ternary operators. This will make the code cleaner and easier to read.

- this.onStartup = options.onStartup || false;
- this.onDatasetOpen = options.onDatasetOpen || false;
+ this.onStartup = Boolean(options.onStartup);
+ this.onDatasetOpen = Boolean(options.onDatasetOpen);

Also applies to: 215-215


Line range hint 268-268: ### Suggest Using Optional Chaining
There are several places in the code where optional chaining could be used to make the code more concise and safe. This modern JavaScript feature helps prevent runtime errors due to attempts to access properties on null or undefined.

- if (result && result.error) {
+ if (result?.error) {

- if (errorBody && errorBody.kind === "Server Error") {
+ if (errorBody?.kind === "Server Error") {

- if (typeAsJSON && typeAsJSON.error) {
+ if (typeAsJSON?.error) {

- if (operatorURI && operatorURI.includes(HASH)) {
+ if (operatorURI?.includes(HASH)) {

- if (currentContext && currentContext.selectedSamples) {
+ if (currentContext?.selectedSamples) {

Also applies to: 560-560, 742-742, 844-844, 893-893


Line range hint 305-305: ### Avoid Using void in Union Types
The use of void in union types can be confusing and misleading. It's better to use undefined in such cases to make the intentions clear and the code more predictable.

- public resolvePlacement(): Promise<void | types.Placement> {
+ public resolvePlacement(): Promise<undefined | types.Placement> {

Line range hint 313-313: ### Static Method Context Issue
Using this in a static context can lead to confusion as it does not behave as it might be expected in an instance method context. It's recommended to use the class name instead of this to refer to static methods or properties.

- const operator = this.fromJSON(json);
+ const operator = Operator.fromJSON(json);
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7cdb3e7 and 6f2ffe9.

Files selected for processing (5)
  • app/packages/components/src/components/Popout/index.tsx (2 hunks)
  • app/packages/operators/src/operators.ts (1 hunks)
  • app/packages/operators/src/useCustomPanelHooks.ts (2 hunks)
  • app/packages/operators/src/usePanelEvent.ts (1 hunks)
  • app/packages/spaces/src/components/AddPanelButton.tsx (2 hunks)
Additional context used
Path-based instructions (5)
app/packages/operators/src/usePanelEvent.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/components/src/components/Popout/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/spaces/src/components/AddPanelButton.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/operators/src/useCustomPanelHooks.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/operators/src/operators.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.

Biome
app/packages/operators/src/useCustomPanelHooks.ts

[error] 39-39: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.


[error] 40-40: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

app/packages/operators/src/operators.ts

[error] 91-91: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 155-155: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 156-156: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 213-213: Unnecessary use of boolean literals in conditional expression. (lint/complexity/noUselessTernary)

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


[error] 215-215: Unnecessary use of boolean literals in conditional expression. (lint/complexity/noUselessTernary)

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


[error] 268-268: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 305-305: void is confusing inside a union type. (lint/suspicious/noConfusingVoidType)

Unsafe fix: Use undefined instead.


[error] 313-313: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)

this refers to the class.
Unsafe fix: Use the class name instead.


[error] 560-560: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 742-742: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 759-759: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 844-844: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 893-893: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

Additional comments not posted (4)
app/packages/operators/src/usePanelEvent.ts (1)

32-32: The update to pass callback as an object in executeOperator aligns with the PR objectives and improves the clarity of parameter passing.

app/packages/components/src/components/Popout/index.tsx (1)

12-12: The addition of popoutProps to PopoutProps and its application in PopoutDiv enhances component flexibility and customizability. Ensure to document these changes to guide developers on how to use the new properties effectively.

Also applies to: 36-36

app/packages/spaces/src/components/AddPanelButton.tsx (1)

49-58: The updated styling and configuration of the Popout component to include maxHeight, overflow, and popoutProps effectively make the add panel popover scrollable, enhancing user experience for scenarios with many panels. Consider conducting user testing to verify the visual and functional aspects of these changes.

app/packages/operators/src/useCustomPanelHooks.ts (1)

16-26: The change in property types from Function to string in CustomPanelProps suggests a significant shift in usage. Ensure to document or comment on these changes to clarify how developers should now use these properties.

Comment on lines +576 to +591
uri: string,
params: unknown = {},
options?: OperatorExecutorOptions
) {
const { operatorURI, params } = resolveOperatorURIWithMethod(uri, p);
const { operatorURI, params: computedParams } = resolveOperatorURIWithMethod(
uri,
params
);
const resolvedOperatorURI = resolveOperatorURI(operatorURI);
const queue = getInvocationRequestQueue();
const request = new InvocationRequest(resolvedOperatorURI, params);
queue.add(request, callback);
const request = new InvocationRequest(
resolvedOperatorURI,
computedParams,
options
);
queue.add(request);
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The script output shows multiple instances of executeOperator being called across various files. However, not all calls include the optional options parameter, which is necessary to match the updated function signature.

Instances that need attention:

  • app/packages/operators/src/useCustomPanelHooks.ts (Lines: 80, 111, 125, 145, 153)
  • app/packages/operators/src/usePanelEvent.ts (Line: 32)
  • app/packages/operators/src/built-in-operators.ts (Lines: 728, 786)
  • app/packages/operators/src/operators.ts (Lines: 434, 537)

These lines should be reviewed and updated to ensure they include the optional options parameter as per the new function signature.

Analysis chain

Update to executeOperator Function Signature and Logic

The update to the executeOperator function to include an optional options parameter and the renaming of params to computedParams within the function body aligns with the PR objectives to make the third parameter explicitly for options. This change enhances the function's flexibility and clarity in handling operator execution options.

However, ensure that all calls to executeOperator throughout the codebase are updated to reflect this new signature to avoid runtime errors.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `executeOperator` match the new signature.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type typescript $'executeOperator'

Length of output: 73



Script:

#!/bin/bash
# Description: Verify all function calls to `executeOperator` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts 'executeOperator'

Length of output: 3333



Script:

#!/bin/bash
# Description: Extract lines where `executeOperator` is called to verify the new function signature.

# Extract lines with `executeOperator` calls
rg --type ts 'executeOperator' -n | while read -r line; do
  file=$(echo "$line" | cut -d: -f1)
  lineno=$(echo "$line" | cut -d: -f2)
  echo "File: $file, Line: $lineno"
  sed -n "${lineno}p" "$file"
  echo
done

Length of output: 20060

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: 1

Outside diff range and nitpick comments (6)
app/packages/core/src/plugins/SchemaIO/components/Button.tsx (1)

5-5: Ensure destructuring of variant is necessary for further operations.

While destructuring variant directly from props is clean for current usage, consider future cases where more properties might be used from props.

fiftyone/operators/types.py (5)

Line range hint 13-13: Remove unnecessary inheritance from object.

- class BaseType(object):
+ class BaseType:

Line range hint 81-84: Simplify conditional assignment using a ternary operator.

- if view is None:
-     view = View()
- else:
-     view = view.clone()
+ view = View() if view is None else view.clone()

Line range hint 805-805: Remove unnecessary inheritance from object.

- class View(object):
+ class View:

Line range hint 1383-1383: Remove unnecessary inheritance from object.

- class Placement(object):
+ class Placement:

Line range hint 1852-1852: Remove unnecessary inheritance from object.

- class ViewTargetOptions(object):
+ class ViewTargetOptions:
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f2ffe9 and c6d0052.

Files selected for processing (5)
  • app/packages/core/src/plugins/SchemaIO/components/Button.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (2 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/IconButtonView.tsx (4 hunks)
  • app/packages/operators/src/useCustomPanelHooks.ts (5 hunks)
  • fiftyone/operators/types.py (7 hunks)
Additional context used
Path-based instructions (4)
app/packages/core/src/plugins/SchemaIO/components/Button.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/plugins/SchemaIO/components/ButtonView.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/plugins/SchemaIO/components/IconButtonView.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/operators/src/useCustomPanelHooks.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.

Biome
app/packages/operators/src/useCustomPanelHooks.ts

[error] 39-39: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.


[error] 40-40: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

Ruff
fiftyone/operators/types.py

13-13: Class BaseType inherits from object (UP004)

Remove object inheritance


81-84: Use ternary operator view = View() if view is None else view.clone() instead of if-else-block (SIM108)

Replace if-else-block with view = View() if view is None else view.clone()


805-805: Class View inherits from object (UP004)

Remove object inheritance


1143-1143: Dictionary key literal "href" repeated (F601)

Remove repeated key literal "href"


1383-1383: Class Placement inherits from object (UP004)

Remove object inheritance


1852-1852: Class ViewTargetOptions inherits from object (UP004)

Remove object inheritance

Additional comments not posted (10)
app/packages/core/src/plugins/SchemaIO/components/Button.tsx (1)

8-8: Conditional color assignment based on variant prop.

This change allows the button color to dynamically adjust based on the variant prop, enhancing UI flexibility.

app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (2)

1-1: Review of new imports and their integration.

The new imports are correctly integrated and used within the components. This ensures that the necessary functionalities are available for the components.

Also applies to: 2-2, 4-4, 6-6


19-19: Use of variant and href in BaseButtonView.

The inclusion of variant and href props enhances the component's flexibility and functionality, allowing it to handle different types and behaviors of buttons.

Also applies to: 23-23

app/packages/core/src/plugins/SchemaIO/components/IconButtonView.tsx (2)

4-4: Review of new imports and their integration.

The new imports are correctly integrated and used within the component, ensuring that the necessary functionalities are available.

Also applies to: 8-8


13-13: Updates to IconButtonView to handle various button styles and behaviors.

The updates provide enhanced flexibility and customization for the IconButtonView component, allowing it to handle different styles and behaviors based on the variant and href props.

Also applies to: 20-20, 30-41, 51-51, 59-71, 77-79, 98-113

app/packages/operators/src/useCustomPanelHooks.ts (2)

16-26: Update CustomPanelProps to use strings for event handlers.

Changing the event handlers to strings likely aligns with a strategy to reference these handlers by identifiers rather than direct function calls, potentially simplifying configuration and integration with dynamic loading or remote execution scenarios.


57-57: Review of useCustomPanelHooks logic and its integration with the updated props.

The logic within useCustomPanelHooks effectively utilizes the updated string-based event handlers, ensuring that they are correctly invoked based on the component lifecycle and state changes. This integration supports dynamic and flexible panel behavior.

Also applies to: 78-78, 85-85, 108-108, 113-123, 130-130, 138-151

fiftyone/operators/types.py (3)

Line range hint 255-305: The btn method has been updated to include a new href parameter, allowing buttons to navigate to URLs. This change aligns with modern web practices and enhances the flexibility of button components in the UI.


Line range hint 1124-1143: The Button class now includes an href parameter, enabling navigation functionality directly from buttons. This is a useful feature for creating more interactive and connected UI components.


2037-2045: The IconButtonView class has been updated to include an href parameter, allowing icon buttons to also perform navigation tasks. This enhancement makes the UI elements more versatile and functional.

fiftyone/operators/types.py Outdated Show resolved Hide resolved
@imanjra imanjra force-pushed the bugfix/python-panels-im-x1 branch from c6d0052 to 4b7e5f7 Compare June 11, 2024 16:25
@imanjra imanjra force-pushed the bugfix/python-panels-im-x1 branch from 4b7e5f7 to 3165db8 Compare June 11, 2024 16:26
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: 1

Outside diff range and nitpick comments (7)
app/packages/operators/src/useCustomPanelHooks.ts (1)

Line range hint 39-40: Avoid using 'Function' as a type for handlers in CustomPanelHooks.

Using 'Function' as a type is unsafe because it accepts any function-like value, which can be a source of bugs. Define the function shape explicitly.

- handlePanelStateChange: Function;
- handlePanelStatePathChange: Function;
+ handlePanelStateChange: (newState: any) => void;
+ handlePanelStatePathChange: (path: string, value: any, schema: any) => void;
app/packages/operators/src/operators.ts (3)

Line range hint 91-91: Correct the order of default parameters in function signatures.

Default parameters should follow the last required parameter or be made required to avoid confusion at the call site.

- constructor(public operatorURI: string, public params: unknown = {}, public options?: OperatorExecutorOptions)
+ constructor(public operatorURI: string, public options?: OperatorExecutorOptions, public params: unknown = {})

Also applies to: 155-156, 759-759


Line range hint 213-215: Remove unnecessary boolean literals in conditional expressions.

Simplify the code by directly assigning the result without using a ternary operator.

- this.canExecute = options.canExecute === false ? false : true;
- this.disableSchemaValidation = options.disableSchemaValidation === true ? true : false;
+ this.canExecute = options.canExecute !== false;
+ this.disableSchemaValidation = !!options.disableSchemaValidation;

Line range hint 268-268: Use optional chaining to simplify null checks.

Refactor the code to use optional chaining, which makes the code cleaner and more readable.

- if (this.executor && !(this.executor instanceof Executor)) {
+ if (this.executor?.!(instanceof Executor)) {

Also applies to: 560-560, 742-742, 844-844, 893-893

fiftyone/operators/types.py (3)

Line range hint 255-313: Refactor the btn method to improve clarity and maintainability.

  • The method btn has been updated to include new parameters such as href. This aligns with the PR objectives to improve button functionalities.
  • Consider using more descriptive variable names for parameters like on_click to clarify that it expects a string representing the function name, not the function itself.
  • The method could benefit from splitting into smaller methods or using helper functions to handle different types of buttons (e.g., icon button vs. regular button) to improve readability and maintainability.

Line range hint 1132-1141: Remove duplicate dictionary key "href" to prevent potential bugs.

- "href": self.href,
  • This change addresses the static analysis hint about the repeated dictionary key "href".

Line range hint 13-13: Remove unnecessary inheritance from object in class definitions.

- class BaseType(object):
+ class BaseType:

- class View(object):
+ class View:

- class Placement(object):
+ class Placement:

- class ViewTargetOptions(object):
+ class ViewTargetOptions:
  • This change addresses the static analysis hints about unnecessary inheritance from object, which is redundant in Python 3.

Also applies to: 813-813, 1390-1390, 1859-1859

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c6d0052 and 3165db8.

Files selected for processing (9)
  • app/packages/components/src/components/Popout/index.tsx (2 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/Button.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (2 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/IconButtonView.tsx (4 hunks)
  • app/packages/operators/src/operators.ts (1 hunks)
  • app/packages/operators/src/useCustomPanelHooks.ts (5 hunks)
  • app/packages/operators/src/usePanelEvent.ts (1 hunks)
  • app/packages/spaces/src/components/AddPanelButton.tsx (2 hunks)
  • fiftyone/operators/types.py (6 hunks)
Files skipped from review due to trivial changes (1)
  • app/packages/components/src/components/Popout/index.tsx
Files skipped from review as they are similar to previous changes (5)
  • app/packages/core/src/plugins/SchemaIO/components/Button.tsx
  • app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx
  • app/packages/core/src/plugins/SchemaIO/components/IconButtonView.tsx
  • app/packages/operators/src/usePanelEvent.ts
  • app/packages/spaces/src/components/AddPanelButton.tsx
Additional context used
Path-based instructions (2)
app/packages/operators/src/useCustomPanelHooks.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/operators/src/operators.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.

Biome
app/packages/operators/src/useCustomPanelHooks.ts

[error] 39-39: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.


[error] 40-40: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

app/packages/operators/src/operators.ts

[error] 91-91: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 155-155: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 156-156: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 213-213: Unnecessary use of boolean literals in conditional expression. (lint/complexity/noUselessTernary)

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


[error] 215-215: Unnecessary use of boolean literals in conditional expression. (lint/complexity/noUselessTernary)

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


[error] 268-268: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 305-305: void is confusing inside a union type. (lint/suspicious/noConfusingVoidType)

Unsafe fix: Use undefined instead.


[error] 313-313: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)

this refers to the class.
Unsafe fix: Use the class name instead.


[error] 560-560: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 742-742: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 759-759: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 844-844: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 893-893: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

Ruff
fiftyone/operators/types.py

13-13: Class BaseType inherits from object (UP004)

Remove object inheritance


81-84: Use ternary operator view = View() if view is None else view.clone() instead of if-else-block (SIM108)

Replace if-else-block with view = View() if view is None else view.clone()


813-813: Class View inherits from object (UP004)

Remove object inheritance


1390-1390: Class Placement inherits from object (UP004)

Remove object inheritance


1859-1859: Class ViewTargetOptions inherits from object (UP004)

Remove object inheritance

Additional comments not posted (2)
app/packages/operators/src/useCustomPanelHooks.ts (1)

16-26: Update CustomPanelProps interface to use string types for event handlers.

This change aligns with the PR objectives to fix issues with Python panels not loading correctly on app reload, by ensuring that event handlers are consistently represented as strings, which are likely serialized/deserialized across different contexts.

app/packages/operators/src/operators.ts (1)

576-591: Refactor executeOperator to use the updated function signature.

The refactoring of executeOperator to include an optional options parameter and the use of resolveOperatorURIWithMethod to handle the operator URI and parameters is a significant improvement. This change enhances flexibility and clarity in handling operator execution options.

@@ -54,7 +54,7 @@ function useCtxChangePanelEvent(panelId, value, operator) {

export function useCustomPanelHooks(props: CustomPanelProps): CustomPanelHooks {
const { panelId } = props;
const [panelState, setPanelState] = usePanelState(null, panelId);
const [panelState] = usePanelState(null, panelId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper usage of executeOperator with the new function signature.

The executeOperator function is called multiple times in this file. Given the changes in its signature, ensure that all calls to this function pass the correct parameters as per the new signature. This includes the addition of the options parameter where necessary.

- executeOperator(props.onLoad, { panel_id: panelId, panel_state: panelState?.state });
+ executeOperator(props.onLoad, { panel_id: panelId, panel_state: panelState?.state }, {});

Also applies to: 78-85, 113-130, 138-151

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [panelState] = usePanelState(null, panelId);
const [panelState] = usePanelState(null, panelId);
// Assuming the executeOperator function is called somewhere in this file, here is an example update:
executeOperator(props.onLoad, { panel_id: panelId, panel_state: panelState?.state }, {});

@imanjra imanjra merged commit 689f284 into py-panels-develop Jun 11, 2024
6 checks passed
@imanjra imanjra deleted the bugfix/python-panels-im-x1 branch June 11, 2024 16:37
@coderabbitai coderabbitai bot mentioned this pull request Oct 10, 2024
7 tasks
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