All files / src/apps/user/pages/knowledge/recommendations RecommendationsCard.tsx

83.33% Statements 5/6
70% Branches 7/10
100% Functions 1/1
80% Lines 4/5

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                            3x             72x 72x 72x                            
import { SectionCard } from "@/components/detail";
import type { RecommendationPrefill } from "@/objects/Knowledge";
import { Lightbulb } from "lucide-react";
import React from "react";
import RecommendationList, {
  type RecommendationScope,
  useKnowledgeRecommendations,
} from "./RecommendationList";
 
/**
 * A page's recommendations in a panel of their own, drawn only when there
 * is something to recommend: a repository's Overview, an agent's Knowledge
 * tab. The list and this card read one query.
 */
const RecommendationsCard: React.FC<
  RecommendationScope & {
    title: string;
    description: string;
    onAttach?: (prefill: RecommendationPrefill) => void;
  }
> = ({ title, description, onAttach, ...scope }) => {
  const { data } = useKnowledgeRecommendations(scope);
  const count = data?.items.length ?? 0;
  Eif (!count && !Object.keys(data?.unavailable ?? {}).length) return null;
  return (
    <SectionCard
      icon={Lightbulb}
      title={title}
      subtitle={count || undefined}
      description={description}
    >
      <RecommendationList {...scope} onAttach={onAttach} empty={null} />
    </SectionCard>
  );
};
 
export default RecommendationsCard;