|
| 1 | +import React, { useState } from "react"; |
| 2 | + |
| 3 | +const PATTERNS = [ |
| 4 | + { |
| 5 | + id: "compression", |
| 6 | + label: "Compression", |
| 7 | + icon: "🗜️", |
| 8 | + color: "#2563eb", |
| 9 | + colorRgb: "37, 99, 235", |
| 10 | + symptom: "Storage or bandwidth costs climbing on repetitive JSON", |
| 11 | + what: "gzip after JSON encode — typically 60–80% smaller. No workflow code changes. The easiest pattern to start with.", |
| 12 | + tradeoff: "Reduces and delays the 2 MB cap, but does not remove it.", |
| 13 | + docHref: "/docs/concepts/data-converter#compression", |
| 14 | + }, |
| 15 | + { |
| 16 | + id: "claimcheck", |
| 17 | + label: "Claim-check", |
| 18 | + icon: "🔗", |
| 19 | + color: "#16a34a", |
| 20 | + colorRgb: "22, 163, 74", |
| 21 | + symptom: "Payloads rejected at the ~2 MB limit with no useful error", |
| 22 | + what: "Offloads payloads above a threshold to an external blob store (S3, GCS, MinIO, local FS). Only a tiny reference travels through Cadence history.", |
| 23 | + tradeoff: "The only pattern that fully removes the size constraint.", |
| 24 | + docHref: "/docs/concepts/data-converter#claim-check", |
| 25 | + }, |
| 26 | + { |
| 27 | + id: "encryption", |
| 28 | + label: "Encryption", |
| 29 | + icon: "🔐", |
| 30 | + color: "#dc2626", |
| 31 | + colorRgb: "220, 38, 38", |
| 32 | + symptom: "PII, PHI, or credentials visible in workflow history or the Cadence UI", |
| 33 | + what: "AES-256-GCM wraps every payload before it reaches history. Without your key, operators see nothing readable.", |
| 34 | + tradeoff: "Covers history payloads only — not search attributes, memo, or logs.", |
| 35 | + docHref: "/docs/concepts/data-converter#encryption", |
| 36 | + }, |
| 37 | +]; |
| 38 | + |
| 39 | +export default function PatternCards() { |
| 40 | + const [openId, setOpenId] = useState<string | null>(null); |
| 41 | + |
| 42 | + return ( |
| 43 | + <div style={{ display: "flex", flexDirection: "column", gap: 12, marginBottom: 24 }}> |
| 44 | + {PATTERNS.map((p) => { |
| 45 | + const isOpen = openId === p.id; |
| 46 | + return ( |
| 47 | + <div |
| 48 | + key={p.id} |
| 49 | + role="button" |
| 50 | + tabIndex={0} |
| 51 | + onClick={() => setOpenId(isOpen ? null : p.id)} |
| 52 | + onKeyDown={(e) => { |
| 53 | + if (e.key === "Enter" || e.key === " ") { |
| 54 | + e.preventDefault(); |
| 55 | + setOpenId(isOpen ? null : p.id); |
| 56 | + } |
| 57 | + }} |
| 58 | + aria-expanded={isOpen} |
| 59 | + style={{ |
| 60 | + border: `2px solid ${isOpen ? p.color : "var(--ifm-color-emphasis-300)"}`, |
| 61 | + borderRadius: 10, |
| 62 | + padding: "14px 18px", |
| 63 | + cursor: "pointer", |
| 64 | + background: isOpen |
| 65 | + ? `rgba(${p.colorRgb}, 0.08)` |
| 66 | + : "var(--ifm-card-background-color, var(--ifm-background-surface-color))", |
| 67 | + transition: "all 0.2s", |
| 68 | + userSelect: "none", |
| 69 | + }} |
| 70 | + > |
| 71 | + {/* Header row */} |
| 72 | + <div style={{ display: "flex", alignItems: "center", gap: 10 }}> |
| 73 | + <span style={{ fontSize: 22 }}>{p.icon}</span> |
| 74 | + <a |
| 75 | + href={p.docHref} |
| 76 | + onClick={(e) => e.stopPropagation()} |
| 77 | + style={{ |
| 78 | + fontWeight: 700, |
| 79 | + fontSize: 15, |
| 80 | + color: isOpen ? p.color : "var(--ifm-color-content)", |
| 81 | + transition: "color 0.2s", |
| 82 | + textDecoration: "none", |
| 83 | + }} |
| 84 | + onMouseEnter={(e) => (e.currentTarget.style.textDecoration = "underline")} |
| 85 | + onMouseLeave={(e) => (e.currentTarget.style.textDecoration = "none")} |
| 86 | + > |
| 87 | + {p.label} |
| 88 | + </a> |
| 89 | + <span |
| 90 | + style={{ |
| 91 | + marginLeft: "auto", |
| 92 | + fontSize: 13, |
| 93 | + color: "var(--ifm-color-content)", |
| 94 | + flex: 1, |
| 95 | + textAlign: "right", |
| 96 | + paddingLeft: 12, |
| 97 | + }} |
| 98 | + > |
| 99 | + {p.symptom} |
| 100 | + </span> |
| 101 | + <span style={{ marginLeft: 10, color: "var(--ifm-color-content-secondary)", fontSize: 14 }}> |
| 102 | + {isOpen ? "▲" : "▼"} |
| 103 | + </span> |
| 104 | + </div> |
| 105 | + |
| 106 | + {/* Expanded content */} |
| 107 | + {isOpen && ( |
| 108 | + <div |
| 109 | + style={{ |
| 110 | + marginTop: 12, |
| 111 | + paddingTop: 12, |
| 112 | + borderTop: `1px solid rgba(${p.colorRgb}, 0.25)`, |
| 113 | + }} |
| 114 | + > |
| 115 | + <p |
| 116 | + style={{ |
| 117 | + margin: "0 0 8px", |
| 118 | + fontSize: 14, |
| 119 | + color: "var(--ifm-color-content)", |
| 120 | + lineHeight: 1.6, |
| 121 | + }} |
| 122 | + > |
| 123 | + {p.what} |
| 124 | + </p> |
| 125 | + <p |
| 126 | + style={{ |
| 127 | + margin: "0 0 12px", |
| 128 | + fontSize: 13, |
| 129 | + color: "var(--ifm-color-content-secondary)", |
| 130 | + fontStyle: "italic", |
| 131 | + lineHeight: 1.5, |
| 132 | + }} |
| 133 | + > |
| 134 | + {p.tradeoff} |
| 135 | + </p> |
| 136 | + <a |
| 137 | + href={p.docHref} |
| 138 | + onClick={(e) => e.stopPropagation()} |
| 139 | + style={{ |
| 140 | + display: "inline-block", |
| 141 | + padding: "6px 14px", |
| 142 | + borderRadius: 6, |
| 143 | + background: p.color, |
| 144 | + color: "white", |
| 145 | + fontWeight: 600, |
| 146 | + fontSize: 13, |
| 147 | + textDecoration: "none", |
| 148 | + }} |
| 149 | + > |
| 150 | + Read the docs → |
| 151 | + </a> |
| 152 | + </div> |
| 153 | + )} |
| 154 | + </div> |
| 155 | + ); |
| 156 | + })} |
| 157 | + </div> |
| 158 | + ); |
| 159 | +} |
0 commit comments