mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The "Selected: star" button only ever ADDED stars: it walked the selection and starred whatever was not starred yet. Once every selected board was starred it did nothing at all, so there was no way to undo from here what it had just done, and its tooltip read "Star the selected boards" whatever state the selection was in. It is a toggle now - none starred stars them all, all starred unstars them all, and a mixed selection stars the rest, leaving the starred alone. The mixed case deliberately does not flip each board independently: one click that starred some boards and un-starred others is not something a button may do. Only the boards that must change are called, because toggleBoardStar flips one board and calling it for an already-starred one would un-star it. The tooltip says which way the button goes right now, set-selected-starred or the new set-selected-unstarred, and it reads the SAME function the click does - two copies of "which way does this button go" would eventually be two answers, and the tooltip would lie about what the click does. The rule itself is models/lib/selectedStars.js: pure, so it is unit-tested rather than reasoned about, including the mixed case and an empty or junk selection. All four buttons on a selection are icon-only now, and they follow the "Selected:" label in the order star, home, archive, duplicate - the two that only mark a board first, the two that change what boards exist last. Archive and duplicate carried their names, which are sentences and pushed the bar onto a second row. Checking that each button says what it is turned up one that did not: the close button that turns Multi-Selection off said "Clear filter", which is what the OTHER one in this bar does, in the search box. It is multi-selection-off now. A guard requires every .board-header-btn in the bar to carry a title, and every title to come out of a translation key rather than being literal English. Both new keys are in all 147 language files as English placeholders, which is what the translation policy does with a string untranslated everywhere, so no language silently loses a tooltip. The seven language files that are symlinks share their target's copy rather than getting a second one, and the 43 files that have no trailing newline still have none. The Font Awesome guard flagged a character in a jade COMMENT, which renders nothing - the same exemption it already makes for arrows and box drawing. It skips comment blocks now, tracked by indentation so a continuation line is skipped too, with a self-check that a rendered line is still caught. Thanks to xet7 !
57 lines
2.3 KiB
JavaScript
57 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
// Which way the "Selected: ★" button goes, and which boards it has to touch.
|
|
//
|
|
// The button used to only ever ADD stars: it walked the selection and starred
|
|
// whatever was not starred yet, so once every selected board was starred there
|
|
// was no way to undo it from here - clicking again did nothing at all.
|
|
//
|
|
// It is a toggle now, and the rule is the one a mixed selection makes obvious:
|
|
//
|
|
// every selected board is starred -> UNSTAR all of them
|
|
// none of them is starred -> star all of them
|
|
// some are starred, some are not -> star the REST, leaving the rest alone
|
|
//
|
|
// So "star" is the action whenever there is anything left to star, and the
|
|
// boards to touch are exactly the unstarred ones; "unstar" happens only when
|
|
// there is nothing left to star, and then every selected board is touched. The
|
|
// mixed case deliberately does NOT flip each board independently: that would
|
|
// star some and unstar others from one click, which no button should do.
|
|
//
|
|
// Pure: no Meteor, no collections, so it can be unit-tested and so the click
|
|
// handler and the tooltip cannot answer this question differently.
|
|
|
|
const SELECTED_STAR_STAR = 'star';
|
|
const SELECTED_STAR_UNSTAR = 'unstar';
|
|
|
|
// boardIds: the selected board ids. isStarred(id): whether that board is
|
|
// starred by the current user.
|
|
// Returns { action, boardIds } - the ids being the ones to TOGGLE, which is
|
|
// what the server method does to one board.
|
|
function selectedStarAction(boardIds, isStarred) {
|
|
const ids = (Array.isArray(boardIds) ? boardIds : []).filter(Boolean);
|
|
if (!ids.length) {
|
|
// Nothing selected: the button is not drawn, but a caller must still get an
|
|
// answer it can act on rather than undefined.
|
|
return { action: SELECTED_STAR_STAR, boardIds: [] };
|
|
}
|
|
const unstarred = ids.filter(id => !isStarred(id));
|
|
return unstarred.length
|
|
? { action: SELECTED_STAR_STAR, boardIds: unstarred }
|
|
: { action: SELECTED_STAR_UNSTAR, boardIds: ids };
|
|
}
|
|
|
|
// The translation key for what a click would do right now.
|
|
function selectedStarTitleKey(action) {
|
|
return action === SELECTED_STAR_UNSTAR
|
|
? 'set-selected-unstarred'
|
|
: 'set-selected-starred';
|
|
}
|
|
|
|
module.exports = {
|
|
SELECTED_STAR_STAR,
|
|
SELECTED_STAR_UNSTAR,
|
|
selectedStarAction,
|
|
selectedStarTitleKey,
|
|
};
|