|
1 | | -import { Extension, FilterState } from '../types'; |
| 1 | +import { useState, useEffect } from 'react'; |
| 2 | +import { MatrixCell } from '../types'; |
2 | 3 |
|
3 | 4 | interface CellDrawerProps { |
4 | 5 | extensionName: string; |
5 | 6 | phpVersion: string; |
6 | | - extension: Extension | undefined; |
7 | | - filters: FilterState; |
| 7 | + cell: MatrixCell | null; |
8 | 8 | onClose: () => void; |
9 | 9 | } |
10 | 10 |
|
11 | | -export function CellDrawer({ extensionName, phpVersion, extension, filters, onClose }: CellDrawerProps) { |
12 | | - if (!extension) return null; |
| 11 | +function formatDuration(startedAt?: string, finishedAt?: string): string | null { |
| 12 | + if (!startedAt || !finishedAt) return null; |
| 13 | + |
| 14 | + const start = new Date(startedAt).getTime(); |
| 15 | + const finish = new Date(finishedAt).getTime(); |
| 16 | + const durationMs = finish - start; |
| 17 | + |
| 18 | + if (durationMs < 0) return null; |
| 19 | + |
| 20 | + const seconds = Math.floor(durationMs / 1000); |
| 21 | + const minutes = Math.floor(seconds / 60); |
| 22 | + const hours = Math.floor(minutes / 60); |
| 23 | + |
| 24 | + if (hours > 0) { |
| 25 | + return `${hours}h ${minutes % 60}m`; |
| 26 | + } else if (minutes > 0) { |
| 27 | + return `${minutes}m ${seconds % 60}s`; |
| 28 | + } else { |
| 29 | + return `${seconds}s`; |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +function formatTimestamp(timestamp?: string): string { |
| 34 | + if (!timestamp) return 'N/A'; |
| 35 | + const date = new Date(timestamp); |
| 36 | + return date.toLocaleString(); |
| 37 | +} |
13 | 38 |
|
14 | | - const relevantAvailability = extension.availability.filter(avail => { |
15 | | - const matchesFilters = |
16 | | - (!filters.channel || avail.channel === filters.channel) && |
17 | | - (!filters.platform || avail.platform === filters.platform) && |
18 | | - (!filters.platformVersion || avail.platform_version === filters.platformVersion) && |
19 | | - (!filters.arch || avail.arch === filters.arch); |
| 39 | +function getStatusColor(status: string): string { |
| 40 | + switch (status) { |
| 41 | + case 'success': |
| 42 | + return 'var(--success)'; |
| 43 | + case 'failure': |
| 44 | + return 'var(--danger)'; |
| 45 | + case 'skipped': |
| 46 | + case 'unknown': |
| 47 | + return 'var(--gray-500)'; |
| 48 | + default: |
| 49 | + return 'var(--gray-400)'; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +function copyToClipboard(text: string): Promise<boolean> { |
| 54 | + if (navigator.clipboard && window.isSecureContext) { |
| 55 | + return navigator.clipboard.writeText(text).then(() => true).catch(() => false); |
| 56 | + } else { |
| 57 | + // Fallback for older browsers |
| 58 | + const textArea = document.createElement('textarea'); |
| 59 | + textArea.value = text; |
| 60 | + textArea.style.position = 'fixed'; |
| 61 | + textArea.style.left = '-999999px'; |
| 62 | + document.body.appendChild(textArea); |
| 63 | + textArea.focus(); |
| 64 | + textArea.select(); |
| 65 | + try { |
| 66 | + document.execCommand('copy'); |
| 67 | + textArea.remove(); |
| 68 | + return Promise.resolve(true); |
| 69 | + } catch (error) { |
| 70 | + textArea.remove(); |
| 71 | + return Promise.resolve(false); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +export function CellDrawer({ extensionName, phpVersion, cell, onClose }: CellDrawerProps) { |
| 77 | + const [copySuccess, setCopySuccess] = useState(false); |
| 78 | + |
| 79 | + useEffect(() => { |
| 80 | + const handleEscape = (e: KeyboardEvent) => { |
| 81 | + if (e.key === 'Escape') { |
| 82 | + onClose(); |
| 83 | + } |
| 84 | + }; |
20 | 85 |
|
21 | | - return matchesFilters && avail.php_versions.includes(phpVersion); |
22 | | - }); |
| 86 | + window.addEventListener('keydown', handleEscape); |
| 87 | + return () => window.removeEventListener('keydown', handleEscape); |
| 88 | + }, [onClose]); |
| 89 | + |
| 90 | + if (!cell) { |
| 91 | + return ( |
| 92 | + <div className="drawer-overlay" onClick={onClose}> |
| 93 | + <div className="drawer drawer-right" onClick={(e) => e.stopPropagation()}> |
| 94 | + <div className="drawer-header"> |
| 95 | + <h2>{extensionName} - PHP {phpVersion}</h2> |
| 96 | + <button onClick={onClose} className="close-button" aria-label="Close drawer">×</button> |
| 97 | + </div> |
| 98 | + <div className="drawer-content"> |
| 99 | + <p className="no-data-message">No build data available for this configuration.</p> |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + const duration = formatDuration(cell.startedAt, cell.finishedAt); |
| 107 | + |
| 108 | + const handleCopyPermalink = async () => { |
| 109 | + const url = new URL(window.location.href); |
| 110 | + url.hash = `${extensionName}-${phpVersion}`; |
| 111 | + const success = await copyToClipboard(url.toString()); |
| 112 | + if (success) { |
| 113 | + setCopySuccess(true); |
| 114 | + setTimeout(() => setCopySuccess(false), 2000); |
| 115 | + } |
| 116 | + }; |
23 | 117 |
|
24 | 118 | return ( |
25 | 119 | <div className="drawer-overlay" onClick={onClose}> |
26 | | - <div className="drawer" onClick={(e) => e.stopPropagation()}> |
| 120 | + <div className="drawer drawer-right" onClick={(e) => e.stopPropagation()}> |
27 | 121 | <div className="drawer-header"> |
28 | 122 | <h2>{extensionName} - PHP {phpVersion}</h2> |
29 | | - <button onClick={onClose} className="close-button">×</button> |
| 123 | + <button onClick={onClose} className="close-button" aria-label="Close drawer">×</button> |
30 | 124 | </div> |
31 | 125 | <div className="drawer-content"> |
32 | | - {relevantAvailability.length === 0 ? ( |
33 | | - <p>Not available with current filters for PHP {phpVersion}</p> |
34 | | - ) : ( |
35 | | - <div className="availability-list"> |
36 | | - <h3>Available on:</h3> |
37 | | - {relevantAvailability.map((avail, idx) => ( |
38 | | - <div key={idx} className="availability-item"> |
39 | | - <div><strong>Channel:</strong> {avail.channel}</div> |
40 | | - <div><strong>Platform:</strong> {avail.platform}</div> |
41 | | - <div><strong>Version:</strong> {avail.platform_version}</div> |
42 | | - <div><strong>Architecture:</strong> {avail.arch}</div> |
43 | | - <div><strong>PHP Versions:</strong> {avail.php_versions.join(', ')}</div> |
| 126 | + {/* Extension info */} |
| 127 | + <div className="detail-section"> |
| 128 | + <h3>Extension</h3> |
| 129 | + <div className="detail-grid"> |
| 130 | + <div className="detail-item"> |
| 131 | + <span className="detail-label">Name</span> |
| 132 | + <span className="detail-value">{extensionName}</span> |
| 133 | + </div> |
| 134 | + {cell.extensionVersion && ( |
| 135 | + <div className="detail-item"> |
| 136 | + <span className="detail-label">Version</span> |
| 137 | + <span className="detail-value">{cell.extensionVersion}</span> |
44 | 138 | </div> |
45 | | - ))} |
| 139 | + )} |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + |
| 143 | + {/* Build status */} |
| 144 | + <div className="detail-section"> |
| 145 | + <h3>Build Status</h3> |
| 146 | + <div className="detail-grid"> |
| 147 | + <div className="detail-item"> |
| 148 | + <span className="detail-label">Status</span> |
| 149 | + <span |
| 150 | + className="detail-value status-badge" |
| 151 | + style={{ backgroundColor: getStatusColor(cell.status), color: 'white' }} |
| 152 | + > |
| 153 | + {cell.status} |
| 154 | + </span> |
| 155 | + </div> |
| 156 | + {cell.category && ( |
| 157 | + <div className="detail-item"> |
| 158 | + <span className="detail-label">Category</span> |
| 159 | + <span className="detail-value">{cell.category}</span> |
| 160 | + </div> |
| 161 | + )} |
| 162 | + </div> |
| 163 | + </div> |
| 164 | + |
| 165 | + {/* Timestamps */} |
| 166 | + {(cell.startedAt || cell.finishedAt) && ( |
| 167 | + <div className="detail-section"> |
| 168 | + <h3>Timing</h3> |
| 169 | + <div className="detail-grid"> |
| 170 | + {cell.startedAt && ( |
| 171 | + <div className="detail-item"> |
| 172 | + <span className="detail-label">Started</span> |
| 173 | + <span className="detail-value">{formatTimestamp(cell.startedAt)}</span> |
| 174 | + </div> |
| 175 | + )} |
| 176 | + {cell.finishedAt && ( |
| 177 | + <div className="detail-item"> |
| 178 | + <span className="detail-label">Finished</span> |
| 179 | + <span className="detail-value">{formatTimestamp(cell.finishedAt)}</span> |
| 180 | + </div> |
| 181 | + )} |
| 182 | + {duration && ( |
| 183 | + <div className="detail-item"> |
| 184 | + <span className="detail-label">Duration</span> |
| 185 | + <span className="detail-value">{duration}</span> |
| 186 | + </div> |
| 187 | + )} |
| 188 | + </div> |
46 | 189 | </div> |
47 | 190 | )} |
| 191 | + |
| 192 | + {/* Links */} |
| 193 | + {(cell.runUrl || cell.artifactUrl) && ( |
| 194 | + <div className="detail-section"> |
| 195 | + <h3>Links</h3> |
| 196 | + <div className="detail-links"> |
| 197 | + {cell.runUrl && ( |
| 198 | + <a |
| 199 | + href={cell.runUrl} |
| 200 | + target="_blank" |
| 201 | + rel="noopener noreferrer" |
| 202 | + className="detail-link" |
| 203 | + > |
| 204 | + <span className="link-icon">🔗</span> |
| 205 | + View Workflow Run |
| 206 | + </a> |
| 207 | + )} |
| 208 | + {cell.artifactUrl && ( |
| 209 | + <a |
| 210 | + href={cell.artifactUrl} |
| 211 | + target="_blank" |
| 212 | + rel="noopener noreferrer" |
| 213 | + className="detail-link" |
| 214 | + > |
| 215 | + <span className="link-icon">📦</span> |
| 216 | + Download Artifact |
| 217 | + </a> |
| 218 | + )} |
| 219 | + </div> |
| 220 | + </div> |
| 221 | + )} |
| 222 | + |
| 223 | + {/* Copy permalink */} |
| 224 | + <div className="detail-section"> |
| 225 | + <button |
| 226 | + onClick={handleCopyPermalink} |
| 227 | + className="copy-permalink-button" |
| 228 | + aria-label="Copy permalink to this cell" |
| 229 | + > |
| 230 | + {copySuccess ? '✓ Copied!' : '🔗 Copy Permalink'} |
| 231 | + </button> |
| 232 | + </div> |
48 | 233 | </div> |
49 | 234 | </div> |
50 | 235 | </div> |
|
0 commit comments