5.7. Add status to RampBox
A ramp can have several loadings at different stages. Which color should it get? That's a question for the model, not for the component:
export type Status = "empty" | "loaded" | "progress" | "not-started" | "";
export class Ramp {
// ...
get isEmpty(): boolean {
return !this.loadings.length;
}
get isLoaded(): boolean {
return !this.loadings.some(l => !l.isLoaded);
}
get isInProgress(): boolean {
return this.loadings.some(l => l.isInProgress);
}
get isSomeNotStarted(): boolean {
return this.loadings.some(l => !l.isStarted);
}
get status(): Status {
if (this.isEmpty) return "empty";
if (this.isLoaded) return "loaded";
if (this.isSomeNotStarted) return "not-started";
if (this.isInProgress) return "progress";
return "";
}
}
The order of the checks matters. An empty ramp has no loading that isn't loaded, so isLoaded is true for it too. That's why isEmpty goes first. Now look at ramp E: 0 of 42 and 3 of 29. One loading hasn't started, one is moving, so both isSomeNotStarted and isInProgress are true. Red should win, so isSomeNotStarted goes first. (isInProgress can't tell them apart anyway: picked !== pallets is true for 0 of 42 too.)
Add the status as a class in RampBox. The colors are already in Ramp.scss:
<main className={ramp.status}>
After a reload, B is green, C and D are yellow, E is red, and the empty A, F and G stay gray.
