* first push * fix snapshot * remove unused vars * update snap * remove some console logs * Remove snapshot * Update * CEC-3770 Update cert expire text (#282) * CEC-3577: fetch T.Rex log from the cloud (#283) * CEC-3577: fetch T.Rex log from the cloud * tabs? * CSS * smells * fix smells and warnings * suggestions * CEC-3577 Style tweak (#284) * CEC-3577: trex logs (#285) * CEC-3577: trex logs add filtering add progress bar for log fetching always fetch all the logs request canceling * don't hide progress * CEC-3751, CEC-3478 misc window status and invalid location value (#287) * CEC-3751 misc window status CEC-3478 invalid location value * Fix snapshot Update browser list * merge develop update snap * resolve comments * add date and time picker seperately, use checkbox for dropdown * added verification for date and fixed time picker * fix snap * resolve comments * removed small bug * tweak layout * added snap shot test for can signals * small change * Fix test * fix sms snap * change function name * mock can signals api * resolved comments * fix ci * Clean up --------- Co-authored-by: jwu-fisker <jwu@fiskerinc.com> Co-authored-by: John Wu <76966357+jwu-fisker@users.noreply.github.com> Co-authored-by: Eduard Voronkin <116690094+eduardvoronkin@users.noreply.github.com>
74 lines
2.0 KiB
JavaScript
74 lines
2.0 KiB
JavaScript
import React, { useContext, useState } from "react";
|
|
import api from "../../services/CANSignalAPI";
|
|
import { validateVIN } from "../../utils/validationSupplier";
|
|
|
|
const CANSignalsExportContext = React.createContext();
|
|
|
|
export const CANSignalsExportProvider = ({ children }) => {
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
const [canSignals, setCanSignals] = useState([]);
|
|
|
|
const getCANSignalList = async (token) => {
|
|
try {
|
|
setBusy(true);
|
|
const result = await api.getCanSignalList(token);
|
|
if (result.error) {
|
|
throw new Error(`Get can signal list error. ${result.message}`);
|
|
}
|
|
setCanSignals(result.data ?? []);
|
|
return result;
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
const getDynamicColumnCANSignals = async (vin, timestart, timeend, cansingals, token) => {
|
|
try {
|
|
setBusy(true)
|
|
if (!vin) return;
|
|
|
|
validateVIN(vin);
|
|
if (timestart > timeend) throw new Error("Start time cannot be after end time");
|
|
const result = await api.getCanSignalsVin(vin, timestart, timeend, cansingals, token);
|
|
if (result.error || !result.ok)
|
|
throw new Error(`Get CAN signals error. ${result.message}`);
|
|
|
|
const blob = await result.blob();
|
|
const reader = new FileReader();
|
|
reader.onload = () => {
|
|
const csvData = reader.result;
|
|
const blob = new Blob([csvData], { type: 'text/csv;charset=utf-8' });
|
|
const link = document.createElement('a');
|
|
link.href = window.URL.createObjectURL(blob);
|
|
link.download = 'CAN_signals.csv';
|
|
link.click();
|
|
};
|
|
reader.readAsText(blob);
|
|
} catch (e) {
|
|
throw new Error(e)
|
|
}
|
|
finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<CANSignalsExportContext.Provider
|
|
value={{
|
|
busy,
|
|
canSignals,
|
|
getCANSignalList,
|
|
getDynamicColumnCANSignals
|
|
}}
|
|
>
|
|
{children}
|
|
</CANSignalsExportContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const useCANSignalsExportContext = () => useContext(CANSignalsExportContext);
|
|
|
|
|
|
|