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

Refactor/sdk and voting tab improvements #1894

Merged
merged 10 commits into from
Feb 17, 2025

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Feb 13, 2025

PR-Codex overview

This PR focuses on enhancing the handling of the "Refuse to Arbitrate" answer in the voting system, ensuring that its title and description are appropriately managed and displayed across various components.

Detailed summary

  • Added RefuseToArbitrateAnswer import in getVoteChoice.ts.
  • Updated getVoteChoice function to return a specific title for vote equal to 0.
  • Refactored populateTemplate.ts to include a new function findAndUpdateRTA for managing the Refuse to Arbitrate option.
  • Introduced StyledEnsureChain in Reveal.tsx and updated button layout.
  • Modified test case to check that only the title is overwritten for existing answers with id 0x0 or 0x00.
  • Enhanced OptionsContainer.tsx to include a tooltip for the Refuse to Arbitrate button and improved layout handling with flex properties.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Dispute answer options now display with enhanced, contextual descriptions and tooltips, including a refined label for the “Refuse to Arbitrate” choice.
    • Vote selection messaging is improved by providing a clearer, descriptive label for votes with no explicit choice.
  • Style

    • Updated layout and conditional display ensure controls align with chain context, offering a more intuitive and responsive interface.

@Harman-singh-waraich Harman-singh-waraich requested a review from a team as a code owner February 13, 2025 07:08
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

This pull request refines the handling of the "Refuse to Arbitrate" answer. In the SDK, the logic in the template population function now checks for an existing answer with ID 0 and creates a customized version before filtering and reinserting it. On the Web side, UI components in the voting flow are updated to conditionally render the refusal option with added tooltips and a new styled component for chain assurance. Additionally, the vote choice utility now returns a proper title when the vote equals zero.

Changes

Files Change Summary
kleros-sdk/src/dataMappings/utils/populateTemplate.ts
web/src/utils/getVoteChoice.ts
Updated dispute answer handling for "Refuse to Arbitrate": In populateTemplate.ts, an existing answer (ID 0) is detected to build a custom refusal answer, while in getVoteChoice.ts the function now returns the refusal title when the vote is 0.
web/src/pages/Cases/CaseDetails/Voting/Classic/OptionsContainer.tsx
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx
Enhanced UI for voting components: Introduced conditional rendering for the RTA button, wrapped option buttons with tooltips displaying answer descriptions, and added a new styled component (StyledEnsureChain) to wrap the chain assurance component. The Reveal component now nests its button within this new wrapper.

Possibly related PRs

  • Fix/use answer id in voting #1839: The changes in the main PR, specifically the refactoring of the populateTemplate function to utilize the RefuseToArbitrateAnswer, are directly related to the modifications in the retrieved PR, which introduces the RefuseToArbitrateAnswer constant and updates the AnswerSchema.
  • fix(web): verdict-answer-decoding #1884: The changes in the main PR, specifically the refactoring of the populateTemplate function to handle the "Refuse to Arbitrate" answer, are related to the modifications in the retrieved PR that also focus on handling answers, particularly in the context of the FinalDecision component's logic.
  • Fix: Ensure that SDK getDispute() returns the RTA/Invalid answer #1831: The changes in the main PR, specifically the refactoring of the populateTemplate function to handle the "Refuse to Arbitrate" answer, are directly related to the modifications in the retrieved PR, which also focuses on ensuring the inclusion of the "Refuse to Arbitrate" option in the getDispute function.

Suggested labels

Type: Enhancement :sparkles:, Package: SDK, Package: Web, Type: UX

Suggested reviewers

  • jaybuidl
  • alcercu

Poem

Hop along, I'm a coding rabbit on the run,
Tweaking dispute answers is so much fun.
I mold each RTA with care and style,
Adding tooltips that make users smile.
With new chains ensured in every line,
Our code hops ahead—simply divine! 🐇🌟


🪧 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 or @coderabbitai title 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

netlify bot commented Feb 13, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit eb9bbe0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/67af7948c8fe52000804be32
😎 Deploy Preview https://deploy-preview-1894--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit eb9bbe0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/67af7948c446a10008c5febf
😎 Deploy Preview https://deploy-preview-1894--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit eb9bbe0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/67af794816a90e0008eec2ef
😎 Deploy Preview https://deploy-preview-1894--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)

14-27: LGTM! Improved customization of "Refuse to Arbitrate" answer.

The changes correctly handle template-specific RTA descriptions while maintaining standard RTA properties.

Consider extracting the RTA ID comparison to a constant to improve maintainability:

+const RTA_ID = BigInt(0);
+
 const templateRTAAnswer = (dispute as DisputeDetails).answers.find(
-  (answer) => answer.id && BigInt(answer.id) === BigInt(0)
+  (answer) => answer.id && BigInt(answer.id) === RTA_ID
 );

 const CustomRTA: DisputeDetails["answers"][number] = {
   ...RefuseToArbitrateAnswer,
   description: templateRTAAnswer?.description ?? RefuseToArbitrateAnswer.description,
 };

 (dispute as DisputeDetails).answers = [
   CustomRTA,
-  ...((dispute as DisputeDetails).answers.filter((answer) => answer.id && BigInt(answer.id) !== BigInt(0)) || []),
+  ...((dispute as DisputeDetails).answers.filter((answer) => answer.id && BigInt(answer.id) !== RTA_ID) || []),
 ];
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 489ad78 and 1b152ac.

📒 Files selected for processing (4)
  • kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1 hunks)
  • web/src/pages/Cases/CaseDetails/Voting/Classic/OptionsContainer.tsx (5 hunks)
  • web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (3 hunks)
  • web/src/utils/getVoteChoice.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: contracts-testing
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (8)
web/src/utils/getVoteChoice.ts (1)

3-3: LGTM! Improved handling of "Refuse to Arbitrate" vote.

The changes correctly handle the special case when vote is 0, providing a proper title from RefuseToArbitrateAnswer instead of a generic "Answer 0x0" string.

Also applies to: 12-12

web/src/pages/Cases/CaseDetails/Voting/Classic/OptionsContainer.tsx (4)

1-1: LGTM! Clean imports and styled component.

The imports are organized well, and the StyledEnsureChain component correctly centers its content.

Also applies to: 7-7, 45-47


61-65: LGTM! Clear RTA visibility logic.

The memoized showRTA value efficiently determines when to show the RTA button based on the presence of an RTA answer in the dispute details.


85-102: LGTM! Enhanced options rendering with tooltips.

The changes improve the user experience by:

  • Safely handling undefined answers
  • Adding tooltips to show answer descriptions
  • Wrapping options in StyledEnsureChain for consistent styling

104-116: LGTM! Clean RTA button implementation.

The RTA button is correctly:

  • Conditionally rendered based on showRTA
  • Styled consistently with other options
  • Wrapped in EnsureChain for chain validation
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (3)

39-41: LGTM! Consider verifying the spacing.

The styled component follows the project's patterns. Note that its margin (8px) is smaller than StyledButton's margin (16px), which might affect the vertical rhythm.


114-122:

❓ Verification inconclusive

LGTM! Verify chain assurance behavior.

The button is correctly wrapped with the chain assurance component while preserving all existing functionality.


🏁 Script executed:

#!/bin/bash
# Description: Verify EnsureChain component's chain assurance behavior

# Search for EnsureChain implementation to understand its behavior
fd -e ts -e tsx 'EnsureChain' components/ -x ast-grep --pattern $'export const EnsureChain = ({ children }) => {
  $$$
}'

Length of output: 219


#!/bin/bash
# Searching the whole repository for the StyledEnsureChain definition to verify its implementation.
rg "StyledEnsureChain" .

LGTM! Manual verification of chain assurance behavior is advised.

The button is correctly wrapped with the chain assurance component while preserving all existing functionality. However, our automated search for the implementation of StyledEnsureChain was inconclusive. Please manually review the StyledEnsureChain definition and confirm that it implements the intended chain assurance logic.


24-24:

❓ Verification inconclusive

Verify the EnsureChain component export.

Let's ensure the component exists and is exported correctly.


🏁 Script executed:

#!/bin/bash
# Description: Verify EnsureChain component exists and is exported correctly

# Search for EnsureChain component definition and export
fd -e ts -e tsx 'EnsureChain' components/ -x ast-grep --pattern $'export { EnsureChain }'

Length of output: 187


Action: Verify the EnsureChain Export and File Location

The import statement in web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx appears correct. However, our initial automated script couldn’t verify the export due to a misconfigured search path. Please manually confirm that the EnsureChain component is defined and exported in its appropriate file (likely within web/src/components/EnsureChain.tsx or web/src/components/EnsureChain.ts).

  • Ensure the file exists in the repository under the correct alias-resolved directory.
  • Verify that the component is properly exported (e.g., using a named export like export { EnsureChain } or an equivalent syntax).

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 13, 2025
Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit eb9bbe0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/67af794856ab0700088e7e52
😎 Deploy Preview https://deploy-preview-1894--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 13, 2025
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: 0

🧹 Nitpick comments (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)

17-33: Good implementation of past feedback with some minor improvements possible.

The function efficiently handles RTA customization using findIndex as suggested. Consider these minor improvements:

-const findAndUpdateRTA = (dispute: DisputeDetails) => {
-  const templateRTAIndex = (dispute as DisputeDetails).answers.findIndex(
+const customizeRefuseToArbitrateAnswer = (dispute: DisputeDetails) => {
+  const templateRTAIndex = dispute.answers.findIndex(
     (answer) => answer.id && BigInt(answer.id) === BigInt(0)
   );
  1. Remove the unnecessary type assertion since dispute is already typed as DisputeDetails.
  2. Consider a more descriptive function name that better explains its purpose.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b709cb2 and 14496f2.

📒 Files selected for processing (1)
  • kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: SonarCloud
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
kleros-sdk/src/dataMappings/utils/populateTemplate.ts (1)

5-15: LGTM! Good refactoring.

The extraction of RTA handling into a separate function improves modularity and readability while maintaining the same functionality.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 14, 2025
Copy link

codeclimate bot commented Feb 14, 2025

Code Climate has analyzed commit eb9bbe0 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

View more on Code Climate.

Copy link

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

🧹 Nitpick comments (1)
web/src/pages/Cases/CaseDetails/Voting/Classic/OptionsContainer.tsx (1)

86-103: Consider simplifying the rendering logic.

While the current implementation works well, consider these improvements:

  1. Use early return pattern instead of null for better readability
  2. Simplify the map function by moving the condition to a filter
-        {isUndefined(disputeDetails?.answers) ? null : (
+        {!disputeDetails?.answers ? null : (
           <StyledEnsureChain>
             <OptionsContainer>
-              {disputeDetails?.answers?.map((answer: Answer) => {
-                return BigInt(answer.id) !== BigInt(0) ? (
+              {disputeDetails.answers
+                .filter((answer) => BigInt(answer.id) !== BigInt(0))
+                .map((answer: Answer) => (
                   <Tooltip text={answer.description} key={answer.title}>
                     <Button
                       text={answer.title}
                       disabled={isSending}
                       isLoading={chosenOption === BigInt(answer.id)}
                       onClick={() => onClick(BigInt(answer.id))}
                     />
                   </Tooltip>
-                ) : null;
-              })}
+                ))}
             </OptionsContainer>
           </StyledEnsureChain>
         )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 14496f2 and eb9bbe0.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/Voting/Classic/OptionsContainer.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
🔇 Additional comments (3)
web/src/pages/Cases/CaseDetails/Voting/Classic/OptionsContainer.tsx (3)

1-1: LGTM! Clean imports and styling changes.

The new imports and styling changes improve the component's structure and layout.

Also applies to: 7-7, 16-16, 21-22, 46-48


49-61: LGTM! Well-structured state management.

The component's interface and state management are clean and follow React best practices.


62-66: LGTM! Clean RTA handling logic.

The memoized updatedRTA value efficiently handles the RTA case with proper fallback.

Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

@alcercu alcercu merged commit 5241361 into dev Feb 17, 2025
25 of 26 checks passed
@alcercu alcercu deleted the refactor/sdk-and-voting-tab-improvements branch February 17, 2025 11:54
@coderabbitai coderabbitai bot mentioned this pull request Feb 17, 2025
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