Files
wekan/models/lib/sandstormAutoOpen.js
T
Lauri Ojansivu d6908cf418 Convert client-reachable CJS helpers from CommonJS to ES modules (2/2).
A transitive walk from client/main.js found the remaining CommonJS
(module.exports) helpers that the rspack client build pulls into the ES
module graph and rejects: 3 client/lib helpers (cardDragGeometry,
inlinedFormManager, popupOffset), 4 imports/lib helpers (boardAutoScroll,
datePickerTime, fileNameDisplay, staleWhileRevalidate), imports/simpleSchema
(its meteor/aldeed:simple-schema require becomes a namespace import),
imports/i18n/loadHelpers, and 4 more models/lib helpers (cardLinkRedirect,
sandstormAutoOpen, securityCategories, securityLogFormat). All become
`export { ... }`; their .cjs unit tests use `await import(...js)`.

The only CJS files still reachable in the walk are server-only: the
server/lib/* files (Meteor never bundles server/ to the client) and the
fs-using models/lib file-storage helpers (reached only via the server-side
fileStoreStrategy; they would fail on require("fs") if they were actually in
the client bundle). Those correctly stay CommonJS.

Full tests/*.test.cjs suite: same 7 pre-existing failures, no new ones.
2026-07-23 18:59:30 +03:00

57 lines
2.2 KiB
JavaScript

'use strict';
// Sandstorm "open one board on start" decision (#2220 follow-up). On Sandstorm the
// grain root ('/') renders All Boards, but historically a grain opened straight into
// its single board. This restores that as a convenience WITHOUT persisting anything:
//
// - a saved default board (a Home board the user explicitly chose) always wins
// -> redirect to it;
// - else, once boards have loaded, exactly ONE board -> just open it (NOT saved —
// setting a Home board is a separate, explicit user action on All Boards);
// - else (zero or many boards, no saved default) -> stay on All Boards.
//
// Kept pure + CommonJS so the branching is unit-testable; the client autorun
// (config/router.js) feeds it reactive inputs and performs the returned action.
//
// Inputs:
// userReady - Meteor.userId() has landed (grain login is async)
// savedDefaultId - the user's profile.defaultBoardId, or falsy
// boardsReady - the boards subscription is ready (count is trustworthy)
// boardCount - number of the user's visible boards
// onlyBoardId - the single board's _id when boardCount === 1
//
// Returns one of:
// { action: 'wait' } - inputs not ready yet
// { action: 'redirect', boardId } - open boardId (nothing is persisted)
// { action: 'stay' } - remain on All Boards
function decideSandstormAutoOpen(input) {
const {
userReady,
savedDefaultId,
boardsReady,
boardCount,
onlyBoardId,
} = input || {};
if (!userReady) return { action: 'wait' };
// A saved Home board (explicitly chosen by the user) always wins.
if (savedDefaultId) {
return { action: 'redirect', boardId: savedDefaultId };
}
// Need the board list loaded before counting, otherwise "0 boards" is ambiguous.
if (!boardsReady) return { action: 'wait' };
// Exactly one board -> just open it. Nothing is saved: choosing a Home board is a
// separate, explicit action (the All Boards home toggle, #2220).
if (boardCount === 1 && onlyBoardId) {
return { action: 'redirect', boardId: onlyBoardId };
}
// Zero or many boards, and nothing saved -> All Boards.
return { action: 'stay' };
}
export { decideSandstormAutoOpen };