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 a copy button to the vote modal for a proposal link #86

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

chalabi2
Copy link
Collaborator

@chalabi2 chalabi2 commented Nov 26, 2024

fixes #26

Summary by CodeRabbit

  • New Features

    • Introduced a new button for sharing proposal links, enhancing accessibility on both desktop and mobile views.
    • Added functionality to manage clipboard copy status for sharing proposals.
  • Improvements

    • Enhanced layout for better display of proposal summaries.
    • Optimized space usage by adjusting the maximum height of the messages section.
    • Refined button state logic for improved interactivity based on proposal and user status.

Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The VoteDetailsModal component has been updated to enhance user experience and functionality. Key changes include the addition of new icons, a clipboard management feature for sharing proposal links, and layout adjustments for better visibility of the proposal summary. The component now includes a share button, improved button state logic based on user roles, and corrected function naming. These modifications aim to improve interactivity and accessibility within the modal.

Changes

File Path Change Summary
components/groups/modals/voteDetailsModal.tsx Added ShareIcon and CheckIcon, introduced copied state and copyProposalLink function, adjusted modal layout, added share button, refined button state logic, and corrected executeWithdrawl function spelling.

Assessment against linked issues

Objective Addressed Explanation
Share a proposal by sharing a URL (26)

Possibly related PRs

Suggested labels

render

Suggested reviewers

  • fmorency

Poem

In the modal where votes do dwell,
A shareable link casts a spell.
With icons bright and layout neat,
Proposals shared, oh what a treat!
Click to copy, watch it soar,
Voting made easy, who could ask for more? 🐰✨


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.

@chalabi2 chalabi2 mentioned this pull request Nov 26, 2024
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 89.74359% with 4 lines in your changes missing coverage. Please review.

Project coverage is 58.91%. Comparing base (263a5e1) to head (1b9efa4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
components/groups/modals/voteDetailsModal.tsx 89.74% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   58.85%   58.91%   +0.06%     
==========================================
  Files         145      145              
  Lines       14040    14071      +31     
==========================================
+ Hits         8263     8290      +27     
- Misses       5777     5781       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Outside diff range and nitpick comments (2)
components/groups/modals/voteDetailsModal.tsx (2)

424-429: Consider enhancing the URL construction

The URL construction looks good, but consider these improvements:

  1. Add error handling for clipboard operations
  2. Consider using environment variables for the base URL instead of window.location.origin
 const copyProposalLink = () => {
-  const url = `${window.location.origin}/groups?policyAddress=${proposal?.group_policy_address}&proposalId=${proposal?.id}`;
-  navigator.clipboard.writeText(url);
-  setCopied(true);
-  setTimeout(() => setCopied(false), 2000);
+  try {
+    const baseUrl = process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
+    const url = `${baseUrl}/groups?policyAddress=${proposal?.group_policy_address}&proposalId=${proposal?.id}`;
+    navigator.clipboard.writeText(url).then(() => {
+      setCopied(true);
+      setTimeout(() => setCopied(false), 2000);
+    }).catch(error => {
+      console.error('Failed to copy:', error);
+    });
+  } catch (error) {
+    console.error('Failed to copy:', error);
+  }
 };

517-531: Consider accessibility improvements for the share button

While the implementation is good, consider these accessibility enhancements:

 <button
   onClick={copyProposalLink}
+  aria-label={copied ? "Copied to clipboard" : "Share proposal"}
+  title="Copy proposal link"
   className="flex flex-row items-center gap-2 hover:bg-[#FFFFFFCC] dark:hover:bg-[#FFFFFF0F] p-2 rounded-full transition-colors duration-200"
 >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 263a5e1 and 1b9efa4.

📒 Files selected for processing (1)
  • components/groups/modals/voteDetailsModal.tsx (5 hunks)
🔇 Additional comments (4)
components/groups/modals/voteDetailsModal.tsx (4)

25-25: LGTM: Clean state management setup

The new imports and state management for the copy functionality are well-structured.

Also applies to: 422-423


483-490: LGTM: Well-structured summary section

The conditional rendering and styling of the summary section is clean and follows best practices.


493-493: Verify the impact of reduced message height

The maximum height of messages section has been reduced from 20rem to 17rem. Ensure this doesn't cut off important content.

✅ Verification successful

Height reduction appears safe based on content patterns

Based on the codebase analysis:

  • The messages section primarily displays message types and basic metadata
  • Similar scrollable containers in the codebase use varying heights:
    • Members list: 22.5rem
    • Message type dropdown: 12.5rem
    • Group details: 9.53rem
  • The message content is compact, showing type and basic fields in a card format
  • The container has overflow-y-auto, ensuring scrollability for edge cases

The reduction from 20rem to 17rem maintains a reasonable viewing area while keeping the modal compact, and scrolling is available when needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for message content patterns to assess typical length
ast-grep --pattern 'proposal?.messages?.map((message: any, index: number) => { $$$' 

Length of output: 85


Script:

#!/bin/bash
# Search for message mapping patterns with different syntax
rg -U "messages.*map.*=>" --type ts --type tsx -A 5

# Search for the container div with height specification
rg "max-h-\[.*rem\].*overflow-y-auto" --type ts --type tsx -A 2 -B 2

Length of output: 180


Script:

#!/bin/bash
# Search for message mapping patterns with different syntax, without file type restrictions
rg -U "messages.*map.*=>" -A 5

# Search for the container div with height specification
rg "max-h-\[.*rem\].*overflow-y-auto" -A 2 -B 2

Length of output: 9361


433-433: Verify modal's maximum height constraint

The modal's max-height is set to 80vh which might be too restrictive on smaller screens.

✅ Verification successful

80vh max-height is consistent with other modals and provides good UX

Looking at the codebase, the 80vh constraint in voteDetailsModal is appropriate because:

  • Other similar complex modals use 70vh (multiMfxMintModal and multiMfxBurnModal)
  • The modal has overflow-y-auto to ensure content is scrollable
  • The constraint prevents the modal from taking up the entire viewport while still providing ample space for content
  • The implementation includes responsive design with flex-col/flex-row layout
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar modals in the codebase to compare height constraints
rg -l "modal-box.*max-h-\[.*vh\]" --type tsx

Length of output: 74


Script:

#!/bin/bash
# Search for similar modals in the codebase with height constraints, accounting for different file extensions
rg -l "modal-box.*max-h-\[.*vh\]" --type ts --type jsx --type tsx --type js

Length of output: 105


Script:

#!/bin/bash
# Search for all modal-box usages to understand common patterns
rg "modal-box" --type ts --type jsx --type tsx --type js -A 2

Length of output: 89


Script:

#!/bin/bash
# Find all modal-related files to analyze modal implementations
fd -e tsx -e jsx -e ts -e js . | rg -i "modal"

Length of output: 1315


Script:

#!/bin/bash
# Search for modal-box class usage with simpler ripgrep command
rg "modal-box" -A 2

Length of output: 8498


Script:

#!/bin/bash
# Search specifically for max-height constraints in modal components
rg "max-h-\[.*vh\]" components/

Length of output: 1428


Script:

#!/bin/bash
# Look at the base modal component implementation
cat components/react/modal.tsx

Length of output: 8219

Comment on lines +591 to +605
<div className="flex-row gap-2 items-center flex md:hidden mb-2">
<button
onClick={copyProposalLink}
className="flex flex-row items-center gap-2 hover:bg-[#FFFFFFCC] dark:hover:bg-[#FFFFFF0F] p-2 rounded-full transition-colors duration-200"
>
{copied ? (
<CheckIcon className="w-4 h-4 text-green-500" />
) : (
<ShareIcon className="w-4 h-4" />
)}
<p className="text-sm font-light text-gray-500 dark:text-gray-400">
{copied ? 'Copied!' : 'Share this proposal'}
</p>
</button>
</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

DRY: Consider extracting share button component

The share button implementation is duplicated between desktop and mobile views. Consider extracting it into a reusable component.

+ const ShareButton = ({ onClick, copied }) => (
+   <button
+     onClick={onClick}
+     aria-label={copied ? "Copied to clipboard" : "Share proposal"}
+     title="Copy proposal link"
+     className="flex flex-row items-center gap-2 hover:bg-[#FFFFFFCC] dark:hover:bg-[#FFFFFF0F] p-2 rounded-full transition-colors duration-200"
+   >
+     {copied ? (
+       <CheckIcon className="w-4 h-4 text-green-500" />
+     ) : (
+       <ShareIcon className="w-4 h-4" />
+     )}
+     <p className="text-sm font-light text-gray-500 dark:text-gray-400">
+       {copied ? 'Copied!' : 'Share this proposal'}
+     </p>
+   </button>
+ );

// Then use it in both places:
- <button onClick={copyProposalLink} className="...">
+ <ShareButton onClick={copyProposalLink} copied={copied} />

Committable suggestion skipped: line range outside the PR's diff.

@fmorency fmorency merged commit e094b2a into main Nov 27, 2024
8 checks passed
@fmorency fmorency deleted the chalabi/proposal_link branch November 27, 2024 14:10
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.

Link to proposal
2 participants