Files
wekan/models/lib/importParts.js
T
Lauri Ojansivu f0745dec4a One import page, for every source, with the same checkboxes the exports use.
The last piece of #1173: "combine all import options to same template". They
were fourteen - a link per source in a pop-over, each going to its own
address - and the page each landed on never said which other sources
existed, so "where do I import a Jira export" was answered by a menu
somewhere else, if you knew it was there.

All Boards / + Add Board / Import is now one full-width page listing every
source it can read: Trello, Jira, CSV/TSV, Excel, Kanboard, NextCloud Deck,
OpenProject, GitHub, GitLab, Gitea, Forgejo, Asana, Zenkit, and a previous
export of this WeKan - named with the Product name this instance is branded
with rather than with a product the reader has never seen.

Under the source picker are the same "what to include" checkboxes every
export offers, from the same list (models/lib/exportFields.js) and sharing
the very same selection state, so a part unticked for an export is unticked
here too. On this side they say what comes IN.

That works for every source without teaching five creators a selection each:
models/lib/importParts.js takes the unticked parts OUT of the parsed
document before any creator sees it, at the one point every source passes
through. A creator that never sees a comment cannot import one. Three things
that pruning gets right and are covered by tests:

- an unselected section is EMPTIED, not deleted - the creators read
  board.comments directly, and undefined is a crash where an empty array is
  "there were none";
- a source's own name for a part goes with it, since Trello calls its
  comments "actions";
- a key the list does not know about is left alone, rather than silently
  dropping data nobody asked about.

/import/:source still works, under its own route name, so every existing
link, bookmark and back button lands where it did. The pop-over keeps the one
import that is not a board: card dependencies.

Thanks to xet7 !
2026-08-14 01:25:26 +03:00

47 lines
1.9 KiB
JavaScript

'use strict';
// WHAT TO IMPORT, applied to the document before a creator sees it (#1173).
//
// The selection popup is one list, and on an export it says what goes out. On
// an IMPORT it says what comes in - and the honest way to make that true for
// every source is to take the parts out of the parsed document rather than to
// teach five creators (WeKan, Trello, Jira, CSV, Kanboard) a selection each.
// A creator that never sees a comment cannot import one.
//
// The keys are the ones a WeKan export writes, plus the names Trello and the
// Kanboard-shaped parsers use for the same things, because the pruning happens
// after parsing and before creation - the one point every source passes through.
//
// A section that is NOT in the selection is emptied, never deleted: the
// creators read `board.cards`, `board.checklists` and so on directly, and an
// undefined array is a crash where an empty one is "there were none".
// selection key -> the arrays it covers, whatever the source calls them
const PART_ARRAYS = {
comments: ['comments', 'cardComments', 'actions'],
checklists: ['checklists', 'checklistItems'],
attachments: ['attachments'],
'custom-fields': ['customFields'],
activities: ['activities'],
subtasks: ['subtaskItems'],
};
function pruneImportDocument(doc, fields) {
// No selection is "everything", the same rule every exporter follows.
if (!doc || typeof doc !== 'object' || !Array.isArray(fields) || fields.length === 0) {
return doc;
}
const wanted = new Set(fields);
// An array is only emptied when its key is a KNOWN part that was not chosen -
// an unknown key is somebody else's data and is left alone.
for (const [key, arrays] of Object.entries(PART_ARRAYS)) {
if (wanted.has(key)) continue;
for (const name of arrays) {
if (Array.isArray(doc[name])) doc[name] = [];
}
}
return doc;
}
export { pruneImportDocument, PART_ARRAYS };