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: add reusable EmptyState component #3692

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

Innocent-Akim
Copy link
Contributor

@Innocent-Akim Innocent-Akim commented Mar 26, 2025

  • Add flexible EmptyState component with multiple variants
  • Support different types: default, search, filter, data, error, tasks, projects
  • Add size variants: sm, md, lg
  • Add visual variants: default, subtle, card
  • Add support for custom illustrations and actions
  • Add comprehensive TypeScript types and documentation
  • Implement responsive design with Tailwind CSS

Description

Please include a summary of the changes and the related issues.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Previous screenshots

Please add here videos or images of the previous status

Current screenshots

Please add here videos or images of the current (new) status

Summary by CodeRabbit

  • New Features
    • Introduced a flexible empty state UI component to display context-specific messages and visuals.
    • Offers customizable options for titles, messages, images, and action buttons.
    • Supports various scenarios such as search, filter, data, error, tasks, and projects.

- Add flexible EmptyState component with multiple variants
- Support different types: default, search, filter, data, error, tasks, projects
- Add size variants: sm, md, lg
- Add visual variants: default, subtle, card
- Add support for custom illustrations and actions
- Add comprehensive TypeScript types and documentation
- Implement responsive design with Tailwind CSS
Copy link
Contributor

coderabbitai bot commented Mar 26, 2025

Walkthrough

This pull request introduces a new React functional component named EmptyState in the web UI. The component is designed to render configurable empty state messages using various default types (e.g., 'default', 'search', 'filter', etc.). It supports several props for customization, including overriding default titles, messages, and images. An interface EmptyStateProps has been added to define the component’s expected properties.

Changes

File Summary
apps/.../empty-state.tsx Added EmptyState component and EmptyStateProps interface to render customizable empty state views.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant ES as EmptyState Component
    U->>ES: Render component with props (type, title, message, etc.)
    ES->>ES: Select default configuration based on type
    ES-->>U: Render empty state (image, title, message, action button if defined)
    U->>ES: Click action button (if available)
    ES->>ES: Invoke onAction callback
Loading

Possibly related PRs

Suggested labels

feature, UI/UX, Improvement, Ever Teams

Suggested reviewers

  • evereq

Poem

I'm a bunny with a code-filled hop,
New empty states now make our UI pop!
With images, texts, and buttons that play,
This rabbit cheers for a brighter day.
Hop along, dear devs, and code away!

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.

apps/web/components/ui/empty-state.tsx

Oops! Something went wrong! :(

ESLint: 8.46.0

ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.

The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@Innocent-Akim Innocent-Akim self-assigned this Mar 26, 2025
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added a flexible and reusable EmptyState component with comprehensive configuration options for displaying empty states across the application.

  • Added support for 7 preset types (default, search, filter, data, error, tasks, projects) with customizable titles, messages and illustrations
  • Implemented 3 size variants (sm, md, lg) with responsive typography and spacing using Tailwind CSS
  • Added 3 visual variants (default, subtle, card) with consistent styling and shadows
  • Integrated optional action button with customizable label and callback
  • Added comprehensive TypeScript types and JSDoc documentation for improved developer experience

💡 (5/5) You can turn off certain types of comments like style here!

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

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)
apps/web/components/ui/empty-state.tsx (4)

52-73: Well-documented props interface with comprehensive options.

The EmptyStateProps interface is well-documented with JSDoc comments for each prop, making it clear what each prop does.

However, consider changing the default for showImage from false to true since the component is styled to accommodate images and this would align better with user expectations.


78-95: Good props handling with sensible defaults.

The component properly destructures props with defaults and creates final values by merging custom inputs with defaults from the selected type.

Note that showImage defaults to false, which means images won't display unless explicitly enabled. Consider if this is the intended default behavior.


96-112: Well-organized style configurations.

The size and variant classes are organized in a clear, maintainable way.

For a small performance optimization, consider moving these style configuration objects outside the component to avoid recreating them on each render.

+ const sizeClasses = {
+   sm: 'p-4 gap-2',
+   md: 'p-8 gap-4',
+   lg: 'p-12 gap-6'
+ };
+ 
+ const variantClasses = {
+   default: 'bg-transparent',
+   subtle: 'bg-muted/50 rounded-lg',
+   card: 'bg-card border rounded-lg shadow-sm'
+ };
+ 
+ const imageSize = {
+   sm: 'w-24 h-24',
+   md: 'w-48 h-48',
+   lg: 'w-64 h-64'
+ };

export const EmptyState: FC<EmptyStateProps> = ({
	type = 'default',
	title: customTitle,
	message: customMessage,
	imageSrc: customImageSrc,
	actionLabel,
	onAction,
	showImage = false,
	className,
	size = 'md',
	variant = 'default'
}) => {
	const { title, message, imageSrc } = defaultConfigs[type];

	const finalTitle = customTitle || title;
	const finalMessage = customMessage || message;
	const finalImageSrc = customImageSrc || imageSrc;

-	const sizeClasses = {
-		sm: 'p-4 gap-2',
-		md: 'p-8 gap-4',
-		lg: 'p-12 gap-6'
-	};
-
-	const variantClasses = {
-		default: 'bg-transparent',
-		subtle: 'bg-muted/50 rounded-lg',
-		card: 'bg-card border rounded-lg shadow-sm'
-	};
-
-	const imageSize = {
-		sm: 'w-24 h-24',
-		md: 'w-48 h-48',
-		lg: 'w-64 h-64'
-	};

150-159: Action button with appropriate conditional rendering.

The button is only shown when both actionLabel and onAction are provided.

The size mapping logic can be simplified and accessibility improved:

<Button
    onClick={onAction}
    variant="default"
-   size={size === 'lg' ? 'lg' : size === 'sm' ? 'sm' : 'default'}
+   size={size === 'md' ? 'default' : size}
    className="mt-4"
+   aria-label={`${actionLabel} for ${finalTitle || 'empty state'}`}
>
    {actionLabel}
</Button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a25c68f and 2a10368.

📒 Files selected for processing (1)
  • apps/web/components/ui/empty-state.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: deploy
🔇 Additional comments (3)
apps/web/components/ui/empty-state.tsx (3)

1-5: Good job with the imports!

The imports are well-organized and appropriate for the component's needs.


128-149: Well-structured title and message rendering.

The title and message elements are properly conditionally rendered with appropriate styling based on the size prop.


160-162: Overall excellent component implementation.

The EmptyState component is well-structured, flexible, and follows React best practices. It provides good customization options while maintaining sensible defaults.

@evereq evereq merged commit 15c26d9 into develop Mar 26, 2025
12 of 13 checks passed
@evereq evereq deleted the feat/add-empty-state-component branch March 26, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants