Skip to content

Conversation

@tractorss
Copy link
Contributor

@tractorss tractorss commented Aug 14, 2025

PR-Codex overview

This PR focuses on refactoring the useTimeline function in the Timeline.tsx file to streamline the handling of timeline items based on the current period index instead of the current item index, improving clarity and functionality.

Detailed summary

  • Changed useTimeline to accept only currentPeriodIndex.
  • Updated the calculation of getSubitems to use currentPeriodIndex instead of currentItemIndex.
  • Simplified the titles array to always include "Commit" unless hidden votes are present.
  • Refactored the return statement of titles to use flatMap for cleaner handling of conditional items.

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

Summary by CodeRabbit

  • Bug Fixes

    • Timeline now correctly identifies and highlights the current period for countdowns and past/current states.
    • “Commit” period appears only when applicable, avoiding incorrect or duplicate phases.
    • Period titles are consistent across cases; “Executed” remains without subitems.
  • Refactor

    • Streamlined period handling and title determination for more predictable Timeline behavior and fewer UI inconsistencies.

@tractorss tractorss requested a review from a team as a code owner August 14, 2025 11:15
@netlify
Copy link

netlify bot commented Aug 14, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 8d0edf4
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/689de246c690230008f8dc11
😎 Deploy Preview https://deploy-preview-2087--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 project configuration.

@netlify
Copy link

netlify bot commented Aug 14, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 8d0edf4
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/689de2468875df00082a15ae
😎 Deploy Preview https://deploy-preview-2087--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 project configuration.

@netlify
Copy link

netlify bot commented Aug 14, 2025

Deploy Preview for kleros-v2-university failed. Why did it fail? →

Name Link
🔨 Latest commit 8d0edf4
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/689de24628ac2300080b8830

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Refactors Timeline.tsx to call useTimeline(dispute, currentPeriodIndex) and update the hook to accept only currentPeriodIndex; standardizes titles, switches countdown and period-state checks to currentPeriodIndex, and conditionally includes the "Commit" period via filtering when hiddenVotes is true.

Changes

Cohort / File(s) Summary
Timeline hook and rendering refactor
web/src/pages/Cases/CaseDetails/Timeline.tsx
useTimeline signature changed to (dispute, currentPeriodIndex). Titles are fixed to ["Evidence","Commit","Voting","Appeal","Executed"]. Period state checks and countdown logic use currentPeriodIndex. "Commit" period is conditionally included by filtering when hiddenVotes is true; last "Executed" item keeps no subitems.

Sequence Diagram(s)

sequenceDiagram
  participant UI as Timeline Component
  participant Hook as useTimeline
  participant Data as Dispute

  UI->>Hook: useTimeline(dispute, currentPeriodIndex)
  Hook->>Data: read periods, hiddenVotes
  Hook-->>UI: computed titles + visible periods (filter Commit if !hiddenVotes)
  UI->>UI: render periods and countdowns based on currentPeriodIndex
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • Refactor/appeal tab #1863: Modifies Timeline rendering and period/currentPeriodIndex handling; overlaps in commit/appeal period logic.

Suggested labels

Package: Web

Suggested reviewers

  • alcercu

Poem

A hop through time, each period in line,
I nibble the code—commit only when fine.
Evidence to Voting, Appeals in sight,
Executed at dawn, carrots by night.
With indices true, I bound and I rhyme,
A timeline well-tended by a tidy hare in time. 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d1910ca and 8d0edf4.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/Timeline.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Cases/CaseDetails/Timeline.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • 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-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/timeline-bug-fix

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@netlify
Copy link

netlify bot commented Aug 14, 2025

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

Name Link
🔨 Latest commit 8d0edf4
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/689de2468c1a130008b71161
😎 Deploy Preview https://deploy-preview-2087--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 project 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: 3

🧹 Nitpick comments (2)
web/src/pages/Cases/CaseDetails/Timeline.tsx (2)

85-91: Nit: fix typo in comment (“loosing” → “losing”)

Minor spelling fix to keep comments clean.

Apply this diff:

-    // only show if loosing option was funded and winner needs funding, else no action is needed from user
+    // only show if losing option was funded and winner needs funding, else no action is needed from user

106-110: Optional: lift titles to a module-level constant

titles is static and recreated on every render. Moving it to a module-level constant avoids re-allocations and clarifies intent.

You can add this at the top-level (outside the hook):

const TIMELINE_TITLES = ["Evidence", "Commit", "Voting", "Appeal", "Executed"] as const;

Then inside the hook:

-  const titles = ["Evidence", "Commit", "Voting", "Appeal", "Executed"];
+  const titles = TIMELINE_TITLES;
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3d211cc and d1910ca.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/Timeline.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/src/pages/Cases/CaseDetails/Timeline.tsx (2)
web/src/utils/date.ts (1)
  • secondsToDayHourMinute (10-16)
web/src/components/StyledSkeleton.tsx (1)
  • StyledSkeleton (8-10)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • 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: Redirect rules - kleros-v2-neo
  • 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: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
web/src/pages/Cases/CaseDetails/Timeline.tsx (1)

71-71: LGTM: Hook usage aligns with simplified signature

Switching to useTimeline(dispute, currentPeriodIndex) matches the new hook contract and removes the previous coupling to currentItemIndex. This simplifies the data flow and avoids ambiguity between item and period indices.

Comment on lines 117 to 129
const getSubitems = (index: number): string[] | React.ReactNode[] => {
if (typeof countdown !== "undefined" && dispute) {
if (index === titles.length - 1) {
return [];
} else if (index === currentItemIndex && countdown === 0) {
} else if (index === currentPeriodIndex && countdown === 0) {
return ["Time's up!"];
} else if (index < currentItemIndex) {
} else if (index < currentPeriodIndex) {
return [];
} else if (index === currentItemIndex) {
} else if (index === currentPeriodIndex) {
return [secondsToDayHourMinute(countdown)];
} else {
return [secondsToDayHourMinute(dispute?.court.timesPerPeriod[index])];
}
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

Fix type mismatch and potential NaN in future-period subitems

secondsToDayHourMinute expects a number, but dispute?.court.timesPerPeriod[index] is typed as string | undefined. This can produce type errors and NaN at runtime when values are undefined or non-numeric. Parse the value and provide a safe default.

Apply this diff:

-      } else {
-        return [secondsToDayHourMinute(dispute?.court.timesPerPeriod[index])];
-      }
+      } else {
+        const raw = dispute?.court.timesPerPeriod?.[index];
+        const periodSeconds = Number(raw ?? 0);
+        return [secondsToDayHourMinute(periodSeconds)];
+      }
📝 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
const getSubitems = (index: number): string[] | React.ReactNode[] => {
if (typeof countdown !== "undefined" && dispute) {
if (index === titles.length - 1) {
return [];
} else if (index === currentItemIndex && countdown === 0) {
} else if (index === currentPeriodIndex && countdown === 0) {
return ["Time's up!"];
} else if (index < currentItemIndex) {
} else if (index < currentPeriodIndex) {
return [];
} else if (index === currentItemIndex) {
} else if (index === currentPeriodIndex) {
return [secondsToDayHourMinute(countdown)];
} else {
return [secondsToDayHourMinute(dispute?.court.timesPerPeriod[index])];
}
} else if (index === currentPeriodIndex) {
return [secondsToDayHourMinute(countdown)];
} else {
- return [secondsToDayHourMinute(dispute?.court.timesPerPeriod[index])];
+ const raw = dispute?.court.timesPerPeriod?.[index];
+ const periodSeconds = Number(raw ?? 0);
+ return [secondsToDayHourMinute(periodSeconds)];
}
🤖 Prompt for AI Agents
In web/src/pages/Cases/CaseDetails/Timeline.tsx around lines 117 to 129,
secondsToDayHourMinute is being passed dispute?.court.timesPerPeriod[index]
which is typed string | undefined causing type errors and possible NaN; convert
the value to a number safely and provide a fallback before calling
secondsToDayHourMinute (e.g. const secs =
Number(dispute?.court.timesPerPeriod[index]); if (!Number.isFinite(secs) ||
isNaN(secs)) use 0 or another sensible default) and pass secs to
secondsToDayHourMinute so the function always receives a valid number.

Comment on lines +121 to 127
} else if (index === currentPeriodIndex && countdown === 0) {
return ["Time's up!"];
} else if (index < currentItemIndex) {
} else if (index < currentPeriodIndex) {
return [];
} else if (index === currentItemIndex) {
} else if (index === currentPeriodIndex) {
return [secondsToDayHourMinute(countdown)];
} else {
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

Clamp “Time’s up!” condition to countdown <= 0 to avoid negative durations

If useCountdown ever returns negative values after the deadline, the UI could show negative durations instead of “Time’s up!”. Using <= 0 is safer and avoids transient negative subitems.

Apply this diff:

-      } else if (index === currentPeriodIndex && countdown === 0) {
+      } else if (index === currentPeriodIndex && countdown <= 0) {
         return ["Time's up!"];
📝 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
} else if (index === currentPeriodIndex && countdown === 0) {
return ["Time's up!"];
} else if (index < currentItemIndex) {
} else if (index < currentPeriodIndex) {
return [];
} else if (index === currentItemIndex) {
} else if (index === currentPeriodIndex) {
return [secondsToDayHourMinute(countdown)];
} else {
} else if (index === currentPeriodIndex && countdown <= 0) {
return ["Time's up!"];
} else if (index < currentPeriodIndex) {
return [];
} else if (index === currentPeriodIndex) {
return [secondsToDayHourMinute(countdown)];
} else {
🤖 Prompt for AI Agents
In web/src/pages/Cases/CaseDetails/Timeline.tsx around lines 121 to 127, the
condition that shows "Time's up!" checks countdown === 0 which can allow
negative durations to render; change the condition to use countdown <= 0 so any
non-positive countdown displays "Time's up!" instead of a negative time string,
keeping the rest of the branch order intact.

@sonarqubecloud
Copy link

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

@jaybuidl jaybuidl merged commit bd4e169 into dev Aug 20, 2025
20 of 24 checks passed
@jaybuidl jaybuidl deleted the fix/timeline-bug-fix branch August 20, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants