diff --git a/src/components/Contexts/VehicleContext.jsx b/src/components/Contexts/VehicleContext.jsx
index ef6b781..4f7d004 100644
--- a/src/components/Contexts/VehicleContext.jsx
+++ b/src/components/Contexts/VehicleContext.jsx
@@ -34,6 +34,7 @@ export const VehicleProvider = ({ children }) => {
const [totalFlashpacks, setTotalFlashpacks] = useState(0);
const [flashpackECUMappings, setFlashpackECUMappings] = useState([])
const [totalFlashpackECUMappings, setTotalFlashpackECUMappings] = useState(0)
+ const [osVersions, setOSVersions] = useState([])
const addConnections = async (cars, token) => {
try {
@@ -331,7 +332,7 @@ export const VehicleProvider = ({ children }) => {
}
};
- const addFlashpackVersion = async (model, trim, year, flashpack, carFlashpackVersions, token) => {
+ const addFlashpackVersion = async (model, trim, year, flashpack, osVersion, carFlashpackVersions, token) => {
try {
setBusy(true);
@@ -340,6 +341,7 @@ export const VehicleProvider = ({ children }) => {
"car_trim": trim,
"car_year": year,
"flashpack": flashpack,
+ "os_version": osVersions,
"ecu_versions": carFlashpackVersions,
}
@@ -424,6 +426,21 @@ export const VehicleProvider = ({ children }) => {
} finally {
setBusy(false);
}
+ };
+
+ const getOSVersions = async (token) => {
+ try {
+ setBusy(true);
+
+ const result = await api.getOSVersions(token);
+ if (result.error) {
+ throw new Error(`Get OS versions error. ${result.message}`);
+ }
+
+ setOSVersions(result.data);
+ } finally {
+ setBusy(false);
+ }
}
return (
@@ -466,6 +483,8 @@ export const VehicleProvider = ({ children }) => {
deleteFlashpackVersion,
deleteFlashpackVersionECUMapping,
getCarFlashpackVersionInfo,
+ osVersions,
+ getOSVersions,
}}
>
{children}
diff --git a/src/components/Flashpack/Add/__snapshots__/index.test.jsx.snap b/src/components/Flashpack/Add/__snapshots__/index.test.jsx.snap
index c704ada..c2930c8 100644
--- a/src/components/Flashpack/Add/__snapshots__/index.test.jsx.snap
+++ b/src/components/Flashpack/Add/__snapshots__/index.test.jsx.snap
@@ -244,6 +244,50 @@ exports[`FlashpackAdd Render 1`] = `
+
diff --git a/src/components/Flashpack/Add/index.jsx b/src/components/Flashpack/Add/index.jsx
index 829d267..0719759 100644
--- a/src/components/Flashpack/Add/index.jsx
+++ b/src/components/Flashpack/Add/index.jsx
@@ -32,9 +32,12 @@ const MainForm = () => {
const [trims, setTrims] = useLocalStorage("FLASHPACK_ADD_TRIMS", modelsTrimsYears.oceanTrims);
const [years, setYears] = useLocalStorage("FLASHPACK_ADD_YEARS", modelsTrimsYears.oceanYears);
const [flashpack, setFlashpack] = useState();
+ const [osVersion, setOSVersion] = useState();
const [mappingInputs, setMappingInputs] = useState([{ ecuName: "", ecuVersion: "" }]);
const {
addFlashpackVersion,
+ getOSVersions,
+ osVersions,
busy,
} = useVehicleContext();
@@ -56,6 +59,19 @@ const MainForm = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ useEffect(() => {
+ (async () => {
+ try {
+ if (!token) return;
+ await getOSVersions(token);
+ } catch (e) {
+ setMessage(e.message);
+ logger.warn(e.stack);
+ }
+ })();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [token]);
+
const onCarModelChange = (event) => {
let newModel = event.target.value
@@ -87,6 +103,10 @@ const MainForm = () => {
setFlashpack(event.target.value);
}
+ const onOSVersionChange = (event) => {
+ setOSVersion(event.target.value);
+ }
+
const onSubmit = async (event) => {
try {
event.preventDefault();
@@ -100,7 +120,7 @@ const MainForm = () => {
})
}
- const result = await addFlashpackVersion(carModel, carTrim, parseInt(carYear), flashpack, carFlashpackVersions, token);
+ const result = await addFlashpackVersion(carModel, carTrim, parseInt(carYear), flashpack, osVersion, carFlashpackVersions, token);
if (!result || result.error) return;
setMessage(`Added ${carYear} ${carModel} ${carTrim} ${flashpack}`);
@@ -157,6 +177,7 @@ const MainForm = () => {
onChange={onFlashpackChange}
type="number"
/>
+
{mappingInputs.map((item, index) => (
diff --git a/src/components/Flashpack/__snapshots__/index.test.jsx.snap b/src/components/Flashpack/__snapshots__/index.test.jsx.snap
index 06f9a5e..754a15f 100644
--- a/src/components/Flashpack/__snapshots__/index.test.jsx.snap
+++ b/src/components/Flashpack/__snapshots__/index.test.jsx.snap
@@ -245,6 +245,29 @@ exports[`Flashpack Render 1`] = `
+
+
+ Part of OS Version
+
+
+ |
{
{row.flashpack}
+
+ {row.os_version}
+
{row.car_model}
@@ -245,7 +252,7 @@ const MainForm = () => {
) : (
{
+ return fetch(`${API_ENDPOINT}/manifest/sums/active_os_versions/`, {
+ method: "GET",
+ headers: Object.assign(
+ { "Content-Type": "application/json" },
+ getAuthHeaderOptions(token)
+ ),
+ }).then(fetchRespHandler)
+ .catch(errorHandler)
+ },
};
export default vehiclesAPI;
|