Files
wekan/models/lib/customFieldsWD.js
T
Lauri Ojansivu 973c2ad901 Fix #3453 #3199; linked-card custom field crash; pin #3843.
- #3453: publish the FULL subtask ancestor chain, not only direct
  parents - the cross-board full-path label vanished after refresh.
- #3748 (defect half): skip unresolvable custom-field definitions on
  linked cards - phantom empty rows and a template TypeError on every
  card details render. The mirroring itself is by design: linked cards
  are pointers; label/custom-field ids are board-scoped; name-based
  inheritance is the copy feature, not the link feature.
- #3199: group each archived card with its own Restore/Delete links and
  add a clear separator below the group (RTL-safe, theme-neutral).
- #3843: comment-editor uploads and the attachments popup now share one
  null-safe meta builder, and tests pin that comment attachments list in
  the card's Attachments section.

Closes #3748: mirroring is by design (see above); the only actionable
defect is fixed in this commit.
Closes #3378: already fixed - notification_cleanup moved off SyncedCron
to a guarded Meteor.setInterval singleton, and quave:synced-cron 2.4.0
handles the E11000 history collision that percolate 1.5.x missed.
Closes #3276: already fixed by d3625db75 - the spent-time badge helpers
now read the live Cards document reactively, so the overtime color flips
immediately; verified behaviorally against the real component.
Closes #3843: behavior verified present and now regression-locked.

Thanks to MPeti1, peterbecich, fxkr, jghaanstra and xet7.
2026-07-17 03:21:02 +03:00

74 lines
2.8 KiB
JavaScript

'use strict';
// #3748: match a card's `customFields` entries to the custom-field definitions
// attached to the card's CURRENT board ("customFields With Definitions").
//
// Linked cards are by design pointers that mirror the original card; labels and
// custom-field DEFINITIONS are board-scoped, so they are deliberately not
// inherited across boards (that remapping-by-name behaviour belongs to the
// COPY path — Cards.copy()/mapCustomFieldsToBoard — not to links). However,
// Cards.link() deep-copies the original document, so a cross-board linked card
// carries a `customFields` snapshot whose definition ids do not exist on the
// viewing board. The old customFieldsWD() returned an empty `{}` placeholder
// for every unmatched entry, which rendered a phantom empty row in the card
// details and made the `cardCustomField` template's getTemplate() helper throw
// "TypeError: Cannot read properties of undefined (reading 'type')" on every
// render. Unmatched entries must be SKIPPED instead.
// A dropdown custom field stores the selected item's id as `value`; the
// human-readable "true value" is the matching dropdown item's name. Any other
// field type (or an id that no longer matches an item) keeps the raw value.
function resolveTrueValue(definition, value) {
const items =
definition && definition.settings && definition.settings.dropdownItems;
if (Array.isArray(items)) {
for (const item of items) {
if (item && item._id === value) {
return item.name;
}
}
}
return value;
}
// customFields: the card's own `customFields` array ([{_id, value}, ...]).
// definitions: the CustomFields definitions attached to the card's board.
// Returns [{_id, value, trueValue, definition}, ...] sorted by definition
// name, with entries whose definition is not on this board left out.
function buildCustomFieldsWD(customFields, definitions) {
if (!Array.isArray(customFields) || !Array.isArray(definitions)) {
return [];
}
const ret = [];
for (const customField of customFields) {
if (!customField) {
continue;
}
const definition = definitions.find(
def => def && def._id === customField._id,
);
if (!definition) {
// e.g. a linked card's snapshot from the original board, or a definition
// that was deleted / detached from this board.
continue;
}
ret.push({
_id: customField._id,
value: customField.value,
trueValue: resolveTrueValue(definition, customField.value),
definition,
});
}
ret.sort((a, b) => {
const aName = a.definition.name;
const bName = b.definition.name;
if (aName === undefined || bName === undefined) {
return 0;
}
return aName.localeCompare(bName);
});
return ret;
}
module.exports = { buildCustomFieldsWD, resolveTrueValue };