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