Skip to content

feat: add null-content and empty-content#7

Merged
smmoosavi merged 1 commit intomainfrom
null-content
Dec 6, 2025
Merged

feat: add null-content and empty-content#7
smmoosavi merged 1 commit intomainfrom
null-content

Conversation

@smmoosavi
Copy link
Copy Markdown
Contributor

@smmoosavi smmoosavi commented Dec 6, 2025

Summary by CodeRabbit

  • New Features
    • Added EmptyContent, NonEmptyContent, and NullContent components to the public API for conditional rendering based on nullability and emptiness; emptiness detection is customizable and supports generic content types.
  • Tests
    • Expanded test suite to cover null/undefined, empty/non-empty, mixed scenarios, arrays/objects/primitives, and custom isEmpty predicates.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 6, 2025

Walkthrough

Adds three new content components — generic EmptyContent<C>, generic NonEmptyContent<C>, and NullContent — with corresponding props interfaces and exports, and expands tests to cover null, empty, non-empty, and mixed content scenarios.

Changes

Cohort / File(s) Summary
New content components
packages/ctablex-core/src/contents/empty-content.tsx, packages/ctablex-core/src/contents/non-empty-content.tsx, packages/ctablex-core/src/contents/null-content.tsx
Introduces EmptyContent<C>, NonEmptyContent<C>, and NullContent plus EmptyContentProps<C>, NonEmptyContentProps<C>, and NullContentProps. EmptyContent/NonEmptyContent accept optional isEmpty?: (content: C) => boolean (default treats empty arrays as empty). Components read content via useContent and conditionally render children.
Public types & declarations
packages/ctablex-core/src/index.ts, packages/ctablex-core/index.d.ts
Adds exports for the three new components and their props types; declaration ordering updated to include these new public signatures without removing existing exports.
Tests
packages/ctablex-core/src/contents/content.test.tsx
Reorganizes and expands tests into describe blocks for nullable, null, empty, non-empty, and mixed cases; adds imports and cases exercising NullContent, EmptyContent, and NonEmptyContent with arrays, primitives, and custom isEmpty.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify index.d.ts and src exports have matching generic signatures and nullable behavior.
  • Review default isEmpty implementation and edge cases (non-array values).
  • Confirm interaction precedence among NullableContent, NullContent, EmptyContent, and NonEmptyContent as covered by tests.
  • Check tests for adequate coverage of custom isEmpty and undefined/null inputs.

Poem

🐇 I nibbled lines of code beneath the moon,
NullContent snoozes where no values bloom,
EmptyContent waits by the silent tray,
NonEmpty hops out when data comes to play,
A little rabbit cheers the new display.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add null-content and empty-content' accurately and concisely describes the main changes. The pull request adds three new content components (NullContent, EmptyContent, and NonEmptyContent) with their associated props interfaces to the public API.
✨ 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 null-content

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

Copy link
Copy Markdown

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c03c449 and 3e5a126.

📒 Files selected for processing (5)
  • packages/ctablex-core/index.d.ts (2 hunks)
  • packages/ctablex-core/src/contents/content.test.tsx (2 hunks)
  • packages/ctablex-core/src/contents/empty-content.tsx (1 hunks)
  • packages/ctablex-core/src/contents/null-content.tsx (1 hunks)
  • packages/ctablex-core/src/index.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/ctablex-core/index.d.ts (3)
packages/ctablex-core/src/contents/empty-content.tsx (2)
  • EmptyContent (13-20)
  • EmptyContentProps (4-7)
packages/ctablex-core/src/index.ts (4)
  • EmptyContent (12-12)
  • EmptyContentProps (13-13)
  • NullContent (20-20)
  • NullContentProps (21-21)
packages/ctablex-core/src/contents/null-content.tsx (2)
  • NullContent (8-15)
  • NullContentProps (4-6)
🪛 GitHub Actions: CI
packages/ctablex-core/index.d.ts

[error] 1-1: git diff --exit-code --name-only failed with exit code 1. Modified file: packages/ctablex-core/index.d.ts.

🔇 Additional comments (5)
packages/ctablex-core/src/contents/null-content.tsx (1)

4-15: NullContent implementation looks correct and minimal

Logic cleanly gates rendering on content === null || content === undefined and otherwise returns null; matches the intended semantics and the tests. No changes needed.

packages/ctablex-core/src/contents/content.test.tsx (1)

12-13: New content tests are comprehensive and consistent with behavior

The new suites for NullableContent, NullContent, and EmptyContent exercise null/undefined, empty vs non-empty arrays, non-array values, and custom isEmpty logic, which nicely pins down the intended semantics. Structure with separate describe blocks improves readability without introducing brittle assertions.

Also applies to: 247-405

packages/ctablex-core/index.d.ts (1)

207-213: NullContent declarations align with implementation

The NullContent and NullContentProps declarations (non-generic, children?: ReactNode, return JSX_2.Element | null) match the implementation in src/contents/null-content.tsx and the intended semantics. Once the EmptyContent declarations are fixed and regenerated, this section should be good.

packages/ctablex-core/src/index.ts (1)

12-13: Public exports for EmptyContent/NullContent are correctly wired

The new exports for EmptyContent/EmptyContentProps and NullContent/NullContentProps follow the existing pattern for other content components and point to the correct source files. Once index.d.ts is updated to match, the public surface will be consistent.

Also applies to: 20-21

packages/ctablex-core/src/contents/empty-content.tsx (1)

4-20: EmptyContent implementation matches the intended generic, overridable “emptiness” semantics

The component cleanly combines a generic isEmpty predicate with a sensible default for arrays and explicit handling of null/undefined. The use of useContent<C>() and EmptyContentProps<C> is consistent and aligns with the tests. No changes needed here; just ensure the public index.d.ts declarations mirror this generic shape (see separate comment).

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c03c449) to head (4449749).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #7   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           35        38    +3     
  Lines          213       233   +20     
  Branches        45        51    +6     
=========================================
+ Hits           213       233   +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
packages/ctablex-core/src/contents/empty-content.tsx (1)

9-11: Extract defaultIsEmpty to a shared utility.

This function is duplicated from packages/ctablex-core/src/contents/non-empty-content.tsx. Consolidate it into a shared utility to maintain consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bed9cc2 and fb8c41d.

📒 Files selected for processing (6)
  • packages/ctablex-core/index.d.ts (3 hunks)
  • packages/ctablex-core/src/contents/content.test.tsx (2 hunks)
  • packages/ctablex-core/src/contents/empty-content.tsx (1 hunks)
  • packages/ctablex-core/src/contents/non-empty-content.tsx (1 hunks)
  • packages/ctablex-core/src/contents/null-content.tsx (1 hunks)
  • packages/ctablex-core/src/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ctablex-core/src/contents/null-content.tsx
  • packages/ctablex-core/src/index.ts
🧰 Additional context used
🧬 Code graph analysis (3)
packages/ctablex-core/src/contents/empty-content.tsx (1)
packages/ctablex-core/src/index.ts (3)
  • EmptyContentProps (13-13)
  • EmptyContent (12-12)
  • useContent (4-4)
packages/ctablex-core/src/contents/content.test.tsx (9)
packages/ctablex-core/src/index.ts (9)
  • ContentProvider (4-4)
  • NullableContent (19-19)
  • ArrayContent (10-10)
  • NullContent (22-22)
  • EmptyContent (12-12)
  • NonEmptyContent (14-14)
  • DefaultContent (17-17)
  • ObjectContent (31-31)
  • KeyContent (34-34)
packages/ctablex-core/src/contents/nullable-content.tsx (1)
  • NullableContent (11-18)
packages/ctablex-core/src/contents/array-content.tsx (1)
  • ArrayContent (18-46)
packages/ctablex-core/src/contents/null-content.tsx (1)
  • NullContent (8-15)
packages/ctablex-core/src/contents/empty-content.tsx (1)
  • EmptyContent (13-20)
packages/ctablex-core/src/contents/non-empty-content.tsx (1)
  • NonEmptyContent (13-20)
packages/ctablex-core/src/contents/default-content.tsx (1)
  • DefaultContent (3-6)
packages/ctablex-core/src/contents/object-content.tsx (1)
  • ObjectContent (21-42)
packages/ctablex-core/src/contents/key-content.tsx (1)
  • KeyContent (3-6)
packages/ctablex-core/index.d.ts (3)
packages/ctablex-core/src/contents/empty-content.tsx (2)
  • EmptyContent (13-20)
  • EmptyContentProps (4-7)
packages/ctablex-core/src/contents/non-empty-content.tsx (2)
  • NonEmptyContent (13-20)
  • NonEmptyContentProps (4-7)
packages/ctablex-core/src/contents/null-content.tsx (2)
  • NullContent (8-15)
  • NullContentProps (4-6)
🔇 Additional comments (7)
packages/ctablex-core/src/contents/non-empty-content.tsx (1)

13-20: LGTM! Component logic is correct.

The component correctly renders children only when content exists (not null/undefined) and is non-empty according to the isEmpty predicate. The inverse logic appropriately returns null for empty or null/undefined content.

packages/ctablex-core/src/contents/empty-content.tsx (1)

13-20: LGTM! Component logic is correct.

The component correctly renders children when content is null, undefined, or empty according to the isEmpty predicate. This provides the inverse behavior of NonEmptyContent.

packages/ctablex-core/src/contents/content.test.tsx (2)

12-14: LGTM! Imports added for new components.

The imports correctly bring in the three new content components for testing.


248-624: Excellent test coverage for the new content components.

The expanded test suite comprehensively covers:

  • NullableContent behavior with null, undefined, custom nullContent, and non-null values
  • NullContent rendering with null, undefined, and non-null content
  • NonEmptyContent scenarios including null, undefined, empty arrays, non-empty arrays, non-array content, and custom isEmpty predicates
  • EmptyContent scenarios with various content types and custom predicates
  • Mixed interactions between NullableContent, EmptyContent, and NonEmptyContent

The test structure is well-organized with clear expectations and good edge case coverage.

packages/ctablex-core/index.d.ts (3)

115-122: LGTM! Type declarations match the implementation.

The EmptyContent<C> and EmptyContentProps<C> declarations correctly include the generic parameter and the isEmpty callback, matching the implementation in packages/ctablex-core/src/contents/empty-content.tsx.


199-206: LGTM! Type declarations match the implementation.

The NonEmptyContent<C> and NonEmptyContentProps<C> declarations correctly include the generic parameter and the isEmpty callback, matching the implementation in packages/ctablex-core/src/contents/non-empty-content.tsx.


217-223: LGTM! Type declarations match the implementation.

The NullContent and NullContentProps declarations are correctly non-generic and include only the children prop, matching the implementation in packages/ctablex-core/src/contents/null-content.tsx.

Copy link
Copy Markdown

@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)
packages/ctablex-core/src/contents/content.test.tsx (1)

337-495: Comprehensive NonEmptyContent/EmptyContent coverage, with a small DRY opportunity

The non empty content tests exercise all key cases (null, undefined, empty/non-empty arrays, and custom object-based isEmpty), and validate interaction with EmptyContent and list rendering. Together with the empty content tests they give strong coverage of the shared emptiness semantics.

Minor suggestion: the isEmpty = (content: object) => Object.keys(content).length === 0; helper is defined multiple times (here and again in the empty content block). You could factor this into a shared top-level helper to reduce duplication and make it easier to tweak the object-emptiness rule in one place:

@@
-import { NonEmptyContent } from './non-empty-content';
+import { NonEmptyContent } from './non-empty-content';
+
+const isObjectEmpty = (content: object) => Object.keys(content).length === 0;
@@
-      const isEmpty = (content: object) => {
-        return Object.keys(content).length === 0;
-      };
+      const isEmpty = isObjectEmpty;
@@
-      const isEmpty = (content: object) => {
-        return Object.keys(content).length === 0;
-      };
+      const isEmpty = isObjectEmpty;
@@
-      const isEmpty = (content: object) => {
-        return Object.keys(content).length === 0;
-      };
+      const isEmpty = isObjectEmpty;

Purely optional, tests are fine as-is.

Also applies to: 553-556

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb8c41d and 4449749.

📒 Files selected for processing (6)
  • packages/ctablex-core/index.d.ts (3 hunks)
  • packages/ctablex-core/src/contents/content.test.tsx (2 hunks)
  • packages/ctablex-core/src/contents/empty-content.tsx (1 hunks)
  • packages/ctablex-core/src/contents/non-empty-content.tsx (1 hunks)
  • packages/ctablex-core/src/contents/null-content.tsx (1 hunks)
  • packages/ctablex-core/src/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/ctablex-core/index.d.ts
  • packages/ctablex-core/src/contents/null-content.tsx
  • packages/ctablex-core/src/index.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/ctablex-core/src/contents/empty-content.tsx (1)
packages/ctablex-core/src/index.ts (3)
  • EmptyContentProps (13-13)
  • EmptyContent (12-12)
  • useContent (4-4)
🔇 Additional comments (7)
packages/ctablex-core/src/contents/non-empty-content.tsx (1)

5-16: NonEmptyContent logic and reuse of defaultIsEmpty look solid

The generic props typing, use of useContent<C>(), and the null/undefined + isEmpty check correctly mirror EmptyContent with inverted rendering semantics. Importing and reusing defaultIsEmpty avoids duplication and keeps the “emptiness” definition centralized. No changes needed.

packages/ctablex-core/src/contents/content.test.tsx (5)

12-14: New content component imports are consistent

Importing NullContent, EmptyContent, and NonEmptyContent here matches the new components added in the contents module and keeps this test suite as the central place validating their interactions. Looks consistent and clear.


248-300: NullableContent scenarios are well covered

These four tests nicely pin down NullableContent behavior for null, undefined, custom nullContent, and non-null content. They give good confidence that NullableContent neither swallows real data nor renders children when content is actually null/undefined.


302-335: NullContent behavior is clearly specified by tests

The null content describe block cleanly encodes the contract: render children only for null/undefined, and render nothing for non-null values. This aligns well with the intended semantics and keeps behavior around “nullish” content unambiguous.


497-566: EmptyContent tests match intended emptiness semantics

These cases clearly establish that EmptyContent treats null, undefined, and empty arrays (or custom-isEmpty empties) as “empty”, while skipping rendering for non-empty arrays and non-array values. This aligns with defaultIsEmpty and helps prevent surprises for primitive values.


568-623: Mixed null/empty tests nicely validate component composition

The mixed null and empty block is very helpful: it confirms that NullableContent’s nullContent takes precedence when content is null/undefined, and that for non-nullish values it delegates correctly to EmptyContent + ArrayContent. This gives high confidence that these wrappers compose correctly in real UIs.

packages/ctablex-core/src/contents/empty-content.tsx (1)

4-20: EmptyContent and defaultIsEmpty are simple and correctly factored

EmptyContent’s logic (render on null/undefined or isEmpty(content)) plus the exported defaultIsEmpty for empty arrays is clear and matches the test expectations. Reusing defaultIsEmpty from other components keeps the notion of “empty” centralized. No changes needed.

@smmoosavi smmoosavi merged commit 3ae6617 into main Dec 6, 2025
4 checks passed
@smmoosavi smmoosavi deleted the null-content branch December 6, 2025 14:13
@coderabbitai coderabbitai bot mentioned this pull request Dec 11, 2025
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