feat(ScheduleView): maintain member order based on team line-up and fallback to alphabetical sorting
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 57s

This commit is contained in:
Torsten Schulz (local)
2026-09-22 14:44:17 +02:00
parent 2536143804
commit 57fe139e67

View File

@@ -1395,8 +1395,21 @@ export default {
? activeMembers.filter((member) => allowedIds.has(Number(member.id)))
: activeMembers;
// Sort members alphabetically by firstName then lastName (case-insensitive)
// Keep the order defined in the team line-up. Members from lower teams
// (which are also eligible) follow afterwards in their own line-up order.
const lineupPositionByMemberId = new Map(
eligibleMemberIds.map((id, index) => [Number(id), index])
);
const sortedVisibleMembers = (visibleMembers || []).slice().sort((a, b) => {
const positionA = lineupPositionByMemberId.get(Number(a.id));
const positionB = lineupPositionByMemberId.get(Number(b.id));
if (positionA != null || positionB != null) {
if (positionA == null) return 1;
if (positionB == null) return -1;
if (positionA !== positionB) return positionA - positionB;
}
// Fall back to an alphabetical order for members without a line-up position.
const fa = (a.firstName || '').toString().toLowerCase();
const fb = (b.firstName || '').toString().toLowerCase();
if (fa < fb) return -1;
@@ -1453,11 +1466,16 @@ export default {
}));
const ids = new Set();
lineupResponses.flat().forEach((assignment) => {
const memberId = Number(assignment?.memberId);
if (Number.isFinite(memberId)) {
ids.add(memberId);
}
lineupResponses.forEach((assignments) => {
assignments
.slice()
.sort((a, b) => Number(a?.position) - Number(b?.position))
.forEach((assignment) => {
const memberId = Number(assignment?.memberId);
if (Number.isFinite(memberId)) {
ids.add(memberId);
}
});
});
return Array.from(ids);
},