mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 04:08:11 +00:00
feat: add hazardous goods declaration feature
- Introduced HazardDeclarationPanel component to display dangerous goods declaration details. - Updated URL constants to include CLEARANCE_PROCEED endpoint for re-requesting operations. - Enhanced permissions to include hazardous approval roles for contract approvals. - Integrated HazardDeclarationPanel into ContractRequestDetailPage and ContractClearanceDetailPage. - Added proceedToOperation method in bookings service for handling operation re-requests. - Updated contract forms and schemas to include hazard class and UN number fields. - Implemented validation for hazardous contracts in the contract creation flow. - Added expiry notice functionality for contracts nearing validity end. - Created tests for expiry notice calculations and labels. - Updated UI components to reflect hazardous cargo information and validation errors.
This commit is contained in:
@@ -33,41 +33,86 @@ import {
|
||||
BookingReferenceYardDto,
|
||||
} from "./dto/booking-reference-data.dto";
|
||||
|
||||
/**
|
||||
* Reference cargo tree: top-level groups, each carrying its selectable
|
||||
* commodities.
|
||||
*
|
||||
* `cargo_types` is an arbitrary-depth tree (Bulk → Steel Billet → S1 → …), but
|
||||
* only a LEAF is a real commodity — an intermediate node is a container for
|
||||
* finer types, and booking against it would be ambiguous. So each group's
|
||||
* `children` are all of its leaf descendants, flattened, whatever the depth.
|
||||
* Deep leaves carry their path below the group ("Steel Billet → S1") so a
|
||||
* generically-named leaf still reads unambiguously in a dropdown.
|
||||
*
|
||||
* A group with no active descendants is its own leaf and is emitted as its
|
||||
* single child — otherwise it is selectable as a group but offers no commodity,
|
||||
* which dead-ends every form that requires one.
|
||||
*/
|
||||
export function buildCargoTypeTree(
|
||||
rows: CargoType[],
|
||||
): BookingReferenceCargoTypeGroupDto[] {
|
||||
const active = rows.filter((r) => r.isActive);
|
||||
const parents = active
|
||||
.filter((r) => !r.parentGroupId)
|
||||
.sort(
|
||||
(a, b) => a.displayOrder - b.displayOrder || a.code.localeCompare(b.code),
|
||||
);
|
||||
|
||||
const byOrder = (a: CargoType, b: CargoType) =>
|
||||
a.displayOrder - b.displayOrder || a.code.localeCompare(b.code);
|
||||
|
||||
const childrenOf = new Map<string, CargoType[]>();
|
||||
for (const row of active) {
|
||||
if (!row.parentGroupId) continue;
|
||||
const siblings = childrenOf.get(row.parentGroupId) ?? [];
|
||||
siblings.push(row);
|
||||
childrenOf.set(row.parentGroupId, siblings);
|
||||
}
|
||||
for (const siblings of childrenOf.values()) siblings.sort(byOrder);
|
||||
|
||||
const parents = active.filter((r) => !r.parentGroupId).sort(byOrder);
|
||||
|
||||
/** Depth-first leaf walk; `trail` is the path below the group. */
|
||||
const collectLeaves = (
|
||||
node: CargoType,
|
||||
trail: string[],
|
||||
seen: Set<string>,
|
||||
): BookingReferenceCargoTypeChildDto[] => {
|
||||
// Admin-entered parent pointers could in principle cycle — never loop.
|
||||
if (seen.has(node.id)) return [];
|
||||
seen.add(node.id);
|
||||
|
||||
const kids = childrenOf.get(node.id) ?? [];
|
||||
if (kids.length === 0) {
|
||||
return [
|
||||
{
|
||||
id: node.id,
|
||||
name: [...trail, node.cargoTypeName].join(" → "),
|
||||
code: node.code,
|
||||
unit_of_measure: node.unitOfMeasure ?? null,
|
||||
},
|
||||
];
|
||||
}
|
||||
const nextTrail = [...trail, node.cargoTypeName];
|
||||
return kids.flatMap((kid) => collectLeaves(kid, nextTrail, seen));
|
||||
};
|
||||
|
||||
return parents.map((parent) => {
|
||||
const children = active
|
||||
.filter((r) => r.parentGroupId === parent.id)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
a.displayOrder - b.displayOrder || a.code.localeCompare(b.code),
|
||||
)
|
||||
.map(
|
||||
(child): BookingReferenceCargoTypeChildDto => ({
|
||||
id: child.id,
|
||||
name: child.cargoTypeName,
|
||||
code: child.code,
|
||||
unit_of_measure: child.unitOfMeasure ?? null,
|
||||
}),
|
||||
);
|
||||
const kids = childrenOf.get(parent.id) ?? [];
|
||||
const children =
|
||||
kids.length === 0
|
||||
? // The group itself is the commodity.
|
||||
[
|
||||
{
|
||||
id: parent.id,
|
||||
name: parent.cargoTypeName,
|
||||
code: parent.code,
|
||||
unit_of_measure: parent.unitOfMeasure ?? null,
|
||||
},
|
||||
]
|
||||
: kids.flatMap((kid) => collectLeaves(kid, [], new Set<string>()));
|
||||
|
||||
const group: BookingReferenceCargoTypeGroupDto = {
|
||||
return {
|
||||
id: parent.id,
|
||||
name: parent.cargoTypeName,
|
||||
code: parent.code,
|
||||
children,
|
||||
};
|
||||
if (children.length > 0) {
|
||||
group.children = children;
|
||||
}
|
||||
return group;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user