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 vote type to governance comment section #1544

Merged
merged 5 commits into from
Sep 10, 2024

Conversation

AMIRKHANEF
Copy link
Member

@AMIRKHANEF AMIRKHANEF commented Sep 9, 2024

Displaying commenters vote type!

address #1495

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced comment functionality with support for replies and voting decisions.
    • Introduced a new VoteType component for displaying voting information.
    • Comments now sort in descending order, showcasing the most recent first.
    • Added new localization entries for voting actions: "Voted Aye", "Voted Nay", and "Voted Abstain".
  • Bug Fixes

    • Improved handling of the address prop to prevent undefined values in the CommentView component.
  • Style

    • Improved code organization and formatting for better readability.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

The pull request introduces enhancements to the governance comment section, including restructuring the Comment component's props, improving sorting logic for comments, and adding new properties to interfaces. It also introduces new translation entries for voting actions. These changes aim to enhance the functionality and organization of the comment system within the governance framework.

Changes

File Change Summary
packages/extension-polkagate/src/fullscreen/governance/post/*.tsx Restructured Comment component props, improved reaction rendering, modified comment sorting, and added new properties to interfaces.
packages/extension/public/locales/en/translation.json Added new translation entries for voting actions.

Assessment against linked issues

Objective Addressed Explanation
Shows date wrong for some comments (#1495) The changes do not address date formatting issues.
Can show each commenter vote type which helps reader (#1495)

Poem

🐇 In the land of governance, comments bloom,
With votes now clear, dispelling the gloom.
Reactions are swift, and sorting's a breeze,
A hop and a skip, with newfound ease!
Let's celebrate changes, both bright and bold,
In the rabbit's realm, new stories unfold! 🌼

Tip

Announcements
  • The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
  • We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 18f00c2 and a93c713.

Files selected for processing (1)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0056b8f and 31afa5a.

Files selected for processing (5)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comments.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/post/Replies.tsx (1 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/utils/types.tsx (2 hunks)
  • packages/extension/public/locales/en/translation.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/extension-polkagate/src/fullscreen/governance/post/Replies.tsx
Additional comments not posted (5)
packages/extension-polkagate/src/fullscreen/governance/post/Comments.tsx (2)

56-56: Improved handling of the address prop.

Passing address ?? '' ensures that the CommentView component receives a non-undefined string, enhancing the robustness of the component's rendering logic.


31-31: Sorting logic updated to descending order.

The change in sorting logic ensures that the most recent comments are displayed first, enhancing user experience by making recent discussions more accessible.

Run the following script to verify the sorting logic:

Verification successful

Sorting logic correctly implemented.

The sorting logic for comments in Comments.tsx is correctly implemented to display the most recent comments first, enhancing the user experience by prioritizing recent discussions.

  • The sortedComments variable sorts comments by created_at in descending order.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the sorting logic for comments.

# Test: Check if the sorting logic correctly sorts comments in descending order.
rg --type typescript -A 5 $'sortedComments'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the sorting logic for comments.

# Test: Check if the sorting logic correctly sorts comments in descending order.
rg 'sortedComments' --glob '*.ts' --glob '*.tsx' -A 5

Length of output: 1790

packages/extension-polkagate/src/fullscreen/governance/utils/types.tsx (2)

13-13: Added reply_reactions to the Reply interface.

This addition enhances the Reply interface by allowing it to track reactions, supporting the new feature of displaying reactions in the governance comment section.


45-45: Added votes property to the CommentType interface.

This addition allows the CommentType interface to track voting decisions, directly supporting the new feature of displaying the vote type of each commenter in the governance comment section.

packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx (1)

Line range hint 18-122: Enhancements to the Comment component.

The introduction of the CommentProps interface and the VoteType component, along with the use of memoization for reactions, significantly enhances the functionality and performance of the Comment component. These changes align well with the PR's objectives to display the vote type and optimize the governance comment section.

@@ -1384,5 +1384,8 @@
"Help?": "",
"Ignore": "",
"Rewards Destination": "",
"{{accountName}} has been successfully removed!": ""
"{{accountName}} has been successfully removed!": "",
"Voted Aye": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Translation entry for "Voted Aye" is missing its translation value.

The key "Voted Aye" has been added to the translation file but lacks an actual translation value. This should be populated to reflect the intended translation in English or marked clearly if it's intended to be filled later.

"{{accountName}} has been successfully removed!": ""
"{{accountName}} has been successfully removed!": "",
"Voted Aye": "",
"Voted Nay": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Translation entry for "Voted Nay" is missing its translation value.

Similar to the previous entry, the key "Voted Nay" is present without a corresponding translation value. Ensure that the translation values are provided to complete the localization support.

"{{accountName}} has been successfully removed!": "",
"Voted Aye": "",
"Voted Nay": "",
"Voted Abstain": ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Translation entry for "Voted Abstain" is missing its translation value.

The key "Voted Abstain" also lacks a translation value. It's important to provide these values to ensure the application's localization features are fully functional and clear to end-users.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 31afa5a and d3773a6.

Files selected for processing (3)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comments.tsx (4 hunks)
  • packages/extension-polkagate/src/hooks/useReferendum.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • packages/extension-polkagate/src/hooks/useReferendum.ts
Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx
Additional comments not posted (1)
packages/extension-polkagate/src/fullscreen/governance/post/Comments.tsx (1)

36-36: Sorting logic change is effective and aligns with PR objectives.

The updated sorting logic correctly prioritizes the most recent comments by sorting them in descending order based on their creation date. This change enhances the user experience by displaying the most relevant comments first.

However, consider handling potential exceptions or errors in date parsing, as new Date() could fail if created_at is not a valid date string.

Run the following script to verify the date parsing:

@@ -54,7 +58,7 @@ export default function Comments ({ address, referendum }: { address: string | u
<Grid container item xs={12}>
{sortedComments?.map((comment, index) => (
<Grid container key={index} sx={{ borderBottom: index !== sortedComments.length - 1 ? `0.01px solid ${theme.palette.text.disabled}` : undefined }}>
<CommentView address={address} comment={comment} />
<CommentView address={address ?? ''} comment={comment} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhanced robustness in handling the address prop.

The update to provide a fallback value ('') for the address prop when it is undefined is a good practice. This ensures that the CommentView component always receives a string value, preventing potential runtime errors.

Consider documenting this behavior in the CommentView component's propTypes or TypeScript definitions to make it clear that address can expect a string and not undefined.

@Nick-1979 Nick-1979 changed the title fix: update governance comment section feat: add vote type to governance comment section Sep 10, 2024
@Nick-1979 Nick-1979 merged commit 3b4f884 into PolkaGate:main Sep 10, 2024
14 checks passed
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.

2 participants