All files / src/apps/user/pages/knowledge/source SourceContent.tsx

80% Statements 4/5
76.47% Branches 13/17
50% Functions 1/2
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                        2x             33x 33x   33x                                                                                        
import { SectionCard } from "@/components/detail";
import type { Knowledge, KnowledgeStats } from "@/objects/Knowledge";
import React from "react";
 
import FindSourcesPanel from "../FindSourcesPanel";
import GraphKnowledgeSection from "../GraphKnowledgeSection";
import { sourceType } from "../sourceTypes";
import WebKnowledgeSection from "../WebKnowledgeSection";
import ConfigField from "./ConfigField";
import DocumentsBreakdown from "./DocumentsBreakdown";
import DocumentsSection from "./DocumentsSection";
import WebInsights from "./web/WebInsights";
 
/**
 * What a source holds, per type, with everything that changes it: a file
 * source's documents (upload, import from a link, folders, reindex), a
 * website's crawls and page history, a graph's canvas, a database's or API's
 * configuration. An empty source the viewer may change can find its own
 * material first.
 */
const SourceContent: React.FC<{
  knowledge: Knowledge;
  stats: KnowledgeStats | null;
  mayChange: boolean;
  empty: boolean;
  editHref: string;
}> = ({ knowledge, stats, mayChange, empty, editHref }) => {
  const meta = sourceType(knowledge.source_type);
  const config = knowledge.source_config ?? {};
 
  return (
    <div className="space-y-5">
      {mayChange && empty && <FindSourcesPanel knowledge={knowledge} />}
 
      {knowledge.source_type === "file" && (
        <>
          <DocumentsBreakdown knowledgeId={knowledge.id} stats={stats} />
          <DocumentsSection knowledgeId={knowledge.id} readOnly={!mayChange} />
        </>
      )}
 
      {knowledge.source_type === "graph" && (
        <GraphKnowledgeSection knowledgeId={knowledge.id} readOnly={!mayChange} />
      )}
 
      {knowledge.source_type === "web" && (
        <>
          <WebInsights knowledge={knowledge} />
          <WebKnowledgeSection knowledge={knowledge} editHref={editHref} readOnly={!mayChange} />
        </>
      )}
 
      {knowledge.source_type !== "file" &&
        knowledge.source_type !== "graph" &&
        knowledge.source_type !== "web" && (
          <SectionCard icon={meta.Icon} title="Source configuration">
            {Object.keys(config).length > 0 ? (
              <div>
                {Object.entries(config).map(([key, value]) => (
                  <ConfigField key={key} fieldKey={key} value={value} />
                ))}
              </div>
            ) : (
              <p className="text-sm text-gray-400 dark:text-gray-500 italic">
                No configuration stored.
              </p>
            )}
          </SectionCard>
        )}
    </div>
  );
};
 
export default SourceContent;