MCPcopy Create free account
hub / github.com/code-pushup/cli / getSortableGroupByRef

Function getSortableGroupByRef

packages/utils/src/lib/reports/sorting.ts:61–90  ·  view source on GitHub ↗
(
  { plugin, slug, weight }: CategoryRef,
  plugins: ScoredReport['plugins'],
)

Source from the content-addressed store, hash-verified

59}
60
61export function getSortableGroupByRef(
62 { plugin, slug, weight }: CategoryRef,
63 plugins: ScoredReport['plugins'],
64): SortableGroup {
65 const groupPlugin = plugins.find(p => p.slug === plugin);
66 if (!groupPlugin) {
67 throwIsNotPresentError(`Plugin ${plugin}`, 'report');
68 }
69
70 const group = groupPlugin.groups?.find(
71 ({ slug: groupSlug }) => groupSlug === slug,
72 );
73 if (!group) {
74 throwIsNotPresentError(`Group ${slug}`, groupPlugin.slug);
75 }
76
77 const sortedAudits = getSortedGroupAudits(group, groupPlugin.slug, plugins);
78 const sortedAuditRefs = group.refs.toSorted((a, b) => {
79 const aIndex = sortedAudits.findIndex(ref => ref.slug === a.slug);
80 const bIndex = sortedAudits.findIndex(ref => ref.slug === b.slug);
81 return aIndex - bIndex;
82 });
83
84 return {
85 ...group,
86 refs: sortedAuditRefs,
87 plugin,
88 weight,
89 };
90}
91
92export function sortReport(report: ScoredReport): ScoredReport {
93 const { categories, plugins } = report;

Callers 3

categoriesDetailsSectionFunction · 0.85
sortReportFunction · 0.85

Calls 2

throwIsNotPresentErrorFunction · 0.85
getSortedGroupAuditsFunction · 0.85

Tested by

no test coverage detected