CEC-4883: update api shape and display trex version on fleets (#418)
This commit is contained in:
@@ -113,18 +113,20 @@ export const FleetProvider = ({ children }) => {
|
|||||||
throw new Error(`Get fleet vehicles error. ${result.message}`);
|
throw new Error(`Get fleet vehicles error. ${result.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectionsResult = await vehiclesAPI.getConnections({ "VINs": result.data }, token)
|
const vins = result.data.map(vehicle => vehicle.vin);
|
||||||
|
const connectionsResult = await vehiclesAPI.getConnections({ "VINs": vins }, token)
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
setFleetVehicles([])
|
setFleetVehicles([])
|
||||||
throw new Error(`Get vehicles connections error. ${result.message}`);
|
throw new Error(`Get vehicles connections error. ${result.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cars = []
|
var cars = []
|
||||||
result.data.forEach((vin) => {
|
result.data.forEach((vehicle) => {
|
||||||
cars.push({
|
cars.push({
|
||||||
vin: vin,
|
vin: vehicle.vin,
|
||||||
connected: connectionsResult[vin] || false,
|
connected: connectionsResult[vehicle.vin] || false,
|
||||||
connectedHMI: connectionsResult[`2:${vin}`] || false
|
connectedHMI: connectionsResult[`2:${vehicle.vin}`] || false,
|
||||||
|
trex_version: vehicle.carstate?.trex_version || "",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -347,8 +347,7 @@ describe("FleetContext", () => {
|
|||||||
describe("getFleetVehicles", () => {
|
describe("getFleetVehicles", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const TestComp = () => {
|
const TestComp = () => {
|
||||||
const { busy, error, fleetVehicles, getFleetVehicles } =
|
const { busy, error, fleetVehicles, getFleetVehicles } = useFleetContext();
|
||||||
useFleetContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -805,16 +804,19 @@ const expectedFleetVehiclesData = [
|
|||||||
vin: "USWESTVIN12345678",
|
vin: "USWESTVIN12345678",
|
||||||
connected: true,
|
connected: true,
|
||||||
connectedHMI: false,
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vin: "USWESTVIN12345679",
|
vin: "USWESTVIN12345679",
|
||||||
connected: true,
|
connected: true,
|
||||||
connectedHMI: false,
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vin: "USWESTVIN12345670",
|
vin: "USWESTVIN12345670",
|
||||||
connected: true,
|
connected: true,
|
||||||
connectedHMI: false,
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -67,17 +67,20 @@ export const useFleetContext = () => ({
|
|||||||
{
|
{
|
||||||
vin: "USWESTVIN12345678",
|
vin: "USWESTVIN12345678",
|
||||||
connected: false,
|
connected: false,
|
||||||
connectedHMI: false
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vin: "USWESTVIN12345679",
|
vin: "USWESTVIN12345679",
|
||||||
connected: true,
|
connected: true,
|
||||||
connectedHMI: true
|
connectedHMI: true,
|
||||||
|
trex_version: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vin: "USWESTVIN12345670",
|
vin: "USWESTVIN12345670",
|
||||||
connected: false,
|
connected: false,
|
||||||
connectedHMI: false
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
return Promise.resolve(result);
|
return Promise.resolve(result);
|
||||||
|
|||||||
@@ -127,6 +127,29 @@ exports[`FleetVehiclesTable Render 1`] = `
|
|||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th>
|
||||||
|
<th
|
||||||
|
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
|
||||||
|
scope="col"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
aria-disabled="false"
|
||||||
|
class="MuiButtonBase-root MuiTableSortLabel-root"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
T.REX Version
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="MuiSvgIcon-root MuiTableSortLabel-icon MuiTableSortLabel-iconDirectionAsc"
|
||||||
|
focusable="false"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
</th>
|
||||||
<th
|
<th
|
||||||
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
|
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
|
||||||
scope="col"
|
scope="col"
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ const tableColumns = [
|
|||||||
id: "vin",
|
id: "vin",
|
||||||
label: "VIN",
|
label: "VIN",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "trex_version",
|
||||||
|
label: "T.REX Version",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "",
|
id: "",
|
||||||
label: "Actions",
|
label: "Actions",
|
||||||
@@ -204,7 +208,8 @@ const MainForm = ({ name }) => {
|
|||||||
}
|
}
|
||||||
<Link key={"link" + car.vin} to={`/vehicle-status/${car.vin}`}>{car.vin}</Link>
|
<Link key={"link" + car.vin} to={`/vehicle-status/${car.vin}`}>{car.vin}</Link>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell key={"cell2" + car.vin} align="center">{Actions(car.vin)}</TableCell>
|
<TableCell key={"cell2" + car.vin} align="center">{car.trex_version}</TableCell>
|
||||||
|
<TableCell key={"cell3" + car.vin} align="center">{Actions(car.vin)}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
)
|
)
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -126,6 +126,29 @@ exports[`VehiclesTab Render 1`] = `
|
|||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th>
|
||||||
|
<th
|
||||||
|
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
|
||||||
|
scope="col"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
aria-disabled="false"
|
||||||
|
class="MuiButtonBase-root MuiTableSortLabel-root"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
T.REX Version
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="MuiSvgIcon-root MuiTableSortLabel-icon MuiTableSortLabel-iconDirectionAsc"
|
||||||
|
focusable="false"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
</th>
|
||||||
<th
|
<th
|
||||||
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
|
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
|
||||||
scope="col"
|
scope="col"
|
||||||
|
|||||||
@@ -34,7 +34,26 @@ const fleets = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const vehicles = ["USWESTVIN12345678", "USWESTVIN12345679", "USWESTVIN12345670"];
|
const vehicles = [
|
||||||
|
{
|
||||||
|
vin: "USWESTVIN12345678",
|
||||||
|
connected: false,
|
||||||
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vin: "USWESTVIN12345679",
|
||||||
|
connected: true,
|
||||||
|
connectedHMI: true,
|
||||||
|
trex_version: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vin: "USWESTVIN12345670",
|
||||||
|
connected: false,
|
||||||
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const fleetsAPI = {
|
const fleetsAPI = {
|
||||||
addFleet: async (fleet) => {
|
addFleet: async (fleet) => {
|
||||||
@@ -63,11 +82,16 @@ const fleetsAPI = {
|
|||||||
return { data: vehicles };
|
return { data: vehicles };
|
||||||
},
|
},
|
||||||
addFleetVehicles: async (_name, payload) => {
|
addFleetVehicles: async (_name, payload) => {
|
||||||
payload.vins && vehicles.push(...payload.vins);
|
payload.vins && vehicles.push(...payload.vins.map((vin => ({
|
||||||
|
vin,
|
||||||
|
connected: false,
|
||||||
|
connectedHMI: false,
|
||||||
|
trex_version: "",
|
||||||
|
}))));
|
||||||
return payload;
|
return payload;
|
||||||
},
|
},
|
||||||
deleteFleetVehicle: async (_name, vehicle) => {
|
deleteFleetVehicle: async (_name, vehicle) => {
|
||||||
const index = vehicles.findIndex(element => element === vehicle.vin);
|
const index = vehicles.findIndex(element => element.vin === vehicle.vin);
|
||||||
if (index >= 0) vehicles.splice(index, 1);
|
if (index >= 0) vehicles.splice(index, 1);
|
||||||
return vehicle.vin;
|
return vehicle.vin;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user