mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Ensure a unique ID for supply routes.
List indexes are not a reliable list key unless the list is static. Indexes will be reused when games are loaded, which prevents the state from updating reliably. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2167
This commit is contained in:
parent
046c863768
commit
c5efc908de
@ -428,6 +428,7 @@ export type Tgo = {
|
|||||||
sidc: string;
|
sidc: string;
|
||||||
};
|
};
|
||||||
export type SupplyRoute = {
|
export type SupplyRoute = {
|
||||||
|
id: string;
|
||||||
points: LatLng[];
|
points: LatLng[];
|
||||||
front_active: boolean;
|
front_active: boolean;
|
||||||
is_sea: boolean;
|
is_sea: boolean;
|
||||||
|
|||||||
@ -7,8 +7,8 @@ export default function SupplyRoutesLayer() {
|
|||||||
const routes = useAppSelector(selectSupplyRoutes).routes;
|
const routes = useAppSelector(selectSupplyRoutes).routes;
|
||||||
return (
|
return (
|
||||||
<LayerGroup>
|
<LayerGroup>
|
||||||
{routes.map((route, idx) => {
|
{routes.map((route) => {
|
||||||
return <SupplyRoute key={idx} route={route} />;
|
return <SupplyRoute key={route.id} route={route} />;
|
||||||
})}
|
})}
|
||||||
</LayerGroup>
|
</LayerGroup>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import uuid
|
||||||
from typing import Any, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
from dcs import Point
|
from dcs import Point
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
@ -62,6 +64,7 @@ class TransportFinder:
|
|||||||
|
|
||||||
|
|
||||||
class SupplyRouteJs(BaseModel):
|
class SupplyRouteJs(BaseModel):
|
||||||
|
id: UUID
|
||||||
points: list[LeafletPoint]
|
points: list[LeafletPoint]
|
||||||
front_active: bool
|
front_active: bool
|
||||||
is_sea: bool
|
is_sea: bool
|
||||||
@ -76,6 +79,19 @@ class SupplyRouteJs(BaseModel):
|
|||||||
game: Game, a: ControlPoint, b: ControlPoint, points: list[Point], sea: bool
|
game: Game, a: ControlPoint, b: ControlPoint, points: list[Point], sea: bool
|
||||||
) -> SupplyRouteJs:
|
) -> SupplyRouteJs:
|
||||||
return SupplyRouteJs(
|
return SupplyRouteJs(
|
||||||
|
# Although these are not persistent objects in the backend, the frontend
|
||||||
|
# needs unique IDs for anything that it will use in a list. That means that
|
||||||
|
# any data that we expose as a list most likely needs a unique ID. List
|
||||||
|
# indexes are **not** sufficient as IDs across game loads, as any indexes
|
||||||
|
# that persist between games will not be updated in the UI.
|
||||||
|
#
|
||||||
|
# Generating a UUID for these ephemeral objects is awkward, but does not
|
||||||
|
# cause any issues since the only thing the ID is used for is to
|
||||||
|
# disambiguate objects across save games.
|
||||||
|
#
|
||||||
|
# https://reactjs.org/docs/lists-and-keys.html#keys
|
||||||
|
# https://github.com/dcs-liberation/dcs_liberation/issues/2167
|
||||||
|
id=uuid.uuid4(),
|
||||||
points=[p.latlng() for p in points],
|
points=[p.latlng() for p in points],
|
||||||
front_active=not sea and a.front_is_active(b),
|
front_active=not sea and a.front_is_active(b),
|
||||||
is_sea=sea,
|
is_sea=sea,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user