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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | 7x 69x 7x 71x 71x 7x 165x 7x 45x 45x 39x 6x 7x 55x 7x 5x 25x 5x 5x 5x 5x 5x | import { SparkBars } from "@/components/charts";
import { MeterBar, Skeleton, StatusBadge } from "@/components/detail";
import React from "react";
import { CATEGORY_CHIP, knowledgeCategory } from "./categories";
import { citationTitles, indexedShare } from "./figures";
import { SOURCE_HEALTH, SOURCE_HEALTH_LABEL } from "./scales";
import { SOURCE_TYPE_KEYS, sourceType } from "./sourceTypes";
/**
* The figures a knowledge card or row shows, shared by the Repositories and
* Sources lists so the two read alike: where it stands, what it holds, how
* much of it is searchable, and how often answers cite it.
*/
/** Where it stands, with why when it needs attention. */
export const HealthBadge: React.FC<{ health: string; reasons?: string[] }> = ({
health,
reasons = [],
}) => (
<span title={reasons.length ? reasons.join(" · ") : undefined}>
<StatusBadge
status={health}
scale={SOURCE_HEALTH}
label={SOURCE_HEALTH_LABEL[health] ?? health}
/>
{reasons.length > 0 && <span className="sr-only">: {reasons.join("; ")}</span>}
</span>
);
/** What kind of knowledge a repository holds: a neutral chip with its icon,
* explained on hover. A category is what it is for, not a status. */
export const CategoryBadge: React.FC<{ category?: string | null }> = ({
category,
}) => {
const meta = knowledgeCategory(category);
return (
<span className={CATEGORY_CHIP} title={`${meta.purpose} ${meta.use}`}>
<meta.Icon className="size-3" aria-hidden="true" />
{meta.label}
</span>
);
};
/** One labelled figure in a card's strip. */
export const Figure: React.FC<{
label: string;
loading?: boolean;
children: React.ReactNode;
}> = ({ label, loading, children }) => (
<div className="min-w-0">
<div className="text-[10px] font-medium uppercase tracking-wide text-gray-400 dark:text-gray-500">
{label}
</div>
<div className="mt-1 min-w-0">
{loading ? <Skeleton className="h-4 w-16" /> : children}
</div>
</div>
);
/** How much of what it holds is indexed: a meter and the count. */
export const IndexedFigure: React.FC<{
indexed: number;
total: number;
noun: string;
}> = ({ indexed, total, noun }) => {
const share = indexedShare(indexed, total);
if (share === null) {
return <span className="text-sm text-gray-400 dark:text-gray-500">Nothing yet</span>;
}
return (
<div className="space-y-1">
<MeterBar
share={share}
tone={share >= 1 ? "ok" : "info"}
label={`${indexed.toLocaleString()} of ${total.toLocaleString()} ${noun} indexed`}
/>
<div className="text-xs text-gray-600 dark:text-gray-300 tabular-nums truncate">
{indexed.toLocaleString()}
<span className="text-gray-400 dark:text-gray-500">
{" "}
of {total.toLocaleString()}
</span>
</div>
</div>
);
};
/** Answers citing it, per day over 30 days, and how many; with `retrieved`,
* how many answers its passages were given to, so a source retrieved often
* and seldom cited reads as one. */
export const CitationsFigure: React.FC<{
daily: number[];
total: number;
retrieved?: number;
}> = ({ daily, total, retrieved }) => (
<div className="flex items-end gap-2 min-w-0">
{daily.length > 0 && (
<SparkBars
values={daily}
titles={citationTitles(daily)}
label="Answers citing it, per day over 30 days"
/>
)}
<span
className={`text-sm font-semibold tabular-nums ${
total > 0 ? "text-gray-900 dark:text-gray-100" : "text-gray-400 dark:text-gray-500"
}`}
>
{total.toLocaleString()}
</span>
{retrieved ? (
<span
className="text-xs text-gray-400 dark:text-gray-500 tabular-nums whitespace-nowrap"
title="Answers its passages were given to, last 30 days (agent chat)"
>
· {retrieved.toLocaleString()} retrieved
</span>
) : null}
</div>
);
/** What a repository holds, by type: each type's icon and count, in the
* registry's order. Named, not tinted. */
export const TypeMix: React.FC<{ byType: Record<string, number> }> = ({ byType }) => {
const keys = [
...SOURCE_TYPE_KEYS.filter((k) => byType[k]),
...Object.keys(byType).filter((k) => !SOURCE_TYPE_KEYS.includes(k)),
];
Iif (!keys.length) return null;
return (
<ul className="flex flex-wrap gap-1.5" aria-label="Sources by type">
{keys.map((key) => {
const { Icon, label } = sourceType(key);
return (
<li
key={key}
title={label}
className="inline-flex items-center gap-1 rounded-md border border-gray-200 dark:border-gray-600 px-1.5 py-0.5 text-[11px] text-gray-600 dark:text-gray-300"
>
<Icon className="size-3 text-gray-400" aria-hidden="true" />
<span className="tabular-nums">{byType[key]}</span>
<span className="sr-only">{label}</span>
</li>
);
})}
</ul>
);
};
|