qi-blood-fluids #74
|
|
@ -13,6 +13,7 @@ import { Spacing } from "@/theme/spacing";
|
||||||
import { ContentLink } from "../../components/navigation/ContentLink";
|
import { ContentLink } from "../../components/navigation/ContentLink";
|
||||||
import { parseNavigableContentReference } from "../../utils/content-reference";
|
import { parseNavigableContentReference } from "../../utils/content-reference";
|
||||||
import { humanizeKey } from "../helpers/value";
|
import { humanizeKey } from "../helpers/value";
|
||||||
|
import { BulletList } from "./BulletList";
|
||||||
|
|
||||||
export interface ContentValueProps {
|
export interface ContentValueProps {
|
||||||
value: unknown;
|
value: unknown;
|
||||||
|
|
@ -20,6 +21,28 @@ export interface ContentValueProps {
|
||||||
emptyText?: string | null;
|
emptyText?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseBullets(text: string): string[] {
|
||||||
|
if (text.includes("\n")) {
|
||||||
|
return text
|
||||||
|
.split("\n")
|
||||||
|
.map((s) => s.replace(/^[•\-\*\d+\.]\s*/, "").trim())
|
||||||
|
.filter((s) => s.length > 0);
|
||||||
|
}
|
||||||
|
if (text.includes(";")) {
|
||||||
|
return text
|
||||||
|
.split(";")
|
||||||
|
.map((s) => s.trim().replace(/^and\s+/i, ""))
|
||||||
|
.filter((s) => s.length > 0);
|
||||||
|
}
|
||||||
|
const parts = text.split(/,\s*(?![^()]*\))/);
|
||||||
|
if (parts.length > 1) {
|
||||||
|
return parts
|
||||||
|
.map((s) => s.trim().replace(/\.$/, "").replace(/^and\s+/i, ""))
|
||||||
|
.filter((s) => s.length > 0);
|
||||||
|
}
|
||||||
|
return [text];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference-aware fallback renderer for arbitrary nested attribute values.
|
* Reference-aware fallback renderer for arbitrary nested attribute values.
|
||||||
*
|
*
|
||||||
|
|
@ -54,6 +77,10 @@ export function ContentValue({
|
||||||
) : null;
|
) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (visible.every((item) => typeof item === "string")) {
|
||||||
|
return <BulletList items={visible as string[]} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.stack}>
|
<View style={styles.stack}>
|
||||||
{visible.map((item, index) => (
|
{visible.map((item, index) => (
|
||||||
|
|
@ -84,12 +111,32 @@ export function ContentValue({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.object}>
|
<View style={styles.object}>
|
||||||
{entries.map(([key, child]) => (
|
{entries.map(([key, child]) => {
|
||||||
<View key={key} style={styles.objectRow}>
|
const isClinical =
|
||||||
<Text style={styles.objectLabel}>{humanizeKey(key)}</Text>
|
key.toLowerCase().includes("clinical") ||
|
||||||
<ContentValue value={child} textStyle={textStyle} />
|
key.toLowerCase().includes("manifestation");
|
||||||
</View>
|
|
||||||
))}
|
const renderChild = () => {
|
||||||
|
if (
|
||||||
|
isClinical &&
|
||||||
|
typeof child === "string" &&
|
||||||
|
child.trim().length > 0
|
||||||
|
) {
|
||||||
|
const bullets = parseBullets(child);
|
||||||
|
if (bullets.length > 1) {
|
||||||
|
return <BulletList items={bullets} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return <ContentValue value={child} textStyle={textStyle} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View key={key} style={styles.objectRow}>
|
||||||
|
<Text style={styles.objectLabel}>{humanizeKey(key)}</Text>
|
||||||
|
{renderChild()}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue