Skip to content

Conversation

@gkrajniak
Copy link
Collaborator

@gkrajniak gkrajniak commented Nov 3, 2025

  • Added support for property field transformations in FieldDefinition, including uppercase, lowercase, capitalize, encode, and decode.
  • Updated utilities like getResourceValueByJsonPath to apply these transformations.
  • Enhanced documentation to reflect the new propertyField behavior.
  • Added unit tests to validate transformations and edge cases.
  • Updated dependencies in package-lock.json and package.json.

Summary by CodeRabbit

  • New Features

    • Added property-field display for nested object values with configurable text transforms (uppercase, lowercase, capitalize, encode, decode).
  • Documentation

    • Expanded examples showing nested property selection and transform sequences in list views.
  • Tests

    • Broadened test coverage for property extraction, transform sequences, Base64 encode/decode, and edge cases.
  • Chores

    • Minor formatting and config adjustments; non-functional template formatting refinements.

- Added support for property field transformations in `FieldDefinition`, including `uppercase`, `lowercase`, `capitalize`, `encode`, and `decode`.
- Updated utilities like `getResourceValueByJsonPath` to apply these transformations.
- Enhanced documentation to reflect the new `propertyField` behavior.
- Added unit tests to validate transformations and edge cases.
- Updated dependencies in `package-lock.json` and `package.json`.
@gkrajniak gkrajniak requested review from a team as code owners November 3, 2025 10:13
@coderabbitai
Copy link

coderabbitai bot commented Nov 3, 2025

Walkthrough

Adds a propertyField mechanism for selecting a sub-key from object fields and applying text transforms (uppercase, lowercase, capitalize, decode, encode). Introduces types, transform pipeline and Base64 helpers, expands resource-field extraction logic and tests, updates docs and template formatting, and tweaks a few config files.

Changes

Cohort / File(s) Summary
Type definitions
projects/lib/models/models/resource.ts
Added TransformType and PropertyField exports; extended FieldDefinition with optional propertyField and Resource with optional data.
Resource field utils
projects/lib/utils/utils/resource-field-by-path.ts
Expanded getResourceValueByJsonPath to accept propertyField, added executeTransform pipeline, and exported encodeBase64 / decodeBase64 with error handling; added guards for array jsonPath/property usage.
Call-site update
projects/lib/utils/utils/get-value-by-path.ts
Removed explicit property argument when calling getResourceValueByJsonPath.
Tests
projects/lib/utils/utils/resource-field-by-path.spec.ts
Added comprehensive tests for propertyField extraction and transform sequences, including Base64 encode/decode cases and edge/error scenarios.
Documentation
docs/readme-generic-ui.md
Documented propertyField usage with examples showing key and transform options; minor example formatting tweaks.
Template formatting
projects/wc/src/app/components/generic-ui/list-view/list-view.component.html
Reflowed HTML markup to multiline formatting; no functional changes.
Config / deps
package.json, projects/lib/jest.config.js
Reordered a devDependency entry in package.json; adjusted global statements coverage threshold in Jest config from -3 to -4.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review transform pipeline ordering and behavior for all TransformType values.
  • Validate Base64 helpers' error handling and cross-environment correctness (TextEncoder/TextDecoder, btoa/atob).
  • Confirm interaction between propertyField, jsonPathExpression, and existing property usage; check tests for coverage of edge cases.

Possibly related PRs

  • Resource ready conditions #100 — modifies the same models file by adding optional fields to resource-related interfaces (potential overlap in interface changes).

Suggested reviewers

  • nexus49

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Enhance property field handling with transformations' directly aligns with the main objective of the changeset. The PR introduces new propertyField functionality with transform capabilities (uppercase, lowercase, capitalize, encode, decode) across models, utilities, tests, and documentation. The title accurately captures this primary enhancement without being overly specific or vague.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-property-fileds-handling-for-scalar-values

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.


- `"label"`: Display name for the field
- `"property"`: JSON path to the resource property (string or array of strings for fallback values)
- `"propertyField"`: In case the property is a scalar value that represents an object, this property can be used to specify the field to be used for display within that object
Copy link
Collaborator Author

@gkrajniak gkrajniak Nov 3, 2025

Choose a reason for hiding this comment

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

doc

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

🧹 Nitpick comments (1)
projects/lib/utils/utils/resource-field-by-path.spec.ts (1)

86-164: Add test coverage for non-string value handling.

The test suite thoroughly covers string transformations but doesn't verify behavior when value[field.propertyField.key] is a non-string type (e.g., number, boolean, object). Consider adding a test case to ensure graceful handling of type mismatches.

Example test to add:

it('handles non-string values gracefully', () => {
  const resource = {
    data: {
      config: { count: 42 }, // number, not string
    },
  } as unknown as Resource;

  const field = {
    property: 'data.config',
    propertyField: { key: 'count', transform: ['uppercase'] },
  } as unknown as FieldDefinition;

  const result = getResourceValueByJsonPath(resource, field);
  // Define expected behavior: should it return undefined, the original value, or throw?
  expect(result).toBeDefined();
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43c6ef7 and 891b46d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • docs/readme-generic-ui.md (4 hunks)
  • package.json (1 hunks)
  • projects/lib/models/models/resource.ts (3 hunks)
  • projects/lib/utils/utils/get-value-by-path.ts (0 hunks)
  • projects/lib/utils/utils/resource-field-by-path.spec.ts (1 hunks)
  • projects/lib/utils/utils/resource-field-by-path.ts (2 hunks)
  • projects/wc/src/app/components/generic-ui/list-view/list-view.component.html (3 hunks)
💤 Files with no reviewable changes (1)
  • projects/lib/utils/utils/get-value-by-path.ts
🧰 Additional context used
🧬 Code graph analysis (2)
projects/lib/utils/utils/resource-field-by-path.spec.ts (2)
projects/lib/models/models/resource.ts (2)
  • Resource (65-72)
  • FieldDefinition (24-45)
projects/lib/utils/utils/resource-field-by-path.ts (1)
  • getResourceValueByJsonPath (8-39)
projects/lib/utils/utils/resource-field-by-path.ts (1)
projects/lib/models/models/resource.ts (3)
  • Resource (65-72)
  • PropertyField (19-22)
  • TransformType (12-17)
🔇 Additional comments (1)
projects/lib/utils/utils/resource-field-by-path.ts (1)

79-101: LGTM! Base64 encoding/decoding implementation is correct.

The UTF-8 handling via TextEncoder/TextDecoder properly supports multi-byte characters, and error handling is appropriate for the transform pipeline use case.

Comment on lines +31 to +36
if (value && field.propertyField) {
return executeTransform(
value[field.propertyField.key],
field.propertyField.transform,
);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add type guard for non-string values before transformation.

The value[field.propertyField.key] expression returns any from the JSONPath query result, but executeTransform expects string | undefined. If the value is a number, boolean, or object, the string transforms (uppercase, lowercase, capitalize) will throw runtime errors since they call String prototype methods without type checking.

Apply this defensive check:

  if (value && field.propertyField) {
+   const fieldValue = value[field.propertyField.key];
+   if (typeof fieldValue !== 'string' && fieldValue != null) {
+     console.warn(
+       `Expected string for propertyField key "${field.propertyField.key}", got ${typeof fieldValue}. Skipping transforms.`,
+     );
+     return fieldValue;
+   }
    return executeTransform(
-     value[field.propertyField.key],
+     fieldValue,
      field.propertyField.transform,
    );
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (value && field.propertyField) {
return executeTransform(
value[field.propertyField.key],
field.propertyField.transform,
);
}
if (value && field.propertyField) {
const fieldValue = value[field.propertyField.key];
if (typeof fieldValue !== 'string' && fieldValue != null) {
console.warn(
`Expected string for propertyField key "${field.propertyField.key}", got ${typeof fieldValue}. Skipping transforms.`,
);
return fieldValue;
}
return executeTransform(
fieldValue,
field.propertyField.transform,
);
}
🤖 Prompt for AI Agents
In projects/lib/utils/utils/resource-field-by-path.ts around lines 31 to 36, the
code calls executeTransform with value[field.propertyField.key] which can be any
JSONPath result; add a type guard so you only call executeTransform when that
extracted value is a string or undefined. Specifically, read the value into a
local (e.g. val), check if typeof val === 'string' || val === undefined, and
only then return executeTransform(val, field.propertyField.transform); otherwise
return the original val (or undefined) without attempting string transformations
to avoid runtime errors.

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

🧹 Nitpick comments (1)
projects/lib/jest.config.js (1)

13-13: Consider maintaining the previous coverage threshold.

The statements threshold has been lowered from -3 to -4, allowing one additional uncovered statement. Since this PR adds new unit tests for property field transformations, could you clarify why the coverage threshold needs to be relaxed? Ideally, coverage requirements should be maintained or improved when adding new functionality.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 891b46d and 46eda10.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • projects/lib/jest.config.js (1 hunks)
  • projects/lib/utils/utils/resource-field-by-path.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🧬 Code graph analysis (1)
projects/lib/utils/utils/resource-field-by-path.spec.ts (2)
projects/lib/models/models/resource.ts (2)
  • Resource (65-72)
  • PropertyField (19-22)
projects/lib/utils/utils/resource-field-by-path.ts (3)
  • getResourceValueByJsonPath (8-39)
  • encodeBase64 (79-90)
  • decodeBase64 (92-101)
🔇 Additional comments (4)
projects/lib/utils/utils/resource-field-by-path.spec.ts (4)

1-19: Excellent test setup!

The imports are clean, mocking strategy is appropriate, and the beforeEach hook ensures test isolation by clearing mocks between runs.


21-254: Outstanding test coverage for getResourceValueByJsonPath!

The test suite comprehensively validates:

  • All transform types (uppercase, lowercase, capitalize, encode, decode)
  • Transform chaining and unknown transforms
  • Error resilience with graceful fallbacks
  • Edge cases (null, undefined, empty arrays, missing properties)
  • Integration with jsonpath queries and propertyField extraction

The tests are well-organized, clearly named, and properly handle mock lifecycle management.


256-307: Thorough coverage of Base64 encoding!

The tests validate ASCII, UTF-8, emojis, empty strings, error throwing, and error logging. Mock management is clean with proper restoration. The approach of using decodeBase64 for verification in UTF-8 tests (lines 264, 269) is pragmatic given the complexity of manually specifying encoded output.


309-359: Excellent coverage of Base64 decoding with round-trip validation!

The tests comprehensively cover ASCII, UTF-8, emojis, empty strings, invalid input handling, error logging, and round-trip encoding/decoding. The round-trip test (lines 353-358) is particularly valuable for ensuring encode and decode work correctly as a pair.

@gkrajniak gkrajniak enabled auto-merge (squash) November 3, 2025 10:54
@gkrajniak gkrajniak merged commit 3512cbd into main Nov 3, 2025
8 checks passed
@gkrajniak gkrajniak deleted the feat/add-property-fileds-handling-for-scalar-values branch November 3, 2025 11:28
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.

5 participants