All files / src/features/Settings/Team/helpers memberSuggestions.ts

100% Statements 10/10
100% Branches 6/6
100% Functions 3/3
100% Lines 7/7

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          2x               2x       13x 13x 21x   6x     18x          
export type MemberSuggestion = {
  email: string;
  name: string;
};
 
const MAX_SUGGESTIONS = 5;
 
/**
 * GB-21471 — filter existing team members to suggest while the PAH types a new
 * owner's email in the Change PAH modal. Matches name or email substring,
 * hides once the query already equals an option's email (nothing left to pick),
 * and caps the list so the dropdown stays compact.
 */
export const filterMemberSuggestions = (
  options: MemberSuggestion[],
  query: string,
): MemberSuggestion[] => {
  const q = query.trim().toLowerCase();
  if (!q) return [];
  if (options.some((o) => o.email.toLowerCase() === q)) return [];
 
  return options
    .filter(
      (o) =>
        o.email.toLowerCase().includes(q) ||
        o.name.toLowerCase().includes(q),
    )
    .slice(0, MAX_SUGGESTIONS);
};