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 panel rows not refreshing on action changes #5164

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

CamronStaley
Copy link
Contributor

@CamronStaley CamronStaley commented Nov 20, 2024

What changes are proposed in this pull request?

fix panel rows not refreshing on action changes

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

2024-11-20 10 17 55

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.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

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

  • Improvements
    • Enhanced the TableView component for better readability and maintainability.
    • Improved tooltip handling for clarity.
    • Adjusted the formatting of the background property in the TableCell component.

@CamronStaley CamronStaley requested a review from ritch November 20, 2024 16:19
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The pull request modifies the TableView component in TableView.tsx. Key changes include the restructuring of the getRowActions function to incorporate additional dependencies in its useCallback hook, ensuring proper updates. The formatting of the background property in the TableCell component has been improved for clarity, and tooltip handling logic has been reformatted. These modifications enhance the readability and maintainability of the code without affecting its core functionality.

Changes

File Path Change Summary
app/packages/core/src/plugins/SchemaIO/components/TableView.tsx - Updated getRowActions function to include new dependencies in useCallback.
- Improved formatting of the background property in TableCell.
- Reformatted tooltip handling logic for clarity.
- Updated function signatures for TableView, getTableData, isAdvancedData, parseAdvancedData, and formatCellValue (internal logic modified).

Possibly related PRs

Suggested reviewers

  • minhtuev
  • ritch

🐰 In the meadow, where bunnies play,
The TableView shines brighter today.
With actions and tooltips, all in a row,
Clarity blooms, watch the code flow!
Hops of joy for changes made,
In our code garden, progress displayed! 🌼


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.

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.

@CamronStaley CamronStaley self-assigned this Nov 20, 2024
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 (2)
app/packages/core/src/plugins/SchemaIO/components/TableView.tsx (2)

38-38: Add TypeScript type annotation for tooltips prop

Consider adding a type annotation for the tooltips prop to improve type safety and documentation.

-    tooltips = [],
+    tooltips: Array<{ value: string; row: number; column: number }> = [],

Line range hint 187-212: Optimize cell rendering and tooltip implementation

Several improvements can be made to enhance performance and readability:

-                      const tooltip = tooltipMap[coordinate];
-                      const content = formatCellValue(item[key], props);
-                      const cell = (
-                        <TableCell
-                          key={key}
-                          sx={{
-                            background: isSelected
-                              ? selectedCellColor
-                              : "unset",
-                          }}
-                          onClick={() => {
-                            handleClick(rowIndex, columnIndex);
-                          }}
-                          {...getComponentProps(props, "tableBodyCell")}
-                        >
-                          {tooltip ? (
-                            <Tooltip title={tooltip} arrow>
-                              <span> {content} </span>
-                            </Tooltip>
-                          ) : (
-                            content
-                          )}
-                        </TableCell>
-                      );
-
-                      return cell;
+                      return (
+                        <TableCell
+                          key={key}
+                          sx={{
+                            background: isSelected ? selectedCellColor : "unset",
+                          }}
+                          onClick={() => handleClick(rowIndex, columnIndex)}
+                          {...getComponentProps(props, "tableBodyCell")}
+                        >
+                          {tooltipMap[coordinate] ? (
+                            <Tooltip title={tooltipMap[coordinate]} arrow>
+                              <span>{formatCellValue(item[key], props)}</span>
+                            </Tooltip>
+                          ) : (
+                            formatCellValue(item[key], props)
+                          )}
+                        </TableCell>
+                      );

Changes:

  1. Removed unnecessary variable declarations
  2. Simplified background styling
  3. Removed extra spaces in tooltip content
  4. Directly used tooltipMap lookup
  5. Simplified the return statement
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ebf6b56 and da6585c.

📒 Files selected for processing (1)
  • app/packages/core/src/plugins/SchemaIO/components/TableView.tsx (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/TableView.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.

🔇 Additional comments (1)
app/packages/core/src/plugins/SchemaIO/components/TableView.tsx (1)

50-69: Dependency array update fixes the refresh issue

The addition of missing dependencies (row_actions, handleClick, panelId, path) to the useCallback hook's dependency array resolves the panel rows not refreshing issue. This ensures the callback is properly updated when these dependencies change.

Let's verify there are no other callbacks missing dependencies:

✅ Verification successful

Let me analyze the useCallback hooks in the codebase to verify if there are any missing dependencies in the dependency arrays.

Let me analyze the results further to check for any potential issues with the dependency arrays.

Based on the comprehensive analysis of the codebase's useCallback hooks and their dependencies, I can now provide the final response:

Dependency array in getRowActions is correctly implemented

The useCallback hook's dependency array for getRowActions includes all the necessary dependencies that are used within the callback: [row_actions, handleClick, panelId, path]. Each of these values is referenced inside the callback function and properly listed in the dependency array. This implementation follows React's best practices for memoization.


Let me try different shell commands to analyze the dependency arrays.


Dependency array in getRowActions is correctly implemented

The useCallback hook's dependency array for getRowActions includes all the necessary dependencies used within the callback:

  • row_actions: Used in the for loop
  • handleClick: Used in the onClick handler
  • panelId: Used in the handleClick call
  • path: Used in the params object

The implementation follows React's best practices for memoization and includes all variables referenced within the callback function in its dependency array.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for useCallback hooks in the codebase to ensure consistent dependency usage
ast-grep --pattern 'useCallback($$$, [$$$])'

Length of output: 273040


Script:

#!/bin/bash
# Search for useCallback hooks with dependencies that are used inside the callback but not listed in the dependency array
ast-grep --pattern 'useCallback(($callback), [$deps])'

Length of output: 56


Script:

#!/bin/bash
# Search for state setters and refs that might be missing from dependency arrays
rg "set\w+\(" --type ts --type tsx | grep -v "useState"

Length of output: 83


Script:

#!/bin/bash
# Search for useCallback hooks and their context
rg "useCallback\(" -A 10 -B 5 "app/packages/core/src/plugins/SchemaIO/components/TableView.tsx"

Length of output: 1355

return computedRowActions;
},
[row_actions, handleClick, panelId, path]
);

const getTooltips = useCallback((tooltipList) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do the same for this function too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems to work fine with my local testing

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.

3 participants