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: Table loading skeleton #663

Conversation

maciaszczykm
Copy link
Member

@maciaszczykm maciaszczykm commented Nov 21, 2024

Zrzut ekranu 2024-11-21 o 08 56 33

Summary by CodeRabbit

  • New Features

    • Introduced a Skeleton component for visually appealing loading placeholders.
    • Added loading state functionality to the Table component, allowing it to display skeleton rows while data is being fetched.
    • New story for the Table component in Storybook to demonstrate the loading state.
  • Bug Fixes

    • Enhanced handling of loading states to ensure a smoother user experience.

@maciaszczykm maciaszczykm requested a review from a team as a code owner November 21, 2024 07:57
Copy link

linear bot commented Nov 21, 2024

Copy link

coderabbitai bot commented Nov 21, 2024

📝 Walkthrough

Walkthrough

This pull request introduces a new Skeleton component for displaying loading states in the application. It modifies the Table component to include optional properties for loading states, allowing it to conditionally render skeleton rows instead of data rows. Additionally, a new story for the loading state is added to the storybook for the Table component, demonstrating the loading functionality.

Changes

File Change Summary
src/components/table/Skeleton.tsx Introduced a new Skeleton component styled with animations for a loading state.
src/components/table/Table.tsx Added loading (boolean) and loadingSkeletonRows (number) properties to TableProps. Updated rendering logic to show skeleton rows when loading is true.
src/stories/Table.stories.tsx Added a new story named Loading to showcase the Table component in a loading state.

Poem

🐰 In the meadow where we play,
A new Skeleton brightens the day.
Loading states now dance and twirl,
While data waits to unfurl.
With each row, a tale to tell,
In our table, all is well! 🌼

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning @pluralsh/eslint-config-typescript > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning @pluralsh/eslint-config-typescript > eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning @pluralsh/eslint-config-typescript > @pluralsh/eslint-config-pluralsh > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning @pluralsh/eslint-config-typescript > eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning @pluralsh/eslint-config-typescript > eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning @pluralsh/eslint-config-typescript > eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning @pluralsh/eslint-config-typescript > eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
error @pluralsh/[email protected]: The engine "node" is incompatible with this module. Expected version "18.19.0". Got "22.9.0"
error Found incompatible module.


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.

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

Copy link

Visit the preview URL for this PR (updated for commit 4920fee):

https://pluralsh-design--pr663-marcin-prod-2905-add-cl6pxhlu.web.app

(expires Thu, 28 Nov 2024 07:59:25 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 784914c934330f8d0a9fd65c68898b3988262b7d

Copy link

@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 (4)
src/components/table/Skeleton.tsx (1)

11-29: Improve animation consistency and component flexibility

The styled component implementation has a few areas for improvement:

  1. Make the animation distance match the background size:
-    '0%': { backgroundPosition: '-250px 0' },
-    '100%': { backgroundPosition: '250px 0' },
+    '0%': { backgroundPosition: '-500px 0' },
+    '100%': { backgroundPosition: '500px 0' },
  1. Consider making dimensions configurable:
-  maxWidth: '400px',
+  maxWidth: ({ maxWidth = '400px' }) => maxWidth,
   width: '100%',
   span: {
     borderRadius: theme.borderRadiuses.medium,
-    maxWidth: '400px',
+    maxWidth: 'inherit',
-    width: 'unset',
-    minWidth: '150px',
+    width: ({ width = '150px' }) => width,
  1. Consider extracting animation duration to a prop:
-    animation: 'moving-gradient 2s infinite linear forwards',
+    animation: ({ duration = '2s' }) => 
+      `moving-gradient ${duration} infinite linear forwards`,
src/stories/Table.stories.tsx (1)

378-386: Consider enhancing the Loading story demonstration

While the basic loading state is implemented correctly, consider these improvements to better showcase the feature:

  1. Add the loadingSkeletonRows prop to demonstrate customizable number of skeleton rows
  2. Add a knob/control for the loading state to allow toggling between loading and loaded states
  3. Document the loading-related props in the story

Example enhancement:

 export const Loading = Template.bind({})
 Loading.args = {
   fillLevel: 0,
   width: '900px',
   height: '400px',
   data: [],
   columns,
   loading: true,
+  loadingSkeletonRows: 5, // Show 5 skeleton rows while loading
 }
+Loading.parameters = {
+  docs: {
+    description: {
+      story: `
+        The Table component supports a loading state that displays skeleton rows.
+        - Use \`loading\` prop to toggle the loading state
+        - Use \`loadingSkeletonRows\` prop to customize the number of skeleton rows
+      `,
+    },
+  },
+}
src/components/table/Table.tsx (2)

381-404: Consider memoizing the columns iteration

While the implementation is correct, we can optimize the columns iteration to prevent unnecessary re-renders.

-{columns.map((_, j) => (
+{useMemo(() => columns.map((_, j) => (
   <Td
     key={j}
     $fillLevel={fillLevel}
     $firstRow={i === 0}
     $padCells={padCells}
     $loose={loose}
     $stickyColumn={stickyColumn}
     $truncateColumn={false}
   >
     <Skeleton />
   </Td>
-))}
+)), [columns, fillLevel, padCells, loose, stickyColumn])}

418-498: Consider adding error boundaries for row rendering

The row rendering logic handles various states well, but could benefit from error boundaries to prevent the entire table from crashing if individual row rendering fails.

Consider wrapping the row rendering logic in an error boundary component to gracefully handle rendering failures:

class RowErrorBoundary extends React.Component {
  state = { hasError: false };
  
  static getDerivedStateFromError(error) {
    return { hasError: true };
  }
  
  render() {
    if (this.state.hasError) {
      return <Tr><Td colSpan={100}>Error rendering row</Td></Tr>;
    }
    return this.props.children;
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fb05211 and 4920fee.

📒 Files selected for processing (3)
  • src/components/table/Skeleton.tsx (1 hunks)
  • src/components/table/Table.tsx (5 hunks)
  • src/stories/Table.stories.tsx (1 hunks)
🔇 Additional comments (6)
src/components/table/Skeleton.tsx (1)

1-29: Verify Table component integration

Let's verify the integration of this Skeleton component with the Table component.

✅ Verification successful

Skeleton component is properly integrated with Table

The verification shows that the Skeleton component is correctly integrated with the Table component:

  • It's properly imported in Table.tsx
  • The Table component has the necessary loading-related props: loading and loadingSkeletonRows
  • The Skeleton is used within the Table's loading state, rendering multiple skeleton rows based on loadingSkeletonRows prop (default: 10)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check how the Skeleton component is imported and used in the Table component
rg -A 5 "import.*Skeleton.*from.*['\"]\.\/Skeleton" src/components/table/

# Check for the usage of loading props in the Table component
ast-grep --pattern 'interface TableProps {
  $$$
  loading?: $_
  $$$
}'

Length of output: 289


Script:

#!/bin/bash
# Check how the Skeleton component is imported and used in the Table component
rg -A 5 "import.*Skeleton" src/components/table/

# Check for any usage of Skeleton component in Table-related files
rg -A 5 "Skeleton" src/components/table/

# Check for loading prop in Table component
rg -A 5 "loading.*?:" src/components/table/

# Find Table component interface or type definitions
ast-grep --pattern 'interface Table {
  $$$
}'

# Also check for TableProps
ast-grep --pattern 'interface TableProps {
  $$$
}'

Length of output: 3659

src/stories/Table.stories.tsx (2)

378-386: LGTM - Story implementation follows established patterns

The Loading story maintains consistency with other stories in terms of:

  • Story structure and binding
  • Component dimensions
  • Basic table properties

378-386: Verify the loading feature implementation

Let's verify the complete implementation of the loading feature:

✅ Verification successful

Loading feature implementation is complete and well-structured

The loading state implementation is properly handled with:

  • A dedicated Skeleton component with styled animation effects
  • Table component properly implements loading state with configurable skeleton rows
  • Loading state controls visibility of content and empty state
  • Loading story demonstrates the feature
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the Skeleton component implementation and related changes

# Check for Skeleton component
echo "Checking for Skeleton component implementation..."
fd -e tsx -e ts "Skeleton" src/components/table/

# Check for Table component changes
echo "Checking for Table component changes..."
rg "loading.*?:|loadingSkeletonRows.*?:" src/components/table/Table.tsx

# Check for test coverage
echo "Checking for test coverage..."
fd -e test.tsx -e test.ts "Table|Skeleton" src/components/table/

Length of output: 541


Script:

#!/bin/bash
# Let's examine the implementation details

# Check Skeleton component implementation
echo "=== Skeleton Component Implementation ==="
cat src/components/table/Skeleton.tsx

# Check Table component's loading handling
echo -e "\n=== Table Component Loading Logic ==="
rg -B 2 -A 4 "loading[?]:" src/components/table/Table.tsx

# Check if there are any tests specifically for loading state
echo -e "\n=== Loading-related Test Cases ==="
rg "loading.*true" src/components/table/ -A 3

Length of output: 1367


Script:

#!/bin/bash
# Let's check how the loading state is actually used in the Table component

# Check Table component's usage of loading props
echo "=== Table Component Loading Implementation ==="
rg -B 5 -A 10 "loading[^:]" src/components/table/Table.tsx

# Check for Skeleton component usage
echo -e "\n=== Skeleton Usage in Table ==="
rg "Skeleton" src/components/table/Table.tsx -A 3

# Check stories for loading state examples
echo -e "\n=== Loading Stories Implementation ==="
rg "loading.*true" src/stories/Table.stories.tsx -A 3

Length of output: 3153

src/components/table/Table.tsx (3)

269-272: LGTM! Efficient memoization of skeleton rows

The skeleton rows array is properly memoized to prevent unnecessary recreations.


Line range hint 513-517: LGTM! Proper empty state handling

The empty state logic correctly handles the interaction between loading and empty states.


42-42: Verify the Skeleton component implementation

The new Skeleton component is imported but its implementation is not included in this PR. Please ensure that:

  1. The Skeleton component is properly implemented and tested
  2. It follows the design system's guidelines for loading states

Also applies to: 54-55

✅ Verification successful

Skeleton component is properly implemented

The Skeleton component exists and is correctly implemented with:

  • Styled-components integration with theme support
  • Proper animation using CSS keyframes for loading effect
  • Appropriate styling for a loading state placeholder
  • Design system integration through theme variables (colors, border-radius)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Skeleton component exists and verify its implementation
fd -e tsx -e ts "Skeleton" src/components/table/

Length of output: 82


Script:

#!/bin/bash
# Check the implementation of the Skeleton component
cat src/components/table/Skeleton.tsx

Length of output: 835

src/components/table/Skeleton.tsx Show resolved Hide resolved
src/components/table/Skeleton.tsx Show resolved Hide resolved
@maciaszczykm maciaszczykm merged commit 10258af into main Nov 21, 2024
13 checks passed
@maciaszczykm maciaszczykm deleted the marcin/prod-2905-add-loadingskeleton-state-for-table-component branch November 21, 2024 08:05
@plural-bot
Copy link
Contributor

🎉 This PR is included in version 3.80.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants