Files
wekan/models/lib/minicardChecklistVisibility.js
T
Lauri Ojansivu 32b61f186f Checklists: "Show on minicard" is an override, so unchecking it hides the checklist.
Reported by email with a screenshot (Swedish): "Även om jag avmarkerar 'Visa på
minikort' (och vill dölja checklistan på minikortet)" - the switch is off and the
checklist is on the minicard anyway.

It was off for everybody. The minicard asked:

  board.allowsChecklistsOnMinicard || checklist.showChecklistAtMinicard

and the board flag defaults to TRUE. An OR cannot be argued with: while the board
setting is on, no value of the checklist's own field changes the answer. The popup
made it look like a working switch - it drew the state from the raw field, which
starts false, so it read OFF beside a checklist that was plainly showing, and
clicking it wrote true and changed nothing visible. Clicking again wrote false and
changed nothing either. Dead in both directions, which is exactly what the
screenshot shows.

The two settings are a DEFAULT and an OVERRIDE, not two ways of saying yes:

  showChecklistAtMinicard === true   -> shown, whatever the board says
  showChecklistAtMinicard === false  -> hidden, whatever the board says
  showChecklistAtMinicard undefined  -> follow the board's default

An override needs three states, so the field loses `defaultValue: false`: with
every checklist born false, "hidden" and "not chosen" are the same value and the
override cannot exist. models/lib/minicardChecklistVisibility.js is the one rule,
used by the minicard, the popup's switch and the toggle - and the toggle now flips
what is ON SCREEN rather than the raw field, because flipping the field is what
made the first click do nothing.

Checklists written under the old default carry a false that meant "follow the
board". Left alone under the new reading it would mean "hide this one" and every
checklist would vanish from every minicard - the mirror image of the bug. The
schema-upgrade step checklist-minicard-unset clears exactly those, and it is the
one step there that must run ONCE EVER rather than once per version: afterwards a
stored false is somebody's choice, and re-running would put their checklists back.
It keeps its own marker beside the schema-upgrade one for that.

tests/minicardChecklistVisibility.test.cjs covers the reported case, the opposite
one, that two clicks return to the board default, and that only true and false are
opinions - a string, a number or a null from an old REST client or a bad import
must not quietly mean "hide". tests/schemaUpgradeSteps.test.cjs gains the step,
including the negative: after it has run, a false set by a person survives the next
release.

Verified by running both suites and the whole node suite (377 suites, 0 failed).
Not verified in a browser: this sandbox has none.

Thanks to xet7 !
2026-08-12 14:45:07 +03:00

52 lines
2.5 KiB
JavaScript

'use strict';
// Which checklists a minicard shows, and what the per-checklist toggle means.
//
// Reported by email with a screenshot (Swedish): "Även om jag avmarkerar 'Visa på
// minikort' (och vill dölja checklistan på minikortet)" - even after unchecking
// "Show on minicard" for a checklist, the checklist is still on the minicard.
//
// It was, for everybody. The board setting `allowsChecklistsOnMinicard` defaults to
// TRUE, and the minicard asked:
//
// board.allowsChecklistsOnMinicard || checklist.showChecklistAtMinicard
//
// An OR cannot be argued with: while the board setting is on, no value of the
// checklist's own field changes the answer. The popup made it look otherwise - it
// drew the switch from the raw field, which starts false, so the switch read OFF
// beside a checklist that was plainly showing, and clicking it set the field to true
// and changed nothing anybody could see. Clicking again set it back. The toggle was
// dead in both directions.
//
// The two settings are a DEFAULT and an OVERRIDE, not two ways of saying yes:
//
// checklist.showChecklistAtMinicard === true -> shown, whatever the board says
// checklist.showChecklistAtMinicard === false -> hidden, whatever the board says
// checklist.showChecklistAtMinicard undefined -> follow the board's default
//
// which is why the field lost its `defaultValue: false`. A stored false has to be
// able to mean "this one, hidden"; if every checklist is born with one, "hidden" and
// "not chosen" are the same value and the override cannot exist. Checklists written
// before this have a false that meant "follow the board" - migrations/ clears those,
// so nothing changes on screen for anyone who never touched the toggle.
//
// Pure and dependency-free so both the model and the tests can use it.
// Is this checklist shown on the minicard?
// checklist the checklist document (only showChecklistAtMinicard is read)
// boardAllows the board's allowsChecklistsOnMinicard default
function isChecklistShownAtMinicard(checklist, boardAllows) {
const own = checklist && checklist.showChecklistAtMinicard;
if (own === true || own === false) return own;
return boardAllows === true;
}
// What the toggle writes: the opposite of what is on screen NOW. Flipping the raw
// field instead is what made the first click do nothing when the board default was
// on (false -> true, still shown).
function toggledChecklistAtMinicard(checklist, boardAllows) {
return !isChecklistShownAtMinicard(checklist, boardAllows);
}
export { isChecklistShownAtMinicard, toggledChecklistAtMinicard };