feat(frontend): make the command-chain editor a collapsible panel
Wrap the mission command-chain editor content in a Collapsible with an expand/collapse trigger in the header row, next to the Override/Legacy/ Defaults badge. The 'Command chain' title folds into the trigger so the card header holds only the toggle and the status badge.
This commit is contained in:
parent
b6e8fa6f90
commit
3ac6ebd87d
1 changed files with 109 additions and 87 deletions
|
|
@ -3,10 +3,13 @@
|
|||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import {
|
||||
Select,
|
||||
|
|
@ -54,6 +57,7 @@ export function MissionCommandChainEditor({
|
|||
}: MissionCommandChainEditorProps) {
|
||||
const router = useRouter();
|
||||
const [pending, setPending] = useState(false);
|
||||
const [contentOpen, setContentOpen] = useState(true);
|
||||
const initialSupervisors = (subordinateId: number) =>
|
||||
links.filter((l) => l.subordinateId === subordinateId).map((l) => l.supervisorId);
|
||||
const [draft, setDraft] = useState<Record<number, number[]>>(() =>
|
||||
|
|
@ -104,95 +108,113 @@ export function MissionCommandChainEditor({
|
|||
};
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex flex-wrap items-center justify-between gap-2 text-base">
|
||||
<span>Command chain</span>
|
||||
<Badge variant="outline">
|
||||
{mode === "stored" ? "Override" : mode === "legacy" ? "Legacy" : "Defaults"}
|
||||
</Badge>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Who was in command of whom for this operation only. Permanent assignments are not
|
||||
changed. Supervisors may rate their subordinate as a command review.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{mode === "legacy" && (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
This mission was rated before the chain existed, so its command reviews follow the
|
||||
original assignment rule and cannot be changed here.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{!editable && lockReason && (
|
||||
<Alert>
|
||||
<AlertDescription>{lockReason}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
<Collapsible open={contentOpen} onOpenChange={setContentOpen}>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex flex-wrap items-center justify-between gap-2 text-base">
|
||||
<div className="flex items-center gap-2">
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 w-7 p-0 text-muted-foreground hover:text-foreground"
|
||||
aria-label={contentOpen ? "Collapse command chain" : "Expand command chain"}
|
||||
>
|
||||
<ChevronDown
|
||||
aria-hidden
|
||||
className={cn("h-4 w-4 transition-transform", contentOpen && "rotate-180")}
|
||||
/>
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<Badge variant="outline">
|
||||
{mode === "stored" ? "Override" : mode === "legacy" ? "Legacy" : "Defaults"}
|
||||
</Badge>
|
||||
</div>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Who was in command of whom for this operation only. Permanent assignments are not
|
||||
changed. Supervisors may rate their subordinate as a command review.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CollapsibleContent className="overflow-hidden">
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{mode === "legacy" && (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
This mission was rated before the chain existed, so its command reviews follow the
|
||||
original assignment rule and cannot be changed here.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{!editable && lockReason && (
|
||||
<Alert>
|
||||
<AlertDescription>{lockReason}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{mode !== "legacy" && (
|
||||
<div className="flex flex-col gap-3">
|
||||
{participants.map((sub) => {
|
||||
const supervisors = draft[sub.id] ?? [];
|
||||
const options = participants.filter(
|
||||
(p) => p.id !== sub.id && !supervisors.includes(p.id),
|
||||
);
|
||||
return (
|
||||
<div key={sub.id} className="flex flex-col gap-1.5">
|
||||
<Label>{sub.name}</Label>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{supervisors.length === 0 && (
|
||||
<span className="text-sm text-muted-foreground">No supervisor</span>
|
||||
)}
|
||||
{supervisors.map((supId) => (
|
||||
<Badge key={supId} variant="secondary" className="gap-1">
|
||||
{nameOf(supId)}
|
||||
{editable && (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Remove ${nameOf(supId)} as supervisor`}
|
||||
onClick={() => removeSupervisor(sub.id, supId)}
|
||||
className="ml-1 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
{mode !== "legacy" && (
|
||||
<div className="flex flex-col gap-3">
|
||||
{participants.map((sub) => {
|
||||
const supervisors = draft[sub.id] ?? [];
|
||||
const options = participants.filter(
|
||||
(p) => p.id !== sub.id && !supervisors.includes(p.id),
|
||||
);
|
||||
return (
|
||||
<div key={sub.id} className="flex flex-col gap-1.5">
|
||||
<Label>{sub.name}</Label>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{supervisors.length === 0 && (
|
||||
<span className="text-sm text-muted-foreground">No supervisor</span>
|
||||
)}
|
||||
</Badge>
|
||||
))}
|
||||
{editable && options.length > 0 && (
|
||||
<Select onValueChange={(value) => addSupervisor(sub.id, Number(value))}>
|
||||
<SelectTrigger aria-label={`Add supervisor for ${sub.name}`}>
|
||||
<SelectValue placeholder="Add supervisor" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options.map((opt) => (
|
||||
<SelectItem key={opt.id} value={String(opt.id)}>
|
||||
{opt.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{supervisors.map((supId) => (
|
||||
<Badge key={supId} variant="secondary" className="gap-1">
|
||||
{nameOf(supId)}
|
||||
{editable && (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Remove ${nameOf(supId)} as supervisor`}
|
||||
onClick={() => removeSupervisor(sub.id, supId)}
|
||||
className="ml-1 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
)}
|
||||
</Badge>
|
||||
))}
|
||||
{editable && options.length > 0 && (
|
||||
<Select onValueChange={(value) => addSupervisor(sub.id, Number(value))}>
|
||||
<SelectTrigger aria-label={`Add supervisor for ${sub.name}`}>
|
||||
<SelectValue placeholder="Add supervisor" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options.map((opt) => (
|
||||
<SelectItem key={opt.id} value={String(opt.id)}>
|
||||
{opt.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{editable && mode !== "legacy" && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button onClick={save} disabled={pending}>
|
||||
Save chain
|
||||
</Button>
|
||||
<Button variant="outline" onClick={reset} disabled={pending}>
|
||||
Reset to defaults
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
{editable && mode !== "legacy" && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button onClick={save} disabled={pending}>
|
||||
Save chain
|
||||
</Button>
|
||||
<Button variant="outline" onClick={reset} disabled={pending}>
|
||||
Reset to defaults
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</CollapsibleContent>
|
||||
</Card>
|
||||
</Collapsible>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue