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 staked pnk per court chart, slightly modify skeleton size, … #1707

Merged
merged 5 commits into from
Oct 11, 2024

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Oct 10, 2024

...abstract BarChart component

closes #1695

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new BarChart component for visualizing data with a bar chart.
    • Added a StakedPNKByCourtsChart component for displaying staked PNK data.
    • Enhanced the Chart component to support a new chart option for "Staked PNK per court."
  • Bug Fixes

    • Streamlined the CasesByCourtsChart component by removing complex configurations and delegating chart logic to the new BarChart component.
  • Style

    • Updated the Header component with a dynamic margin-bottom style for improved layout consistency.

PR-Codex overview

This PR introduces a new chart component for displaying staked PNK data per court, enhances the existing charts, and refactors the code for better organization and readability.

Detailed summary

  • Added StakedPNKByCourtsChart component for displaying staked PNK data.
  • Integrated StakedPNKByCourtsChart in Chart component.
  • Introduced new chart option for "Staked PNK per court".
  • Refactored CasesByCourtsChart to use BarChart component.
  • Updated styling and layout adjustments in various components.

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

Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The changes introduce a new BarChart component for visualizing data using a bar chart with the react-chartjs-2 library. The CasesByCourtsChart component is refactored to utilize this new component, simplifying its internal logic. Additionally, a new StakedPNKByCourtsChart component is created, which also uses the BarChart for rendering. The Chart component is updated to support a new chart option for "Staked PNK per court," integrating the new StakedPNKByCourtsChart component.

Changes

File Path Change Summary
web/src/pages/Home/CourtOverview/BarChart.tsx Introduced BarChart component; added interfaces IBarChartData and IBarChartProps.
web/src/pages/Home/CourtOverview/CasesByCourtsChart.tsx Refactored CasesByCourtsChart to use BarChart, simplified data handling, added CasesByCourtsChartData type.
web/src/pages/Home/CourtOverview/Chart.tsx Updated to support new chart option "Staked PNK per court"; added processedStakedPNKData function.
web/src/pages/Home/CourtOverview/StakedPNKByCourtsChart.tsx Introduced StakedPNKByCourtsChart component; added StakedPNKByCourtsChartData type and interface.
web/src/pages/Home/CourtOverview/Header.tsx Added margin-bottom style to StyledHeader using responsiveSize; cleaned up import statements.

Assessment against linked issues

Objective Addressed Explanation
Extra chart on the home page: Staked PNK per court (#1695)

Possibly related PRs

  • feat(web): extra statistic on homepage #1671: The CasesByCourtsChart component now imports the BarChart component and the IBarChartData interface from the BarChart.tsx file, indicating a direct relationship with the changes made in the main PR where the BarChart component and IBarChartData interface were introduced.

Suggested labels

Type: Feature🗿

Suggested reviewers

  • Harman-singh-waraich
  • alcercu

Poem

In the land of charts so bright,
A BarChart hops into sight.
Cases and stakes, all in a row,
With colors and labels, watch them glow!
From data to visuals, a joyful dance,
In the world of code, we take a chance! 🐇📊


🪧 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 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 Oct 10, 2024

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

Name Link
🔨 Latest commit c0b259e
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/67090676d1db8600088d911c

Copy link

netlify bot commented Oct 10, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit c0b259e
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/67090676b86bc40008eb1c22
😎 Deploy Preview https://deploy-preview-1707--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

netlify bot commented Oct 10, 2024

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

Name Link
🔨 Latest commit c0b259e
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/67090676cb306a00080b7699

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

🧹 Outside diff range and nitpick comments (2)
web/src/pages/Home/CourtOverview/StakedPNKByCourtsChart.tsx (1)

10-20: LGTM: Component implementation is clean and focused.

The StakedPNKByCourtsChart component is well-implemented. It correctly uses the defined interface, transforms the input data appropriately, and renders the BarChart component with the required props.

Consider adding a prop for customizing the chart (e.g., colors, title) to make the component more flexible:

 interface IStakedPNKByCourtsChart {
   data: StakedPNKByCourtsChartData;
+  chartOptions?: {
+    colors?: string[];
+    title?: string;
+  };
 }

-const StakedPNKByCourtsChart: React.FC<IStakedPNKByCourtsChart> = ({ data }) => {
+const StakedPNKByCourtsChart: React.FC<IStakedPNKByCourtsChart> = ({ data, chartOptions }) => {
   const chartData: IBarChartData = {
     labels: data.labels,
     data: data.stakes,
     total: data.totalStake,
+    ...chartOptions,
   };

   return <BarChart chartData={chartData} />;
 };

This change would allow users of this component to customize the chart appearance if needed.

web/src/pages/Home/CourtOverview/Chart.tsx (1)

103-114: Consistent rendering and addition of new chart case

  • The new case "stakedPNKPerCourt" is correctly added to the ChartComponent, rendering StakedPNKByCourtsChart when processedStakedPNKData is available.
  • The StyledSkeleton height is consistently set to 234 across all cases, ensuring uniformity in the UI.

Consider defining a constant for the skeleton height to enhance maintainability and readability.

Apply this suggestion to define a constant:

+const SKELETON_HEIGHT = 234;

Then, replace hardcoded height values:

-<StyledSkeleton height={234} />
+<StyledSkeleton height={SKELETON_HEIGHT} />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1f37740 and 395c8d8.

📒 Files selected for processing (4)
  • web/src/pages/Home/CourtOverview/BarChart.tsx (1 hunks)
  • web/src/pages/Home/CourtOverview/CasesByCourtsChart.tsx (2 hunks)
  • web/src/pages/Home/CourtOverview/Chart.tsx (3 hunks)
  • web/src/pages/Home/CourtOverview/StakedPNKByCourtsChart.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (10)
web/src/pages/Home/CourtOverview/StakedPNKByCourtsChart.tsx (3)

1-2: LGTM: Imports are appropriate.

The imports are correct and necessary for the component being created. React is imported for the JSX syntax, and BarChart along with its interface are imported from a local file.


4-4: LGTM: Type definition is well-structured.

The StakedPNKByCourtsChartData type is well-defined and appropriately represents the data structure for staked PNK by courts. The naming is clear, and the export allows for reuse in other components if needed.


6-8: LGTM: Interface is well-defined.

The IStakedPNKByCourtsChart interface is correctly defined. It uses the previously created type and follows naming conventions. The interface is concise and focused, which contributes to good maintainability.

web/src/pages/Home/CourtOverview/CasesByCourtsChart.tsx (3)

1-2: Good use of the shared BarChart component

Importing and reusing the BarChart component enhances code reuse and simplifies the CasesByCourtsChart component.


11-14: chartData mapping aligns with IBarChartData

The construction of chartData correctly maps the properties from data to match the IBarChartData interface, ensuring accurate data is passed to the BarChart component.


17-17: Component correctly renders BarChart with chartData

The return statement properly renders the BarChart component, passing the constructed chartData as a prop.

web/src/pages/Home/CourtOverview/Chart.tsx (4)

15-15: Import statement for StakedPNKByCourtsChart looks good

The import of StakedPNKByCourtsChart and its associated data type StakedPNKByCourtsChartData is correct.


32-32: Added 'Staked PNK per court' to chart options

The new chart option { text: "Staked PNK per court", value: "stakedPNKPerCourt" } is appropriately added to CHART_OPTIONS.


86-96: Processing data for 'Staked PNK per court' is correct

The processedStakedPNKData is correctly computed by reducing courtsChartData. The labels, stakes, and totalStake are accurately calculated using the provided data.


114-114: Updated dependencies in useMemo hook

Including processedStakedPNKData in the dependencies array ensures that the memoized ChartComponent updates when the data changes.

web/src/pages/Home/CourtOverview/BarChart.tsx Outdated Show resolved Hide resolved
web/src/pages/Home/CourtOverview/BarChart.tsx Show resolved Hide resolved
web/src/pages/Home/CourtOverview/BarChart.tsx Outdated Show resolved Hide resolved
web/src/pages/Home/CourtOverview/BarChart.tsx Outdated Show resolved Hide resolved
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 395c8d8 and 8ad5c9f.

📒 Files selected for processing (1)
  • web/src/pages/Home/CourtOverview/BarChart.tsx (1 hunks)
🧰 Additional context used

web/src/pages/Home/CourtOverview/BarChart.tsx Show resolved Hide resolved
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8ad5c9f and a8314bb.

📒 Files selected for processing (1)
  • web/src/pages/Home/CourtOverview/BarChart.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
web/src/pages/Home/CourtOverview/BarChart.tsx (3)

27-35: Well-defined interfaces for improved type safety

The interfaces IBarChartData and IBarChartProps are well-structured and provide good type safety for the component. They clearly define the expected shape of the data and props, which will help prevent potential runtime errors and improve code maintainability.


48-94: Well-configured chart options with consistent styling

The chart options are comprehensively defined and well-structured. The use of theme values for styling ensures consistency with the overall application design. The configuration for scales, tooltips, and data labels is detailed and should provide a good user experience.

However, please note the previous comment about redundant tooltips configuration, which should be addressed.


96-117: Clean and efficient render function

The render function is concise and effectively utilizes the configured options and data. The use of the ChartDataLabels plugin is appropriate for displaying data labels on the chart. The component is correctly exported as the default export, making it easy to import and use in other parts of the application.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 11, 2024
Copy link

codeclimate bot commented Oct 11, 2024

Code Climate has analyzed commit c0b259e 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

@Harman-singh-waraich Harman-singh-waraich left a comment

Choose a reason for hiding this comment

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

lgtm!

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

🧹 Outside diff range and nitpick comments (1)
web/src/pages/Home/CourtOverview/Header.tsx (1)

17-17: LGTM: Responsive margin addition improves layout.

The addition of a responsive margin-bottom to the StyledHeader component is a good improvement. It enhances the layout and spacing of the header, especially on larger screens.

Consider adding a comment explaining the purpose of this margin, e.g.:

margin-bottom: ${responsiveSize(16, 0)}; // Adds space below header on larger screens

This would help future developers understand the intent behind this styling decision.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 07f9f1f and c0b259e.

📒 Files selected for processing (1)
  • web/src/pages/Home/CourtOverview/Header.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
web/src/pages/Home/CourtOverview/Header.tsx (2)

4-5: LGTM: Import statement reorganization.

Moving the responsiveSize import statement to the top of the file improves code organization and readability. This change doesn't affect the functionality and follows good coding practices.


Line range hint 1-37: Overall assessment: Changes improve code quality and layout.

The modifications to this file, including the import statement reorganization and the addition of responsive margin, contribute positively to the codebase. These changes align well with the PR objectives of modifying skeleton sizes and improving overall layout. The use of responsiveSize for the margin ensures consistent appearance across different screen sizes, which is a good practice for responsive design.

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 added this pull request to the merge queue Oct 11, 2024
Merged via the queue into dev with commit 3d5ce0e Oct 11, 2024
13 of 24 checks passed
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.

Extra chart on the home page: Staked PNK per court
3 participants