SPB Git

Repository Public

Themes.tsx 6.0 KB 112 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : studio/web/src/Themes.tsx9 * Module           : studio10 * Repository       : https://git.spboucher.ai/ka-maps-engine11 * Created          : 2026-12-0112 * Last Modified    : 2026-12-0113 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { useState } from 'react';43import { api, APP_LABEL, fmtDate, PLATFORM_LABEL } from './api.ts';44import { Link, type Meta, navigate } from './main.tsx';45import { Issues, Notice, useAsync } from './ui.tsx';4647/** Résumé d'un ensemble de canaux : « v3 partout » ou le détail. */48export function channelSummary(channels: any[], total: number): string {49  if (!channels.length) return 'non diffusé';50  const stable = new Set(channels.map((c) => c.stable_version));51  const cand = channels.filter((c) => c.candidate_version !== null);52  let s = stable.size === 1 && channels.length === total ? `v${[...stable][0] ?? '—'} sur les ${total} canaux` : `${[...stable].filter((v) => v !== null).map((v) => `v${v}`).join(', ')} selon le canal`;53  if (cand.length) s += ` · ${cand.length} diffusion${cand.length > 1 ? 's' : ''} en cours`;54  return s;55}5657export function Themes({ meta }: { meta: Meta }) {58  const { data, error, reload } = useAsync(() => api.get('/api/themes'), []);59  const [form, setForm] = useState<{ id: string; title: string; copyFrom: string } | null>(null);60  const [err, setErr] = useState<any>(null);61  const total = meta.apps.length * meta.platforms.length;62  const create = async () => {63    setErr(null);64    try {65      await api.post('/api/themes', form);66      navigate(`/themes/${form!.id}`);67    } catch (e: any) {68      setErr(e);69    }70  };71  return (72    <>73      <div className="head">74        <div><h1>Thèmes</h1><p className="muted">Documents <code>kastyle/1</code> servis par {meta.publicMaps.replace('https://', '')}. Chaque enregistrement est une révision de brouillon ; une publication crée une version immuable.</p></div>75        <button className="btn" onClick={() => setForm({ id: '', title: '', copyFrom: data?.themes?.[0]?.id ?? '' })}>Nouveau thème</button>76      </div>77      {error ? <Notice kind="bad">{error}</Notice> : null}78      {form ? (79        <div className="panel" style={{ marginBottom: 16 }}>80          <h3 style={{ marginTop: 0 }}>Nouveau thème</h3>81          <div className="row">82            <label className="f">Identifiant<input type="text" value={form.id} placeholder="ex. hiver" onChange={(e) => setForm({ ...form, id: e.target.value.toLowerCase() })} /></label>83            <label className="f">Titre<input type="text" value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })} /></label>84            <label className="f">Copier depuis<select value={form.copyFrom} onChange={(e) => setForm({ ...form, copyFrom: e.target.value })}>{data?.themes.map((t: any) => <option key={t.id}>{t.id}</option>)}</select></label>85            <button className="btn primary" onClick={create} style={{ alignSelf: 'flex-end' }}>Créer le brouillon</button>86            <button className="btn" onClick={() => setForm(null)} style={{ alignSelf: 'flex-end' }}>Annuler</button>87          </div>88          {err ? (err.detail?.errors ? <Issues title={err.message} errors={err.detail.errors} /> : <Notice kind="bad">{err.message}</Notice>) : null}89        </div>90      ) : null}91      <div className="table-wrap">92        <table>93          <thead><tr><th>Thème</th><th>Dernière version</th><th>En service</th><th>Brouillon</th><th></th></tr></thead>94          <tbody>95            {data?.themes.map((t: any) => (96              <tr key={t.id}>97                <td><Link to={`/themes/${t.id}`}><strong>{t.title}</strong></Link><br /><code>{t.id}</code> {t.archived_at ? <span className="tag">archivé</span> : null}</td>98                <td>{t.latestVersion ? `v${t.latestVersion}` : '—'} <span className="faint small">({t.versions} publiée{t.versions > 1 ? 's' : ''})</span></td>99                <td>{channelSummary(t.channels, total)}100                  {t.channels.filter((c: any) => c.candidate_version !== null).slice(0, 3).map((c: any) => <div key={c.app + c.platform} className="small muted">{APP_LABEL[c.app]} {PLATFORM_LABEL[c.platform]} : v{c.candidate_version} à {c.candidate_percent} %</div>)}</td>101                <td>{t.draft?.unpublished ? <><span className="tag warn">non publié</span> <span className="small muted">{t.draft.author}, {fmtDate(t.draft.at)}</span></> : <span className="faint">à jour</span>}</td>102                <td><button className="btn small" onClick={() => navigate(`/themes/${t.id}`)}>Ouvrir</button></td>103              </tr>104            ))}105          </tbody>106        </table>107      </div>108      <p className="small faint" style={{ marginTop: 10 }}><button className="btn small" onClick={reload}>Actualiser</button></p>109    </>110  );111}112
Files main
Menu

Theme