WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@fbosch
Copy link

@fbosch fbosch commented Aug 7, 2024

Addresses the issue #5617

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced filtering support: Filter functions now correctly handle both array and scalar column values. This improvement extends filtering capabilities across diverse data types, allowing filters to work reliably whether columns contain arrays or single values.

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 9, 2025

Walkthrough

Three array filter functions in the table-core library are enhanced to support both array-valued and scalar-valued row values. Each function now conditionally applies array or scalar comparison logic based on the row value type, maintaining backward compatibility with existing function signatures.

Changes

Cohort / File(s) Summary
Array filter functions enhancement
packages/table-core/src/filterFns.ts
Modified arrIncludes, arrIncludesAll, and arrIncludesSome to handle both array and scalar row values. Each function now applies type-appropriate comparison logic: array-based includes/matching for array values, and direct equality/inequality checks for scalar values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

  • Verify edge case handling for each function, particularly the distinct logic branches (all vs. some matching for arrIncludesAll and arrIncludesSome)
  • Confirm backward compatibility with existing array-valued row data
  • Review scalar value comparison logic for correctness (strict equality usage, inequality semantics in arrIncludesAll)

Poem

🐰 Three filter friends, now twice as nice,
They juggle arrays and scalars with spice,
With type-aware logic, both path and scalar,
Our filter functions grow stronger, more dazzler! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only mentions 'Addresses the issue #5617' without following the required template structure, missing sections for detailed changes explanation, checklist items, and release impact assessment. Expand the description to include the required template sections: 'Changes' section explaining what was modified and why, completed checklist items confirming testing and contribution guide adherence, and 'Release Impact' section noting if a changeset was generated.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: array filterFns' clearly references the core changes affecting array filter functions, which aligns with the primary objective of fixing how these functions handle both array and scalar values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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)
packages/table-core/src/filterFns.ts (1)

45-54: Array vs scalar handling in arrIncludes* looks correct; consider caching row.getValue once

The new logic for arrIncludes, arrIncludesAll, and arrIncludesSome keeps the old behavior for array-valued cells and adds sensible scalar fallbacks (strict equality, “all equal”, and “any equal” respectively). This should address non-array values cleanly without breaking existing array use-cases.

To tighten things up and avoid multiple row.getValue(columnId) calls per row/filter item, you could cache the cell value once in each function and reuse it in both branches:

 const arrIncludes: FilterFn<any> = (
   row,
   columnId: string,
   filterValue: unknown,
 ) => {
-  if (Array.isArray(row.getValue(columnId))) {
-    return row.getValue<unknown[]>(columnId)?.includes(filterValue)
-  }
-  return filterValue === row.getValue(columnId)
+  const value = row.getValue(columnId)
+  if (Array.isArray(value)) {
+    return (value as unknown[]).includes(filterValue)
+  }
+  return filterValue === value
 }

 const arrIncludesAll: FilterFn<any> = (
   row,
   columnId: string,
   filterValue: unknown[],
 ) => {
-  if (Array.isArray(row.getValue(columnId))) {
-    return !filterValue.some(
-      val => !row.getValue<unknown[]>(columnId)?.includes(val)
-    )
-  }
-  return !filterValue.some(val => val !== row.getValue(columnId))
+  const value = row.getValue(columnId)
+  if (Array.isArray(value)) {
+    return !filterValue.some(
+      val => !(value as unknown[]).includes(val),
+    )
+  }
+  return !filterValue.some(val => val !== value)
 }

 const arrIncludesSome: FilterFn<any> = (
   row,
   columnId: string,
   filterValue: unknown[],
 ) => {
-  if (Array.isArray(row.getValue(columnId))) {
-    return filterValue.some(val =>
-      row.getValue<unknown[]>(columnId)?.includes(val)
-    )
-  }
-  return filterValue.some(val => val === row.getValue(columnId))
+  const value = row.getValue(columnId)
+  if (Array.isArray(value)) {
+    return filterValue.some(val =>
+      (value as unknown[]).includes(val),
+    )
+  }
+  return filterValue.some(val => val === value)
 }

This keeps semantics the same while slightly improving readability and avoiding repeated lookups and generic calls.

Also applies to: 58-69, 73-84

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e172109 and 6fa1b0c.

📒 Files selected for processing (1)
  • packages/table-core/src/filterFns.ts (3 hunks)

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