CEC-2144, CEC-2338 Add deploy by fleets and fix fleets table (#192)
* Add fix for fleets search * Decompose fleets table * Add deploy by fleets * Add snapshots
This commit is contained in:
@@ -6,7 +6,8 @@ import { validateStatusMessage } from "../../utils/statusMessage";
|
||||
const FINAL_UPDATE_STATES = ["package_install_complete"];
|
||||
const CarUpdatesContext = React.createContext();
|
||||
|
||||
const validateDeployCarUpdates = (data) => {
|
||||
|
||||
const validateDeployClosure = (data, propertyName, errPfx) => {
|
||||
if (data === null) {
|
||||
throw new Error("No car update data");
|
||||
}
|
||||
@@ -15,11 +16,21 @@ const validateDeployCarUpdates = (data) => {
|
||||
throw new Error("Manifest id required");
|
||||
}
|
||||
|
||||
if (!data.vins || data.vins.length === 0) {
|
||||
throw new Error("Cars are required");
|
||||
const { [propertyName]: value } = data;
|
||||
if (!value || value.length === 0) {
|
||||
throw new Error(`${errPfx} are required`);
|
||||
}
|
||||
}
|
||||
|
||||
const validateDeployCarUpdates = (data) => {
|
||||
return validateDeployClosure(data, 'vins', 'Cars')
|
||||
};
|
||||
|
||||
const validateDeployFleetUpdates = (data) => {
|
||||
return validateDeployClosure(data, 'fleet_names', 'Fleets')
|
||||
};
|
||||
|
||||
|
||||
export const CarUpdatesProvider = ({ children }) => {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [carUpdates, setCarUpdates] = useState([]);
|
||||
@@ -43,6 +54,22 @@ export const CarUpdatesProvider = ({ children }) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
const deployFleetUpdates = async (data, token) => {
|
||||
let result;
|
||||
|
||||
try {
|
||||
setBusy(true);
|
||||
validateDeployFleetUpdates(data);
|
||||
result = await api.createFleetUpdates(data, token);
|
||||
if (result.error)
|
||||
throw new Error(`Deploy fleet updates error. ${result.message}`);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const getCarUpdates = async (search, token) => {
|
||||
let result;
|
||||
|
||||
@@ -204,6 +231,7 @@ export const CarUpdatesProvider = ({ children }) => {
|
||||
carUpdates,
|
||||
totalCarUpdates,
|
||||
deployCarUpdates,
|
||||
deployFleetUpdates,
|
||||
getCarUpdates,
|
||||
getLog,
|
||||
getVINUpdates,
|
||||
|
||||
Reference in New Issue
Block a user