SPB Git

Repository Public

Status.tsx 4.8 KB 115 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SPSearch8 * File             : web/bot/src/Status.tsx9 * Module           : web10 * Repository       : https://git.spboucher.ai/spweb11 * Project Website  : https://search.spboucher.ai12 * Created          : 2026-11-2713 * Last Modified    : 2026-11-2714 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { Async, Icon, Pill, fmtDateTime, fmtRel, isoDate, useDocumentTitle, useFetch, type Tone } from '@spweb/shared-ui';44import { useT } from '@spweb/shared-ui/i18n/bot';45import type { StatusDoc } from './types';4647const OVERALL: Record<string, Tone> = { operational: 'ok', degraded: 'warn', paused: 'warn', down: 'danger' };48const COMPONENT: Record<string, Tone> = { ok: 'ok', degraded: 'warn', down: 'danger' };4950export function Status() {51  const { t, tx, lang } = useT();52  const state = useFetch<StatusDoc>('/api/public/status', 30000);53  useDocumentTitle(t('status.meta'));54  const s = state.data;55  const tone = s ? OVERALL[s.overall] ?? 'info' : 'info';56  const comps = s?.components ?? [];57  const up = comps.filter((c) => c.status === 'ok').length;58  return (59    <>60      <div className={`status-banner status-${s ? tone : 'wait'}`} aria-live="polite">61        <div className="wrap status-banner-in">62          <div>63            <p className="eyebrow">{t('status.eyebrow')}</p>64            <h1>{s ? tx(`status.overall.${s.overall}`, t('status.overall.unknown', { s: s.overall })) : t('status.title')}</h1>65          </div>66          {s && (67            <dl className="status-facts">68              <div><dt>{t('status.components')}</dt><dd>{t('status.count', { ok: up, n: comps.length })}</dd></div>69              <div>70                <dt>{t('status.last')}</dt>71                <dd><time dateTime={isoDate(s.updated_at)} title={fmtDateTime(s.updated_at, lang)}>{fmtRel(s.updated_at, lang)}</time></dd>72              </div>73            </dl>74          )}75        </div>76      </div>77      <div className="wrap page">78        <div aria-live="polite">79          <Async state={state}>80            {(d) => (81              <section aria-labelledby="comp-h">82                <header className="sec-head">83                  <h2 id="comp-h">{t('status.components')}</h2>84                  <p className="sec-aside status-auto"><Icon name="clock" size={16} /> {t('status.auto')}</p>85                </header>86                <div className="table-scroll">87                  <table className="table status-table">88                    <caption className="sr-only">{t('status.components')}</caption>89                    <thead>90                      <tr><th scope="col">{t('status.name')}</th><th scope="col">{t('status.state')}</th><th scope="col" className="num">{t('status.since')}</th></tr>91                    </thead>92                    <tbody>93                      {(d.components ?? []).map((c) => (94                        <tr key={c.name}>95                          <th scope="row"><code>{c.name}</code></th>96                          <td><Pill tone={COMPONENT[c.status] ?? 'info'}>{tx(`status.${c.status}`, c.status)}</Pill></td>97                          <td className="num">98                            {c.since != null99                              ? <time dateTime={isoDate(c.since)}>{fmtRel(c.since, lang)} <span className="muted">· {fmtDateTime(c.since, lang)}</span></time>100                              : '—'}101                          </td>102                        </tr>103                      ))}104                    </tbody>105                  </table>106                </div>107              </section>108            )}109          </Async>110        </div>111      </div>112    </>113  );114}115
Files main
Menu

Theme