Skip to content

fix. convert all fields to String before matching#1032

Open
balog-b wants to merge 1 commit intostagingfrom
bugfix/search-not-working-in-onedeepentitypage
Open

fix. convert all fields to String before matching#1032
balog-b wants to merge 1 commit intostagingfrom
bugfix/search-not-working-in-onedeepentitypage

Conversation

@balog-b
Copy link
Copy Markdown
Contributor

@balog-b balog-b commented Apr 25, 2026

Closes #998

Summary by CodeRabbit

  • Bug Fixes
    • Improved search filtering to correctly handle different data types in search fields, ensuring more reliable and consistent filtering results.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmsch-cst Ready Ready Preview, Comment Apr 25, 2026 10:52am
cmsch-felezobal Ready Ready Preview, Comment Apr 25, 2026 10:52am
cmsch-golyakorte Ready Ready Preview, Comment Apr 25, 2026 10:52am
cmsch-skktv Ready Ready Preview, Comment Apr 25, 2026 10:52am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 25, 2026

📝 Walkthrough

Walkthrough

The normalSearch filter function in the overview template was updated to explicitly convert field values to strings before performing lowercase and substring matching, improving handling of non-string field contents in search operations.

Changes

Cohort / File(s) Summary
Template Search Filter Update
backend/src/main/resources/templates/overview4.html
Updated normalSearch function to normalize field values by converting them to strings before lowercasing and substring matching, ensuring compatibility with non-string field types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A tiny tweak, so small and neat,
String conversion, bittersweet,
Now searches work on tasks galore,
No more searching in the dark before!
With types aligned, the results appear,
Hopping through data crystal clear! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting all fields to strings before matching operations in the search functionality.
Linked Issues check ✅ Passed The code change addresses issue #998 by fixing data-type handling in the normalSearch function to properly handle non-string field values before comparison.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the search functionality in overview4.html by normalizing field values to strings, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/search-not-working-in-onedeepentitypage

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/src/main/resources/templates/overview4.html (1)

232-239: ⚠️ Potential issue | 🟠 Major

fuzzyFilter remains broken for entities with fuzzy search enabled.

The issue is confirmed: EventEntity, GalleryEntity, ErrorLogEntity, AdmissionEntryEntity, and EmailTemplateEntity all have fuzzy = true. The fuzzyFilter function at lines 232-239 calls .trim() directly on potentially non-string or null values, which will throw a TypeError and abort the search.

Formatted values from OverviewBuilder.getTableData and GenerateOverview.formatValue can be Boolean, HTML strings, or null — values that don't have a .trim() method. This is especially problematic for EventEntity, which is mentioned in the linked issue #998.

Apply the same String(...) normalization used elsewhere in the PR:

Proposed fix
 function fuzzyFilter(data, searchTerm) {
     let result = false;
     const fields = /*[[${searchSettings.rows}]]*/ [];
     for (let field in fields) {
-        result = result || isFuzzyMatch(data[fields[field]].trim(), searchTerm.trim());
+        const raw = data[fields[field]];
+        const value = raw == null ? "" : String(raw);
+        result = result || isFuzzyMatch(value.trim(), searchTerm.trim());
     }
     return result;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/main/resources/templates/overview4.html` around lines 232 - 239,
The fuzzyFilter function currently calls .trim() directly on data values and the
searchTerm which can be null/non-string and causes TypeError; update fuzzyFilter
(the function named fuzzyFilter and its loop over fields) to normalize both the
field value and searchTerm with String(...) (or String(value ?? '')) before
calling .trim(), e.g. convert data[fields[field]] to String(data[fields[field]]
?? '') and convert searchTerm to String(searchTerm ?? '') so isFuzzyMatch always
receives strings and does not throw.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/src/main/resources/templates/overview4.html`:
- Around line 185-193: In normalSearch, converting field values with
String(data[fields[field]]) turns null/undefined into "null"/"undefined" which
bypasses the value guard; update the implementation to treat nullish values as
empty strings before doing the contains check (e.g., read the raw value from
data using data[fields[field]] and normalize null/undefined to '' before
converting/casing and comparing with searchTerm) so that missing fields don't
match searches for "null"/"undefined"; adjust references in the function
(normalSearch, fields, data[fields[field]], searchTerm) accordingly.

---

Outside diff comments:
In `@backend/src/main/resources/templates/overview4.html`:
- Around line 232-239: The fuzzyFilter function currently calls .trim() directly
on data values and the searchTerm which can be null/non-string and causes
TypeError; update fuzzyFilter (the function named fuzzyFilter and its loop over
fields) to normalize both the field value and searchTerm with String(...) (or
String(value ?? '')) before calling .trim(), e.g. convert data[fields[field]] to
String(data[fields[field]] ?? '') and convert searchTerm to String(searchTerm ??
'') so isFuzzyMatch always receives strings and does not throw.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 62b5b425-5e3c-49e9-8e4a-d262bcebc50c

📥 Commits

Reviewing files that changed from the base of the PR and between 6be8ff1 and 8953046.

📒 Files selected for processing (1)
  • backend/src/main/resources/templates/overview4.html

Comment on lines +185 to +193
function normalSearch(data, searchTerm) {
let result = false;
const fields = /*[[${searchSettings.rows}]]*/ [];
for (let field in fields) {
const value = String(data[fields[field]]);
result = result || (value && value.toLowerCase().includes(searchTerm.toLowerCase()));
}
return result;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Edge case: null/undefined field values become matchable strings.

String(null) and String(undefined) produce the literal strings "null" / "undefined", which are truthy and will pass the value && ... guard. As a result, a user searching for the substring null or undefined will match rows where the corresponding field is actually missing. The pre-existing value && short-circuit is now effectively dead code, since String(...) always returns a non-empty string for these cases.

Consider normalizing nullish values to an empty string instead:

♻️ Proposed refinement
 function normalSearch(data, searchTerm) {
     let result = false;
     const fields = /*[[${searchSettings.rows}]]*/ [];
     for (let field in fields) {
-        const value = String(data[fields[field]]);
-        result = result || (value && value.toLowerCase().includes(searchTerm.toLowerCase()));
+        const raw = data[fields[field]];
+        const value = raw == null ? "" : String(raw);
+        result = result || (value !== "" && value.toLowerCase().includes(searchTerm.toLowerCase()));
     }
     return result;
 }
📝 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
function normalSearch(data, searchTerm) {
let result = false;
const fields = /*[[${searchSettings.rows}]]*/ [];
for (let field in fields) {
const value = String(data[fields[field]]);
result = result || (value && value.toLowerCase().includes(searchTerm.toLowerCase()));
}
return result;
}
function normalSearch(data, searchTerm) {
let result = false;
const fields = /*[[${searchSettings.rows}]]*/ [];
for (let field in fields) {
const raw = data[fields[field]];
const value = raw == null ? "" : String(raw);
result = result || (value !== "" && value.toLowerCase().includes(searchTerm.toLowerCase()));
}
return result;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/main/resources/templates/overview4.html` around lines 185 - 193,
In normalSearch, converting field values with String(data[fields[field]]) turns
null/undefined into "null"/"undefined" which bypasses the value guard; update
the implementation to treat nullish values as empty strings before doing the
contains check (e.g., read the raw value from data using data[fields[field]] and
normalize null/undefined to '' before converting/casing and comparing with
searchTerm) so that missing fields don't match searches for "null"/"undefined";
adjust references in the function (normalSearch, fields, data[fields[field]],
searchTerm) accordingly.

@balog-b balog-b requested a review from SzBeni2003 April 25, 2026 12:15
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.

Searching in tasks,riddles,events not working in OneDeepEntityPages

1 participant