()
| 348 | |
| 349 | export function renderIndex() { |
| 350 | function BlockServices() { |
| 351 | const [blockServices, setBlockServices] = useState(null); |
| 352 | const [locations, setLocations] = useState(null); |
| 353 | useEffect(async () => { |
| 354 | const resp = await registryReq('ALL_BLOCK_SERVICES_DEPRECATED', {}); |
| 355 | setBlockServices(resp); |
| 356 | }, []); |
| 357 | |
| 358 | useEffect(async () => { |
| 359 | const resp = await registryReq('LOCATIONS', {}); |
| 360 | var locationsMap = new Map(); |
| 361 | for (const location of resp.Locations) { |
| 362 | locationsMap.set(location.Id, location.Name); |
| 363 | } |
| 364 | setLocations(locationsMap); |
| 365 | }, []); |
| 366 | |
| 367 | if (blockServices === null || locations === null) { |
| 368 | return p.h('em', null, 'Loading...'); |
| 369 | } |
| 370 | |
| 371 | const now = new Date(); |
| 372 | const rows = []; |
| 373 | let failureDomains = new Set(); |
| 374 | let capacity = 0; |
| 375 | let available = 0; |
| 376 | let blocks = 0n; |
| 377 | for (const bs of blockServices.BlockServices) { |
| 378 | failureDomains.add(bs.FailureDomain); |
| 379 | capacity += bs.CapacityBytes; |
| 380 | available += bs.AvailableBytes; |
| 381 | blocks += BigInt(bs.Blocks); |
| 382 | rows.push([ |
| 383 | bs.FailureDomain, |
| 384 | bs.Addrs.Addr1, |
| 385 | bs.Addrs.Addr2, |
| 386 | bs.Path, |
| 387 | bs.Id, |
| 388 | bs.Flags, |
| 389 | bs.FlagsLastChanged, |
| 390 | bs.StorageClass, |
| 391 | bs.Blocks, |
| 392 | bs.CapacityBytes, |
| 393 | bs.AvailableBytes, |
| 394 | bs.LastSeen, |
| 395 | bs.HasFiles, |
| 396 | ]); |
| 397 | } |
| 398 | const cols = [ |
| 399 | {name: 'FailureDomain'}, |
| 400 | {name: 'Address 1'}, |
| 401 | {name: 'Address 2'}, |
| 402 | {name: 'Path', render: t => p.h('code', {}, t)}, |
| 403 | {name: 'Id', render: t => p.h('code', {}, t)}, |
| 404 | {name: 'Flags', string: stringifyShortFlags, render: t => p.h('code', {}, t)}, |
| 405 | {name: 'FlagsLastChanged', render: flc => stringifyAgo(new Date(flc), now)}, |
| 406 | {name: 'StorageClass', string: stringifyStorageClass}, |
| 407 | {name: 'Blocks'}, |
nothing calls this directly
no test coverage detected