Files
wekan/server/lib/cardMatch.js
T
Lauri OjansivuandClaude Opus 4.8 b998246c35 Fix #5910 and add #6034: board search matches comments, drag-drop search results
Board-level search now matches text inside card comments, consistent with global
search (#5910); the (title OR description OR comment) rule is extracted to the
unit-tested helper server/lib/cardMatch.js. Search-result cards can be dragged
directly onto board lists, reusing card.move() (#6034, MVP: drops append to end
of the target list).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 14:38:28 +03:00

48 lines
1.5 KiB
JavaScript

/**
* Pure, dependency-free card text-matching helper.
*
* Single source of truth for "does this card match a free-text query",
* shared by board-level and global search so both behave consistently.
*
* #5910: board-level search must also match text inside card comments,
* exactly like global search does. The query is matched (case-insensitively)
* against the card title, description, AND every comment text.
*
* This module intentionally has NO Meteor / collection imports so it can be
* imported directly by unit tests (mocha + chai) without a running app.
*
* @param {Object} card
* @param {string} [card.title]
* @param {string} [card.description]
* @param {string[]} [card.commentTexts] - texts of the card's comments
* @param {string} query - free-text query
* @returns {boolean} true if the query matches title, description or any comment
*/
export function cardMatchesQuery(card, query) {
const c = card || {};
const q = (query == null ? '' : String(query)).toLowerCase();
// Empty query matches everything (mirrors existing search.logic behaviour).
if (q === '') {
return true;
}
const haystacks = [];
if (c.title) {
haystacks.push(String(c.title));
}
if (c.description) {
haystacks.push(String(c.description));
}
if (Array.isArray(c.commentTexts)) {
for (const t of c.commentTexts) {
if (t) {
haystacks.push(String(t));
}
}
}
return haystacks.some(h => h.toLowerCase().includes(q));
}