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: Show different statuses on graph #156

Merged
merged 3 commits into from
Oct 22, 2024
Merged

Conversation

adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Oct 22, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced Job History Chart with color-coded status representation for better visual clarity.
    • Dynamic tooltips now provide detailed information on job statuses when hovering over chart elements.
  • Bug Fixes

    • Improved data aggregation logic for job counts by status, ensuring accurate representation in the UI.
  • Documentation

    • Added comments and reorganized query components for improved clarity in the underlying logic.

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces significant changes to the JobHistoryChart.tsx component and the job.ts API router. In the chart component, a new color mapping for job statuses is implemented, enhancing the visual representation by allowing stacked bars for different job statuses. The tooltip functionality is also improved to display detailed information dynamically. In the API router, the dailyCount query is restructured to aggregate job counts by status, utilizing subqueries and inner joins for enhanced data retrieval. These modifications improve both the front-end display and back-end data handling for job histories.

Changes

File Path Change Summary
apps/webservice/src/app/[workspaceSlug]/systems/JobHistoryChart.tsx - Added statusColors object for job status color mapping.
- Modified chart data structure to include statusCounts.
- Updated tooltip for dynamic content.
- Changed bar rendering to support stacked representation.
packages/api/src/router/job.ts - Enhanced dailyCount query to aggregate job counts by status using a subquery.
- Updated releaseJobTriggerQuery with inner joins to access job statuses.
- Adjusted method signatures for various queries to include new logic.

Possibly related PRs

  • fix: Job distribution graph #152: The changes in this PR involve updating the API query method for job triggers, which is directly related to the modifications made in the JobHistoryChart.tsx component of the main PR, where the API query for job triggers was also updated.
  • fix: Optimize job policy query #153: Although this PR focuses on optimizing job policy queries, it involves changes to the releaseJobTriggers query logic, which may indirectly relate to the overall job data handling in the main PR, particularly in how job statuses are processed.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c070f06 and 53dd5d8.

📒 Files selected for processing (2)
  • apps/webservice/src/app/[workspaceSlug]/systems/JobHistoryChart.tsx (3 hunks)
  • packages/api/src/router/job.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (9)
apps/webservice/src/app/[workspaceSlug]/systems/JobHistoryChart.tsx (6)

7-7: LGTM: Import statements updated correctly.

The new imports for Tailwind CSS colors and ChartTooltip are appropriate for the changes made in this file.

Also applies to: 15-15


21-45: LGTM: New constants improve code clarity and address previous feedback.

The statusColors and statusLabels constants enhance code readability and maintainability. They also effectively address the previous review comment about improving tooltip readability with user-friendly status labels.


58-63: Chart data preparation aligns with backend changes, but consider key normalization.

The chartData preparation now correctly uses statusCounts from dailyCounts.data, aligning with the backend changes. However, the previous suggestion to normalize the keys to lowercase hasn't been implemented, which might cause issues with the dataKey used in the Bar components.

Consider normalizing the keys as suggested previously:

 const date = new Date(d).toISOString();
-return { date, ...dayData };
+return { date, ...Object.fromEntries(
+  Object.entries(dayData).map(([key, value]) => [key.toLowerCase(), value])
+) };

This ensures consistency between the data keys and the dataKey used in the chart rendering.


71-74: Total jobs calculation updated, but consider safeguarding against invalid values.

The total jobs calculation now correctly uses totalCount from dailyCounts.data, aligning with the new data structure. However, the previous suggestion to safeguard against invalid totalCount values hasn't been implemented.

Consider implementing the safeguard as suggested previously:

 const totalJobs = dailyCounts.data?.reduce(
-  (acc, c) => acc + Number(c.totalCount),
+  (acc, c) => acc + (Number(c.totalCount) || 0),
   0,
 );

This ensures that any invalid totalCount values default to 0, maintaining an accurate total.


140-167: LGTM: Improved chart rendering and tooltip, but consider adding name prop to Bar components.

The refactored tooltip content and dynamic generation of Bar components significantly enhance the chart's visual representation and interactivity. The tooltip now provides detailed information for each status, and the stacked bar representation improves data visualization.

Consider implementing the name prop in the Bar components as suggested previously:

 {Object.entries(statusColors).map(([status, color]) => (
   <Bar
     key={status}
     dataKey={status.toLowerCase()}
     stackId="jobs"
     fill={color}
+    name={statusLabels[status as JobStatus]}
   />
 ))}

This ensures that the tooltip displays the correct status labels for each bar segment.

Also applies to: 169-176


Line range hint 1-183: Overall, significant improvements to JobHistoryChart component.

The changes in this file greatly enhance the data visualization and user interaction of the JobHistoryChart component. The new color mapping, improved tooltip, and dynamic bar generation align well with the backend modifications and provide a more informative and visually appealing chart.

To further improve the component, consider implementing the remaining suggestions:

  1. Normalize the keys in chartData preparation to ensure consistency with dataKey in Bar components.
  2. Safeguard against invalid totalCount values in the total jobs calculation.
  3. Add the name prop to Bar components for accurate tooltip labels.

These final touches will enhance the robustness and user experience of the component.

packages/api/src/router/job.ts (3)

Line range hint 29-30: LGTM: Inner join with job table added

The addition of the inner join with the job table is a good change. It ensures that only job triggers with associated jobs are returned, which is consistent with the new requirements for aggregating job statuses.


Line range hint 196-201: LGTM: Additional joins for environment policy data

The new joins with environmentPolicy and environmentPolicyReleaseWindow tables are well-implemented. These additions provide the necessary data for calculating the rolloutDate in the result mapping, enhancing the functionality of the byReleaseId query.


88-118: LGTM: Improved job status aggregation

The new implementation of the dailyCount query is well-structured and provides the necessary data for the front-end changes. The use of a subquery to aggregate job counts by status, followed by the main query to create a JSON object of status counts, is an efficient approach.

Some notable improvements:

  1. The use of date_trunc with timezone conversion ensures consistent date grouping across different timezones.
  2. The jsonb_object_agg function efficiently creates a JSON object of status counts.

However, for large datasets, this query might face performance issues. To optimize performance, consider adding an index on the createdAt column of the releaseJobTrigger table and the status column of the job table. Run the following script to check if these indexes exist:

If these indexes don't exist, consider adding them to improve query performance.


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.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e6e9666 and c070f06.

📒 Files selected for processing (2)
  • apps/webservice/src/app/[workspaceSlug]/systems/JobHistoryChart.tsx (3 hunks)
  • packages/api/src/router/job.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
apps/webservice/src/app/[workspaceSlug]/systems/JobHistoryChart.tsx (1)

21-32: Ensure all JobStatus values are included in statusColors mapping

To prevent any missing or unintended behaviors in the chart rendering, please verify that all possible JobStatus enum values are included in the statusColors mapping. Missing statuses might lead to bars not displaying or errors during rendering.

packages/api/src/router/job.ts (2)

88-105: Aggregation subquery is well-constructed

The subquery correctly aggregates the count of jobs per status and date. The use of joins and groupings is appropriate and aligns with the objective of enhancing data retrieval for job statuses.


107-117: Ensure all job statuses are included in statusCounts

Verify that the statusCounts JSON object includes all possible JobStatus values, even those with zero counts. This will prevent potential issues in the front-end display where certain statuses might be expected but absent.

Comment on lines +156 to +163
{Object.entries(statusColors).map(([status, color]) => (
<Bar
key={status}
dataKey={status.toLowerCase()}
stackId="jobs"
fill={color}
/>
))}
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

Specify name prop in Bar components for accurate tooltips

To ensure the tooltip displays the correct status labels, include the name prop in each Bar component, using the statusLabels mapping.

Modify the Bar components as follows:

 {Object.entries(statusColors).map(([status, color]) => (
   <Bar
     key={status}
     dataKey={status.toLowerCase()}
     stackId="jobs"
     fill={color}
+    name={statusLabels[status.toLowerCase()] || status}
   />
 ))}

This provides the tooltip with the appropriate label for each status segment.

Committable suggestion was skipped due to low confidence.

packages/api/src/router/job.ts Show resolved Hide resolved
packages/api/src/router/job.ts Outdated Show resolved Hide resolved
@adityachoudhari26 adityachoudhari26 merged commit de9f31f into main Oct 22, 2024
6 checks passed
@adityachoudhari26 adityachoudhari26 deleted the pretty-graph-eng-229 branch October 22, 2024 00:46
@coderabbitai coderabbitai bot mentioned this pull request Oct 22, 2024
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.

1 participant