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: added common component for project activity #6212

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

gakshita
Copy link
Collaborator

@gakshita gakshita commented Dec 17, 2024

Summary

  • This PR adds a common dynamic component for activity

Summary by CodeRabbit

  • New Features

    • Introduced ActivityBlockComponent for displaying structured activity information.
    • Added ActivityItem component to showcase individual activity items.
    • Created User component for displaying user-related information based on activity.
    • Implemented helper functions for activity type mapping and user-friendly message generation.
    • Added new enum members INITIATIVE_DESCRIPTION and PROJECT_DESCRIPTION to enhance activity categorization.
  • Documentation

    • Updated export statements for better accessibility of new components within the activity module.

Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

This pull request introduces a set of new React components and utilities for managing and displaying project activities. Notable additions include the ActivityBlockComponent, ActivityItem, and User components, along with a helper module for mapping activity types to icons and generating user-friendly messages. The changes aim to enhance the rendering of project activities with customizable options and responsive design.

Changes

File Change Summary
web/core/components/common/activity/activity-block.tsx New ActivityBlockComponent with props for rendering activity blocks, including icon, activity details, and tooltip
web/core/components/common/activity/activity-item.tsx New ActivityItem component using ActivityBlockComponent to display project activities
web/core/components/common/activity/helper.tsx Added iconsMap and messages function for generating activity icons and user-friendly messages
web/core/components/common/activity/index.ts Export statement for re-exporting activity-related entities
web/core/components/common/activity/user.tsx New User component for rendering user information in activities
web/core/components/common/index.ts Added export for the new activity module
packages/types/src/enums.ts Added INITIATIVE_DESCRIPTION and PROJECT_DESCRIPTION members to EFileAssetType enum

Sequence Diagram

sequenceDiagram
    participant User as User Component
    participant ActivityItem as Activity Item
    participant ActivityBlock as Activity Block Component
    participant Helper as Activity Helper

    User->>ActivityItem: Render with activity data
    ActivityItem->>Helper: Get icon and message
    Helper-->>ActivityItem: Return icon and message
    ActivityItem->>ActivityBlock: Pass icon, activity, message
    ActivityBlock->>ActivityBlock: Render activity block with tooltip
Loading

Poem

🐰 In the realm of code, a new tale unfolds,
Activities dancing, their stories untold.
Icons and messages, a rabbit's delight,
Rendering projects with pixels so bright!
Hop, hop, hooray for components so neat! 🎉

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f598653 and 9227939.

📒 Files selected for processing (1)
  • packages/types/src/enums.ts (1 hunks)
🔇 Additional comments (1)
packages/types/src/enums.ts (1)

63-64: LGTM! The new enum members are well-structured.

The additions follow the established naming conventions and align with the PR's objective of enhancing project activity functionality.

Let's verify the usage of these new enum members:


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.

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

🧹 Nitpick comments (4)
web/core/components/common/activity/activity-item.tsx (1)

10-14: Consider adding runtime prop validation

For better development experience and runtime safety, consider adding prop-types validation.

Example implementation:

import PropTypes from 'prop-types';

// ... component code ...

ActivityItem.propTypes = {
  activity: PropTypes.shape({
    field: PropTypes.string.isRequired,
    // add other required activity properties
  }).isRequired,
  showProject: PropTypes.bool,
  ends: PropTypes.oneOf(['top', 'bottom', undefined])
};
web/core/components/common/activity/activity-block.tsx (1)

12-18: Props interface could be improved with better type safety

The ends prop type could be more strictly typed using a union literal type.

Consider this improvement:

type TActivityBlockComponent = {
  icon?: ReactNode;
  activity: TProjectActivity;
-  ends: "top" | "bottom" | undefined;
+  ends?: "top" | "bottom";
  children: ReactNode;
  customUserName?: string;
};
web/core/components/common/activity/helper.tsx (2)

31-66: Consider organizing icons by category for better maintainability

The icon mapping, while comprehensive, could be better organized by grouping related icons together.

Consider restructuring the icons map:

const ACTIVITY_ICONS = {
  project: {
    name: <Type className="h-3.5 w-3.5 text-custom-text-200" />,
    description: <AlignLeft className="h-3.5 w-3.5 text-custom-text-200" />,
    // ... other project-related icons
  },
  features: {
    is_epic_enabled: <LayoutGrid className="h-3.5 w-3.5 text-custom-text-200" />,
    is_workflow_enabled: <GitBranch className="h-3.5 w-3.5 text-custom-text-200" />,
    // ... other feature-related icons
  },
  // ... other categories
} as const;

export const iconsMap: ActivityIconMap = {
  ...ACTIVITY_ICONS.project,
  ...ACTIVITY_ICONS.features,
  // ... spread other categories
  default: <Network className="h-3.5 w-3.5 text-custom-text-200" />,
};

74-78: Improve type safety of boolean action text helper

The getBooleanActionText function could benefit from stricter typing.

Consider this improvement:

const getBooleanActionText = (value: 'true' | 'false' | string): string => {
  if (value === "true") return "enabled";
  if (value === "false") return "disabled";
  return value;
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4507802 and 93d545d.

📒 Files selected for processing (6)
  • web/core/components/common/activity/activity-block.tsx (1 hunks)
  • web/core/components/common/activity/activity-item.tsx (1 hunks)
  • web/core/components/common/activity/helper.tsx (1 hunks)
  • web/core/components/common/activity/index.ts (1 hunks)
  • web/core/components/common/activity/user.tsx (1 hunks)
  • web/core/components/common/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • web/core/components/common/activity/index.ts
🧰 Additional context used
🪛 Biome (1.9.4)
web/core/components/common/activity/activity-item.tsx

[error] 27-27: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

🔇 Additional comments (1)
web/core/components/common/index.ts (1)

8-8: LGTM! Export follows established pattern

The new export follows the existing pattern and correctly exposes the activity module.

Comment on lines +15 to +17
{customUserName || activity.actor_detail?.display_name.includes("-intake") ? (
<span className="text-custom-text-100 font-medium">{customUserName || "Plane"}</span>
) : (
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checks for actor_detail properties

The current implementation could throw runtime errors if actor_detail or display_name is undefined.

Suggested fix:

- {customUserName || activity.actor_detail?.display_name.includes("-intake") ? (
+ {customUserName || (activity.actor_detail?.display_name || "").includes("-intake") ? (
📝 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
{customUserName || activity.actor_detail?.display_name.includes("-intake") ? (
<span className="text-custom-text-100 font-medium">{customUserName || "Plane"}</span>
) : (
{customUserName || (activity.actor_detail?.display_name || "").includes("-intake") ? (
<span className="text-custom-text-100 font-medium">{customUserName || "Plane"}</span>
) : (

Comment on lines +18 to +24
<Link
href={`/${activity?.workspace_detail?.slug}/profile/${activity?.actor_detail?.id}`}
className="hover:underline text-custom-text-100 font-medium"
>
{activity.actor_detail?.display_name}
</Link>
)}
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

Add safety checks for profile link and enhance accessibility

The profile link construction needs safety checks for undefined values, and the link should have proper accessibility attributes.

Suggested improvements:

<Link
- href={`/${activity?.workspace_detail?.slug}/profile/${activity?.actor_detail?.id}`}
+ href={activity?.workspace_detail?.slug && activity?.actor_detail?.id 
+   ? `/${activity.workspace_detail.slug}/profile/${activity.actor_detail.id}`
+   : "#"}
- className="hover:underline text-custom-text-100 font-medium"
+ className="hover:underline text-custom-text-100 font-medium"
+ aria-label={`View ${activity.actor_detail?.display_name}'s profile`}
>
  {activity.actor_detail?.display_name}
</Link>
📝 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
<Link
href={`/${activity?.workspace_detail?.slug}/profile/${activity?.actor_detail?.id}`}
className="hover:underline text-custom-text-100 font-medium"
>
{activity.actor_detail?.display_name}
</Link>
)}
<Link
href={activity?.workspace_detail?.slug && activity?.actor_detail?.id
? `/${activity.workspace_detail.slug}/profile/${activity.actor_detail.id}`
: "#"}
className="hover:underline text-custom-text-100 font-medium"
aria-label={`View ${activity.actor_detail?.display_name}'s profile`}
>
{activity.actor_detail?.display_name}
</Link>
)}

Comment on lines +26 to +28
<ActivityBlockComponent icon={icon} activity={activity} ends={ends} customUserName={customUserName}>
<>{message}</>
</ActivityBlockComponent>
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

Remove unnecessary fragment and add error handling

  1. The fragment wrapper is unnecessary as noted by static analysis.
  2. Consider adding error boundary protection for message generation.

Suggested improvements:

<ActivityBlockComponent icon={icon} activity={activity} ends={ends} customUserName={customUserName}>
- <>{message}</>
+ {message}
</ActivityBlockComponent>

Also, consider wrapping the message generation in a try-catch:

- const { message, customUserName } = messages(activity);
+ let message, customUserName;
+ try {
+   ({ message, customUserName } = messages(activity));
+ } catch (error) {
+   console.error('Failed to generate activity message:', error);
+   message = 'Activity details unavailable';
+   customUserName = undefined;
+ }
📝 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
<ActivityBlockComponent icon={icon} activity={activity} ends={ends} customUserName={customUserName}>
<>{message}</>
</ActivityBlockComponent>
<ActivityBlockComponent icon={icon} activity={activity} ends={ends} customUserName={customUserName}>
{message}
</ActivityBlockComponent>
🧰 Tools
🪛 Biome (1.9.4)

[error] 27-27: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

// hooks
const { isMobile } = usePlatformOS();

if (!activity) return <></>;
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

Consider adding error boundary or proper error handling

The early return with empty fragment when activity is null could be improved with proper error handling.

Consider adding error boundary or proper error state:

- if (!activity) return <></>;
+ if (!activity) {
+   console.warn("ActivityBlockComponent: No activity provided");
+   return null;
+ }
📝 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
if (!activity) return <></>;
if (!activity) {
console.warn("ActivityBlockComponent: No activity provided");
return null;
}

Comment on lines +32 to +35
<div className="absolute left-[13px] top-0 bottom-0 w-0.5 bg-custom-background-80" aria-hidden />
<div className="flex-shrink-0 ring-6 w-7 h-7 rounded-full overflow-hidden flex justify-center items-center z-[4] bg-custom-background-80 text-custom-text-200">
{icon ? icon : <Network className="w-3.5 h-3.5" />}
</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

Improve accessibility for activity timeline

The timeline implementation could benefit from better accessibility attributes.

Add proper ARIA attributes and semantic HTML:

- <div className="absolute left-[13px] top-0 bottom-0 w-0.5 bg-custom-background-80" aria-hidden />
+ <div 
+   className="absolute left-[13px] top-0 bottom-0 w-0.5 bg-custom-background-80" 
+   role="separator"
+   aria-label="Activity timeline"
+ />
📝 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="absolute left-[13px] top-0 bottom-0 w-0.5 bg-custom-background-80" aria-hidden />
<div className="flex-shrink-0 ring-6 w-7 h-7 rounded-full overflow-hidden flex justify-center items-center z-[4] bg-custom-background-80 text-custom-text-200">
{icon ? icon : <Network className="w-3.5 h-3.5" />}
</div>
<div
className="absolute left-[13px] top-0 bottom-0 w-0.5 bg-custom-background-80"
role="separator"
aria-label="Activity timeline"
/>
<div className="flex-shrink-0 ring-6 w-7 h-7 rounded-full overflow-hidden flex justify-center items-center z-[4] bg-custom-background-80 text-custom-text-200">
{icon ? icon : <Network className="w-3.5 h-3.5" />}
</div>

Comment on lines +68 to +279
) : (
<span className="font-medium text-custom-text-100">{activity.old_value || "Unknown cycle"}</span>
)}
</>
),
};
case "modules":
return {
message: (
<>
<span>
{verb} this project {verb === "removed" ? "from" : "to"} the module{" "}
</span>
<span className="font-medium text-custom-text-100">
{verb === "removed" ? oldValue : newValue || "Unknown module"}
</span>
</>
),
};
case "labels":
return {
message: (
<>
{verb} the label{" "}
<span className="font-medium text-custom-text-100">{newValue || oldValue || "Untitled label"}</span>
</>
),
};
case "inbox":
return {
message: <>{newValue ? "enabled" : "disabled"} inbox</>,
};
case "page":
return {
message: (
<>
{newValue ? "created" : "removed"} the project page{" "}
<span className="font-medium text-custom-text-100">{newValue || oldValue || "Untitled page"}</span>
</>
),
};
case "network":
return {
message: <>{newValue ? "enabled" : "disabled"} network access</>,
};
case "identifier":
return {
message: (
<>
updated project identifier to <span className="font-medium text-custom-text-100">{newValue || "none"}</span>
</>
),
};
case "timezone":
return {
message: (
<>
changed project timezone to{" "}
<span className="font-medium text-custom-text-100">{newValue || "default"}</span>
</>
),
};
case "module_view":
case "cycle_view":
case "issue_views_view":
case "page_view":
case "intake_view":
return {
message: (
<>
{getBooleanActionText(newValue)} {activityType.replace(/_view$/, "").replace(/_/g, " ")} view
</>
),
};
case "is_project_updates_enabled":
return {
message: <>{getBooleanActionText(newValue)} project updates</>,
};
case "is_epic_enabled":
return {
message: <>{getBooleanActionText(newValue)} epics</>,
};
case "is_workflow_enabled":
return {
message: <>{getBooleanActionText(newValue)} custom workflow</>,
};
case "is_time_tracking_enabled":
return {
message: <>{getBooleanActionText(newValue)} time tracking</>,
};
case "is_issue_type_enabled":
return {
message: <>{getBooleanActionText(newValue)} issue types</>,
};
default:
return {
message: `${verb} ${activityType.replace(/_/g, " ")} `,
};
}
};
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

Consider breaking down the message generation logic

The message generation function is quite large and handles many cases. This could be split into smaller, more manageable functions.

Consider breaking down the switch statement into separate handlers:

const messageHandlers = {
  priority: (activity: TProjectActivity) => ({
    message: (
      <>
        set the priority to <span className="font-medium text-custom-text-100">{activity.new_value || "none"}</span>
      </>
    ),
  }),
  // ... other handlers
};

export const messages = (activity: TProjectActivity) => {
  const handler = messageHandlers[activity.field];
  return handler ? handler(activity) : {
    message: `${activity.verb} ${activity.field.replace(/_/g, " ")} `,
  };
};

This would make the code more maintainable and easier to test.

Comment on lines +172 to +179
<a
href={`/${activity.workspace_detail?.slug}/projects/${activity.project}/cycles/${activity.new_identifier}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex font-medium text-custom-text-100"
>
{activity.new_value}
</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for navigation links

The cycle link implementation could benefit from proper error handling for missing slugs or identifiers.

Add proper checks:

{verb !== "removed" && activity.workspace_detail?.slug && activity.new_identifier ? (
  <a
    href={`/${activity.workspace_detail.slug}/projects/${activity.project}/cycles/${activity.new_identifier}`}
    target="_blank"
    rel="noopener noreferrer"
    className="inline-flex font-medium text-custom-text-100"
  >
    {activity.new_value}
  </a>
) : (
  <span className="font-medium text-custom-text-100">
    {activity.new_value || "Unknown cycle"}
  </span>
)}
📝 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
<a
href={`/${activity.workspace_detail?.slug}/projects/${activity.project}/cycles/${activity.new_identifier}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex font-medium text-custom-text-100"
>
{activity.new_value}
</a>
{verb !== "removed" && activity.workspace_detail?.slug && activity.new_identifier ? (
<a
href={`/${activity.workspace_detail.slug}/projects/${activity.project}/cycles/${activity.new_identifier}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex font-medium text-custom-text-100"
>
{activity.new_value}
</a>
) : (
<span className="font-medium text-custom-text-100">
{activity.new_value || "Unknown cycle"}
</span>
)}

@pushya22 pushya22 merged commit 1a715c9 into preview Dec 17, 2024
12 of 14 checks passed
@pushya22 pushya22 deleted the chore-project-activity-dynamic branch December 17, 2024 11:33
mathalav55 pushed a commit that referenced this pull request Dec 18, 2024
* chore: added common component for project activity

* fix: added enum

* fix: added enum for initiatives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants