import { useState, type ReactNode } from "react"; import { History } from "lucide-react"; import { useFieldHistory, useFieldHistoryScope } from "../FieldHistory/FieldHistoryProvider"; import { FieldHistoryModal } from "../FieldHistory/FieldHistoryModal"; import { isEmptyFieldValue } from "../../utils/fieldHistory/isEmptyFieldValue"; /** A profile section's read view: rows holding one field, or two short ones side by side. */ export const ProfileRows = ({ children }: { children: ReactNode }) => (
{children}
); export const ProfileRow = ({ children }: { children: ReactNode }) => (
{children}
); /** The label; while the section's history is on, a changed field's label opens its history. */ const ProfileFieldLabel = ({ label, path }: { label: string; path?: string }) => { const scope = useFieldHistoryScope(); const { isActive, getFieldHistory, attributionFor } = useFieldHistory(); const [open, setOpen] = useState(false); const timeline = isActive && scope?.id && path ? getFieldHistory(scope.resourceType, scope.id, path, label) : null; if (!timeline) return {label}; return ( <> setOpen(false)} layout="list" attribution={scope?.id ? attributionFor(scope.resourceType, scope.id) : undefined} /> ); }; export interface ProfileFieldProps { label: string; value?: ReactNode; path?: string; /** What a blank value reads as; a dash unless the question simply was not answered. */ empty?: string; children?: ReactNode; } export const ProfileField = ({ label, value, path, empty = "—", children }: ProfileFieldProps) => { const blank = children === undefined && isEmptyFieldValue(value); return (
{children ?? ( {blank ? empty : value} )}
); }; /** One labelled control in a section's edit form; `wide` spans both columns. */ export const ProfileInput = ({ id, label, wide = false, children, }: { id?: string; label: string; wide?: boolean; children: ReactNode; }) => (
{id ? : {label}} {children}
);