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: add header to sidebar + add full width state #37597

Merged
merged 4 commits into from
Nov 21, 2024

Conversation

jsartisan
Copy link
Contributor

@jsartisan jsartisan commented Nov 20, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced _Sheet and _Sidebar components with new props for handling transition events (onEnter, onExit).
    • Introduced SidebarContent component for better organization of sidebar content.
    • Added a new story for Sidebar demonstrating render prop usage.
  • Improvements

    • Updated state management in SidebarProvider for more flexible sidebar behavior.
    • Improved CSS transitions for smoother animations in the sidebar.
    • Enhanced type definitions for better clarity and functionality in state management.
  • Bug Fixes

    • Adjusted rendering logic to ensure correct display of sidebar states.

Automation

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

🔍 Cypress test results

Tip

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


Wed, 20 Nov 2024 14:52:18 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Chores
    • Removed several configuration files related to observability tools, including Docker Compose, Grafana dashboards, data sources, and Prometheus settings.
    • These changes streamline the observability setup by eliminating outdated or unused configurations.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes introduce enhancements to the _Sheet and _Sidebar components within the design system. New props for handling transition events, such as onEnter, onExit, and their counterparts, have been added to improve control over animations. The sidebar's internal state management has been updated to a more flexible system, allowing for various states like "expanded" and "collapsed". Additionally, new styling and structural modifications have been made to improve the user interface and responsiveness.

Changes

File Change Summary
.../Sheet/src/Sheet.tsx Added onEnter and onExit props to _Sheet component; updated CSSTransition to utilize these props for transition event handling; modified destructuring of props.
.../Sheet/src/types.ts Updated SheetProps interface to include onEnter, onExit, and onExited callback properties.
.../Sidebar/src/Sidebar.tsx Introduced new animation event props (onEnter, onEntered, onExit, onExited); updated internal state management; encapsulated rendering logic in a new SidebarContent component.
.../Sidebar/src/SidebarContent.tsx Defined SidebarContentProps interface; updated function signature to accept new props; enhanced rendering structure with Flex components.
.../Sidebar/src/SidebarProvider.tsx Transitioned to a generalized state management system using SidebarState; updated props and internal state handling; reorganized imports for clarity.
.../Sidebar/src/styles.module.css Modified transition effects for smoother animations; added new styles for .sidebarHeader and adjusted existing styles based on component states.
.../Sidebar/src/types.ts Updated SidebarContextType, SidebarProviderProps, and SidebarProps interfaces to reflect new state management and added optional properties for transition handling.
.../Sidebar/stories/Sidebar.stories.tsx Removed SidebarContent from certain stories; added new story WithRenderProps to demonstrate render prop pattern; updated args to include default title for the Sidebar.

Possibly related PRs

Suggested labels

Enhancement, Design System Product, Widgets Product, Task, IDE Pod, ADS Components, ok-to-test

Suggested reviewers

  • sagar-qa007
  • ApekshaBhosale
  • albinAppsmith

🎉 In the land of code, where components reside,
New props were added, with transitions to guide.
The sidebar now dances, the sheet glides with grace,
Enhancements abound, in this digital space!
So let’s celebrate changes, both big and small,
For each line of code, we’re having a ball! 🎈

Warning

Rate limit exceeded

@jsartisan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe97bb and a8170df.


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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label 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 (12)
app/client/packages/design-system/widgets/src/components/Sheet/src/types.ts (1)

10-13: Add JSDoc comments for transition callbacks

The transition lifecycle callbacks would benefit from documentation explaining their sequence and purpose.

+ /**
+  * Called when the sheet begins to enter
+  */
  onEnter?: () => void;
  onEntered?: () => void;
+ /**
+  * Called when the sheet begins to exit
+  */
  onExit?: () => void;
  onExited?: () => void;
app/client/packages/design-system/widgets/src/components/Sidebar/src/types.ts (1)

19-19: Add JSDoc documentation for SidebarState

Consider adding JSDoc documentation to describe the purpose and usage of each state.

+/**
+ * Represents the possible states of the sidebar
+ * @property collapsed - Sidebar is minimized
+ * @property expanded - Sidebar is at its default width
+ * @property full-width - Sidebar takes up full available width
+ */
 export type SidebarState = "collapsed" | "expanded" | "full-width";
app/client/packages/design-system/widgets/src/components/Sheet/src/Sheet.tsx (1)

36-39: Add TypeScript types for transition handlers

Consider adding proper TypeScript types for the transition handlers to ensure type safety.

+ import { type TransitionStatus } from 'react-transition-group';

  interface SheetProps {
+   onEnter?: (node: HTMLElement) => void;
+   onEntered?: (node: HTMLElement, isAppearing: boolean) => void;
+   onExit?: (node: HTMLElement) => void;
+   onExited?: (node: HTMLElement) => void;
    // ... other props
  }
app/client/packages/design-system/widgets/src/components/Sidebar/src/Sidebar.tsx (2)

25-47: Consider memoizing event handlers

The animation event handlers could be memoized using useCallback to prevent unnecessary re-renders.

-  const onEnter = () => {
+  const onEnter = React.useCallback(() => {
     setIsAnimating(true);
     onEnterProp?.();
-  };
+  }, [onEnterProp]);

-  const onEntered = () => {
+  const onEntered = React.useCallback(() => {
     setIsAnimating(false);
     onEnteredProp?.();
-  };
+  }, [onEnteredProp]);

Line range hint 11-116: Consider splitting component responsibilities

The Sidebar component handles multiple concerns (animation, state management, rendering logic). Consider:

  1. Moving animation logic to a custom hook
  2. Separating mobile and desktop implementations into distinct components
app/client/packages/design-system/widgets/src/components/Sidebar/stories/Sidebar.stories.tsx (1)

134-157: Consider type safety improvements for render props

While the implementation is good, consider adding explicit typing for the render prop function parameters.

- {({ isAnimating, state }) => (
+ {({ isAnimating, state }: { isAnimating: boolean; state: 'collapsed' | 'expanded' }) => (
app/client/packages/design-system/widgets/src/components/Sidebar/src/styles.module.css (1)

139-151: Consider simplifying the selectors

The current implementation works, but could be more maintainable with a simplified selector structure.

-.mainSidebar[data-state="full-width"][data-side="start"]:is(
-    [data-variant="sidebar"]
-  )
-  .sidebar {
+.mainSidebar[data-state="full-width"][data-variant="sidebar"] .sidebar {
   border-inline-end: none;
+  border-inline-start: none;
 }
-
-.mainSidebar[data-state="full-width"][data-side="end"]:is(
-    [data-variant="sidebar"]
-  )
-  .sidebar {
-  border-inline-start: none;
-}
app/client/packages/design-system/widgets/src/components/Sidebar/src/SidebarContent.tsx (4)

10-14: Extend SidebarContentProps with HTML attributes for better compatibility

To allow standard HTML div attributes to be passed to SidebarContent, consider extending React.HTMLAttributes<HTMLDivElement>.

Apply this diff:

-interface SidebarContentProps {
+interface SidebarContentProps extends React.HTMLAttributes<HTMLDivElement> {
  title?: string;
  className?: string;
  children: React.ReactNode;
}

17-20: Use ForwardRefRenderFunction for proper typing

For better type inference with forwardRef, consider typing _SidebarContent using React.ForwardRefRenderFunction.

Apply this diff:

-const _SidebarContent = (
-  props: SidebarContentProps,
-  ref: Ref<HTMLDivElement>,
-) => {
+const _SidebarContent: React.ForwardRefRenderFunction<
+  HTMLDivElement,
+  SidebarContentProps
+> = (props, ref) => {

29-29: Avoid spreading unnecessary props onto the div

Since all necessary props are already destructured, consider removing {...rest} to prevent unintended attributes from being passed to the div.

Apply this diff:

     <div
       className={clsx(styles.sidebarContent, className)}
       data-sidebar="content"
       ref={ref}
-      {...rest}
     >

38-38: Simplify conditional rendering of the title

The Boolean wrapper is unnecessary. You can directly use title && for conditional rendering.

Apply this diff:

-{Boolean(title) && <Text lineClamp={1}>{title}</Text>}
+{title && <Text lineClamp={1}>{title}</Text>}
app/client/packages/design-system/widgets/src/components/Sidebar/src/SidebarProvider.tsx (1)

45-46: Simplify the toggleSidebar function

The return statement is unnecessary here. You can simplify the function for better readability.

Apply this diff:

-const toggleSidebar = React.useCallback(() => {
-  return state === "collapsed" ? setState("expanded") : setState("collapsed");
-}, [setState, state]);
+const toggleSidebar = React.useCallback(() => {
+  setState(state === "collapsed" ? "expanded" : "collapsed");
+}, [setState, state]);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7b81c3e and 0fe97bb.

📒 Files selected for processing (8)
  • app/client/packages/design-system/widgets/src/components/Sheet/src/Sheet.tsx (2 hunks)
  • app/client/packages/design-system/widgets/src/components/Sheet/src/types.ts (1 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/Sidebar.tsx (2 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/SidebarContent.tsx (1 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/SidebarProvider.tsx (3 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/styles.module.css (4 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/types.ts (1 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/stories/Sidebar.stories.tsx (3 hunks)
🔇 Additional comments (17)
app/client/packages/design-system/widgets/src/components/Sheet/src/types.ts (1)

Line range hint 3-14: LGTM! Clean interface extension with proper typing

The SheetProps interface correctly extends HeadlessModalOverlayProps and implements the transition callbacks with appropriate types.

app/client/packages/design-system/widgets/src/components/Sidebar/src/types.ts (5)

4-5: Strong typing improvement with discriminated union state

The change from boolean to SidebarState type provides better type safety and more flexibility for future state additions.


11-13: Well-structured controlled component pattern

The props follow React's controlled component pattern with optional controlled (state, onStateChange) and uncontrolled (defaultState) modes.


25-28: LGTM: Standard animation lifecycle callbacks

Animation callbacks follow React-Transition-Group's established patterns.


29-34: Well-typed render prop pattern

The children prop type correctly handles both direct ReactNode and render prop patterns with proper typing.


36-36: Verify title prop usage

The title prop appears to be added without context. Please verify its intended usage and consider documenting its purpose.

app/client/packages/design-system/widgets/src/components/Sheet/src/Sheet.tsx (1)

18-21: LGTM: Clean transition handler props implementation

The new transition event handlers follow React conventions and align well with CSSTransition's API.

app/client/packages/design-system/widgets/src/components/Sidebar/src/Sidebar.tsx (3)

9-9: LGTM! Props and imports are well-structured.

The new animation event props and title prop follow React conventions.

Also applies to: 16-21


49-55: Address TypeScript type assertion

The @ts-expect-error comment suggests a type inference issue. Consider properly typing the ref to avoid the type assertion.

Could you share the type definition for sidebarRef to help resolve this typing issue?

Also applies to: 107-107


91-114: Review nested CSSTransition behavior

The nested CSSTransition components might cause animation timing issues as both transitions share the same handlers and nodeRef. Consider:

  1. Using different refs for each transition
  2. Adjusting timeout values to ensure smooth transitions

Have you tested the animation behavior with different state combinations?

app/client/packages/design-system/widgets/src/components/Sidebar/stories/Sidebar.stories.tsx (3)

25-25: LGTM: Default title prop addition

The addition of the default title prop aligns with the PR objective.


37-37: LGTM: Simplified component structure

Direct usage of DemoContent improves clarity and maintainability.


124-166: LGTM: Well-structured render props story

The new story effectively demonstrates the sidebar's state management capabilities and animation status. Good use of conditional rendering and icon states.

app/client/packages/design-system/widgets/src/components/Sidebar/src/styles.module.css (4)

40-40: LGTM! Improved animation smoothness

The change from linear to ease-in-out provides better visual feedback.


79-83: LGTM! Well-structured transitions and proper use of design tokens

The separated transition properties and use of design system color token align with best practices.


85-86: LGTM! Clean implementation of full-width state


224-231: LGTM! Header styling follows design system patterns

Proper use of design tokens for border styling.

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

🧹 Outside diff range and nitpick comments (5)
app/client/packages/design-system/widgets/src/components/Sidebar/src/SidebarContent.tsx (1)

41-49: Consider extracting the toggle logic

The icon selection and state toggle logic could be simplified by extracting it into helper functions or variables.

+ const isFullWidth = state === "full-width";
+ const toggleIcon = isFullWidth ? "arrows-diagonal-minimize" : "arrows-diagonal-2";
+ const handleToggle = () => setState(isFullWidth ? "expanded" : "full-width");

 <Button
   color="neutral"
-  icon={
-    state === "full-width"
-      ? "arrows-diagonal-minimize"
-      : "arrows-diagonal-2"
-  }
-  onPress={() =>
-    setState(state === "full-width" ? "expanded" : "full-width")
-  }
+  icon={toggleIcon}
+  onPress={handleToggle}
   variant="ghost"
 />
app/client/packages/design-system/widgets/src/components/Sidebar/src/Sidebar.tsx (2)

27-28: Consider adding type safety to state management

While the state management is correct, consider adding explicit types for the state values to improve type safety.

- const [isAnimating, setIsAnimating] = useState(false);
+ const [isAnimating, setIsAnimating] = useState<boolean>(false);

31-49: Consider consolidating animation handlers

The animation handlers follow a repetitive pattern. Consider creating a single handler factory to reduce code duplication.

const createAnimationHandler = (isStart: boolean, callback?: () => void) => () => {
  setIsAnimating(isStart);
  callback?.();
};
app/client/packages/design-system/widgets/src/components/Sidebar/src/styles.module.css (2)

139-151: Consider simplifying the full-width border selectors

The current selectors are quite specific. Consider combining them for better maintainability:

-.mainSidebar[data-state="full-width"][data-side="start"]:is(
-    [data-variant="sidebar"]
-  )
-  .sidebar {
-  border-inline-end: none;
-}
-
-.mainSidebar[data-state="full-width"][data-side="end"]:is(
-    [data-variant="sidebar"]
-  )
-  .sidebar {
-  border-inline-start: none;
-}
+.mainSidebar[data-state="full-width"][data-variant="sidebar"] .sidebar {
+  border-inline: none;
+}

231-238: Consider adding padding to the header

The header might benefit from some vertical padding for better visual hierarchy.

 .sidebarHeader {
   border-bottom: var(--border-width-1) solid var(--color-bd-elevation-1);
+  padding: var(--spacing-2) var(--spacing-3);
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe97bb and a8170df.

📒 Files selected for processing (3)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/Sidebar.tsx (2 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/SidebarContent.tsx (1 hunks)
  • app/client/packages/design-system/widgets/src/components/Sidebar/src/styles.module.css (5 hunks)
🔇 Additional comments (9)
app/client/packages/design-system/widgets/src/components/Sidebar/src/SidebarContent.tsx (3)

4-14: LGTM! Well-structured interface and imports

The interface definition is clear and the imports are properly organized.


16-21: LGTM! Clean component setup

Good implementation of ref forwarding and props handling.


30-55: LGTM! Well-implemented sidebar content structure

The component successfully implements the header and full-width state requirements while maintaining good separation of concerns and responsive behavior.

app/client/packages/design-system/widgets/src/components/Sidebar/src/Sidebar.tsx (3)

3-23: LGTM: Clean prop structure and imports

The new animation callback props and imports are well-organized and follow React best practices.


51-57: LGTM: Clean content rendering implementation

The content rendering logic elegantly handles both function and regular children while properly passing state information.


93-100: Verify nested CSSTransition behavior

The nested CSSTransition components might cause animation timing issues. Consider testing various state transitions thoroughly to ensure smooth animations.

app/client/packages/design-system/widgets/src/components/Sidebar/src/styles.module.css (3)

40-40: LGTM: Improved transition smoothness

The switch to ease-in-out timing function provides better animation feel compared to linear transitions.

Also applies to: 79-83


85-86: LGTM: Clean full-width state implementation

Simple and effective implementation of the full-width state.


188-193: LGTM: Proper scroll container implementation

Good implementation of scrollable content container with appropriate overflow handling.

@znamenskii-ilia znamenskii-ilia added the ok-to-test Required label for CI label Nov 20, 2024
@jsartisan jsartisan merged commit 89f9b59 into release Nov 21, 2024
60 checks passed
@jsartisan jsartisan deleted the chore/sidebar-callbacks branch November 21, 2024 05:05
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 27, 2024
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Enhanced `_Sheet` and `_Sidebar` components with new props for
handling transition events (`onEnter`, `onExit`).
- Introduced `SidebarContent` component for better organization of
sidebar content.
  - Added a new story for `Sidebar` demonstrating render prop usage.

- **Improvements**
- Updated state management in `SidebarProvider` for more flexible
sidebar behavior.
  - Improved CSS transitions for smoother animations in the sidebar.
- Enhanced type definitions for better clarity and functionality in
state management.

- **Bug Fixes**
- Adjusted rendering logic to ensure correct display of sidebar states.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11935118755>
> Commit: a8170df
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11935118755&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Wed, 20 Nov 2024 14:52:18 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Chores**
- Removed several configuration files related to observability tools,
including Docker Compose, Grafana dashboards, data sources, and
Prometheus settings.
- These changes streamline the observability setup by eliminating
outdated or unused configurations.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants