All files / src/domain version-filter.ts

51.28% Statements 20/39
84.61% Branches 11/13
42.1% Functions 8/19
51.28% Lines 20/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  1x 1x     1x 1x 3x 3x 1x 1x     1x 1x 1x     1x 1x 1x 3x 3x 1x 1x                 1x 1x          
import type { UserStory } from "./types.js"
 
export function sortVersionIdsDesc(ids: string[]): string[] {
  return [...ids].sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))
}
 
export function sortVersionIdsAsc(ids: string[]): string[] {
  return [...ids].sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
}
 
export function versionIdsFromStories(stories: UserStory[]): string[] {
  return sortVersionIdsDesc([...new Set(stories.map((s) => s.version))])
}
 
/** Board default: latest version only. */
export function defaultSelectedVersionIds(versionIds: string[]): string[] {
  return versionIds.length > 0 ? [versionIds[0]] : []
}
 
/** Sprints/Epics default: all versions selected, oldest-first order. */
export function allSelectedVersionIds(versionIds: string[]): string[] {
  return sortVersionIdsAsc(versionIds)
}
 
export function filterStoriesByVersions(
  stories: UserStory[],
  selected: ReadonlySet<string>,
): UserStory[] {
  if (selected.size === 0) {
    return []
  }
  return stories.filter((s) => selected.has(s.version))
}
 
export function epicIdsForStories(stories: UserStory[]): string[] {
  return [...new Set(stories.map((s) => s.epic))].sort((a, b) =>
    a.localeCompare(b, undefined, { numeric: true }),
  )
}