Add the daily team administration, recruitment retouches, the Watchers' balm and a new Guild layout
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7ed63fff49
commit
b179a40a04
36 changed files with 799 additions and 298 deletions
|
|
@ -5,25 +5,12 @@ import { Tabs } from "../../../components/Tabs.jsx";
|
|||
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
|
||||
import { cancelExpedition, updateExpeditionSettings } from "../cardsApi.js";
|
||||
import { DATE_FORMATTER } from "./adminFormat.js";
|
||||
import { inRange, parse } from "./adminSettings.js";
|
||||
import { EXPEDITION_OPEN_PATH, EXPEDITION_SETTING_GROUPS, EXPEDITION_SETTING_THEMES, expeditionSettingLabel, formatSettingValue } from "./expeditionSettingFields.js";
|
||||
import { ApplyBar, DefaultHint, NumberInput, SettingsGroup } from "./SettingFields.jsx";
|
||||
import { readPath, same, toDraft, useSettingsDraft, writePath } from "./settingsDraft.js";
|
||||
|
||||
const DESTINATION_WEIGHT = { min: 0, max: 100 };
|
||||
|
||||
const readPath = (source, path) => path.split(".").reduce((value, key) => value?.[key], source);
|
||||
|
||||
function writePath(target, path, value) {
|
||||
const keys = path.split(".");
|
||||
keys.slice(0, -1).reduce((node, key) => node[key], target)[keys.at(-1)] = value;
|
||||
}
|
||||
|
||||
const same = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|
||||
const toDraft = (value) => (typeof value === "boolean" ? value : Array.isArray(value) ? value.map(String) : String(value));
|
||||
const fromDraft = (value) => (typeof value === "boolean" ? value : Array.isArray(value) ? value.map(parse) : parse(value));
|
||||
const validValue = (field, value) => (field.kind === "bool" ? typeof value === "boolean" : (Array.isArray(value) ? value : [value]).every((item) => inRange(item, field.min, field.max)));
|
||||
const withUnit = (value, unit) => (unit ? `${value} ${unit}` : String(value));
|
||||
const formatDefault = (value, unit) => (typeof value === "boolean" ? (value ? "oui" : "non") : Array.isArray(value) ? value.map((item) => withUnit(item, unit)).join(" / ") : withUnit(value, unit));
|
||||
|
||||
// Tous les réglages modifiables ici : ceux des groupes rangés dans un onglet (bornes du schéma) et ceux de chaque destination.
|
||||
// L'ouverture (bandeau d'état) et le prix d'un Éclat (Boutique) se règlent ailleurs.
|
||||
function editableFields(schema, destinations) {
|
||||
|
|
@ -38,70 +25,6 @@ function editableFields(schema, destinations) {
|
|||
|
||||
const PANEL_THEME = new Map(EXPEDITION_SETTING_THEMES.flatMap((theme) => theme.panels.map((panel) => [panel, theme.id])));
|
||||
|
||||
// Brouillon commun à tous les onglets : seules les valeurs touchées y figurent, le reste se lit dans les réglages enregistrés.
|
||||
function useSettingsDraft(settings, fields) {
|
||||
const [draft, setDraft] = useState({});
|
||||
const value = (path) => (path in draft ? fromDraft(draft[path]) : readPath(settings, path));
|
||||
const raw = (path) => (path in draft ? draft[path] : toDraft(readPath(settings, path)));
|
||||
const touched = fields.filter((field) => field.path in draft);
|
||||
const invalid = touched.filter((field) => !validValue(field, value(field.path)));
|
||||
const changes = touched.filter((field) => validValue(field, value(field.path)) && !same(value(field.path), readPath(settings, field.path)));
|
||||
const set = (path, next) => setDraft((current) => ({ ...current, [path]: next }));
|
||||
const reset = () => setDraft({});
|
||||
return { value, raw, invalid, changes, set, reset };
|
||||
}
|
||||
|
||||
function DefaultHint({ field, value, defaults, busy, onReset }) {
|
||||
const fallback = readPath(defaults, field.path);
|
||||
if (fallback === undefined || same(value, fallback)) return null;
|
||||
return <button className="nebula-admin-setting-default" type="button" disabled={busy} title="Rétablir la valeur par défaut" onClick={onReset}>
|
||||
Défaut : {formatDefault(fallback, field.unit)} <span aria-hidden="true">↺</span>
|
||||
</button>;
|
||||
}
|
||||
|
||||
function NumberInput({ field, value, label, busy, onChange }) {
|
||||
return <span className="nebula-admin-setting-input" data-unit={field.unit || undefined}>
|
||||
<input className="nds-input" type="number" inputMode="numeric" min={field.min} max={field.max} step="1" value={value} disabled={busy} aria-label={label} aria-invalid={!inRange(parse(value), field.min, field.max) || undefined} onChange={(event) => onChange(event.target.value)} />
|
||||
{field.unit && <span aria-hidden="true">{field.unit}</span>}
|
||||
</span>;
|
||||
}
|
||||
|
||||
// Un réglage : interrupteur, nombre ou suite de nombres, avec son état (modifié, invalide) et la valeur par défaut s'il s'en écarte.
|
||||
function SettingField({ field, draft, settings, defaults, busy }) {
|
||||
const value = draft.value(field.path);
|
||||
const raw = draft.raw(field.path);
|
||||
const changed = !same(value, readPath(settings, field.path));
|
||||
const invalid = !validValue(field, value);
|
||||
const label = field.unit ? `${field.label} (${field.unit})` : field.label;
|
||||
const state = { "data-changed": changed || undefined, "data-invalid": invalid || undefined };
|
||||
const hint = <DefaultHint field={field} value={value} defaults={defaults} busy={busy} onReset={() => draft.set(field.path, toDraft(readPath(defaults, field.path)))} />;
|
||||
const error = invalid && <small role="alert">Entier de {field.min.toLocaleString("fr-FR")} à {field.max.toLocaleString("fr-FR")}</small>;
|
||||
if (field.kind === "bool") return <div className="nebula-admin-expedition-field" {...state}>
|
||||
<span className="nebula-admin-setting-label">{field.label}</span>
|
||||
<button className="nds-button" data-size="sm" data-variant={raw ? "primary" : "secondary"} type="button" aria-pressed={raw} aria-label={field.label} disabled={busy} onClick={() => draft.set(field.path, !raw)}>{raw ? "Oui" : "Non"}</button>
|
||||
{hint}
|
||||
</div>;
|
||||
if (Array.isArray(raw)) return <fieldset className="nebula-admin-expedition-field" {...state}>
|
||||
<legend>{field.label}</legend>
|
||||
<div className="nebula-admin-expedition-items">{raw.map((item, index) => <label key={index}><span>{field.items?.[index] ?? index + 1}</span>
|
||||
<NumberInput field={field} value={item} label={`${label} · ${field.items?.[index] ?? index + 1}`} busy={busy} onChange={(next) => draft.set(field.path, raw.map((current, position) => (position === index ? next : current)))} />
|
||||
</label>)}</div>
|
||||
{error}{hint}
|
||||
</fieldset>;
|
||||
return <label className="nebula-admin-expedition-field" {...state}><span className="nebula-admin-setting-label">{field.label}</span>
|
||||
<NumberInput field={field} value={raw} label={label} busy={busy} onChange={(next) => draft.set(field.path, next)} />
|
||||
{error}{hint}
|
||||
</label>;
|
||||
}
|
||||
|
||||
function SettingsGroup({ group, fields, ...props }) {
|
||||
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-group" aria-labelledby={`nebula-admin-expedition-${group.id}`}>
|
||||
<div className="nds-section-heading nebula-admin-panel-heading"><h3 id={`nebula-admin-expedition-${group.id}`}>{group.title}</h3></div>
|
||||
<p className="nebula-form-help">{group.help}</p>
|
||||
<div className="nebula-admin-expedition-fields">{fields.map((field) => <SettingField key={field.path} field={field} {...props} />)}</div>
|
||||
</section>;
|
||||
}
|
||||
|
||||
// Destinations : proposées ou non, et poids dans le tirage du jour. Leurs textes vivent dans le fichier du serveur.
|
||||
function DestinationSettings({ destinations, draft, settings, defaults, busy }) {
|
||||
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-group" aria-labelledby="nebula-admin-expedition-destinations">
|
||||
|
|
@ -164,34 +87,6 @@ function ExpeditionsStatus({ enabled, today, destinations, busy, onToggle, onCan
|
|||
</section>;
|
||||
}
|
||||
|
||||
// Barre commune : nombre de réglages modifiés ou invalides, puis confirmation avec la liste des changements.
|
||||
function ApplyBar({ draft, settings, destinations, busy, onApply }) {
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const { changes, invalid } = draft;
|
||||
if (!changes.length && !invalid.length) return null;
|
||||
const count = (total, word) => `${total} réglage${total > 1 ? "s" : ""} ${word}${total > 1 ? "s" : ""}`;
|
||||
return <div className="nds-panel nebula-admin-apply-bar" role="region" aria-label="Modifications en attente">
|
||||
<p role="status">{[changes.length && count(changes.length, "modifié"), invalid.length && count(invalid.length, "invalide")].filter(Boolean).join(" · ")}</p>
|
||||
<div className="nds-toolbar">
|
||||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} aria-label="Annuler les modifications" onClick={draft.reset}>Annuler</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || !changes.length || invalid.length > 0} onClick={() => setConfirming(true)}>Appliquer</button>
|
||||
</div>
|
||||
{confirming && <ConfirmModal
|
||||
title={`Appliquer ${count(changes.length, "modifié")} ?`}
|
||||
message="Les nouveaux réglages s’appliquent aux prochains départs. Les expéditions en route gardent ceux de leur départ."
|
||||
confirmLabel="Appliquer"
|
||||
onClose={async (confirmed) => {
|
||||
setConfirming(false);
|
||||
if (confirmed) await onApply();
|
||||
}}
|
||||
>
|
||||
<ul className="nebula-admin-apply-changes">{changes.map((field) => <li key={field.path}>
|
||||
<span>{expeditionSettingLabel(field.path, destinations)}</span> : {formatSettingValue(readPath(settings, field.path))} → <strong>{formatSettingValue(draft.value(field.path))}</strong>
|
||||
</li>)}</ul>
|
||||
</ConfirmModal>}
|
||||
</div>;
|
||||
}
|
||||
|
||||
export function ExpeditionSettings({ dashboard, busy, runMutation, refreshDashboard }) {
|
||||
const { settings, defaults, schema, destinations } = dashboard.expeditionSettings;
|
||||
const [themeId, setThemeId] = useState(EXPEDITION_SETTING_THEMES[0].id);
|
||||
|
|
@ -227,6 +122,6 @@ export function ExpeditionSettings({ dashboard, busy, runMutation, refreshDashbo
|
|||
{theme.panels.map((panel) => (panel === "destinations"
|
||||
? <DestinationSettings key={panel} destinations={destinations} {...props} />
|
||||
: <SettingsGroup key={panel} group={EXPEDITION_SETTING_GROUPS.find((group) => group.id === panel)} fields={fields.filter((field) => field.panel === panel)} {...props} />))}
|
||||
<ApplyBar draft={draft} settings={settings} destinations={destinations} busy={busy} onApply={apply} />
|
||||
<ApplyBar draft={draft} settings={settings} busy={busy} onApply={apply} message="Les nouveaux réglages s’appliquent aux prochains départs. Les expéditions en route gardent ceux de leur départ." labelOf={(path) => expeditionSettingLabel(path, destinations)} formatValue={formatSettingValue} />
|
||||
</div>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue