All files / src/components/collection sections.ts

100% Statements 1/1
100% Branches 0/0
100% Functions 1/1
100% Lines 1/1

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                                                              759x    
import { CollectionViewProps } from "@/components/collection/CollectionView";
import React from "react";
 
/** A titled group within the body — e.g. "Your Skills" / "System Skills".
 *  Each carries its own items and empty state (and may override `loading`,
 *  for groups that arrive from different queries); the toolbar above filters
 *  them all. */
export interface ResourceCollectionSection<T>
  extends Omit<CollectionViewProps<T>, "view" | "filtered"> {
  label: string;
  /** A quiet line after the label: what the group is ("Before the model
   *  reads the request"). */
  hint?: React.ReactNode;
  /** Defaults to the section's item count. */
  count?: number;
  /** Right-aligned action on the section heading. */
  action?: React.ReactNode;
  /** Hide the whole section (heading included) when it has no items and
   *  nothing is loading — for a group that simply does not apply yet. */
  hideWhenEmpty?: boolean;
}
 
/**
 * Type-erase one section so groups of *different* types can share a body —
 * a page's own skills beside the platform's system skills, custom tools
 * beside built-ins. The renderers are still checked against `T` here, at the
 * call site, which is the only place that knows what the group holds.
 */
export function collectionSection<T>(
  section: ResourceCollectionSection<T>,
): ResourceCollectionSection<unknown> {
  return section as unknown as ResourceCollectionSection<unknown>;
}