Files
lincodex/frontend/src/entities/match/model/views.ts
T

39 lines
1.5 KiB
TypeScript

import type { SpecializationCode } from "../../../shared/api/schemas";
import type { MatchCardModel } from "./adapter";
import { specializationCodes } from "./labels";
/** The view that shows every specialization, each entry labelled with its own. */
export const allSpecializationsView = "all";
export type SpecializationView = typeof allSpecializationsView | SpecializationCode;
/** Stable key of one entry: one candidate under one specialization. */
export function matchCardKey(card: Pick<MatchCardModel, "candidateHandle" | "specialization">) {
return `${card.candidateHandle}:${card.specialization}`;
}
/** Specializations that occur in the result, in catalog order. */
export function specializationsInResult(cards: readonly MatchCardModel[]): SpecializationCode[] {
const present = new Set(cards.map((card) => card.specialization));
return specializationCodes.filter((code) => present.has(code));
}
/**
* Entries of one specialization view. Selecting a specialization only hides
* the others; the server order inside each group is kept and no entry
* borrows a confirmation from another specialization.
*/
export function cardsForView(
cards: readonly MatchCardModel[],
view: SpecializationView,
): MatchCardModel[] {
return view === allSpecializationsView
? [...cards]
: cards.filter((card) => card.specialization === view);
}
/** Short display form of an opaque handle; the full handle is used for requests only. */
export function shortHandle(handle: string): string {
return "LX-" + handle.slice(-8);
}