fix(classifier): keep everything after "_" as one leaf when parsing a path
parseFolderLevels split the whole string on "-" and only looked for "_" in the last segment, so a date revision shattered: "LKU-123456-PM-SCH-0001_2025-11-17 (IFI)" became …/0001_2025/11/17 (IFI). Split on the "_" first instead — the tracking number (before "_") nests by "-", and everything AFTER the "_" is one leaf kept whole, hyphens and all. Test: the date-revision path yields …/0001/"2025-11-17 (IFI)". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
70c6946e56
commit
5f1df08077
2 changed files with 15 additions and 6 deletions
|
|
@ -467,12 +467,18 @@
|
|||
function parseFolderLevels(name) {
|
||||
var s = String(name == null ? '' : name).trim();
|
||||
if (!s) return [];
|
||||
var segs = s.split('-');
|
||||
var last = segs.pop();
|
||||
var u = last.indexOf('_');
|
||||
if (u >= 0) { segs.push(last.slice(0, u)); segs.push(last.slice(u + 1)); }
|
||||
else { segs.push(last); }
|
||||
return segs.map(function (x) { return x.trim(); }).filter(Boolean);
|
||||
var u = s.indexOf('_'); // the "_" separates the tracking number from the leaf
|
||||
if (u < 0) {
|
||||
// No "_" → a pure tracking-number path: nest by "-".
|
||||
return s.split('-').map(function (x) { return x.trim(); }).filter(Boolean);
|
||||
}
|
||||
// Tracking number (before "_") nests by "-"; everything AFTER the "_" is
|
||||
// ONE leaf, kept whole — the revision may itself contain hyphens, e.g. a
|
||||
// date revision "2025-11-17 (IFI)".
|
||||
var segs = s.slice(0, u).split('-').map(function (x) { return x.trim(); }).filter(Boolean);
|
||||
var leaf = s.slice(u + 1).trim();
|
||||
if (leaf) segs.push(leaf);
|
||||
return segs;
|
||||
}
|
||||
// Children array for a tracking node (or the roots for null), or null.
|
||||
function trackingChildren(parentId) {
|
||||
|
|
|
|||
|
|
@ -595,12 +595,15 @@ test('parseFolderLevels: split by - then a final _ into nested levels', async ({
|
|||
full: c.parseFolderLevels('BMB-187023-PM-MOM-0001_A (IFR)'),
|
||||
leafOnly: c.parseFolderLevels('A (IFR)'),
|
||||
noRev: c.parseFolderLevels('CPO-0001'),
|
||||
dateRev: c.parseFolderLevels('LKU-123456-PM-SCH-0001_2025-11-17 (IFI)'),
|
||||
};
|
||||
});
|
||||
expect(r.three).toEqual(['CPO', '0001', '0 (IFU)']);
|
||||
expect(r.full).toEqual(['BMB', '187023', 'PM', 'MOM', '0001', 'A (IFR)']);
|
||||
expect(r.leafOnly).toEqual(['A (IFR)']);
|
||||
expect(r.noRev).toEqual(['CPO', '0001']);
|
||||
// A date revision after "_" stays one leaf — its hyphens are NOT split.
|
||||
expect(r.dateRev).toEqual(['LKU', '123456', 'PM', 'SCH', '0001', '2025-11-17 (IFI)']);
|
||||
});
|
||||
|
||||
test('add-folder builds a nested chain sharing common ancestors', async ({ page }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue