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

feat: scrollable tabs list #38855

Merged
merged 21 commits into from
Jan 29, 2025
Merged

Conversation

alex-golovanov
Copy link
Contributor

@alex-golovanov alex-golovanov commented Jan 27, 2025

Description

Adding a scrollable list template component for DismissibleTab.

Fixes #37692

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/13028881854
Commit: 2007e08
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Wed, 29 Jan 2025 10:42:35 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new DismissibleTabBar component with advanced tab management capabilities.
    • Added ability to dynamically add and close tabs.
    • Implemented scrollable tab bar with sticky add button functionality.
  • Improvements

    • Enhanced event handling for tab close actions.
    • Improved component flexibility with ref forwarding in ScrollArea.
  • Design System Updates

    • Created new styled components for tab bar layout.
    • Added TypeScript interfaces for better type safety.
    • New Storybook story for DismissibleTabBar to showcase functionality.

Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request introduces a new DismissibleTabBar component in the design system, enhancing tab management functionality. The implementation includes a scrollable tab bar with an add button, event handling for tab interactions, and responsive design. The changes focus on creating a flexible, reusable component for managing tabs with customizable behavior like adding, closing, and selecting tabs.

Changes

File Change Summary
DismissibleTab/DismissibleTab.tsx Added handleClose function using useCallback for improved event handling.
DismissibleTab/DismissibleTabBar.stories.tsx Created new Storybook story with interactive tab management.
DismissibleTab/DismissibleTabBar.styles.ts Introduced styled components for tab bar layout and styling.
DismissibleTab/DismissibleTabBar.tsx New component for scrollable, dismissible tab bar with add functionality.
DismissibleTab/DismissibleTabBar.types.ts Added DismissibleTabBarProps interface.
DismissibleTab/index.ts Updated exports to include new tab bar components.
ScrollArea/ScrollArea.tsx Refactored to use React.forwardRef for improved ref handling.

Assessment against linked issues

Objective Addressed Explanation
Scrollable tabs with add button
Add button with vertical border on scroll
Customizable onAddClick
Customizable onTabClick
Customizable onCloseClick

Possibly related PRs

  • feat: New tab ui changes #33228: The changes in the main PR introduce a new function handleClose in the DismissibleTab component, which is related to the user interface changes for tabs, enhancing the event handling logic for closing tabs.
  • fix: Tabs UI updates #33536: This PR addresses UI updates for the Tabs component, which includes changes to how tabs are displayed and interacted with, aligning with the modifications made in the DismissibleTab component.
  • feat: IDE tab list search view #34759: The addition of the DismissibleTab component and its props in the main PR relates to the overall enhancement of tab functionality, which is also a focus in this PR that adds search functionality to the overflow list of tabs.

Suggested reviewers

  • ankitakinger
  • hetunandu

Poem

🏷️ Tabs that dance and slide with grace,
A scrolling stage, a dynamic space
Add, dismiss, with just a click
Design system magic, smooth and slick!
Coding poetry in motion 🚀


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c6c283 and 2007e08.

📒 Files selected for processing (1)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.tsx
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests

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.

@github-actions github-actions bot added IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo Enhancement New feature or request labels Jan 27, 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: 4

🧹 Nitpick comments (5)
app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.styles.ts (1)

5-12: Consider using CSS variables for dimensions.

Hard-coded values should be replaced with CSS variables for better maintainability.

 export const Root = styled.div`
   display: flex;
   align-items: center;
   overflow: hidden;
   white-space: nowrap;
   position: relative;
-  height: 32px;
+  height: var(--ads-v2-spaces-8);
 `;
app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.tsx (2)

16-19: Use CSS variables for scroll area dimensions.

Magic numbers in SCROLL_AREA_STYLE should be replaced with CSS variables.

 const SCROLL_AREA_STYLE = {
-  height: 34,
-  top: 1,
+  height: 'var(--ads-v2-spaces-8)',
+  top: 'var(--ads-v2-spaces-px)',
 };

21-81: Consider adding error boundary.

The component should be wrapped in an error boundary to gracefully handle rendering failures.

Would you like me to provide an implementation for the error boundary component?

app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.stories.tsx (1)

42-60: Consider extracting tab selection logic into a separate utility function.

The tab selection logic after closure is complex. Consider extracting it into a separate utility function for better maintainability and testability.

+ const getNextActiveTab = (
+   tabs: Array<{ id: string; label: string }>,
+   closedTabIndex: number,
+   currentActiveId: string
+ ) => {
+   if (closedTabIndex >= tabs.length) {
+     const nextIndex = Math.max(0, closedTabIndex - 1);
+     return tabs[nextIndex].id;
+   }
+   return tabs[closedTabIndex].id;
+ };

  const handleClose = (tabId: string) => () => {
    const closedTabIndex = tabs.findIndex((tab) => tab.id === tabId);
    const filteredTabs = tabs.filter((tab) => tab.id !== tabId);

    setTabs(filteredTabs);

    if (activeTabId === tabId && filteredTabs.length) {
-     if (closedTabIndex >= filteredTabs.length) {
-       const nextIndex = Math.max(0, closedTabIndex - 1);
-       const nextTab = filteredTabs[nextIndex];
-       setActiveTabId(nextTab.id);
-     } else {
-       const nextTab = filteredTabs[closedTabIndex];
-       setActiveTabId(nextTab.id);
-     }
+     setActiveTabId(getNextActiveTab(filteredTabs, closedTabIndex, activeTabId));
    }
  };
app/client/packages/design-system/ads/src/ScrollArea/ScrollArea.tsx (1)

36-44: Improve type safety for ref handling.

The ref handling logic could benefit from better type safety and simplification.

  useEffect(
    function init() {
-     const currentRef =
-       (typeof ref === "function" ? null : ref?.current) || localRef.current;
+     const currentRef = ref && 'current' in ref ? ref.current : localRef.current;

      if (currentRef) initialize(currentRef);
    },
    [initialize, ref],
  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d63d7a and cf0324e.

📒 Files selected for processing (7)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTab.tsx (3 hunks)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.stories.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.styles.ts (1 hunks)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.types.ts (1 hunks)
  • app/client/packages/design-system/ads/src/DismissibleTab/index.ts (1 hunks)
  • app/client/packages/design-system/ads/src/ScrollArea/ScrollArea.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
🔇 Additional comments (3)
app/client/packages/design-system/ads/src/DismissibleTab/index.ts (1)

3-4: LGTM! Clean barrel file exports.

The new exports are well-organized and follow the established pattern.

app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.types.ts (1)

4-10: Consider adding validation for minimum children.

The children prop accepts single or multiple tabs, but doesn't enforce a minimum requirement. Consider adding a runtime check or type constraint to ensure at least one tab is always present.

 export interface DismissibleTabBarProps {
   children:
     | React.ReactElement<DismissibleTabProps>
-    | React.ReactElement<DismissibleTabProps>[];
+    | [React.ReactElement<DismissibleTabProps>, ...React.ReactElement<DismissibleTabProps>[]];
   onTabAdd: () => void;
   disableAdd?: boolean;
 }
app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTab.tsx (1)

20-27: LGTM! Well-implemented event handling.

The handleClose implementation correctly prevents event propagation and is properly memoized.

@alex-golovanov alex-golovanov added the ok-to-test Required label for CI label Jan 27, 2025
…ssibleTabBar.styles.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Member

@hetunandu hetunandu left a comment

Choose a reason for hiding this comment

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

update button disabled prop and scrolling to be part of the tab bar.

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

🧹 Nitpick comments (4)
app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.stories.tsx (2)

42-60: Simplify tab closure logic and add validation.

Consider adding validation and simplifying the logic:

 const handleClose = (tabId: string) => () => {
+  if (tabs.length === 0) return;
+
   const closedTabIndex = tabs.findIndex((tab) => tab.id === tabId);
   const filteredTabs = tabs.filter((tab) => tab.id !== tabId);
 
   setTabs(filteredTabs);
 
-  if (activeTabId === tabId && filteredTabs.length) {
-    if (closedTabIndex >= filteredTabs.length) {
-      const nextIndex = Math.max(0, closedTabIndex - 1);
-      const nextTab = filteredTabs[nextIndex];
+  if (activeTabId !== tabId || !filteredTabs.length) return;
 
-      setActiveTabId(nextTab.id);
-    } else {
-      const nextTab = filteredTabs[closedTabIndex];
+  const nextIndex = closedTabIndex >= filteredTabs.length 
+    ? Math.max(0, closedTabIndex - 1) 
+    : closedTabIndex;
 
-      setActiveTabId(nextTab.id);
-    }
-  }
+  setActiveTabId(filteredTabs[nextIndex].id);
 };

31-33: Add prop validation for containerWidth.

Consider adding validation to ensure containerWidth is positive and reasonable.

 interface StoryProps extends DismissibleTabBarProps {
+  /** Width of the container in pixels. Must be between 200 and 600. */
   containerWidth: number;
 }
+
+const isValidWidth = (width: number) => width >= 200 && width <= 600;
app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.styles.ts (1)

5-12: Extract animation duration to CSS variable.

Consider moving the hardcoded animation duration to a CSS variable for consistency and maintainability.

 export const animatedLeftBorder = (showLeftBorder: boolean) => css`
-  transition: border-color 0.5s ease;
+  transition: border-color var(--ads-v2-transition-duration-base) ease;
   border-left: 1px solid transparent;
 
   border-left-color: ${showLeftBorder
     ? "var(--ads-v2-color-border-muted)"
     : "transparent"};
 `;
app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.tsx (1)

71-83: Add error handling for scrollIntoView.

Consider adding try-catch block to handle browsers that don't support smooth scrolling.

 useEffect(
   function scrollAddedTabIntoView() {
     const element = sentinelRightRef.current;
 
     if (element && totalChildren > prevTotalChildren) {
+      try {
         element.scrollIntoView({
           inline: "center",
           behavior: "smooth",
         });
+      } catch (error) {
+        console.warn('Smooth scrolling not supported:', error);
+        element.scrollIntoView();
+      }
     }
   },
   [totalChildren, prevTotalChildren],
 );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e4cbb72 and 2e82109.

📒 Files selected for processing (3)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.stories.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.styles.ts (1 hunks)
  • app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
🔇 Additional comments (1)
app/client/packages/design-system/ads/src/DismissibleTab/DismissibleTabBar.stories.tsx (1)

66-73: Use functional updates for state changes.

Direct mutation of ref value could lead to issues. Consider using functional updates for safer state management.

Comment on lines 71 to 83
useEffect(
function scrollAddedTabIntoView() {
const element = sentinelRightRef.current;

if (element && totalChildren > prevTotalChildren) {
element.scrollIntoView({
inline: "center",
behavior: "smooth",
});
}
},
[totalChildren, prevTotalChildren],
);
Copy link
Member

Choose a reason for hiding this comment

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

This is not the same as activeTab. A previously added tab, could get active outside of a tabs selection and that would be needed a scroll into view

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's not meant to be active, we only need to scroll to a newly added tab, which will be marked active.

Copy link
Member

Choose a reason for hiding this comment

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

So the consumer handles the scroll to an active tab that is not new?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored.

@hetunandu hetunandu removed their request for review January 29, 2025 08:25
@alex-golovanov alex-golovanov merged commit 3ab237d into release Jan 29, 2025
51 checks passed
@alex-golovanov alex-golovanov deleted the feat/37692-scrollable-tabs-list branch January 29, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate "Tabs" component which is scrollable with a list of tabs with add button
3 participants