|
| 1 | +import React, { useState, useMemo } from 'react'; |
| 2 | +import data from '@/data/licensing/legacy-plans.json'; |
| 3 | + |
| 4 | +type ServiceEntry = { |
| 5 | + name: string; |
| 6 | + serviceId: string; |
| 7 | + plans: Record<string, boolean>; |
| 8 | +}; |
| 9 | + |
| 10 | +type Category = { |
| 11 | + name: string; |
| 12 | + services: ServiceEntry[]; |
| 13 | +}; |
| 14 | + |
| 15 | +type EnhancementEntry = { |
| 16 | + name: string; |
| 17 | + docsUrl?: string; |
| 18 | + plans: Record<string, boolean | string>; |
| 19 | +}; |
| 20 | + |
| 21 | +type LegacyData = { |
| 22 | + metadata: Record<string, any>; |
| 23 | + usageAllocations: Record<string, any>; |
| 24 | + categories: Category[]; |
| 25 | + enhancements: EnhancementEntry[]; |
| 26 | +}; |
| 27 | + |
| 28 | +const legacyData = data as LegacyData; |
| 29 | + |
| 30 | +const PLANS = ['Starter', 'Teams']; |
| 31 | + |
| 32 | +function renderCellValue(value: boolean | string): React.ReactNode { |
| 33 | + if (value === true) return '✅'; |
| 34 | + if (value === false) return '❌'; |
| 35 | + return value; |
| 36 | +} |
| 37 | + |
| 38 | +const headerStyle: React.CSSProperties = { |
| 39 | + textAlign: 'center', |
| 40 | + border: '1px solid #999CAD', |
| 41 | + background: '#AFB2C2', |
| 42 | + color: 'var(--sl-color-gray-1)', |
| 43 | + fontFamily: 'AeonikFono', |
| 44 | + fontSize: '14px', |
| 45 | + fontWeight: '500', |
| 46 | + lineHeight: '16px', |
| 47 | + letterSpacing: '-0.15px', |
| 48 | + padding: '12px 8px', |
| 49 | +}; |
| 50 | + |
| 51 | +const bodyFont: React.CSSProperties = { |
| 52 | + color: 'var(--sl-color-gray-1)', |
| 53 | + fontFamily: 'AeonikFono', |
| 54 | + fontSize: '14px', |
| 55 | + fontWeight: '400', |
| 56 | + lineHeight: '16px', |
| 57 | + letterSpacing: '-0.15px', |
| 58 | +}; |
| 59 | + |
| 60 | +const cellStyle: React.CSSProperties = { |
| 61 | + border: '1px solid #999CAD', |
| 62 | + padding: '12px 8px', |
| 63 | + textAlign: 'center', |
| 64 | + whiteSpace: 'normal', |
| 65 | +}; |
| 66 | + |
| 67 | +const categoryRowStyle: React.CSSProperties = { |
| 68 | + border: '1px solid #999CAD', |
| 69 | + padding: '10px 8px', |
| 70 | + fontFamily: 'AeonikFono', |
| 71 | + fontSize: '14px', |
| 72 | + fontWeight: '600', |
| 73 | + color: 'var(--sl-color-gray-1)', |
| 74 | + background: 'color-mix(in srgb, var(--sl-color-gray-6) 50%, transparent)', |
| 75 | +}; |
| 76 | + |
| 77 | +const inputStyle: React.CSSProperties = { |
| 78 | + color: '#707385', |
| 79 | + fontFamily: 'AeonikFono', |
| 80 | + fontSize: '14px', |
| 81 | + fontWeight: '500', |
| 82 | + lineHeight: '24px', |
| 83 | + letterSpacing: '-0.2px', |
| 84 | +}; |
| 85 | + |
| 86 | +export default function LegacyLicensingCoverage() { |
| 87 | + const [filter, setFilter] = useState(''); |
| 88 | + const lowerFilter = filter.toLowerCase(); |
| 89 | + |
| 90 | + const filteredCategories = useMemo(() => { |
| 91 | + if (!lowerFilter) return legacyData.categories; |
| 92 | + return legacyData.categories |
| 93 | + .map((cat) => ({ |
| 94 | + ...cat, |
| 95 | + services: cat.services.filter((svc) => |
| 96 | + svc.name.toLowerCase().includes(lowerFilter) |
| 97 | + ), |
| 98 | + })) |
| 99 | + .filter((cat) => cat.services.length > 0); |
| 100 | + }, [lowerFilter]); |
| 101 | + |
| 102 | + const filteredEnhancements = useMemo(() => { |
| 103 | + if (!lowerFilter) return legacyData.enhancements; |
| 104 | + return legacyData.enhancements.filter((e) => |
| 105 | + e.name.toLowerCase().includes(lowerFilter) |
| 106 | + ); |
| 107 | + }, [lowerFilter]); |
| 108 | + |
| 109 | + const hasResults = |
| 110 | + filteredCategories.length > 0 || filteredEnhancements.length > 0; |
| 111 | + |
| 112 | + return ( |
| 113 | + <div className="w-full"> |
| 114 | + <div className="flex flex-wrap gap-3 mb-4 mt-3"> |
| 115 | + <input |
| 116 | + type="text" |
| 117 | + placeholder="Filter by service or feature name..." |
| 118 | + value={filter} |
| 119 | + onChange={(e) => setFilter(e.target.value)} |
| 120 | + className="border rounded px-3 py-2 w-full max-w-sm" |
| 121 | + style={inputStyle} |
| 122 | + /> |
| 123 | + </div> |
| 124 | + |
| 125 | + <div className="block max-w-full overflow-x-auto overflow-y-hidden"> |
| 126 | + <table |
| 127 | + style={{ |
| 128 | + display: 'table', |
| 129 | + borderCollapse: 'collapse', |
| 130 | + tableLayout: 'fixed', |
| 131 | + width: '100%', |
| 132 | + minWidth: '100%', |
| 133 | + }} |
| 134 | + > |
| 135 | + <colgroup> |
| 136 | + <col style={{ width: '52%' }} /> |
| 137 | + <col style={{ width: '24%' }} /> |
| 138 | + <col style={{ width: '24%' }} /> |
| 139 | + </colgroup> |
| 140 | + <thead> |
| 141 | + <tr> |
| 142 | + <th style={{ ...headerStyle, textAlign: 'left' }}> |
| 143 | + AWS Services |
| 144 | + </th> |
| 145 | + {PLANS.map((plan) => ( |
| 146 | + <th key={plan} style={headerStyle}> |
| 147 | + Legacy Plan: {plan} |
| 148 | + </th> |
| 149 | + ))} |
| 150 | + </tr> |
| 151 | + </thead> |
| 152 | + <tbody style={bodyFont}> |
| 153 | + {!hasResults && ( |
| 154 | + <tr> |
| 155 | + <td |
| 156 | + colSpan={PLANS.length + 1} |
| 157 | + style={{ ...cellStyle, textAlign: 'center', padding: '24px' }} |
| 158 | + > |
| 159 | + No matching services or features found. |
| 160 | + </td> |
| 161 | + </tr> |
| 162 | + )} |
| 163 | + {filteredCategories.map((cat) => ( |
| 164 | + <React.Fragment key={cat.name}> |
| 165 | + <tr> |
| 166 | + <td |
| 167 | + colSpan={PLANS.length + 1} |
| 168 | + style={categoryRowStyle} |
| 169 | + > |
| 170 | + {cat.name} |
| 171 | + </td> |
| 172 | + </tr> |
| 173 | + {cat.services.map((svc, idx) => ( |
| 174 | + <tr key={`${cat.name}-${idx}`}> |
| 175 | + <td style={{ ...cellStyle, textAlign: 'left' }}> |
| 176 | + {svc.serviceId ? ( |
| 177 | + <a href={`/aws/services/${svc.serviceId}/`}> |
| 178 | + {svc.name} |
| 179 | + </a> |
| 180 | + ) : ( |
| 181 | + svc.name |
| 182 | + )} |
| 183 | + </td> |
| 184 | + {PLANS.map((plan) => ( |
| 185 | + <td key={plan} style={cellStyle}> |
| 186 | + {renderCellValue(svc.plans[plan])} |
| 187 | + </td> |
| 188 | + ))} |
| 189 | + </tr> |
| 190 | + ))} |
| 191 | + </React.Fragment> |
| 192 | + ))} |
| 193 | + |
| 194 | + {filteredEnhancements.length > 0 && ( |
| 195 | + <> |
| 196 | + <tr> |
| 197 | + <td |
| 198 | + colSpan={PLANS.length + 1} |
| 199 | + style={categoryRowStyle} |
| 200 | + > |
| 201 | + Emulator Enhancements |
| 202 | + </td> |
| 203 | + </tr> |
| 204 | + {filteredEnhancements.map((enh, idx) => ( |
| 205 | + <tr key={`enh-${idx}`}> |
| 206 | + <td style={{ ...cellStyle, textAlign: 'left' }}> |
| 207 | + {enh.docsUrl ? ( |
| 208 | + <a href={enh.docsUrl}>{enh.name}</a> |
| 209 | + ) : ( |
| 210 | + enh.name |
| 211 | + )} |
| 212 | + </td> |
| 213 | + {PLANS.map((plan) => ( |
| 214 | + <td |
| 215 | + key={plan} |
| 216 | + style={{ |
| 217 | + ...cellStyle, |
| 218 | + fontSize: |
| 219 | + typeof enh.plans[plan] === 'string' |
| 220 | + ? '12px' |
| 221 | + : '14px', |
| 222 | + }} |
| 223 | + > |
| 224 | + {renderCellValue(enh.plans[plan])} |
| 225 | + </td> |
| 226 | + ))} |
| 227 | + </tr> |
| 228 | + ))} |
| 229 | + </> |
| 230 | + )} |
| 231 | + </tbody> |
| 232 | + </table> |
| 233 | + </div> |
| 234 | + </div> |
| 235 | + ); |
| 236 | +} |
0 commit comments