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(admin): ability to diff chart revisions #3460

Merged
merged 3 commits into from
Apr 9, 2024

Conversation

marcelgerber
Copy link
Member

@marcelgerber marcelgerber commented Apr 8, 2024

Just a tiny thing I was working on, and which is gonna be super useful:

CleanShot 2024-04-08 at 18 14 02

Copy link

coderabbitai bot commented Apr 8, 2024

Walkthrough

The recent updates focus on improving data handling and user interaction in an admin site's chart editing and history comparison features. The changes include transitioning the config property to a JSON type for better flexibility across components, enhancing data manipulation capabilities. Moreover, a new comparison tool has been introduced to facilitate easy visualization of differences in chart configurations and enable users to revert changes efficiently, enhancing the overall editing experience.

Changes

Files Change Summary
adminSiteClient/ChartEditor.ts, adminSiteClient/apiRouter.ts Transitioned config property from string to Json type. Added Json import from @ourworldindata/utils.
adminSiteClient/EditorHistoryTab.tsx Added compareModal feature for comparing configurations, including UI elements and logic updates.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

@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

Actionable comments outside the diff hunks (1)
adminSiteServer/apiRouter.ts (1)

Line range hint 233-1123: The saveGrapher function is complex and handles multiple responsibilities. Consider refactoring it into smaller, more focused functions to improve modularity and maintainability. This approach would enhance readability and make the code easier to manage and understand.

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a49f0e0 and dc69d8e.
Files selected for processing (3)
  • adminSiteClient/ChartEditor.ts (2 hunks)
  • adminSiteClient/EditorHistoryTab.tsx (3 hunks)
  • adminSiteServer/apiRouter.ts (3 hunks)
Additional comments not posted (11)
adminSiteClient/EditorHistoryTab.tsx (4)

17-17: Introduce isCompareModalOpen observable for modal visibility control.


28-62: Implement a computed property compareModal for rendering the comparison modal.

  • Ensure that the modal's visibility is tied to isCompareModalOpen.
  • Validate the use of ReactDiffViewer for displaying differences, including proper configuration for comparing JSON values.
  • Check the modal styling and behavior, ensuring it provides a good user experience.

76-82: Add a button to trigger the comparison modal.

  • Confirm the button's functionality and its conditional rendering based on the presence of a previousLog.
  • Assess the UI design and placement within the component.

144-144: Pass previousLog for comparison in LogRenderer.

  • Verify the logic for determining the previousLog and its implications for the comparison feature.
  • Ensure that this approach correctly handles edge cases, such as the first log entry.
adminSiteClient/ChartEditor.ts (2)

16-16: Import Json type from @ourworldindata/utils.

  • Confirm the import's correctness and its usage across the file.

43-43: Change config property type from string to Json in the Log interface.

  • Evaluate the impact of this change on data handling and manipulation.
  • Ensure compatibility with existing code and data structures.
adminSiteServer/apiRouter.ts (5)

54-60: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-57]

The imports are well-organized and relevant to the file's functionality. Good job maintaining a clean and understandable imports section.


204-213: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [186-210]

Consider adding a parameter to the getLogsByChartId function to control the number of logs returned. This enhancement would increase the function's flexibility and adaptability to different use cases.

- async function getLogsByChartId(knex: db.KnexReadonlyTransaction, chartId: number): Promise<{...}[]> {
+ async function getLogsByChartId(knex: db.KnexReadonlyTransaction, chartId: number, limit: number = 50): Promise<{...}[]> {
...
-        LIMIT 50`,
+        LIMIT ?`,
        [chartId, limit]

204-213: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-1123]

Ensure that all user inputs are properly sanitized and validated across the application, especially before being used in database queries or other sensitive operations. This practice is crucial for maintaining the security and integrity of the application.


204-213: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-1123]

Review database interactions for optimization opportunities, particularly in functions with multiple database operations or hardcoded limits. Consider the performance implications of API design and strive for efficient database queries and reduced API response times.


204-213: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-1123]

Consider refactoring the code for better organization and readability. Separating concerns and breaking down large functions into smaller, more focused ones would enhance maintainability. Additionally, ensure consistent and comprehensive error handling across all API route handlers to improve the robustness of the application.

@marcelgerber marcelgerber force-pushed the admin-compare-revisions branch from 40cffb4 to 528583c Compare April 9, 2024 08:34
@marcelgerber marcelgerber merged commit abbc4e5 into master Apr 9, 2024
15 of 17 checks passed
@marcelgerber marcelgerber deleted the admin-compare-revisions branch April 9, 2024 08:35
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