|
| 1 | +import * as React from 'react'; |
| 2 | +import { observer } from 'mobx-react'; |
| 3 | +import { |
| 4 | + PillWidget, |
| 5 | + ReactorPanelModel, |
| 6 | + SearchableTableWidget, |
| 7 | + TablePillWidget, |
| 8 | + TableRow, |
| 9 | + styled |
| 10 | +} from '@journeyapps-labs/reactor-mod'; |
| 11 | + |
| 12 | +export interface PlaygroundTablesPanelWidgetProps { |
| 13 | + model: ReactorPanelModel; |
| 14 | +} |
| 15 | + |
| 16 | +enum TableColumns { |
| 17 | + NAME = 'name', |
| 18 | + STATUS = 'status', |
| 19 | + OWNER = 'owner', |
| 20 | + TAGS = 'tags', |
| 21 | + LATENCY = 'latency' |
| 22 | +} |
| 23 | + |
| 24 | +interface DemoTableRow extends TableRow { |
| 25 | + cells: { |
| 26 | + [TableColumns.NAME]: string; |
| 27 | + [TableColumns.STATUS]: { |
| 28 | + label: string; |
| 29 | + color: string; |
| 30 | + meta?: string; |
| 31 | + }; |
| 32 | + [TableColumns.OWNER]: string; |
| 33 | + [TableColumns.TAGS]: string[]; |
| 34 | + [TableColumns.LATENCY]: string; |
| 35 | + }; |
| 36 | +} |
| 37 | + |
| 38 | +const TABLE_ROWS: DemoTableRow[] = [ |
| 39 | + { |
| 40 | + key: 'core-builds', |
| 41 | + groupKey: 'Core services', |
| 42 | + cells: { |
| 43 | + [TableColumns.NAME]: 'Build queue', |
| 44 | + [TableColumns.STATUS]: { label: 'Stable', color: '#7fd29a', meta: '12 jobs' }, |
| 45 | + [TableColumns.OWNER]: 'Platform', |
| 46 | + [TableColumns.TAGS]: ['worker', 'queue', 'prod'], |
| 47 | + [TableColumns.LATENCY]: '42 ms' |
| 48 | + } |
| 49 | + }, |
| 50 | + { |
| 51 | + key: 'core-auth', |
| 52 | + groupKey: 'Core services', |
| 53 | + cells: { |
| 54 | + [TableColumns.NAME]: 'Auth gateway', |
| 55 | + [TableColumns.STATUS]: { label: 'Watching', color: '#f0c36a', meta: '2 retries' }, |
| 56 | + [TableColumns.OWNER]: 'Security', |
| 57 | + [TableColumns.TAGS]: ['edge', 'jwt'], |
| 58 | + [TableColumns.LATENCY]: '83 ms' |
| 59 | + } |
| 60 | + }, |
| 61 | + { |
| 62 | + key: 'core-events', |
| 63 | + groupKey: 'Core services', |
| 64 | + cells: { |
| 65 | + [TableColumns.NAME]: 'Event relay', |
| 66 | + [TableColumns.STATUS]: { label: 'Stable', color: '#7fd29a', meta: 'live' }, |
| 67 | + [TableColumns.OWNER]: 'Platform', |
| 68 | + [TableColumns.TAGS]: ['stream', 'sync'], |
| 69 | + [TableColumns.LATENCY]: '57 ms' |
| 70 | + } |
| 71 | + }, |
| 72 | + { |
| 73 | + key: 'core-audit', |
| 74 | + groupKey: 'Core services', |
| 75 | + cells: { |
| 76 | + [TableColumns.NAME]: 'Audit trail', |
| 77 | + [TableColumns.STATUS]: { label: 'Queued', color: '#d4a95f', meta: 'backfill' }, |
| 78 | + [TableColumns.OWNER]: 'Security', |
| 79 | + [TableColumns.TAGS]: ['logs', 'retention'], |
| 80 | + [TableColumns.LATENCY]: '118 ms' |
| 81 | + } |
| 82 | + }, |
| 83 | + { |
| 84 | + key: 'ux-table', |
| 85 | + groupKey: 'UI surfaces', |
| 86 | + cells: { |
| 87 | + [TableColumns.NAME]: 'Table tokens', |
| 88 | + [TableColumns.STATUS]: { label: 'Needs review', color: '#7aa6c2', meta: 'reactor' }, |
| 89 | + [TableColumns.OWNER]: 'Design systems', |
| 90 | + [TableColumns.TAGS]: ['theme', 'rows', 'hover'], |
| 91 | + [TableColumns.LATENCY]: 'n/a' |
| 92 | + } |
| 93 | + }, |
| 94 | + { |
| 95 | + key: 'ux-editor', |
| 96 | + groupKey: 'UI surfaces', |
| 97 | + cells: { |
| 98 | + [TableColumns.NAME]: 'Editor theme pass', |
| 99 | + [TableColumns.STATUS]: { label: 'Complete', color: '#5cc9a7', meta: '8 themes' }, |
| 100 | + [TableColumns.OWNER]: 'Frontend', |
| 101 | + [TableColumns.TAGS]: ['editor', 'selection'], |
| 102 | + [TableColumns.LATENCY]: 'n/a' |
| 103 | + } |
| 104 | + }, |
| 105 | + { |
| 106 | + key: 'ux-panels', |
| 107 | + groupKey: 'UI surfaces', |
| 108 | + cells: { |
| 109 | + [TableColumns.NAME]: 'Panel chrome', |
| 110 | + [TableColumns.STATUS]: { label: 'Exploring', color: '#7aa6c2', meta: 'tokens' }, |
| 111 | + [TableColumns.OWNER]: 'Frontend', |
| 112 | + [TableColumns.TAGS]: ['tabs', 'headers'], |
| 113 | + [TableColumns.LATENCY]: 'n/a' |
| 114 | + } |
| 115 | + }, |
| 116 | + { |
| 117 | + key: 'ux-status', |
| 118 | + groupKey: 'UI surfaces', |
| 119 | + cells: { |
| 120 | + [TableColumns.NAME]: 'Status surfaces', |
| 121 | + [TableColumns.STATUS]: { label: 'Complete', color: '#5cc9a7', meta: 'qa pass' }, |
| 122 | + [TableColumns.OWNER]: 'Design systems', |
| 123 | + [TableColumns.TAGS]: ['pills', 'cards'], |
| 124 | + [TableColumns.LATENCY]: 'n/a' |
| 125 | + } |
| 126 | + }, |
| 127 | + { |
| 128 | + key: 'ops-cache', |
| 129 | + groupKey: 'Operations', |
| 130 | + cells: { |
| 131 | + [TableColumns.NAME]: 'Cache warmers', |
| 132 | + [TableColumns.STATUS]: { label: 'Degraded', color: '#d98686', meta: '1 region' }, |
| 133 | + [TableColumns.OWNER]: 'SRE', |
| 134 | + [TableColumns.TAGS]: ['jobs', 'background'], |
| 135 | + [TableColumns.LATENCY]: '137 ms' |
| 136 | + } |
| 137 | + }, |
| 138 | + { |
| 139 | + key: 'ops-backups', |
| 140 | + groupKey: 'Operations', |
| 141 | + cells: { |
| 142 | + [TableColumns.NAME]: 'Snapshot backups', |
| 143 | + [TableColumns.STATUS]: { label: 'Stable', color: '#7fd29a', meta: 'nightly' }, |
| 144 | + [TableColumns.OWNER]: 'SRE', |
| 145 | + [TableColumns.TAGS]: ['storage', 'recovery'], |
| 146 | + [TableColumns.LATENCY]: '91 ms' |
| 147 | + } |
| 148 | + }, |
| 149 | + { |
| 150 | + key: 'ops-regions', |
| 151 | + groupKey: 'Operations', |
| 152 | + cells: { |
| 153 | + [TableColumns.NAME]: 'Regional failover', |
| 154 | + [TableColumns.STATUS]: { label: 'Watching', color: '#f0c36a', meta: 'eu-west' }, |
| 155 | + [TableColumns.OWNER]: 'Infra', |
| 156 | + [TableColumns.TAGS]: ['routing', 'health'], |
| 157 | + [TableColumns.LATENCY]: '104 ms' |
| 158 | + } |
| 159 | + }, |
| 160 | + { |
| 161 | + key: 'ops-alerts', |
| 162 | + groupKey: 'Operations', |
| 163 | + cells: { |
| 164 | + [TableColumns.NAME]: 'Alert fanout', |
| 165 | + [TableColumns.STATUS]: { label: 'Degraded', color: '#d98686', meta: 'slack' }, |
| 166 | + [TableColumns.OWNER]: 'Infra', |
| 167 | + [TableColumns.TAGS]: ['pager', 'notifications'], |
| 168 | + [TableColumns.LATENCY]: '166 ms' |
| 169 | + } |
| 170 | + } |
| 171 | +]; |
| 172 | + |
| 173 | +export const PlaygroundTablesPanelWidget: React.FC<PlaygroundTablesPanelWidgetProps> = observer(() => { |
| 174 | + return ( |
| 175 | + <S.Container> |
| 176 | + <SearchableTableWidget<DemoTableRow> |
| 177 | + columns={[ |
| 178 | + { |
| 179 | + key: TableColumns.NAME, |
| 180 | + display: 'Name', |
| 181 | + accessorSearch: (cell) => cell |
| 182 | + }, |
| 183 | + { |
| 184 | + key: TableColumns.STATUS, |
| 185 | + display: 'Status', |
| 186 | + noWrap: true, |
| 187 | + accessor: (cell: DemoTableRow['cells'][TableColumns.STATUS]) => ( |
| 188 | + <PillWidget label={cell.label} color={cell.color} meta={cell.meta ? { label: cell.meta } : null} /> |
| 189 | + ), |
| 190 | + accessorSearch: (cell) => cell.label |
| 191 | + }, |
| 192 | + { |
| 193 | + key: TableColumns.OWNER, |
| 194 | + display: 'Owner', |
| 195 | + accessorSearch: (cell) => cell |
| 196 | + }, |
| 197 | + { |
| 198 | + key: TableColumns.TAGS, |
| 199 | + display: 'Tags', |
| 200 | + accessor: (cell: string[]) => ( |
| 201 | + <S.Tags> |
| 202 | + {cell.map((tag, index) => ( |
| 203 | + <TablePillWidget key={`${tag}-${index}`} special={index === 0}> |
| 204 | + {tag} |
| 205 | + </TablePillWidget> |
| 206 | + ))} |
| 207 | + </S.Tags> |
| 208 | + ), |
| 209 | + accessorSearch: (cell) => cell.join(' ') |
| 210 | + }, |
| 211 | + { |
| 212 | + key: TableColumns.LATENCY, |
| 213 | + display: 'Latency', |
| 214 | + noWrap: true, |
| 215 | + shrink: true, |
| 216 | + accessorSearch: (cell) => cell |
| 217 | + } |
| 218 | + ]} |
| 219 | + rows={TABLE_ROWS} |
| 220 | + renderGroup={(event) => ({ |
| 221 | + defaultCollapsed: false, |
| 222 | + children: `${event.groupKey} (${event.rows.length})` |
| 223 | + })} |
| 224 | + emptyLabel="No demo rows match the current search" |
| 225 | + /> |
| 226 | + </S.Container> |
| 227 | + ); |
| 228 | +}); |
| 229 | + |
| 230 | +namespace S { |
| 231 | + export const Container = styled.div` |
| 232 | + padding: 12px; |
| 233 | + display: flex; |
| 234 | + flex-direction: column; |
| 235 | + row-gap: 12px; |
| 236 | + min-height: 100%; |
| 237 | + box-sizing: border-box; |
| 238 | + `; |
| 239 | + |
| 240 | + export const Tags = styled.div` |
| 241 | + display: flex; |
| 242 | + gap: 6px; |
| 243 | + flex-wrap: wrap; |
| 244 | + `; |
| 245 | +} |
0 commit comments