-
Notifications
You must be signed in to change notification settings - Fork 1
feat: support objects nested in arrays in i18n content #146
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
Conversation
🦋 Changeset detectedLatest commit: 651a9e0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #146 +/- ##
==========================================
+ Coverage 98.10% 98.15% +0.04%
==========================================
Files 17 17
Lines 475 487 +12
Branches 112 117 +5
==========================================
+ Hits 466 478 +12
Misses 9 9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the i18n content handling to support objects nested within arrays, expanding the capability of the getAllUniqueKeys
function to traverse more complex data structures.
- Enhanced
getAllUniqueKeys
function to recursively process arrays and nested objects within arrays - Added comprehensive test coverage for objects nested in arrays and arrays within arrays scenarios
- Updated test fixtures and snapshots to include gallery content with nested i18n structure
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
libs/astro-utils-i18n/src/utils/collection.ts | Enhanced getAllUniqueKeys function to handle arrays and nested objects within arrays |
libs/astro-utils-i18n/test/utils/collection.spec.ts | Added test cases for objects nested in arrays and arrays within arrays |
libs/astro-utils-i18n/test/utils/snapshots/collection.spec.ts.snap | Updated snapshots for new test cases |
libs/astro-loader-i18n/test/fixtures/collections.ts | Added gallery fixture with nested i18n objects in arrays |
libs/astro-loader-i18n/test/loaders/snapshots/i18n-file-loader.spec.ts.snap | Updated snapshots with gallery test data |
.changeset/plain-worms-find.md | Added changeset documenting the new feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
// Wrap array in an object to reuse the function and ignore its key | ||
getAllUniqueKeys({ array: item }, keys, true); |
Copilot
AI
Oct 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded 'array' key used as a wrapper creates an implicit dependency and reduces code clarity. Consider using a more descriptive constant or a different approach that doesn't require wrapping arrays in artificial objects.
// Wrap array in an object to reuse the function and ignore its key | |
getAllUniqueKeys({ array: item }, keys, true); | |
// Recurse into arrays within arrays | |
getAllUniqueKeys(item, keys, true); |
Copilot uses AI. Check for mistakes.
export function getAllUniqueKeys(obj: Record<string, unknown>, keys = new Set<string>(), ignore?: boolean): Set<string> { | ||
Object.entries(obj).forEach(([key, value]) => { | ||
keys.add(key); | ||
if (value && typeof value === "object" && !Array.isArray(value)) { | ||
getAllUniqueKeys(value as Record<string, unknown>, keys); | ||
if (!ignore) keys.add(key); | ||
if (value && typeof value === "object") { | ||
if (Array.isArray(value)) { | ||
value.forEach((item) => { | ||
if (item && typeof item === "object") { | ||
// Recurse into objects and arrays within arrays | ||
if (Array.isArray(item)) { | ||
// Wrap array in an object to reuse the function and ignore its key |
Copilot
AI
Oct 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ignore
parameter lacks clear documentation and its purpose is not immediately obvious from the function signature. Consider adding JSDoc documentation or renaming the parameter to something more descriptive like skipCurrentLevelKeys
.
Copilot uses AI. Check for mistakes.
No description provided.