Merge pull request 'extra-ordinary-vessel' (#70) from extra-ordinary-vessel into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-mobile-ui/pulls/70 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
eee9b3b380
|
|
@ -22,7 +22,15 @@ export function ModuleCatalogCardRenderer({
|
||||||
}: CollectionItemRendererProps) {
|
}: CollectionItemRendererProps) {
|
||||||
const attributes = item.attributes;
|
const attributes = item.attributes;
|
||||||
const title = asString(attributes.name) || item.title;
|
const title = asString(attributes.name) || item.title;
|
||||||
const label = asString(attributes.content_label) || item.summary || null;
|
const label =
|
||||||
|
asString(attributes.sub_title) ||
|
||||||
|
asString(attributes.content_label) ||
|
||||||
|
(asString(attributes.title) && asString(attributes.title) !== title
|
||||||
|
? asString(attributes.title)
|
||||||
|
: null) ||
|
||||||
|
asString(attributes.description) ||
|
||||||
|
item.summary ||
|
||||||
|
null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,195 @@
|
||||||
|
import React, { useMemo } from "react";
|
||||||
|
import { ScrollView, StyleSheet } from "react-native";
|
||||||
|
|
||||||
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
|
import {
|
||||||
|
bareAttributeKey,
|
||||||
|
findAttributePresentationRule,
|
||||||
|
getEmptyDisplayText,
|
||||||
|
presentationDisplayOrder,
|
||||||
|
shouldRenderAttribute,
|
||||||
|
} from "../../utils/attribute-presentation";
|
||||||
|
import {
|
||||||
|
asRecord,
|
||||||
|
asString,
|
||||||
|
asStringArray,
|
||||||
|
humanizeKey,
|
||||||
|
} from "../helpers/value";
|
||||||
|
import { BulletList } from "../shared/BulletList";
|
||||||
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
|
import { ContentValue } from "../shared/ContentValue";
|
||||||
|
import { Hero } from "../shared/Hero";
|
||||||
|
import { ImageGallery } from "../shared/ImageGallery";
|
||||||
|
import { ObjectSections } from "../shared/ObjectSections";
|
||||||
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
|
|
||||||
|
const RESERVED_KEYS = new Set([
|
||||||
|
"name",
|
||||||
|
"title",
|
||||||
|
"sub_title",
|
||||||
|
"subtitle",
|
||||||
|
"code",
|
||||||
|
"sort_order",
|
||||||
|
"link",
|
||||||
|
"images",
|
||||||
|
"media",
|
||||||
|
"point_images",
|
||||||
|
]);
|
||||||
|
|
||||||
|
function toParagraphs(value: unknown): string[] {
|
||||||
|
if (!value) return [];
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.map(asString).filter(Boolean);
|
||||||
|
}
|
||||||
|
const str = asString(value);
|
||||||
|
if (!str) return [];
|
||||||
|
return str.split(/\n+/).map((s) => s.trim()).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ExtraOrdinaryVesselsDetailRenderer({
|
||||||
|
content,
|
||||||
|
data,
|
||||||
|
definitions,
|
||||||
|
presentationAttributes,
|
||||||
|
}: DetailRendererProps) {
|
||||||
|
const title =
|
||||||
|
asString(data.name) ||
|
||||||
|
asString(data.title) ||
|
||||||
|
content.title;
|
||||||
|
|
||||||
|
const subtitle =
|
||||||
|
asString(data.sub_title) ||
|
||||||
|
asString(data.subtitle) ||
|
||||||
|
undefined;
|
||||||
|
|
||||||
|
const mediaValue = data.images ?? data.media ?? data.point_images;
|
||||||
|
const media = Array.isArray(mediaValue)
|
||||||
|
? mediaValue.filter(
|
||||||
|
(item): item is Record<string, unknown> =>
|
||||||
|
item !== null && typeof item === "object" && !Array.isArray(item),
|
||||||
|
)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const orderedAttributes = useMemo(() => {
|
||||||
|
const rootDefinitions = definitions.filter((definition) => definition.is_root);
|
||||||
|
const definitionByBareKey = new Map(
|
||||||
|
rootDefinitions.map((definition) => [
|
||||||
|
definition.code || bareAttributeKey(definition.attribute_key),
|
||||||
|
definition,
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
const contractIndex = new Map(
|
||||||
|
presentationAttributes.map((rule, index) => [rule.attribute_key, index]),
|
||||||
|
);
|
||||||
|
|
||||||
|
const keys: string[] = [];
|
||||||
|
const seen = new Set<string>();
|
||||||
|
|
||||||
|
for (const definition of rootDefinitions) {
|
||||||
|
const key = definition.code || bareAttributeKey(definition.attribute_key);
|
||||||
|
if (!key || seen.has(key)) continue;
|
||||||
|
seen.add(key);
|
||||||
|
keys.push(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for attributes in data that may not have root definitions
|
||||||
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
if (!seen.has(key) && value !== null && value !== undefined && value !== "") {
|
||||||
|
seen.add(key);
|
||||||
|
keys.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys
|
||||||
|
.flatMap((key) => {
|
||||||
|
if (RESERVED_KEYS.has(key)) return [];
|
||||||
|
|
||||||
|
const value = data[key];
|
||||||
|
const definition = definitionByBareKey.get(key);
|
||||||
|
const rule = findAttributePresentationRule(
|
||||||
|
definition?.attribute_key ?? key,
|
||||||
|
presentationAttributes,
|
||||||
|
);
|
||||||
|
if (rule && !shouldRenderAttribute(value, rule)) return [];
|
||||||
|
|
||||||
|
const label =
|
||||||
|
definition?.label?.trim() ||
|
||||||
|
humanizeKey(key);
|
||||||
|
const emptyText = getEmptyDisplayText(value, rule);
|
||||||
|
const index = rule ? contractIndex.get(rule.attribute_key) ?? 0 : 0;
|
||||||
|
const order = presentationDisplayOrder(rule, definition?.sort_order, index);
|
||||||
|
|
||||||
|
return [{ key, label, value, emptyText, order }];
|
||||||
|
})
|
||||||
|
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
||||||
|
}, [data, definitions, presentationAttributes]);
|
||||||
|
|
||||||
|
const renderAttributeValue = (key: string, value: unknown, emptyText: string | null) => {
|
||||||
|
if (key === "clinical_manifestation" || key === "clinical_manifestations") {
|
||||||
|
const items = Array.isArray(value)
|
||||||
|
? asStringArray(value)
|
||||||
|
: typeof value === "string"
|
||||||
|
? value
|
||||||
|
.split(/,\s*(?![^()]*\))/)
|
||||||
|
.map((s) => s.trim().replace(/\.$/, ""))
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
if (items.length > 0) {
|
||||||
|
return <BulletList items={items} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
const strings = asStringArray(value);
|
||||||
|
if (strings.length > 0) {
|
||||||
|
return <BulletList items={strings} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
||||||
|
return <ObjectSections value={asRecord(value)} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const paragraphs = toParagraphs(value);
|
||||||
|
if (paragraphs.length > 0) {
|
||||||
|
return <Paragraphs items={paragraphs} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <ContentValue value={value} emptyText={emptyText ?? undefined} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
contentContainerStyle={styles.content}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
>
|
||||||
|
<Hero title={title} subtitle={subtitle} />
|
||||||
|
|
||||||
|
{media.length > 0 ? <ImageGallery images={media} /> : null}
|
||||||
|
|
||||||
|
{orderedAttributes.map((attribute) => (
|
||||||
|
<SectionCard key={attribute.key} title={attribute.label}>
|
||||||
|
{renderAttributeValue(attribute.key, attribute.value, attribute.emptyText)}
|
||||||
|
</SectionCard>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<ContentLinkAttributeSections
|
||||||
|
data={data}
|
||||||
|
definitions={definitions}
|
||||||
|
presentationAttributes={presentationAttributes}
|
||||||
|
/>
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
content: {
|
||||||
|
paddingHorizontal: 18,
|
||||||
|
paddingTop: 16,
|
||||||
|
paddingBottom: 40,
|
||||||
|
gap: 14,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
@ -6,4 +6,16 @@ import { asString } from "../helpers/value";
|
||||||
import { Hero } from "../shared/Hero"; import { ImageGallery } from "../shared/ImageGallery";
|
import { Hero } from "../shared/Hero"; import { ImageGallery } from "../shared/ImageGallery";
|
||||||
import { KeyValueGrid } from "../shared/KeyValueGrid";
|
import { KeyValueGrid } from "../shared/KeyValueGrid";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
export function IndexEntryDetailRenderer({content,data,definitions,presentationAttributes}:DetailRendererProps){ return <ScrollView contentContainerStyle={{paddingHorizontal:18,paddingTop:16,paddingBottom:40,gap:14}}><Hero title={content.title}/><ImageGallery images={[]}/><SectionCard title="Details"><KeyValueGrid rows={Object.entries(data).filter(([,v])=>typeof v==="string"||typeof v==="number").map(([k,v])=>({label:k,value:String(v)}))}/></SectionCard><ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/></ScrollView>; }
|
export function IndexEntryDetailRenderer({content,data,definitions,presentationAttributes}:DetailRendererProps){
|
||||||
|
const subtitle = asString(data.sub_title) || asString(data.subtitle) || undefined;
|
||||||
|
return (
|
||||||
|
<ScrollView contentContainerStyle={{paddingHorizontal:18,paddingTop:16,paddingBottom:40,gap:14}}>
|
||||||
|
<Hero title={content.title} subtitle={subtitle}/>
|
||||||
|
<ImageGallery images={[]}/>
|
||||||
|
<SectionCard title="Details">
|
||||||
|
<KeyValueGrid rows={Object.entries(data).filter(([,v])=>typeof v==="string"||typeof v==="number").map(([k,v])=>({label:k,value:String(v)}))}/>
|
||||||
|
</SectionCard>
|
||||||
|
<ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/>
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ import { ThreeBurnersCollectionRenderer, ThreeBurnersCardRenderer } from "./coll
|
||||||
import { ThreeBurnersDetailRenderer } from "./details/ThreeBurnersDetailRenderer";
|
import { ThreeBurnersDetailRenderer } from "./details/ThreeBurnersDetailRenderer";
|
||||||
import { SixStagesDetailRenderer } from "./details/SixStagesDetailRenderer";
|
import { SixStagesDetailRenderer } from "./details/SixStagesDetailRenderer";
|
||||||
import { TcmPatternDetailRenderer } from "./details/TcmPatternDetailRenderer";
|
import { TcmPatternDetailRenderer } from "./details/TcmPatternDetailRenderer";
|
||||||
|
import { ExtraOrdinaryVesselsDetailRenderer } from "./details/ExtraOrdinaryVesselsDetailRenderer";
|
||||||
|
|
||||||
export const collectionRenderers: Readonly<Record<string, CollectionRendererComponent>> = Object.freeze({
|
export const collectionRenderers: Readonly<Record<string, CollectionRendererComponent>> = Object.freeze({
|
||||||
module_catalog_collection: ModuleCatalogCollectionRenderer,
|
module_catalog_collection: ModuleCatalogCollectionRenderer,
|
||||||
|
|
@ -109,6 +110,7 @@ export const collectionItemRenderers: Readonly<Record<string, CollectionItemRend
|
||||||
m0017_ct0002_card: ThreeBurnersCardRenderer,
|
m0017_ct0002_card: ThreeBurnersCardRenderer,
|
||||||
});
|
});
|
||||||
export const detailRenderers: Readonly<Record<string, DetailRendererComponent>> = Object.freeze({
|
export const detailRenderers: Readonly<Record<string, DetailRendererComponent>> = Object.freeze({
|
||||||
|
extra_ordinary_vessel_detail: ExtraOrdinaryVesselsDetailRenderer,
|
||||||
module_catalog_detail: IndexEntryDetailRenderer,
|
module_catalog_detail: IndexEntryDetailRenderer,
|
||||||
acu_point_index_detail: IndexEntryDetailRenderer,
|
acu_point_index_detail: IndexEntryDetailRenderer,
|
||||||
meridian_index_detail: MeridianPointsDetailRenderer,
|
meridian_index_detail: MeridianPointsDetailRenderer,
|
||||||
|
|
@ -355,6 +357,13 @@ export function resolveDetailRenderer(
|
||||||
) {
|
) {
|
||||||
return TcmPatternDetailRenderer;
|
return TcmPatternDetailRenderer;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
normalizedTemplate?.startsWith("m0020_") ||
|
||||||
|
normalizedModule === "m0020" ||
|
||||||
|
code === "extra_ordinary_vessel_detail"
|
||||||
|
) {
|
||||||
|
return ExtraOrdinaryVesselsDetailRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
if (code && detailRenderers[code]) return detailRenderers[code];
|
if (code && detailRenderers[code]) return detailRenderers[code];
|
||||||
reportMissingRenderer("detail", code);
|
reportMissingRenderer("detail", code);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue