mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Two fixes to the #6465 inline Add List composer: 1) Save button did nothing. The inline composer calls createListAfter WITHOUT nextListId, but the server check() used Match.OneOf(String,null,undefined) (not Match.Optional) for it. Meteor check throws "Match failed [400]" on a MISSING object key unless the sub-pattern is Match.Optional, so every inline add-list 400'd. The omittable params (swimlaneId/afterListId/nextListId/type) are now Match.Optional, so callers may omit them. 2) Empty swimlane/board now shows a + button, and the create-list form appears only after clicking it (a swimlane that already has lists keeps using the per-list-header add-list button — no + button needed). The reveal is scoped to the clicked swimlane via a wekan-add-list-empty Session flag, cleared on save/close. Tests: models/lib/createListParams.js + tests/createListParams.test.cjs mirror the method's param contract (incl. Meteor's missing-key rule) with the exact client shapes + negatives, and a source guard that the check uses Match.Optional; tests/upcomingUiGuards.test.cjs gains guards for the empty-state + button reveal. Wired into test:unit:node.
46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// Contract for the `createListAfter` Meteor method params (server/models/lists.js),
|
|
// mirrored as a pure function so the exact param shapes the clients send can be
|
|
// unit-tested without a Meteor runtime.
|
|
//
|
|
// Crucially this models Meteor `check`'s object-pattern rule: a MISSING key is only
|
|
// allowed when its sub-pattern is Match.Optional. title/boardId are required Strings;
|
|
// swimlaneId/afterListId/nextListId/type are optional (may be absent, undefined, or
|
|
// — for the id fields — null). The #6465 inline add-list composer omits nextListId,
|
|
// which is exactly what regressed with the previous non-Optional check.
|
|
|
|
const REQUIRED_STRING = ['title', 'boardId'];
|
|
const OPTIONAL_ID = ['swimlaneId', 'afterListId', 'nextListId']; // string | null | undefined | absent
|
|
const OPTIONAL_STRING = ['type']; // string | undefined | absent
|
|
const ALLOWED = new Set([...REQUIRED_STRING, ...OPTIONAL_ID, ...OPTIONAL_STRING]);
|
|
|
|
function validateCreateListParams(params) {
|
|
if (!params || typeof params !== 'object' || Array.isArray(params)) return false;
|
|
|
|
for (const k of REQUIRED_STRING) {
|
|
if (typeof params[k] !== 'string') return false;
|
|
}
|
|
|
|
for (const k of OPTIONAL_ID) {
|
|
if (k in params) {
|
|
const v = params[k];
|
|
if (!(v === null || v === undefined || typeof v === 'string')) return false;
|
|
}
|
|
}
|
|
|
|
for (const k of OPTIONAL_STRING) {
|
|
if (k in params) {
|
|
const v = params[k];
|
|
if (!(v === undefined || typeof v === 'string')) return false;
|
|
}
|
|
}
|
|
|
|
for (const k of Object.keys(params)) {
|
|
if (!ALLOWED.has(k)) return false; // no unexpected keys (check() rejects extras)
|
|
}
|
|
return true;
|
|
}
|
|
|
|
module.exports = { validateCreateListParams };
|