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

chore: Function Render of State Inspector #38893

Merged
merged 5 commits into from
Jan 31, 2025

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Jan 29, 2025

Description

  • Creates a common JSONViewer component
  • Refactors current PeekOverlay component
    • Separates out JSONViewer parts
    • Breaks down file into smaller files
    • fixes lint warnings
    • Removes unused analytics of PeekOverlay
  • Uses the JSONViewer component in the State Inspector

Fixes #38874

Automation

/ok-to-test tags="@tag.IDE"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13066102138
Commit: b7319e7
Cypress dashboard.
Tags: @tag.IDE
Spec:


Fri, 31 Jan 2025 04:28:58 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new JSONViewer component for rendering JSON data
    • Added custom gutter configuration support in CodeEditor
    • Enhanced StateInspector with improved JSON rendering
  • Refactor

    • Restructured PeekOverlayPopup component
    • Replaced ReactJson with custom JSONViewer
    • Improved styling and type definitions for JSON-related components
  • Chores

    • Reorganized imports and constants
    • Added new utility functions for data handling

Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request introduces a comprehensive refactoring of the JSON viewer and peek overlay components in the Appsmith client application. The changes focus on improving the rendering and styling of JSON data, introducing a new JSONViewer component, and restructuring the peek overlay functionality. The modifications aim to enhance the user experience when inspecting complex data structures and functions within the state inspector and code editor.

Changes

File Change Summary
PeekOverlayPopup/... Restructured imports, added new utility functions, styled components, and constants for peek overlay
CodeEditor/index.tsx Added GutterConfig interface and updated EditorProps
Debugger/StateInspector/... Replaced ReactJson with new JSONViewer component
JSONViewer/... Created new component, types, constants, and styling for JSON rendering

Assessment against linked issues

Objective Addressed Explanation
Fix function rendering in peek overlay
Improve State Inspector display

Suggested Labels

enhancement, ide-product, task

Suggested Reviewers

  • ankitakinger
  • alex-golovanov

Poem

Code transforms like morning dew 🌅
JSON dancing, styles anew
Components bloom with grace and might
Refactoring brings pure delight! 🚀
Peek and inspect with crystal clear view

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@hetunandu
Copy link
Member Author

/build-deploy-preview

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jan 29, 2025
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/13028934930.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 38893.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-38893.dp.appsmith.com

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/13049451730.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 38893.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-38893.dp.appsmith.com

@github-actions github-actions bot added Bug Something isn't working Debugger Product Issues related to the debugger IDE Pod Issues that new developers face while exploring the IDE and removed Bug Something isn't working labels Jan 30, 2025
@hetunandu hetunandu added the ok-to-test Required label for CI label Jan 30, 2025
@github-actions github-actions bot added the Bug Something isn't working label Jan 30, 2025
@github-actions github-actions bot removed the Bug Something isn't working label Jan 30, 2025
@github-actions github-actions bot added the Bug Something isn't working label Jan 30, 2025
@hetunandu hetunandu marked this pull request as ready for review January 31, 2025 03:55
@hetunandu hetunandu added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jan 31, 2025
@github-actions github-actions bot removed the Bug Something isn't working label Jan 31, 2025
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

🧹 Nitpick comments (14)
app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/utils.ts (2)

3-5: Add null check for propertyPath parameter.

While the function works, it could be more robust with parameter validation.

 export const getPropertyData = (src: unknown, propertyPath: string[]) => {
+  if (!Array.isArray(propertyPath)) return src;
   return propertyPath.length > 0 ? get(src, propertyPath) : src;
 };

6-16: Consider using type predicates for better type narrowing.

The type checks are correct, but we can improve type safety.

-export const getDataTypeHeader = (data: unknown) => {
+export const getDataTypeHeader = (data: unknown): string => {
   const dataType = typeof data;

   if (dataType === "object") {
     if (Array.isArray(data)) return "array";

     if (data === null) return "null";
   }

   return dataType;
 };
app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/styles.ts (3)

4-18: Consider using design system variable for box-shadow color.

The implementation looks good, but there's a hardcoded color value in the box-shadow property.

Consider replacing the hardcoded color with a design system variable:

-  box-shadow: 0 0 10px #0000001a; // color used from designs
+  box-shadow: 0 0 10px var(--ads-v2-color-shadow);

20-26: LGTM! Consider using design system variable for font size.

The styling is clean and consistent with the design system. Consider using a design system variable for the font size if available.

-  font-size: 10px;
+  font-size: var(--ads-v2-font-size-xs);

32-37: Maintain consistency with font size variables.

Similar to the DataType component, consider using a design system variable for the font size.

-  font-size: 10px;
+  font-size: var(--ads-v2-font-size-xs);
app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/PeekOverlayPopup.tsx (5)

1-18: Fix inconsistent import statement formatting.

Line 8 is missing the curly braces for the import statement, unlike other similar imports.

-import { componentWillAppendToBody } from "react-append-to-body";
+import { componentWillAppendToBody } from "react-append-to-body";

57-67: Add type annotations to improve type safety.

The destructured array from useMemo lacks type annotations, which could lead to type inference issues.

-  const [jsData, dataType] = useMemo(
+  const [jsData, dataType]: [unknown, string] = useMemo(

71-85: Extract magic numbers into named constants.

The value 300 (pixel width) and 8 (minimum left padding) should be extracted into named constants for better maintainability.

+const OVERLAY_WIDTH_PX = 300;
+const MIN_LEFT_PADDING_PX = 8;

const getPositionValues = useCallback(() => {
  const positionValues: { $left: string; $bottom?: string; $top?: string } = {
-    $left: Math.max(position.right - 300, 8) + "px",
+    $left: Math.max(position.right - OVERLAY_WIDTH_PX, MIN_LEFT_PADDING_PX) + "px",
  };

69-69: Optimize debounced event handler.

Consider using useMemo for the debounced function to prevent recreation on every render.

-const debouncedHide = debounce(hidePeekOverlay, PEEK_OVERLAY_DELAY);
+const debouncedHide = useMemo(
+  () => debounce(hidePeekOverlay, PEEK_OVERLAY_DELAY),
+  [hidePeekOverlay]
+);

Also applies to: 87-90, 96-98


Line range hint 111-126: Simplify repetitive rendering logic.

The multiple conditional renders for primitive types can be simplified using a map or switch statement.

-        {dataType === "function" && <div>{jsData.toString()}</div>}
-        {dataType === "boolean" && <div>{jsData.toString()}</div>}
-        {dataType === "string" && <div>{jsData.toString()}</div>}
-        {dataType === "number" && <div>{jsData.toString()}</div>}
+        {["function", "boolean", "string", "number"].includes(dataType) && (
+          <div>{jsData.toString()}</div>
+        )}
app/client/src/components/editorComponents/JSONViewer/constants.ts (1)

13-22: Add documentation for reactJsonProps configuration.

While the configuration is comprehensive, adding JSDoc comments would help explain the purpose and impact of each property.

+/**
+ * Default configuration for react-json-view component
+ * @property {boolean} enableClipboard - Enables/disables copy to clipboard
+ * @property {boolean} displayDataTypes - Shows/hides data type labels
+ * @property {number} collapsed - Depth level for collapsing nested objects
+ */
 export const reactJsonProps = {
   name: null,
   enableClipboard: false,
   displayDataTypes: false,
app/client/src/components/editorComponents/JSONViewer/JSONViewer.tsx (1)

7-16: Consider memoizing the component for better performance.

Since the component receives props that could be complex objects, memoization would help prevent unnecessary re-renders.

-export function JSONViewer(props: JSONViewerProps) {
+export const JSONViewer = React.memo(function JSONViewer(props: JSONViewerProps) {
   const fontSize = FontSize[props.size];
   const iconSize = IconSize[props.size];

   return (
     <Styled.Container $fontSize={fontSize} $iconSize={iconSize}>
       <ReactJson src={props.src} {...reactJsonProps} />
     </Styled.Container>
   );
-}
+});
app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.tsx (1)

73-74: Consider using a more semantic container for overflow content.

The Flex component is being used primarily for overflow behavior. A more semantic choice would be a dedicated scrollable container.

-<Flex className="as-mask" overflowY="auto" px="spaces-3">
+<Styled.ScrollContainer className="as-mask" px="spaces-3">
   <JSONViewer size={Size.MEDIUM} src={selectedItemCode} />
-</Flex>
+</Styled.ScrollContainer>
app/client/src/components/editorComponents/JSONViewer/styles.ts (1)

Line range hint 3-105: Consider using CSS custom properties for better maintainability.

The CSS template uses repeated font size and icon size props. Consider using CSS custom properties to reduce repetition and improve maintainability.

 const ReactJSONViewerOverrider = css<{ $fontSize: string; $iconSize: string }>`
+  --json-viewer-font-size: ${({ $fontSize }) => $fontSize};
+  --json-viewer-icon-size: ${({ $iconSize }) => $iconSize};
   font-size: var(--json-viewer-font-size) !important;

   .node-ellipsis,
   .function-collapsed span:nth-child(2),
   .string-value span {
-    font-size: ${({ $fontSize }) => $fontSize} !important;
+    font-size: var(--json-viewer-font-size) !important;
   }
   // ... rest of the styles
   .icon-container {
-    width: ${({ $iconSize }) => $iconSize} !important;
-    height: ${({ $iconSize }) => $iconSize} !important;
+    width: var(--json-viewer-icon-size) !important;
+    height: var(--json-viewer-icon-size) !important;
   }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 754d3ef and b7319e7.

📒 Files selected for processing (13)
  • app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/Analytics.ts (0 hunks)
  • app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/PeekOverlayPopup.tsx (3 hunks)
  • app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/constants.ts (1 hunks)
  • app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/styles.ts (1 hunks)
  • app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/utils.ts (1 hunks)
  • app/client/src/components/editorComponents/CodeEditor/index.tsx (3 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.test.tsx (8 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.tsx (3 hunks)
  • app/client/src/components/editorComponents/JSONViewer/JSONViewer.tsx (1 hunks)
  • app/client/src/components/editorComponents/JSONViewer/constants.ts (1 hunks)
  • app/client/src/components/editorComponents/JSONViewer/index.ts (1 hunks)
  • app/client/src/components/editorComponents/JSONViewer/styles.ts (3 hunks)
  • app/client/src/components/editorComponents/JSONViewer/types.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/Analytics.ts
✅ Files skipped from review due to trivial changes (2)
  • app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/constants.ts
  • app/client/src/components/editorComponents/JSONViewer/index.ts
🔇 Additional comments (10)
app/client/src/components/editorComponents/CodeEditor/index.tsx (2)

131-131: LGTM! Good refactoring of constant import.

Moving the PEEK_OVERLAY_DELAY constant to a dedicated constants file improves code organization.

Also applies to: 164-164


Line range hint 203-219: Well-structured interface definition for gutter configuration.

The GutterConfig interface is well-designed with clear property definitions:

  • line: Line number for the gutter
  • element: HTML Element to be added
  • isFocusedAction: Callback for focus events

The integration with EditorProps through customGutter property is clean.

app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/utils.ts (1)

1-1: LGTM!

Good choice using Lodash's get for safe property access.

app/client/src/components/editorComponents/CodeEditor/PeekOverlayPopup/styles.ts (3)

1-2: LGTM! Clean imports.

The imports are minimal and appropriate for the styled components implementation.


28-30: LGTM! Simple and effective divider extension.

Clean extension of the design system's Divider component.


39-43: LGTM! Well-structured JSON wrapper.

Good implementation with appropriate height constraints and scroll behavior.

app/client/src/components/editorComponents/JSONViewer/types.ts (1)

1-9: LGTM! Well-structured type definitions.

The type definitions are clear and follow TypeScript best practices. Using unknown for src is a good choice for type safety.

app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.tsx (1)

15-18: LGTM! Good extraction of padding constant.

Moving padding to a constant improves maintainability and reusability.

app/client/src/components/editorComponents/JSONViewer/styles.ts (1)

107-109: LGTM! Clean styled-component implementation.

The Container component correctly implements the CSS template with required props.

app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.test.tsx (1)

36-40: LGTM! Consistent theme provider implementation.

All test cases are properly wrapped with ThemeProvider, ensuring consistent theme context.

Also applies to: 62-66, 84-88, 101-105, 122-126, 131-135, 145-149, 163-167

@hetunandu hetunandu merged commit 0f8e41f into release Jan 31, 2025
75 of 77 checks passed
@hetunandu hetunandu deleted the fix/peekoverly-function-render branch January 31, 2025 05:19
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Debugger Product Issues related to the debugger IDE Pod Issues that new developers face while exploring the IDE ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Peek overlay and State inspector function rendering is broken
2 participants