1
0
Fork 0

Compare commits

..

No commits in common. "969ca75a70eff86f729843256b7da5ece95b7bc0" and "9a0b78fcf084c2f1c12afbd9da6984dce504714f" have entirely different histories.

10 changed files with 25 additions and 39293 deletions

View file

@ -1,25 +1,5 @@
# Changelog
# v0.8.1
Threat estimates now read at a glance on the mission page, a Discord release-notes command ships, and the Labor Crew panel loads correctly again.
### Features
- **Threat assessment.** Staff can now estimate how likely the unit is to meet each enemy force type. From the new Intelligence tab on a mission, add rows pairing a force type with a likelihood (Very Unlikely to Very Likely). The mission page renders it as a color-coded dossier table, shaded from slate to red by severity, with a smart icon per force type (helicopter, plane, armor, infantry, and more). Leave the list empty to hide the table.
- **Release notes for Discord.** A new `/changelog` command posts release notes straight to Discord, so the community sees what shipped without opening the site.
### Improvements
- The `/changelog` command now supports version ranges, so release notes can span a set of tags.
### Fixes
- **Labor Crew panel loads.** The game-structures panel for Labor Crews was not loading its data correctly and now renders as intended.
---
# v0.8.0
This release is about helping the community grow. You can now earn XP for contributing, the wiki got a fresh new look, and the world map is simpler to browse.

View file

@ -1,6 +1,6 @@
{
"name": "polaris-task-force",
"version": "0.8.1",
"version": "0.8.0",
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
"license": "MIT",
"type": "module",

View file

@ -22,7 +22,6 @@ import { MissionObjectives } from "@/components/frontend/intelligence/MissionObj
import { hasPermission } from "@/utils/access-control/hasPermission";
import { redactText } from "@/lib/redaction";
import { MissionFactions } from "@/components/frontend/intelligence/MissionFactions";
import { MissionThreatAssessment } from "@/components/frontend/intelligence/MissionThreatAssessment";
import { MissionRoles } from "@/components/frontend/intelligence/MissionRoles";
import { MissionRoleSignups } from "@/components/frontend/intelligence/MissionRoleSignups";
import { MissionLogistics } from "@/components/frontend/intelligence/MissionLogistics";
@ -507,11 +506,6 @@ export default async function MissionDetailPage({ params }: MissionDetailPagePro
</ItemContent>
</Item>
<MissionThreatAssessment
likelihoods={mission.threatAssessment?.likelihoods ?? null}
missionId={mission.id}
/>
<MissionBriefingSection briefing={mission.briefing ?? null} />
<MissionObjectives

View file

@ -757,57 +757,6 @@ export const Missions: CollectionConfig = {
},
],
},
{
label: "Intelligence",
description:
"Analyst estimates of the threat the unit is likely to face during this operation.",
fields: [
{
name: "threatAssessment",
type: "group",
label: "Threat Assessment",
admin: {
description:
"Likelihood that the unit will encounter each enemy force type during the mission. Rendered as a color-coded table on the mission page.",
},
fields: [
{
name: "likelihoods",
type: "array",
labels: { singular: "Likelihood", plural: "Likelihoods" },
admin: {
description:
"One row per enemy force type. Leave empty to hide the table on the mission page.",
},
fields: [
{
name: "category",
type: "text",
required: true,
admin: {
description:
'Enemy force type, e.g. "Light Infantry", "Armor", "Rotary Air".',
},
},
{
name: "likelihood",
type: "select",
required: true,
defaultValue: "possible",
options: [
{ label: "Very Unlikely", value: "veryUnlikely" },
{ label: "Unlikely", value: "unlikely" },
{ label: "Possible", value: "possible" },
{ label: "Likely", value: "likely" },
{ label: "Very Likely", value: "veryLikely" },
],
},
],
},
],
},
],
},
{
label: "Dedicated Server",
description: "Server-specific details, like the IP, port, mission file, mod list, etc.",

View file

@ -1,9 +1,8 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
import { useEffect, useState } from "react";
import { UsersIcon } from "lucide-react";
import { toast, useAllFormFields, useDocumentInfo } from "@payloadcms/ui";
import { reduceFieldsToValues } from "payload/shared";
import { toast, useDocumentInfo, useField } from "@payloadcms/ui";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@ -26,45 +25,20 @@ interface LaborEdit {
unitSalary: string;
}
/** Form-state shape of a laborRequirements row (collection field names). */
interface LaborRequirementRow {
classification?: number | { id: number } | null;
requiredHeadcount?: number | null;
maxHeadcount?: number | null;
enforcedSalary?: number | null;
}
/** Relationship values arrive as raw ids (depth=0) or populated objects. */
function relId(value: unknown): number | null {
if (typeof value === "number") return value;
if (value !== null && typeof value === "object" && "id" in value) {
const id = (value as { id: unknown }).id;
return typeof id === "number" ? id : null;
}
return null;
}
export function LaborCrewPanel() {
const documentInfo = useDocumentInfo();
const [formFields] = useAllFormFields();
// Array fields store only a row count at their own path in Payload's form
// state; rebuild the actual rows from the flattened field tree instead.
const laborRequirements = useMemo(() => {
const data = reduceFieldsToValues(formFields, true) as {
laborRequirements?: LaborRequirementRow[];
};
return Array.isArray(data.laborRequirements) ? data.laborRequirements : [];
}, [formFields]);
const requirementsKey = JSON.stringify(laborRequirements);
const requirementsRef = useRef(laborRequirements);
requirementsRef.current = laborRequirements;
const laborRequirementsField = useField<{
classificationId?: number | null;
requiredHeadcount?: number | null;
maxHeadcount?: number | null;
enforcedSalary?: number | null;
}[]>({
path: "laborRequirements",
});
const [crew, setCrew] = useState<LaborCrew[]>([]);
const [edits, setEdits] = useState<Record<number, LaborEdit>>({});
const [loadingClassifications, setLoadingClassifications] = useState(false);
const [loadFailed, setLoadFailed] = useState(false);
const [savingId, setSavingId] = useState<number | null>(null);
// Fetch classifications and current crew from REST
@ -73,50 +47,31 @@ export function LaborCrewPanel() {
async function loadData() {
setLoadingClassifications(true);
setLoadFailed(false);
try {
const staffingParams = new URLSearchParams({
depth: "0",
limit: "100",
"where[structure][equals]": String(documentInfo.id),
"where[positionType][equals]": "labor",
"where[status][equals]": "active",
});
const [classificationsRes, crewRes] = await Promise.all([
fetch("/api/labor-classifications?depth=0&limit=100"),
fetch(`/api/npc-staffing?${staffingParams.toString()}`),
fetch("/api/labor-classifications?depth=0"),
fetch(`/api/npc-staffing?where.structure.id=${documentInfo.id}&depth=0`),
]);
if (cancelled) return;
if (!classificationsRes.ok || !crewRes.ok) {
throw new Error(
`Labor data request failed (classifications ${classificationsRes.status}, staffing ${crewRes.status})`,
);
}
const classificationsBody = await classificationsRes.json();
const crewBody = await crewRes.json();
const classifications = classificationsBody?.docs as
| LaborClassificationOption[]
| undefined;
if (!Array.isArray(classifications)) {
throw new Error("Unexpected labor classifications response shape");
}
const crewDocs: any[] = Array.isArray(crewBody?.docs) ? crewBody.docs : [];
const classifications = (await classificationsRes.json()).docs as LaborClassificationOption[];
const crewDocs = await crewRes.json();
// Build crew list from laborRequirements + current npc-staffing docs
const requirementList = requirementsRef.current;
const requirementList = laborRequirementsField.value ?? [];
const newCrew: LaborCrew[] = requirementList.flatMap((req) => {
const classification = classifications.find(
(c) => c.id === relId(req.classification),
(c) => c.id === req.classificationId,
);
if (!classification) return [];
const crewMembers = crewDocs.filter(
(m) => relId(m.laborClassification) === classification.id,
const crewMembers = (crewDocs.docs ?? []).filter(
(m: any) =>
m.positionType === "labor" &&
m.laborClassification?.id === classification.id,
);
const headcount = crewMembers.reduce((sum, m) => sum + (m.headcount ?? 1), 0);
const headcount = crewMembers.reduce((sum: number, m: any) => sum + (m.headcount ?? 1), 0);
const unitSalary = crewMembers[0]?.salary ?? classification.defaultUnitSalary ?? 0;
return {
@ -131,9 +86,7 @@ export function LaborCrewPanel() {
});
setCrew(newCrew);
} catch (err) {
console.error("[LaborCrewPanel] Failed to load labor data", err);
setLoadFailed(true);
} catch {
toast.error("Failed to load labor data");
} finally {
setLoadingClassifications(false);
@ -142,10 +95,7 @@ export function LaborCrewPanel() {
if (documentInfo.id) loadData();
return () => { cancelled = true; };
// requirementsKey tracks the labor requirements content; requirementsRef
// always holds the latest rows without retriggering the effect.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [documentInfo.id, requirementsKey]);
}, [documentInfo.id, laborRequirementsField.value]);
function getEdit(crewItem: LaborCrew): LaborEdit {
return edits[crewItem.classificationId] ?? {
@ -236,10 +186,6 @@ export function LaborCrewPanel() {
<CardContent>
{loadingClassifications ? (
<p className="text-sm text-muted-foreground">Loading crew data...</p>
) : loadFailed ? (
<p className="text-sm text-muted-foreground">
Labor data could not be loaded. Reload the page to try again.
</p>
) : crew.length === 0 ? (
<p className="text-sm text-muted-foreground">No labor classifications configured for this structure.</p>
) : (
@ -300,7 +246,6 @@ export function LaborCrewPanel() {
)}
</div>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => void handleSave(item)}

View file

@ -1,330 +0,0 @@
import {
BiohazardIcon,
BinocularsIcon,
CastleIcon,
FlameIcon,
HelicopterIcon,
PackageIcon,
PlaneIcon,
PlaneTakeoffIcon,
RadarIcon,
RadioIcon,
RocketIcon,
ShieldIcon,
ShipIcon,
TruckIcon,
UsersIcon,
type LucideIcon,
} from "lucide-react";
type Likelihood = "veryUnlikely" | "unlikely" | "possible" | "likely" | "veryLikely";
interface LikelihoodEntry {
category: string;
likelihood: Likelihood;
id?: string | null;
}
interface MissionThreatAssessmentProps {
likelihoods: LikelihoodEntry[] | null;
/** Optional mission id, used to derive the deterministic REF code in the strip. */
missionId?: number;
}
/**
* Tactical dossier readout of the analyst threat estimate. Higher likelihood of
* an enemy force type reads as more dangerous, so the ramp runs cool (slate) for
* "Very Unlikely" up to red for "Very Likely". The value is always spelled out,
* so color is reinforcement only, never the sole signal.
*/
const likelihoodStyles: Record<
Likelihood,
{ label: string; className: string; dot: string }
> = {
veryUnlikely: { label: "Very Unlikely", className: "text-slate-300", dot: "bg-slate-300" },
unlikely: { label: "Unlikely", className: "text-sky-400", dot: "bg-sky-400" },
possible: { label: "Possible", className: "text-amber-400", dot: "bg-amber-400" },
likely: { label: "Likely", className: "text-orange-400", dot: "bg-orange-400" },
veryLikely: { label: "Very Likely", className: "text-red-400", dot: "bg-red-400" },
};
/**
* Heuristic force-type glyph. Categories are free text, so we match on
* substrings in priority order (first hit wins): specific platforms before
* generic domains, and air-defense before the bare "defense" catch-all. Unknown
* categories simply render without an icon. Keywords are lowercase; matching is
* case-insensitive `includes`.
*/
const CATEGORY_ICON_RULES: { Icon: LucideIcon; keywords: string[] }[] = [
{ Icon: HelicopterIcon, keywords: ["heli", "rotary", "rotor", "chopper", "dustoff"] },
{
Icon: PlaneIcon,
keywords: [
"plane",
"jet",
"aircraft",
"fighter",
"bomber",
"fixed-wing",
"fixed wing",
"air wing",
"airwing",
"air support",
],
},
{ Icon: PlaneTakeoffIcon, keywords: ["drone", "uav", "quadcopter", "fpv", "mavic", "loitering"] },
{
Icon: ShieldIcon,
keywords: [
"air defense",
"air defence",
"airdefence",
"iads",
"anti-air",
"antiair",
"surface-to-air",
"sam site",
"patriot",
"tunguska",
"pantsir",
"shilka",
"tor-m2",
"tor m2",
],
},
{
Icon: RocketIcon,
keywords: [
"rocket",
"missile",
"artillery",
"arty",
"mortar",
"howitzer",
"mlrs",
"cannon",
"gun line",
"gunline",
"field gun",
],
},
{
Icon: ShipIcon,
keywords: [
"naval",
"navy",
"ship",
"boat",
"maritime",
"amphibious",
"harbor",
"harbour",
"riverine",
"lhd",
"srf",
],
},
{
Icon: TruckIcon,
keywords: [
"armor",
"armour",
"tank",
"afv",
"apc",
"ifv",
"mbt",
"mech",
"technical",
"gun truck",
"mrap",
],
},
{
Icon: UsersIcon,
keywords: [
"infantry",
"rifle",
"foot",
"dismount",
"soldier",
"troop",
"grunt",
"para",
"ranger",
"commando",
"squad",
"insurgent",
],
},
{
Icon: CastleIcon,
keywords: [
"static",
"fortif",
"bunker",
"defense",
"defence",
"outpost",
"emplacement",
"objective",
"obstacle",
"minefield",
"landmine",
"ied",
"ambush",
],
},
{
Icon: BinocularsIcon,
keywords: [
"recon",
"scout",
"surveil",
"observation",
"spotter",
"sniper",
"designator",
"jtac",
"marc",
],
},
{
Icon: RadarIcon,
keywords: ["radar", "sensor", "counter-battery", "counter battery", "sigint", "c4isr", "c4i"],
},
{
Icon: RadioIcon,
keywords: ["comms", "communication", "radio", "electronic", "jammer", "ecm", "signal", "network"],
},
{
Icon: PackageIcon,
keywords: [
"logistic",
"supply",
"resupply",
"convoy",
"fuel",
"ammo",
"ammunition",
"transport",
"cargo",
"truck",
],
},
{ Icon: FlameIcon, keywords: ["flame", "incendiary", "thermite", "phosphorus"] },
{
Icon: BiohazardIcon,
keywords: ["chemical", "biochem", "cbrn", "nbc", "radiolog", "toxic", "nerve agent", "mustard"],
},
];
function resolveCategoryIcon(category: string): LucideIcon | null {
const value = category.toLowerCase();
for (const rule of CATEGORY_ICON_RULES) {
if (rule.keywords.some((keyword) => value.includes(keyword))) {
return rule.Icon;
}
}
return null;
}
export function MissionThreatAssessment({
likelihoods,
missionId,
}: MissionThreatAssessmentProps) {
if (!likelihoods || likelihoods.length === 0) {
return null;
}
const refCode = missionId != null ? String(missionId).padStart(3, "0") : null;
return (
<section
aria-label="Threat Assessment"
className="relative overflow-hidden rounded-none border border-border/70 bg-card"
>
{/* Faint grid texture: constant opacity, never brightens. */}
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 z-[1] opacity-[0.04]"
style={{
backgroundImage:
"linear-gradient(to right, white 1px, transparent 1px), linear-gradient(to bottom, white 1px, transparent 1px)",
backgroundSize: "28px 28px",
}}
/>
{/* Corner brackets. */}
<div aria-hidden="true" className="pointer-events-none absolute inset-2 z-30">
<span className="absolute left-0 top-0 size-3 border-l border-t border-white/25" />
<span className="absolute right-0 top-0 size-3 border-r border-t border-white/25" />
<span className="absolute bottom-0 left-0 size-3 border-b border-l border-white/25" />
<span className="absolute bottom-0 right-0 size-3 border-b border-r border-white/25" />
</div>
{/* Classification strip. */}
<div
aria-hidden="true"
className="relative z-20 flex items-center justify-between border-b border-white/15 bg-black/50 px-5 py-1.5 backdrop-blur-sm"
>
<span className="flex items-center gap-1.5 font-mono text-[9px] uppercase tracking-widest text-white/60">
<RadarIcon className="size-3" />
Threat Assessment // Intel
</span>
{refCode && (
<span className="font-mono text-[9px] uppercase tracking-widest text-white/60">
REF {refCode}
</span>
)}
</div>
{/* Likelihood rows. */}
<table className="relative z-10 w-full border-collapse text-sm">
<caption className="sr-only">
Likelihood of encountering each enemy force type during this operation.
</caption>
<thead>
<tr className="border-b border-white/15">
<th
scope="col"
className="px-5 pb-2 pt-3 text-left font-mono text-[9px] font-medium uppercase tracking-widest text-white/40"
>
Force Type
</th>
<th
scope="col"
className="px-5 pb-2 pt-3 text-right font-mono text-[9px] font-medium uppercase tracking-widest text-white/40"
>
Likelihood
</th>
</tr>
</thead>
<tbody className="divide-y divide-white/10">
{likelihoods.map((entry, index) => {
const style = likelihoodStyles[entry.likelihood] ?? likelihoodStyles.possible;
const Icon = resolveCategoryIcon(entry.category);
return (
<tr key={entry.id ?? `${entry.category}-${index}`}>
<th scope="row" className="px-5 py-2.5 text-left align-middle">
<span className="flex items-center gap-2 font-mono text-xs font-medium uppercase tracking-wider text-white/70">
{Icon && <Icon aria-hidden="true" className="size-3.5 shrink-0 text-white/40" />}
<span>{entry.category}</span>
</span>
</th>
<td className="px-5 py-2.5 text-right align-middle">
<span
className={`inline-flex items-center justify-end gap-2 whitespace-nowrap font-mono text-xs font-semibold uppercase tracking-wider ${style.className}`}
>
<span aria-hidden="true" className={`size-1.5 shrink-0 ${style.dot}`} />
{style.label}
</span>
</td>
</tr>
);
})}
</tbody>
</table>
</section>
);
}

View file

@ -1,23 +0,0 @@
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
await db.execute(sql`
CREATE TYPE "public"."enum_missions_threat_assessment_likelihoods_likelihood" AS ENUM('veryUnlikely', 'unlikely', 'possible', 'likely', 'veryLikely');
CREATE TABLE "missions_threat_assessment_likelihoods" (
"_order" integer NOT NULL,
"_parent_id" integer NOT NULL,
"id" varchar PRIMARY KEY NOT NULL,
"category" varchar NOT NULL,
"likelihood" "enum_missions_threat_assessment_likelihoods_likelihood" DEFAULT 'possible' NOT NULL
);
ALTER TABLE "missions_threat_assessment_likelihoods" ADD CONSTRAINT "missions_threat_assessment_likelihoods_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."missions"("id") ON DELETE cascade ON UPDATE no action;
CREATE INDEX "missions_threat_assessment_likelihoods_order_idx" ON "missions_threat_assessment_likelihoods" USING btree ("_order");
CREATE INDEX "missions_threat_assessment_likelihoods_parent_id_idx" ON "missions_threat_assessment_likelihoods" USING btree ("_parent_id");`)
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
DROP TABLE "missions_threat_assessment_likelihoods" CASCADE;
DROP TYPE "public"."enum_missions_threat_assessment_likelihoods_likelihood";`)
}

View file

@ -119,7 +119,6 @@ import * as migration_20261007_183000_add_missing_mcp_key_capabilities from './2
import * as migration_20261009_160740_add_campaign_on_hold_status from './20261009_160740_add_campaign_on_hold_status';
import * as migration_20261009_185259_add_wiki_featured_curation from './20261009_185259_add_wiki_featured_curation';
import * as migration_20261009_201920_add_contribution_entries from './20261009_201920_add_contribution_entries';
import * as migration_20261010_050644_add_mission_threat_assessment from './20261010_050644_add_mission_threat_assessment';
export const migrations = [
{
@ -725,11 +724,6 @@ export const migrations = [
{
up: migration_20261009_201920_add_contribution_entries.up,
down: migration_20261009_201920_add_contribution_entries.down,
name: '20261009_201920_add_contribution_entries',
},
{
up: migration_20261010_050644_add_mission_threat_assessment.up,
down: migration_20261010_050644_add_mission_threat_assessment.down,
name: '20261010_050644_add_mission_threat_assessment'
name: '20261009_201920_add_contribution_entries'
},
];

View file

@ -3784,24 +3784,6 @@ export interface Mission {
id?: string | null;
}[]
| null;
/**
* Likelihood that the unit will encounter each enemy force type during the mission. Rendered as a color-coded table on the mission page.
*/
threatAssessment?: {
/**
* One row per enemy force type. Leave empty to hide the table on the mission page.
*/
likelihoods?:
| {
/**
* Enemy force type, e.g. "Light Infantry", "Armor", "Rotary Air".
*/
category: string;
likelihood: 'veryUnlikely' | 'unlikely' | 'possible' | 'likely' | 'veryLikely';
id?: string | null;
}[]
| null;
};
gameDetails: {
serverDetails: {
serverIp: string;
@ -9012,17 +8994,6 @@ export interface MissionsSelect<T extends boolean = true> {
threatLevel?: T;
id?: T;
};
threatAssessment?:
| T
| {
likelihoods?:
| T
| {
category?: T;
likelihood?: T;
id?: T;
};
};
gameDetails?:
| T
| {