feat(six-stages): implement six stages collection and detail renderers with dynamic ordering
This commit is contained in:
parent
2a3c08ef57
commit
effaf75cf3
|
|
@ -21,10 +21,16 @@ export function ModuleCatalogCardRenderer({
|
|||
onPress,
|
||||
}: CollectionItemRendererProps) {
|
||||
const attributes = item.attributes;
|
||||
const title = asString(attributes.name) || item.title;
|
||||
const rawTitle = asString(attributes.name) || item.title;
|
||||
const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/);
|
||||
const title = parenMatch
|
||||
? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim()
|
||||
: rawTitle;
|
||||
const parenSubtitle = parenMatch ? parenMatch[2].trim() : null;
|
||||
|
||||
const label =
|
||||
parenSubtitle ||
|
||||
asString(attributes.sub_title) ||
|
||||
asString(attributes.content_label) ||
|
||||
(asString(attributes.title) && asString(attributes.title) !== title
|
||||
? asString(attributes.title)
|
||||
: null) ||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,145 @@
|
|||
import React from "react";
|
||||
import { Pressable, StyleSheet, Text, View } from "react-native";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||
|
||||
import { Colors } from "@/theme";
|
||||
import { asNumber, asString, humanizeKey } from "../helpers/value";
|
||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||
import { SectionCard } from "../shared/SectionCard";
|
||||
import type {
|
||||
CollectionItemRendererProps,
|
||||
CollectionRendererProps,
|
||||
} from "../../types/renderer.types";
|
||||
|
||||
export function SixStagesCollectionRenderer(props: CollectionRendererProps) {
|
||||
const overviewText = asString(props.items[0]?.attributes.stage_overview).trim();
|
||||
|
||||
const header = overviewText ? (
|
||||
<View style={styles.overviewContainer}>
|
||||
<SectionCard title="Overview" defaultExpanded={true}>
|
||||
<Text style={styles.overviewText}>{overviewText}</Text>
|
||||
</SectionCard>
|
||||
</View>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<CollectionScaffold
|
||||
{...props}
|
||||
header={header}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function SixStagesCardRenderer({
|
||||
item,
|
||||
onPress,
|
||||
}: CollectionItemRendererProps) {
|
||||
const attributes = item.attributes;
|
||||
const rawTitle = asString(attributes.name) || item.title;
|
||||
const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/);
|
||||
const title = parenMatch
|
||||
? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim()
|
||||
: rawTitle;
|
||||
const parenSubtitle = parenMatch ? parenMatch[2].trim() : null;
|
||||
|
||||
const label =
|
||||
parenSubtitle ||
|
||||
asString(attributes.sub_title) ||
|
||||
null;
|
||||
|
||||
const cleanTitle = humanizeKey(title);
|
||||
const cleanLabel = label ? humanizeKey(label) : null;
|
||||
|
||||
const count = asNumber(attributes.content_count);
|
||||
const rawContentLabel = asString(attributes.content_label);
|
||||
const contentLabel = rawContentLabel ? humanizeKey(rawContentLabel) : null;
|
||||
|
||||
const badgeText =
|
||||
count !== null && count > 0 && contentLabel
|
||||
? `${count} ${contentLabel}`
|
||||
: contentLabel || (count !== null ? `${count}` : null);
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
|
||||
>
|
||||
<View style={styles.iconWrapper}>
|
||||
<Ionicons name="book-outline" size={22} color={Colors.primary} />
|
||||
</View>
|
||||
|
||||
<View style={styles.textContainer}>
|
||||
<Text style={styles.title}>{cleanTitle}</Text>
|
||||
{cleanLabel ? (
|
||||
<Text style={styles.description} numberOfLines={1}>
|
||||
{cleanLabel}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
{badgeText ? (
|
||||
<View style={styles.badge}>
|
||||
<Text style={styles.badgeText}>{badgeText}</Text>
|
||||
</View>
|
||||
) : null}
|
||||
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
overviewContainer: {
|
||||
marginBottom: verticalScale(14),
|
||||
},
|
||||
overviewText: {
|
||||
fontSize: moderateScale(14),
|
||||
lineHeight: moderateScale(22),
|
||||
color: "#374151",
|
||||
},
|
||||
row: {
|
||||
minHeight: moderateScale(68),
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
padding: moderateScale(14),
|
||||
},
|
||||
pressed: {
|
||||
opacity: 0.72,
|
||||
},
|
||||
iconWrapper: {
|
||||
width: moderateScale(40),
|
||||
height: moderateScale(40),
|
||||
borderRadius: moderateScale(20),
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
backgroundColor: "#E8F5E9",
|
||||
},
|
||||
textContainer: {
|
||||
flex: 1,
|
||||
marginLeft: moderateScale(12),
|
||||
marginRight: moderateScale(10),
|
||||
},
|
||||
title: {
|
||||
fontSize: moderateScale(15),
|
||||
fontWeight: "600",
|
||||
color: Colors.textPrimary,
|
||||
marginBottom: verticalScale(2),
|
||||
},
|
||||
description: {
|
||||
fontSize: moderateScale(12),
|
||||
color: Colors.textSecondary,
|
||||
},
|
||||
badge: {
|
||||
backgroundColor: "#F3F4F6",
|
||||
borderRadius: moderateScale(12),
|
||||
paddingHorizontal: moderateScale(9),
|
||||
paddingVertical: verticalScale(5),
|
||||
marginRight: moderateScale(8),
|
||||
},
|
||||
badgeText: {
|
||||
fontSize: moderateScale(11),
|
||||
fontWeight: "700",
|
||||
color: Colors.textSecondary,
|
||||
},
|
||||
});
|
||||
|
|
@ -1,8 +1,13 @@
|
|||
import React from "react";
|
||||
import React, { useMemo } from "react";
|
||||
import { ScrollView, StyleSheet } from "react-native";
|
||||
|
||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||
import { asString, humanizeKey } from "../helpers/value";
|
||||
import {
|
||||
findAttributePresentationRule,
|
||||
isEmptyValue,
|
||||
presentationDisplayOrder,
|
||||
} from "../../utils/attribute-presentation";
|
||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||
import { ContentValue } from "../shared/ContentValue";
|
||||
import { Hero } from "../shared/Hero";
|
||||
|
|
@ -19,18 +24,43 @@ const CATALOG_METADATA_KEYS = new Set([
|
|||
"link",
|
||||
"point_images",
|
||||
"default_image_id",
|
||||
"stage_overview",
|
||||
]);
|
||||
|
||||
export function SixStagesDetailRenderer({
|
||||
content,
|
||||
data,
|
||||
definitions,
|
||||
presentationAttributes,
|
||||
}: DetailRendererProps) {
|
||||
const title =
|
||||
const rawTitle =
|
||||
asString(data.name) ||
|
||||
asString(data.title) ||
|
||||
content.title ||
|
||||
"Six Stages";
|
||||
const title = humanizeKey(rawTitle);
|
||||
|
||||
const orderedSections = useMemo(() => {
|
||||
const definitionByLabel = new Map(
|
||||
(definitions ?? []).map((d) => [d.code, d.label]),
|
||||
);
|
||||
|
||||
return Object.entries(data)
|
||||
.filter(
|
||||
([key, value]) =>
|
||||
!RESERVED_KEYS.has(key) &&
|
||||
!CATALOG_METADATA_KEYS.has(key) &&
|
||||
!isEmptyValue(value),
|
||||
)
|
||||
.map(([key, value]) => {
|
||||
const rule = findAttributePresentationRule(key, presentationAttributes);
|
||||
const order = presentationDisplayOrder(rule);
|
||||
const rawLabel = definitionByLabel.get(key) || key;
|
||||
const label = humanizeKey(rawLabel);
|
||||
return { key, value, order, label };
|
||||
})
|
||||
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
||||
}, [data, definitions, presentationAttributes]);
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
|
|
@ -39,13 +69,11 @@ export function SixStagesDetailRenderer({
|
|||
>
|
||||
<Hero title={title} subtitle={content.summary ?? undefined} />
|
||||
|
||||
{Object.entries(data)
|
||||
.filter(([key]) => !RESERVED_KEYS.has(key) && !CATALOG_METADATA_KEYS.has(key))
|
||||
.map(([key, value]) => (
|
||||
<SectionCard key={key} title={humanizeKey(key)}>
|
||||
<ContentValue value={value} />
|
||||
</SectionCard>
|
||||
))}
|
||||
{orderedSections.map(({ key, value, label }) => (
|
||||
<SectionCard key={key} title={label}>
|
||||
<ContentValue value={value} />
|
||||
</SectionCard>
|
||||
))}
|
||||
|
||||
<ContentLinkAttributeSections
|
||||
data={data}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import { TwelveChannelsCollectionRenderer, TwelveChannelsCardRenderer } from "./
|
|||
import { TwelveChannelsDetailRenderer } from "./details/TwelveChannelsDetailRenderer";
|
||||
import { ThreeBurnersCollectionRenderer, ThreeBurnersCardRenderer } from "./collections/ThreeBurnersRenderers";
|
||||
import { ThreeBurnersDetailRenderer } from "./details/ThreeBurnersDetailRenderer";
|
||||
import { SixStagesCollectionRenderer, SixStagesCardRenderer } from "./collections/SixStagesRenderers";
|
||||
import { SixStagesDetailRenderer } from "./details/SixStagesDetailRenderer";
|
||||
import { TcmPatternDetailRenderer } from "./details/TcmPatternDetailRenderer";
|
||||
import { ExtraOrdinaryVesselsDetailRenderer } from "./details/ExtraOrdinaryVesselsDetailRenderer";
|
||||
|
|
@ -78,6 +79,13 @@ export const collectionRenderers: Readonly<Record<string, CollectionRendererComp
|
|||
m0018_ct0002_collection: TwelveChannelsCollectionRenderer,
|
||||
three_burners_collection: ThreeBurnersCollectionRenderer,
|
||||
m0017_ct0002_collection: ThreeBurnersCollectionRenderer,
|
||||
six_stages_collection: SixStagesCollectionRenderer,
|
||||
m0015_ct0001_collection: SixStagesCollectionRenderer,
|
||||
m0015_ct0002_collection: SixStagesCollectionRenderer,
|
||||
m0015_ct0003_collection: SixStagesCollectionRenderer,
|
||||
m0015_ct0004_collection: SixStagesCollectionRenderer,
|
||||
m0015_ct0005_collection: SixStagesCollectionRenderer,
|
||||
m0015_ct0006_collection: SixStagesCollectionRenderer,
|
||||
});
|
||||
export const collectionItemRenderers: Readonly<Record<string, CollectionItemRendererComponent>> = Object.freeze({
|
||||
module_catalog_card: ModuleCatalogCardRenderer,
|
||||
|
|
@ -108,6 +116,13 @@ export const collectionItemRenderers: Readonly<Record<string, CollectionItemRend
|
|||
m0018_ct0002_card: TwelveChannelsCardRenderer,
|
||||
three_burners_card: ThreeBurnersCardRenderer,
|
||||
m0017_ct0002_card: ThreeBurnersCardRenderer,
|
||||
six_stages_card: SixStagesCardRenderer,
|
||||
m0015_ct0001_card: SixStagesCardRenderer,
|
||||
m0015_ct0002_card: SixStagesCardRenderer,
|
||||
m0015_ct0003_card: SixStagesCardRenderer,
|
||||
m0015_ct0004_card: SixStagesCardRenderer,
|
||||
m0015_ct0005_card: SixStagesCardRenderer,
|
||||
m0015_ct0006_card: SixStagesCardRenderer,
|
||||
});
|
||||
export const detailRenderers: Readonly<Record<string, DetailRendererComponent>> = Object.freeze({
|
||||
extra_ordinary_vessel_detail: ExtraOrdinaryVesselsDetailRenderer,
|
||||
|
|
@ -232,6 +247,12 @@ export function resolveCollectionRenderer(
|
|||
if (normalizedTemplate === "m0017_ct0002" || (normalizedModule === "m0017" && normalizedTemplate?.includes("ct0002"))) {
|
||||
return ThreeBurnersCollectionRenderer;
|
||||
}
|
||||
if (
|
||||
normalizedTemplate?.startsWith("m0015_ct000") &&
|
||||
normalizedTemplate !== "m0015_ct0007"
|
||||
) {
|
||||
return SixStagesCollectionRenderer;
|
||||
}
|
||||
|
||||
if (code && collectionRenderers[code]) return collectionRenderers[code];
|
||||
reportMissingRenderer("collection", code);
|
||||
|
|
@ -272,6 +293,12 @@ export function resolveCollectionItemRenderer(
|
|||
if (normalizedTemplate === "m0017_ct0002" || (normalizedModule === "m0017" && normalizedTemplate?.includes("ct0002"))) {
|
||||
return ThreeBurnersCardRenderer;
|
||||
}
|
||||
if (
|
||||
normalizedTemplate?.startsWith("m0015_ct000") &&
|
||||
normalizedTemplate !== "m0015_ct0007"
|
||||
) {
|
||||
return SixStagesCardRenderer;
|
||||
}
|
||||
|
||||
if (code && collectionItemRenderers[code]) return collectionItemRenderers[code];
|
||||
reportMissingRenderer("collection-item", code);
|
||||
|
|
|
|||
Loading…
Reference in New Issue