Skip to content

Conversation

@utkuakyuz
Copy link
Owner

Resolves #24

Overview
This PR adds two new statistical features to the VirtualDiffViewer component:

  • Line Count Statistics: Display added, removed, and modified line counts
  • Object Count Statistics: Count added, removed, and modified objects when using compare-key method

Line Count Statistics

  • showLineCount prop (default: false)
  • Displays format: +5 added lines, -3 removed lines, ~2 modified lines, 10 total line changes
  • Shows "No line changes" when total is 0

Object Count Statistics

  • showObjectCountStats prop (default: false)
  • Only works with arrayDiffMethod: "compare-key"
  • Displays format: +2 added objects, -1 removed objects, ~3 modified objects, 6 total object changes
  • Shows "No object changes" when total is 0

Docs

  • Updated README with comprehensive feature documentation
  • Added usage examples and requirements
  • Included props table with new properties
  • Added utility function documentation
  • Condensed README for better readability

Demo Updates

  • Added tab-based navigation (Main Viewer / Object Count Example)
  • Automatic config switching between tabs
  • Example using json3.json and json4.json with "oid" compareKey
  • Bidirectional config management (preserves user settings)

Bug Fixes

  • Added guards in get-inline-syntax-highlight.ts and row-renderer-grid.tsx
  • Prevented undefined text parameter errors

Exports

  • Exported calculateObjectCountStats utility function for external use

Usage Example

<VirtualDiffViewer
  oldValue={oldData}
  newValue={newData}
  showLineCount={true}
  showObjectCountStats={true}
  differOptions={{
    arrayDiffMethod: "compare-key",
    compareKey: "id"
  }}
/>

- Introduced a new configuration option to show line counts in the diff viewer.
- Added a LineCountDisplay component to visualize added, removed, and modified lines.
- Updated the VirtualizedDiffViewer to calculate and display line count statistics based on the diff data.
- Enhanced the Sidebar component to include a checkbox for toggling the line count display.
- Updated styles for the new line count display feature.
@netlify
Copy link

netlify bot commented Oct 25, 2025

Deploy Preview for virtual-react-json-diff ready!

Name Link
🔨 Latest commit 81bcf78
🔍 Latest deploy log https://app.netlify.com/projects/virtual-react-json-diff/deploys/68fce497d11a0100083e516e
😎 Deploy Preview https://deploy-preview-25--virtual-react-json-diff.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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @utkuakyuz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the VirtualDiffViewer component by integrating new statistical features: line count and object count displays. These additions provide users with more detailed insights into the changes between two JSON structures. Alongside these core features, the PR includes robust documentation updates, an improved demo experience, and critical bug fixes to ensure stability and usability.

Highlights

  • Line Count Statistics: Introduced a new "showLineCount" prop to display added, removed, and modified line counts in the VirtualDiffViewer.
  • Object Count Statistics: Added a "showObjectCountStats" prop to count added, removed, and modified objects, specifically when using the "compare-key" array diff method.
  • Documentation Updates: The README has been comprehensively updated with new feature documentation, usage examples, prop tables, and utility function details.
  • Demo Enhancements: The demo application now features tab-based navigation, automatic configuration switching, and bidirectional config management to showcase the new features.
  • Bug Fixes: Implemented guards in "get-inline-syntax-highlight.ts" and "row-renderer-grid.tsx" to prevent errors from undefined text parameters.
  • Utility Export: The "calculateObjectCountStats" utility function is now exported for external use.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces line and object count statistics, which is a great new feature. The implementation is mostly solid, with new components for displaying stats and utility functions for calculations. I've left a few comments with suggestions for improvement:

  • Refactoring duplicated CSS to improve maintainability.
  • Simplifying some conditional rendering logic in the main viewer component.
  • Improving the robustness of the object count calculation logic.
  • Avoiding direct console logging from within the library.

Overall, these are great additions. Addressing the feedback will make the new features more robust and maintainable.

Comment on lines +127 to +143
const newArr = newArraysWithKey.find((newArr, newIndex) => {
try {
const newSignature = `${newIndex}-${newArr.length}-${JSON.stringify(newArr.map((item: any) => item[compareKey]).sort())}`;
if (processedNewArrays.has(newSignature))
return false;

const oldKeys = oldArr.map((item: any) => item[compareKey]).sort();
const newKeys = newArr.map((item: any) => item[compareKey]).sort();
const commonKeys = oldKeys.filter((key: any) => newKeys.includes(key));

return commonKeys.length > 0; // Arrays share at least one key
}
catch (error) {
console.warn("Error processing new array:", error);
return false;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current array matching logic, which finds the first new array that shares at least one key with an old array (commonKeys.length > 0), could be fragile. If an old array could potentially match multiple new arrays, this logic will arbitrarily pick the first one it finds. This may not be the best match (e.g., the one with the most overlap), which could lead to inaccurate object change counts.

Consider a more robust matching strategy, perhaps by calculating an "overlap score" (e.g., based on the number of common keys) and choosing the pair with the highest score. This would make the statistics more reliable, especially for complex diffs.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Single array matching is OK for now, I already implemented for single array use. If a user request for multiple arrays, we can think about it.

Copy link
Owner Author

Choose a reason for hiding this comment

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

#26 open issue

Comment on lines +46 to +153
.line-count-display {
display: flex;
gap: 12px;
margin-top: 5px;
align-items: center;
font-size: 11px;
color: #f8f8f2;
margin-left: auto;
justify-content: space-between;
}

.line-count-item-sub-holder {
display: flex;
align-items: center;
gap: 4px;
}

.line-count-item {
padding: 2px 6px;
border-radius: 3px;
font-weight: 500;
white-space: nowrap;
}

.line-count-item.added {
background: rgba(100, 182, 67, 0.2);
color: #a5ff99;
border: 1px solid rgba(100, 182, 67, 0.3);
}

.line-count-item.removed {
background: rgba(160, 128, 100, 0.2);
color: #ffaa99;
border: 1px solid rgba(160, 128, 100, 0.3);
}

.line-count-item.modified {
background: rgba(182, 180, 67, 0.2);
color: #ecff99;
border: 1px solid rgba(182, 180, 67, 0.3);
}

.line-count-item.total {
background: rgba(69, 96, 248, 0.2);
color: #4560f8;
border: 1px solid rgba(69, 96, 248, 0.3);
}

.line-count-item.no-changes {
background: rgba(248, 248, 242, 0.1);
color: #f8f8f2;
border: 1px solid rgba(248, 248, 242, 0.2);
}

/* OBJECT COUNT DISPLAY */
.object-count-display {
display: flex;
gap: 12px;
margin-top: 5px;
align-items: center;
font-size: 11px;
color: #f8f8f2;
margin-left: auto;
justify-content: space-between;
}

.object-count-item-sub-holder {
display: flex;
align-items: center;
gap: 4px;
}

.object-count-item {
padding: 2px 6px;
border-radius: 3px;
font-weight: 500;
white-space: nowrap;
}

.object-count-item.added {
background: rgba(100, 182, 67, 0.2);
color: #a5ff99;
border: 1px solid rgba(100, 182, 67, 0.3);
}

.object-count-item.removed {
background: rgba(160, 128, 100, 0.2);
color: #ffaa99;
border: 1px solid rgba(160, 128, 100, 0.3);
}

.object-count-item.modified {
background: rgba(182, 180, 67, 0.2);
color: #ecff99;
border: 1px solid rgba(182, 180, 67, 0.3);
}

.object-count-item.total {
background: rgba(69, 96, 248, 0.2);
color: #4560f8;
border: 1px solid rgba(69, 96, 248, 0.3);
}

.object-count-item.no-changes {
background: rgba(248, 248, 242, 0.1);
color: #f8f8f2;
border: 1px solid rgba(248, 248, 242, 0.2);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There is significant CSS duplication between the styles for .line-count-display and .object-count-display. The rules for ...-display, ...-item-sub-holder, ...-item, and the modifier classes (.added, .removed, etc.) are identical.

To improve maintainability and reduce code size, you could consolidate these into a set of common classes. For example:

/* Common base class */
.stats-display {
  display: flex;
  gap: 12px;
  margin-top: 5px;
  /* ... other common styles */
}

.stats-item {
  /* ... common item styles */
}

.stats-item.added {
  /* ... added styles */
}
/* etc. */

Then, in your React components, you can use these classes like <div class="stats-display line-count-display">.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Later please, all can be refactored, I have plans for it.

@utkuakyuz utkuakyuz merged commit 60a95f5 into main Oct 25, 2025
4 checks passed
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.

Display number of modifications on viewer

1 participant