Skip to content

Conversation

@anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Jan 16, 2025

Description

This PR includes following changes:

  • Global empty state component added.
    • Detailed screen
    • Simple screen
    • Section screen
  • Asset path helper function added.

Type of Change

  • Improvement
  • Code refactoring

References

[WEB-3166]

Summary by CodeRabbit

  • New Features

    • Introduced three new empty state components: DetailedEmptyState, SimpleEmptyState, and SectionEmptyState
    • Added a new hook useResolvedAssetPath for dynamic asset path resolution
    • Expanded empty state component library with customizable UI options for different scenarios
  • Documentation

    • Updated module exports to include new empty state components

@makeplane
Copy link

makeplane bot commented Jan 16, 2025

Pull Request Linked with Plane Issues

Comment Automatically Generated by Plane

1 similar comment
@makeplane
Copy link

makeplane bot commented Jan 16, 2025

Pull Request Linked with Plane Issues

Comment Automatically Generated by Plane

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces a comprehensive set of empty state components and a utility hook for asset path resolution. The changes include three new React components: DetailedEmptyState, SimpleEmptyState, and SectionEmptyState, each designed to provide flexible and customizable empty state UI representations. Additionally, a new useResolvedAssetPath hook has been added to help manage asset paths dynamically based on the current theme.

Changes

File Change Summary
web/core/components/empty-state/detailed-empty-state-root.tsx New DetailedEmptyState component with customizable props for title, description, buttons, and asset display
web/core/components/empty-state/index.ts Added exports for new empty state components: detailed-empty-state-root, simple-empty-state-root, and section-empty-state-root
web/core/components/empty-state/section-empty-state-root.tsx New SectionEmptyState component with icon, title, description, and optional action element
web/core/components/empty-state/simple-empty-state-root.tsx New SimpleEmptyState component with configurable size and asset display
web/core/hooks/use-resolved-asset-path.tsx New useResolvedAssetPath hook for dynamic asset path resolution based on theme

Sequence Diagram

sequenceDiagram
    participant User
    participant EmptyStateComponent
    participant AssetPathHook
    participant ThemeResolver

    User->>EmptyStateComponent: Render with props
    EmptyStateComponent->>AssetPathHook: Resolve asset path
    AssetPathHook->>ThemeResolver: Get current theme
    ThemeResolver-->>AssetPathHook: Return theme (light/dark)
    AssetPathHook-->>EmptyStateComponent: Return resolved asset path
    EmptyStateComponent->>User: Render empty state UI
Loading

Possibly related PRs

Suggested reviewers

  • SatishGandham
  • sriramveeraghanta
  • rahulramesha

Poem

🐰 Empty states, oh so neat,
Components dancing to a rhythmic beat
Themes light and dark, paths resolved with care
Buttons and icons, a UI so fair
Rabbit's code hops with joy today! 🎉

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.

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.

@anmolsinghbhatia anmolsinghbhatia marked this pull request as ready for review January 16, 2025 15:33
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 (7)
web/core/hooks/use-resolved-asset-path.tsx (2)

14-14: Consider handling undefined theme state explicitly.

The current theme resolution defaults to "dark" for any non-"light" theme. Consider handling undefined theme state explicitly for better predictability.

-  const theme = resolvedTheme === "light" ? "light" : "dark";
+  const theme = resolvedTheme === "dark" ? "dark" : "light";

16-16: Simplify path construction logic.

The current string concatenation logic is complex and could be simplified for better readability.

-  return `${additionalPath && additionalPath !== "" ? `${basePath}${additionalPath}` : basePath}-${theme}.${extension}`;
+  const path = additionalPath ? `${basePath}${additionalPath}` : basePath;
+  return `${path}-${theme}.${extension}`;
web/core/components/empty-state/section-empty-state-root.tsx (1)

5-10: Consider adding prop-types validation.

While TypeScript provides type safety at compile time, consider adding runtime prop-types validation for better debugging in development.

+import PropTypes from 'prop-types';

 type Props = {
   icon: React.ReactNode;
   title: string;
   description?: string;
   actionElement?: React.ReactNode;
 };

+SectionEmptyState.propTypes = {
+  icon: PropTypes.node.isRequired,
+  title: PropTypes.string.isRequired,
+  description: PropTypes.string,
+  actionElement: PropTypes.node
+};
web/core/components/empty-state/simple-empty-state-root.tsx (1)

33-37: Optimize static function with useCallback.

The getTitleClassName function can be memoized since it's a static function that only depends on the hasDescription parameter.

-const getTitleClassName = (hasDescription: boolean) =>
+const getTitleClassName = React.useCallback((hasDescription: boolean) =>
   cn("font-medium whitespace-pre-line", {
     "text-sm text-custom-text-400": !hasDescription,
     "text-lg text-custom-text-300": hasDescription,
-  });
+  }),
+  []
+);
web/core/components/empty-state/detailed-empty-state-root.tsx (3)

11-30: LGTM! Well-structured type definitions.

The type definitions are comprehensive and provide good flexibility. Consider using branded types for the size property to improve type safety.

-type EmptyStateSize = "sm" | "md" | "lg";
+const EMPTY_STATE_SIZES = ["sm", "md", "lg"] as const;
+type EmptyStateSize = typeof EMPTY_STATE_SIZES[number];

74-75: Consider performance optimization for large screens.

The container uses fixed padding which might not scale well on very large screens. Consider using container queries or max-width constraints.

-<div className="flex items-center justify-center min-h-full min-w-full overflow-y-auto py-10 md:px-20 px-5">
+<div className="flex items-center justify-center min-h-full min-w-full overflow-y-auto py-10 px-5 md:px-20 max-w-screen-2xl mx-auto">

77-78: Enhance text elements accessibility.

Consider adding ARIA roles and proper heading levels for better screen reader support.

-<h3 className={cn("text-xl font-semibold", { "font-medium": !description })}>{title}</h3>
-{description && <p className="text-sm">{description}</p>}
+<h3 role="heading" aria-level={3} className={cn("text-xl font-semibold", { "font-medium": !description })}>{title}</h3>
+{description && <p role="contentinfo" className="text-sm text-custom-text-300">{description}</p>}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 95f43a7 and a704c6a.

📒 Files selected for processing (5)
  • web/core/components/empty-state/detailed-empty-state-root.tsx (1 hunks)
  • web/core/components/empty-state/index.ts (1 hunks)
  • web/core/components/empty-state/section-empty-state-root.tsx (1 hunks)
  • web/core/components/empty-state/simple-empty-state-root.tsx (1 hunks)
  • web/core/hooks/use-resolved-asset-path.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
web/core/components/empty-state/index.ts (1)

4-6: LGTM! Well-organized barrel exports.

The new exports follow a consistent naming convention and are well-organized using the barrel pattern.

web/core/components/empty-state/detailed-empty-state-root.tsx (1)

38-57: Verify button size prop type compatibility.

The size prop passed to the Button component might have a type mismatch. The EmptyStateSize type ("sm" | "md" | "lg") may not match the Button component's size prop type from @plane/ui.

Comment on lines +15 to +22
<div className="flex flex-col gap-4 items-center justify-center rounded-md border border-custom-border-200 p-10">
<div className="flex flex-col items-center gap-2">
<div className="flex items-center justify-center size-8 bg-custom-background-80 rounded">{icon}</div>
<span className="text-sm font-medium">{title}</span>
{description && <span className="text-xs text-custom-text-300">{description}</span>}
</div>
{actionElement && <>{actionElement}</>}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance accessibility attributes.

Add appropriate ARIA attributes to improve accessibility for screen readers.

-    <div className="flex flex-col gap-4 items-center justify-center rounded-md border border-custom-border-200 p-10">
+    <div 
+      role="region" 
+      aria-label={title}
+      className="flex flex-col gap-4 items-center justify-center rounded-md border border-custom-border-200 p-10"
+    >
       <div className="flex flex-col items-center gap-2">
-        <div className="flex items-center justify-center size-8 bg-custom-background-80 rounded">{icon}</div>
+        <div className="flex items-center justify-center size-8 bg-custom-background-80 rounded" aria-hidden="true">{icon}</div>
-        <span className="text-sm font-medium">{title}</span>
+        <h2 className="text-sm font-medium">{title}</h2>
-        {description && <span className="text-xs text-custom-text-300">{description}</span>}
+        {description && <p className="text-xs text-custom-text-300">{description}</p>}
       </div>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="flex flex-col gap-4 items-center justify-center rounded-md border border-custom-border-200 p-10">
<div className="flex flex-col items-center gap-2">
<div className="flex items-center justify-center size-8 bg-custom-background-80 rounded">{icon}</div>
<span className="text-sm font-medium">{title}</span>
{description && <span className="text-xs text-custom-text-300">{description}</span>}
</div>
{actionElement && <>{actionElement}</>}
</div>
<div
role="region"
aria-label={title}
className="flex flex-col gap-4 items-center justify-center rounded-md border border-custom-border-200 p-10"
>
<div className="flex flex-col items-center gap-2">
<div className="flex items-center justify-center size-8 bg-custom-background-80 rounded" aria-hidden="true">{icon}</div>
<h2 className="text-sm font-medium">{title}</h2>
{description && <p className="text-xs text-custom-text-300">{description}</p>}
</div>
{actionElement && <>{actionElement}</>}
</div>

Comment on lines +44 to +55
{assetPath && (
<div className={sizeConfig[size].container}>
<Image
src={assetPath}
alt={title}
height={sizeConfig[size].dimensions}
width={sizeConfig[size].dimensions}
layout="responsive"
lazyBoundary="100%"
/>
</div>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update Image component implementation.

The current Image component implementation uses deprecated props and lacks error handling.

       {assetPath && (
         <div className={sizeConfig[size].container}>
           <Image
             src={assetPath}
             alt={title}
             height={sizeConfig[size].dimensions}
             width={sizeConfig[size].dimensions}
-            layout="responsive"
+            style={{ width: '100%', height: 'auto' }}
             lazyBoundary="100%"
+            loading="lazy"
+            onError={(e) => {
+              console.error('Failed to load image:', assetPath);
+              e.currentTarget.style.display = 'none';
+            }}
           />
         </div>
       )}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{assetPath && (
<div className={sizeConfig[size].container}>
<Image
src={assetPath}
alt={title}
height={sizeConfig[size].dimensions}
width={sizeConfig[size].dimensions}
layout="responsive"
lazyBoundary="100%"
/>
</div>
)}
{assetPath && (
<div className={sizeConfig[size].container}>
<Image
src={assetPath}
alt={title}
height={sizeConfig[size].dimensions}
width={sizeConfig[size].dimensions}
style={{ width: '100%', height: 'auto' }}
lazyBoundary="100%"
loading="lazy"
onError={(e) => {
console.error('Failed to load image:', assetPath);
e.currentTarget.style.display = 'none';
}}
/>
</div>
)}

Comment on lines +42 to +61
return (
<div className="text-center flex flex-col gap-2.5 items-center">
{assetPath && (
<div className={sizeConfig[size].container}>
<Image
src={assetPath}
alt={title}
height={sizeConfig[size].dimensions}
width={sizeConfig[size].dimensions}
layout="responsive"
lazyBoundary="100%"
/>
</div>
)}

<h3 className={getTitleClassName(!!description)}>{title}</h3>

{description && <p className="text-base font-medium text-custom-text-400 whitespace-pre-line">{description}</p>}
</div>
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance accessibility attributes.

Add appropriate ARIA attributes and semantic HTML elements to improve accessibility.

-    <div className="text-center flex flex-col gap-2.5 items-center">
+    <div 
+      role="region" 
+      aria-label={title}
+      className="text-center flex flex-col gap-2.5 items-center"
+    >
       {assetPath && (
-        <div className={sizeConfig[size].container}>
+        <div className={sizeConfig[size].container} aria-hidden="true">
           <Image />
         </div>
       )}

-      <h3 className={getTitleClassName(!!description)}>{title}</h3>
+      <h2 className={getTitleClassName(!!description)}>{title}</h2>

-      {description && <p className="text-base font-medium text-custom-text-400 whitespace-pre-line">{description}</p>}
+      {description && (
+        <p 
+          className="text-base font-medium text-custom-text-400 whitespace-pre-line"
+          aria-describedby={`${title}-description`}
+          id={`${title}-description`}
+        >
+          {description}
+        </p>
+      )}
     </div>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (
<div className="text-center flex flex-col gap-2.5 items-center">
{assetPath && (
<div className={sizeConfig[size].container}>
<Image
src={assetPath}
alt={title}
height={sizeConfig[size].dimensions}
width={sizeConfig[size].dimensions}
layout="responsive"
lazyBoundary="100%"
/>
</div>
)}
<h3 className={getTitleClassName(!!description)}>{title}</h3>
{description && <p className="text-base font-medium text-custom-text-400 whitespace-pre-line">{description}</p>}
</div>
);
return (
<div
role="region"
aria-label={title}
className="text-center flex flex-col gap-2.5 items-center"
>
{assetPath && (
<div className={sizeConfig[size].container} aria-hidden="true">
<Image
src={assetPath}
alt={title}
height={sizeConfig[size].dimensions}
width={sizeConfig[size].dimensions}
layout="responsive"
lazyBoundary="100%"
/>
</div>
)}
<h2 className={getTitleClassName(!!description)}>{title}</h2>
{description && (
<p
className="text-base font-medium text-custom-text-400 whitespace-pre-line"
aria-describedby={`${title}-description`}
id={`${title}-description`}
>
{description}
</p>
)}
</div>
);

Comment on lines +81 to +83
{assetPath && (
<Image src={assetPath} alt={title} width={384} height={250} layout="responsive" lazyBoundary="100%" />
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update Image component implementation.

The current implementation has several issues:

  1. The layout prop is deprecated in Next.js Image component
  2. The alt text could be more descriptive
  3. Missing loading state handling
  4. No error boundary for image loading failures
-{assetPath && (
-  <Image src={assetPath} alt={title} width={384} height={250} layout="responsive" lazyBoundary="100%" />
-)}
+{assetPath && (
+  <div className="relative w-full aspect-[1.536] max-w-[384px] mx-auto">
+    <Image
+      src={assetPath}
+      alt={`Empty state illustration for ${title}`}
+      fill
+      className="object-contain"
+      sizes="(max-width: 384px) 100vw, 384px"
+      priority={false}
+      onError={(e) => {
+        console.error('Failed to load empty state image:', e);
+      }}
+    />
+  </div>
+)}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{assetPath && (
<Image src={assetPath} alt={title} width={384} height={250} layout="responsive" lazyBoundary="100%" />
)}
{assetPath && (
<div className="relative w-full aspect-[1.536] max-w-[384px] mx-auto">
<Image
src={assetPath}
alt={`Empty state illustration for ${title}`}
fill
className="object-contain"
sizes="(max-width: 384px) 100vw, 384px"
priority={false}
onError={(e) => {
console.error('Failed to load empty state image:', e);
}}
/>
</div>
)}

@pushya22 pushya22 merged commit 4432be1 into preview Jan 17, 2025
20 of 22 checks passed
@pushya22 pushya22 deleted the dev-global-empty-state-components branch January 17, 2025 08:22
@coderabbitai coderabbitai bot mentioned this pull request Jan 17, 2025
6 tasks
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.

4 participants