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

fix: update referendum comments #1548

Merged
merged 15 commits into from
Sep 28, 2024
Merged

Conversation

AMIRKHANEF
Copy link
Member

@AMIRKHANEF AMIRKHANEF commented Sep 10, 2024

Close: #1495

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced an "Edited" tag for modified comments, enhancing user context.
    • Improved handling of comments related to referendums with new data structures and fetching methods.
  • Enhancements

    • Enhanced user reaction handling and display of comment metadata for better clarity.
    • Updated comment rendering logic to differentiate based on comment sources.
  • Bug Fixes

    • Corrected conditional rendering for comment sources within the comment display logic.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

This pull request introduces enhancements to the comment handling system in the governance module. A new EditedTag component is added to indicate if comments have been modified after creation. The Comment component is updated to include this new tag and adjust the rendering of usernames and source labels. Additionally, new interfaces and a function are introduced in the helpers file to support fetching and structuring referendum comments and votes, improving the overall data handling in the governance context.

Changes

File Path Change Summary
packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx Added EditedTag component to indicate edited comments. Updated logic for displaying usernames and the source label based on the noSource prop. Refactored commenterAddress handling to improve address formatting.
packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts Introduced new interfaces for comment and vote structures. Added getReferendumCommentsSS function to fetch and format comments and votes for referendums, handling errors and structuring data effectively.
packages/extension-polkagate/src/hooks/useReferendum.ts Added state management for comments associated with referendums and updated logic to merge comments from different sources, ensuring replies are prioritized correctly. Integrated fetching of comments alongside referendum data.

Assessment against linked issues

Objective Addressed Explanation
Shows date wrong for some comments (#1495) The changes do not address the date display issue.
Can show each commenter vote type which helps reader (#1495) The new functionality allows for better handling of voting information through structured comment data.

Possibly related PRs

Suggested reviewers

  • AMIRKHANEF

🐰 In the meadow, comments bloom,
With tags of "Edited," they lift the gloom.
Sources now dance, both SS and PA,
In governance chats, they frolic and play.
Fetching and merging, a seamless delight,
Hopping through updates, all feels just right! 🌼


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.

@AMIRKHANEF AMIRKHANEF reopened this Sep 10, 2024
@Nick-1979
Copy link
Member

Still some Unknown NANs

@AMIRKHANEF
Copy link
Member Author

Still some Unknown NANs

Resolved as much as possible.

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

Outside diff range and nitpick comments (1)
packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx (1)

152-160: Consider renaming the noSource prop for clarity.

The noSource prop determines whether the comment is from Polkassembly or SubSquare. The name noSource might be misleading, as it suggests the absence of a source.

Consider renaming it to isPolkassembly or isFromPolkassembly to enhance readability and make the code self-explanatory.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fb847cb and 01cd1df.

Files selected for processing (2)
  • packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts (3 hunks)
Additional comments not posted (3)
packages/extension-polkagate/src/fullscreen/governance/post/Comment.tsx (3)

169-170: Successfully integrated VoteType component to display voter decisions.

The inclusion of the VoteType component correctly displays each commenter's vote type, fulfilling one of the key objectives outlined in the PR. This enhancement provides readers with valuable context about the voting stance of each commenter.


175-179: Consistent display of source labels based on comment origin.

The conditional rendering of 'Polkassembly' or 'SubSquare' labels accurately reflects the source of each comment, improving transparency for users.


183-183: Proper placement of the EditedTag component.

The EditedTag is appropriately rendered, ensuring that edited comments are clearly indicated to users, which enhances trust and transparency.

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

🧹 Outside diff range and nitpick comments (2)
packages/extension-polkagate/src/hooks/useReferendum.ts (2)

47-47: Initialize State Variable with Explicit Default

The state variable referendumCommentsSS is initialized without an explicit default value. To prevent potential undefined behavior, consider initializing it with null or an empty array, depending on how it's used later in the code.

Suggested change:

-const [referendumCommentsSS, setReferendumCommentsSS] = useState<CommentType[] | null>();
+const [referendumCommentsSS, setReferendumCommentsSS] = useState<CommentType[] | null>(null);

386-389: Handle Errors When Fetching Comments

Currently, errors when fetching comments using getReferendumCommentsSS are logged but not handled gracefully:

getReferendumCommentsSS(chainName, id).then((res) => {
  setReferendumCommentsSS(res);
}).catch(console.error);

Consider providing user feedback or setting an appropriate state to handle the error in the UI.

Suggested change:

 getReferendumCommentsSS(chainName, id).then((res) => {
   setReferendumCommentsSS(res);
-}).catch(console.error);
+}).catch((error) => {
+  console.error(error);
+  // Optionally set an error state or fallback
+  setReferendumCommentsSS(null);
+});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e726039 and f1dafe4.

📒 Files selected for processing (2)
  • packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts (11 hunks)
  • packages/extension-polkagate/src/hooks/useReferendum.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/fullscreen/governance/utils/helpers.ts
🔇 Additional comments (3)
packages/extension-polkagate/src/hooks/useReferendum.ts (3)

11-11: Verify Type Definitions and Imports

The import statement adds CommentType, Referendum, ReferendumHistory, ReferendumPA, ReferendumSb, and TopMenu from '../fullscreen/governance/utils/types'. Ensure that these types are correctly defined and exported in the specified path to prevent any type errors or import issues.


17-17: Confirm Availability of Imported Helper Functions

The import now includes getReferendumCommentsSS and isFinished from '../fullscreen/governance/utils/helpers'. Please verify that these functions are properly implemented and exported in the helpers module.


326-326: Ensure Accurate Timestamp Handling

When setting the created_at property, multiple sources are considered:

created_at: referendumPA?.created_at || (referendumSb?.created_block_timestamp && referendumSb.created_block_timestamp * 1000) || createdAtOC,

Ensure that the timestamps from different sources are in the same format (e.g., milliseconds since the epoch) to prevent discrepancies in date display. Also, verify that createdAtOC is correctly calculated.

@Nick-1979 Nick-1979 merged commit da77ba5 into PolkaGate:main Sep 28, 2024
8 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 28, 2024
## [0.13.1](v0.13.0...v0.13.1) (2024-09-28)

### Bug Fixes

* update referendum comments ([#1548](#1548)) ([da77ba5](da77ba5))
@AMIRKHANEF AMIRKHANEF deleted the GovernanceComment branch September 28, 2024 12:58
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.

comment section in governance issues
2 participants