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

[WEB-2601] improvement: add click to copy issue identifier on peek-overview and issue detail page. #5760

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Oct 7, 2024

Screen.Recording.2024-10-07.at.4.21.43.PM.mov

Summary by CodeRabbit

  • New Features
    • Introduced a click-to-copy feature for issue identifiers, enhancing user convenience.
    • Added a new IdentifierText component to manage the display and copying of issue identifiers.
  • Improvements
    • Streamlined the IssueIdentifier component for better structure and functionality.
    • Integrated toast notifications to confirm successful copying of identifiers.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes in this pull request focus on enhancing the IssueIdentifier component within the issue-identifier.tsx file. A new prop, enableClickToCopyIdentifier, is introduced to enable a click-to-copy feature for the issue identifier. Additionally, a new IdentifierText component is created to manage the rendering and copying functionality. The IssueIdentifier component is updated to utilize IdentifierText, and the click-to-copy feature is integrated into the IssueTypeSwitcher component.

Changes

File Path Change Summary
web/ce/components/issues/issue-details/issue-identifier.tsx - Added new prop enableClickToCopyIdentifier?: boolean to TIssueIdentifierBaseProps.
- Updated export for TIssueIdentifierProps.
- Introduced new component IdentifierText for rendering and copying functionality.
web/ce/components/issues/issue-details/issue-type-switcher.tsx - Updated IssueIdentifier return statement to include enableClickToCopyIdentifier.

Possibly related PRs

Suggested labels

✨feature, 🌟enhancement

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham

🐰 In the meadow, we hop with glee,
A click-to-copy feature, oh what a spree!
With identifiers now at our paw,
Copying them is a joyful flaw.
So let’s cheer for the code, so bright,
Making our tasks a pure delight! 🌼✨


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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7bb0400 and de46e1e.

📒 Files selected for processing (2)
  • web/ce/components/issues/issue-details/issue-identifier.tsx (4 hunks)
  • web/ce/components/issues/issue-details/issue-type-switcher.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
web/ce/components/issues/issue-details/issue-type-switcher.tsx (1)

23-23: LGTM! Verify IssueIdentifier implementation.

The addition of the enableClickToCopyIdentifier prop to the IssueIdentifier component aligns with the PR objective of adding a click-to-copy feature for the issue identifier. The implementation looks correct and maintains the existing functionality of the component.

To ensure the new prop is properly handled, please verify the implementation of the IssueIdentifier component. Run the following script to check its implementation:

web/ce/components/issues/issue-details/issue-identifier.tsx (6)

4-4: Modules are correctly imported

The imports setToast, TOAST_TYPE, and Tooltip are appropriately added and used within the code.


16-16: New optional prop added consistently

The addition of the optional prop enableClickToCopyIdentifier to TIssueIdentifierBaseProps maintains consistency with the existing props structure.


29-29: Exporting TIssueIdentifierProps for external use

By exporting TIssueIdentifierProps, you allow other modules to utilize this type, enhancing reusability.


31-35: Definition of TIdentifierTextProps is clear and concise

The new type TIdentifierTextProps is well-defined and follows naming conventions.


70-70: Default prop value assignment is appropriate

Setting a default value for enableClickToCopyIdentifier during destructuring ensures that the component behaves correctly even if the prop is undefined.


88-92: IdentifierText component integrated correctly

The IdentifierText component is properly utilized with the correct props, promoting code reusability and cleanliness.

Comment on lines +51 to +67
return (
<Tooltip tooltipContent="Click to copy" disabled={!enableClickToCopyIdentifier} position="top">
<span
className={cn(
"text-base font-medium text-custom-text-300",
{
"cursor-pointer": enableClickToCopyIdentifier,
},
textContainerClassName
)}
onClick={handleCopyIssueIdentifier}
>
{identifier}
</span>
</Tooltip>
);
};
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 for interactive elements

The <span> element is being used as an interactive element due to the onClick handler. For better accessibility, it should be focusable and operable via keyboard.

Consider adding role="button" and tabIndex={0} to make the element accessible:

 <span
   className={cn(
     "text-base font-medium text-custom-text-300",
     {
       "cursor-pointer": enableClickToCopyIdentifier,
     },
     textContainerClassName
   )}
+  role={enableClickToCopyIdentifier ? "button" : undefined}
+  tabIndex={enableClickToCopyIdentifier ? 0 : undefined}
   onClick={handleCopyIssueIdentifier}
+  onKeyPress={(e) => {
+    if (enableClickToCopyIdentifier && (e.key === 'Enter' || e.key === ' ')) {
+      handleCopyIssueIdentifier();
+    }
+  }}
 >

This change ensures users who navigate via keyboard can interact with the element.

📝 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 (
<Tooltip tooltipContent="Click to copy" disabled={!enableClickToCopyIdentifier} position="top">
<span
className={cn(
"text-base font-medium text-custom-text-300",
{
"cursor-pointer": enableClickToCopyIdentifier,
},
textContainerClassName
)}
onClick={handleCopyIssueIdentifier}
>
{identifier}
</span>
</Tooltip>
);
};
return (
<Tooltip tooltipContent="Click to copy" disabled={!enableClickToCopyIdentifier} position="top">
<span
className={cn(
"text-base font-medium text-custom-text-300",
{
"cursor-pointer": enableClickToCopyIdentifier,
},
textContainerClassName
)}
role={enableClickToCopyIdentifier ? "button" : undefined}
tabIndex={enableClickToCopyIdentifier ? 0 : undefined}
onClick={handleCopyIssueIdentifier}
onKeyPress={(e) => {
if (enableClickToCopyIdentifier && (e.key === 'Enter' || e.key === ' ')) {
handleCopyIssueIdentifier();
}
}}
>
{identifier}
</span>
</Tooltip>
);
};

Comment on lines +37 to +67
export const IdentifierText: React.FC<TIdentifierTextProps> = (props) => {
const { identifier, enableClickToCopyIdentifier = false, textContainerClassName } = props;
// handlers
const handleCopyIssueIdentifier = () => {
if (enableClickToCopyIdentifier) {
navigator.clipboard.writeText(identifier).then(() => {
setToast({
type: TOAST_TYPE.SUCCESS,
title: "Issue ID copied to clipboard",
});
});
}
};

return (
<Tooltip tooltipContent="Click to copy" disabled={!enableClickToCopyIdentifier} position="top">
<span
className={cn(
"text-base font-medium text-custom-text-300",
{
"cursor-pointer": enableClickToCopyIdentifier,
},
textContainerClassName
)}
onClick={handleCopyIssueIdentifier}
>
{identifier}
</span>
</Tooltip>
);
};
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 clipboard operations

The navigator.clipboard.writeText method may fail due to browser permissions or security settings, which could leave the user unaware of the failure.

Consider adding error handling to inform the user if copying to the clipboard fails.

Apply this diff to include error handling:

 const handleCopyIssueIdentifier = () => {
   if (enableClickToCopyIdentifier) {
-    navigator.clipboard.writeText(identifier).then(() => {
+    navigator.clipboard.writeText(identifier)
+      .then(() => {
         setToast({
           type: TOAST_TYPE.SUCCESS,
           title: "Issue ID copied to clipboard",
         });
-    });
+      })
+      .catch(() => {
+        setToast({
+          type: TOAST_TYPE.ERROR,
+          title: "Failed to copy Issue ID",
+        });
+      });
   }
 };
📝 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
export const IdentifierText: React.FC<TIdentifierTextProps> = (props) => {
const { identifier, enableClickToCopyIdentifier = false, textContainerClassName } = props;
// handlers
const handleCopyIssueIdentifier = () => {
if (enableClickToCopyIdentifier) {
navigator.clipboard.writeText(identifier).then(() => {
setToast({
type: TOAST_TYPE.SUCCESS,
title: "Issue ID copied to clipboard",
});
});
}
};
return (
<Tooltip tooltipContent="Click to copy" disabled={!enableClickToCopyIdentifier} position="top">
<span
className={cn(
"text-base font-medium text-custom-text-300",
{
"cursor-pointer": enableClickToCopyIdentifier,
},
textContainerClassName
)}
onClick={handleCopyIssueIdentifier}
>
{identifier}
</span>
</Tooltip>
);
};
export const IdentifierText: React.FC<TIdentifierTextProps> = (props) => {
const { identifier, enableClickToCopyIdentifier = false, textContainerClassName } = props;
// handlers
const handleCopyIssueIdentifier = () => {
if (enableClickToCopyIdentifier) {
navigator.clipboard.writeText(identifier)
.then(() => {
setToast({
type: TOAST_TYPE.SUCCESS,
title: "Issue ID copied to clipboard",
});
})
.catch(() => {
setToast({
type: TOAST_TYPE.ERROR,
title: "Failed to copy Issue ID",
});
});
}
};
return (
<Tooltip tooltipContent="Click to copy" disabled={!enableClickToCopyIdentifier} position="top">
<span
className={cn(
"text-base font-medium text-custom-text-300",
{
"cursor-pointer": enableClickToCopyIdentifier,
},
textContainerClassName
)}
onClick={handleCopyIssueIdentifier}
>
{identifier}
</span>
</Tooltip>
);
};

@sriramveeraghanta sriramveeraghanta added this to the v0.24.0 milestone Oct 8, 2024
type: TOAST_TYPE.SUCCESS,
title: "Issue ID copied to clipboard",
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please handle the error scenario with catch?

@pushya22 pushya22 merged commit 6e52f1b into preview Oct 8, 2024
14 of 15 checks passed
@pushya22 pushya22 deleted the improvement/issue-identifier branch October 8, 2024 13:13
sriramveeraghanta pushed a commit that referenced this pull request Oct 10, 2024
@sriramveeraghanta sriramveeraghanta modified the milestones: v0.24.0, v0.23.1 Oct 10, 2024
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