From 019b1bc0344f695259f2a44abe0aaa56ef3f4e17 Mon Sep 17 00:00:00 2001 From: Tristan Timblin Date: Thu, 28 Sep 2023 14:35:18 -0700 Subject: [PATCH] CEC-5039: view and update sums_version column (#452) * CEC-5039: view and update sums_version column * move async function * add deps * useEffect * add deps --- .../App/__snapshots__/App.test.js.snap | 7 ++ .../Details/__snapshots__/index.test.jsx.snap | 7 ++ src/components/Cars/Status/Details/index.jsx | 3 + .../__snapshots__/DetailsTab.test.jsx.snap | 7 ++ .../Status/__snapshots__/index.test.jsx.snap | 7 ++ .../Update/__snapshots__/index.test.jsx.snap | 94 +++++++++++++++++++ src/components/Cars/Update/index.jsx | 17 ++++ src/components/SearchSelect/SearchSelect.jsx | 57 +++++++++++ src/components/SearchSelect/index.js | 1 + 9 files changed, 200 insertions(+) create mode 100644 src/components/SearchSelect/SearchSelect.jsx create mode 100644 src/components/SearchSelect/index.js diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index 7318107..04f7423 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -11693,6 +11693,13 @@ exports[`App Route /vehicle-status authenticated 1`] = ` :

+

+ + Version + + : + / +

Model diff --git a/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap b/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap index b60da02..eff462a 100644 --- a/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap +++ b/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap @@ -36,6 +36,13 @@ exports[`VehicleDetailsTab Render 1`] = ` :

+

+ + Version + + : + / +

Model diff --git a/src/components/Cars/Status/Details/index.jsx b/src/components/Cars/Status/Details/index.jsx index b359a6f..27bb2f1 100644 --- a/src/components/Cars/Status/Details/index.jsx +++ b/src/components/Cars/Status/Details/index.jsx @@ -113,6 +113,9 @@ const MainForm = ({ vin }) => {

ICCID: {vehicle.iccid}

+

+ Version: {vehicle.os_version} / {vehicle.sums_version} +

Model: {vehicle.model}

diff --git a/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap b/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap index 40bbfa5..48a25a2 100644 --- a/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap +++ b/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap @@ -44,6 +44,13 @@ exports[`DetailsTab Render 1`] = `
:

+

+ + Version + + : + / +

Model diff --git a/src/components/Cars/Status/__snapshots__/index.test.jsx.snap b/src/components/Cars/Status/__snapshots__/index.test.jsx.snap index 7ada9d4..e09f5ac 100644 --- a/src/components/Cars/Status/__snapshots__/index.test.jsx.snap +++ b/src/components/Cars/Status/__snapshots__/index.test.jsx.snap @@ -260,6 +260,13 @@ exports[`CarStatus Render 1`] = ` :

+

+ + Version + + : + / +

Model diff --git a/src/components/Cars/Update/__snapshots__/index.test.jsx.snap b/src/components/Cars/Update/__snapshots__/index.test.jsx.snap index e0d7314..9a9e826 100644 --- a/src/components/Cars/Update/__snapshots__/index.test.jsx.snap +++ b/src/components/Cars/Update/__snapshots__/index.test.jsx.snap @@ -107,6 +107,100 @@ exports[`VehicleUpdate Render 1`] = ` +

+
+ +
+ +
+ + +
+ +
+
+
diff --git a/src/components/Cars/Update/index.jsx b/src/components/Cars/Update/index.jsx index 31fe76d..8f9f7a0 100644 --- a/src/components/Cars/Update/index.jsx +++ b/src/components/Cars/Update/index.jsx @@ -19,6 +19,8 @@ import { useVehicleContext, VehicleProvider } from "../../Contexts/VehicleContext"; +import SearchSelect from "../../SearchSelect/SearchSelect"; +import api from "../../../services/updatesAPI" import useStyles from "../../useStyles"; @@ -32,6 +34,8 @@ const MainForm = () => { const [redirect, setRedirect] = useState(null); const classes = useStyles(); + const [sumsVersion, setSumsVersion] = useState(""); + const iccidEl = useRef(null); const modelEl = useRef(null); const yearEl = useRef(null); @@ -84,6 +88,7 @@ const MainForm = () => { useEffect(() => { setSelectedLogLevel(vehicle.log_level ?? selectedLogLevel); + setSumsVersion(vehicle.sums_version); iccidEl.current.value = vehicle.iccid ?? "" modelEl.current.value = vehicle.model ?? "Ocean" yearEl.current.value = vehicle.year ?? "2022" @@ -155,6 +160,7 @@ const MainForm = () => { const formData = { vin: vin, iccid: iccidEl.current.value, + sums_version: sumsVersion, model: modelEl.current.value, year: parseInt(yearEl.current.value), trim: trimEl.current.value, @@ -189,6 +195,11 @@ const MainForm = () => { } }; + async function getSums() { + const { data } = await api.getSUMSVersions(token); + return data.map((sums) => sums.version); + } + if (redirect && redirect.length > 0) { return ; } @@ -227,6 +238,12 @@ const MainForm = () => { fullWidth inputRef={iccidEl} /> + getSums()} + /> { }, + getData = () => [], + research = false, +}) { + const [open, setOpen] = React.useState(false); + const [searchCount, setSearchCount] = React.useState(0); + const [inputValue, setInputValue] = React.useState(""); + const [options, setOptions] = React.useState([{ label: value }]); + + React.useEffect(() => { + function canSearch() { + if (research || searchCount === 0) { + return true; + } + return false; + } + + async function fetchData() { + setOptions(await getData(value)); + } + + if (!open && canSearch()) { + fetchData(); + setSearchCount((searchCount) => searchCount + 1); + } + }, [open, value, research, searchCount, getData]); + + return ( + setValue(value)} + inputValue={inputValue} + onInputChange={(_, inputValue) => setInputValue(inputValue)} + open={open} + onOpen={() => setOpen(true)} + onClose={() => setOpen(false)} + options={options} + renderInput={(params) => + + } + /> + ); +} \ No newline at end of file diff --git a/src/components/SearchSelect/index.js b/src/components/SearchSelect/index.js new file mode 100644 index 0000000..41feef2 --- /dev/null +++ b/src/components/SearchSelect/index.js @@ -0,0 +1 @@ +export * from "./SearchSelect"; \ No newline at end of file