Files
wekan/models/lib/linkedCardTitle.js
T
Lauri Ojansivu 8d1fae4f7d Convert client-reachable models/lib helpers from CommonJS to ES modules (1/2).
The rspack client build treats a `module.exports` file imported into the
client bundle as an ES module and throws
"ES Modules may not assign module.exports" at evaluation time, aborting
the whole client module chain (No such template: swimlane / notifications
/ boardButtons, blank board, missing top bar). This is not an rspack
version regression (the lockfile has pinned ~1.7.x since v8.40); it is
that WeKan added CommonJS helpers to the client bundle.

Convert the 42 client-reachable pure-logic models/lib helpers from
`module.exports = { ... }` to `export { ... }`, and calendarFilter's
internal require('./swimlaneFilter') to an import with a .js extension
(node ESM needs it; rspack/reify tolerate it). Server-only helpers that
use node built-ins (fs/path/child_process) stay CommonJS. The plain-Node
.cjs unit tests for these helpers now use `await import(...js)` (wrapped
in an async IIFE); a source-guard in importVirtualMembers was updated
from module.exports to export. Verified: the full tests/*.test.cjs suite
has the SAME 7 pre-existing failures as before this change and no new
ones.
2026-07-23 18:55:30 +03:00

38 lines
1.6 KiB
JavaScript

'use strict';
// #4249 "sometimes filter by card title doesn't work". Renaming a linked card
// (or linked board) card updated only the LINKED target's title via
// getRealId()/linkedId, leaving the linking card's OWN `title` field stale.
// Filter-by-title queries each card document's own `title` field, so a linked
// card silently dropped out of title filters after its title was changed.
//
// computeTitleUpdateTargets() lists every document whose title must be written
// on a rename: always the linking card's own document (so it stays filterable
// and has a correct fallback title), plus the linked target (the original card
// or the linked board) so the existing mirror behavior is preserved.
// Meteor-free so it can be unit tested.
//
// card: { _id, linkedId, type } with type:
// 'cardType-linkedCard' -> linked card
// 'cardType-linkedBoard' -> linked board
// anything else -> a normal card
function computeTitleUpdateTargets(card) {
const targets = [];
if (!card || !card._id) return targets;
if (card.type === 'cardType-linkedCard') {
// The linking card's own document — this is what filter-by-title reads.
targets.push({ collection: 'cards', id: card._id });
// The original card it mirrors (previous behavior).
if (card.linkedId) targets.push({ collection: 'cards', id: card.linkedId });
} else if (card.type === 'cardType-linkedBoard') {
targets.push({ collection: 'cards', id: card._id });
if (card.linkedId) targets.push({ collection: 'boards', id: card.linkedId });
} else {
targets.push({ collection: 'cards', id: card._id });
}
return targets;
}
export { computeTitleUpdateTargets };