Basic MultiJobs
This commit is contained in:
parent
91027e79af
commit
8ad5b7876c
25 changed files with 539 additions and 142 deletions
|
@ -1,5 +1,4 @@
|
|||
import React, { useReducer, createContext, useMemo } from "react";
|
||||
import { jobStatus } from "./JobContext.jsx";
|
||||
|
||||
const StoreContext = createContext();
|
||||
|
||||
|
@ -7,6 +6,11 @@ const ACTIONS = {
|
|||
UPDATE: "u",
|
||||
};
|
||||
|
||||
|
||||
const pipelineMappingsMock = [["primary", "secondary1","tertiary1"],
|
||||
["primary", "secondary1", "tertiary2"],
|
||||
["primary", "secondary2", "tertiary3"]];
|
||||
|
||||
const silencedMock = new Array(10).fill(0).map((v, i) => ({
|
||||
name: `Test${i + 1}`,
|
||||
class: `SomeTestClass${i % 2 ? i - 1 : i / 2}`,
|
||||
|
@ -39,36 +43,58 @@ const failingMock = new Array(12).fill(0).map((v, i) => ({
|
|||
jobStatus: (() => {
|
||||
switch (i) {
|
||||
case 1:
|
||||
return jobStatus.OK;
|
||||
return "o";
|
||||
case 3:
|
||||
return jobStatus.ERROR;
|
||||
return "e";
|
||||
case 4:
|
||||
return jobStatus.PENDING;
|
||||
return "p";
|
||||
case 5:
|
||||
return jobStatus.ACTIVE;
|
||||
return "a";
|
||||
case 6:
|
||||
return jobStatus.CANCELED;
|
||||
return "c";
|
||||
case 8:
|
||||
return jobStatus.QUEUED;
|
||||
return "q";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
})(),
|
||||
}));
|
||||
|
||||
const localStorage = {setItem: ()=>{}, getItem: ()=>{}};
|
||||
|
||||
const localSettings = localStorage.getItem("settings");
|
||||
const defaultSettings = {
|
||||
focusJob: true,
|
||||
simplifiedControls: true,
|
||||
logAppDetails: true,
|
||||
defaultRegion: "us",
|
||||
defaultPage: "failing",
|
||||
};
|
||||
|
||||
const settings = localSettings ? JSON.parse(localSettings) : defaultSettings;
|
||||
const settingsKeys = Object.keys(defaultSettings);
|
||||
|
||||
const initialState = {
|
||||
pages: ["failing", "alerting", "jobs", "catalog", "settings", "about"],
|
||||
intervals: [],
|
||||
catalog: catalogMock,
|
||||
failing: failingMock,
|
||||
silenced: silencedMock,
|
||||
pipelineMappings: pipelineMappingsMock,
|
||||
regions: [],
|
||||
catalogSearch: "",
|
||||
focusJob: false,
|
||||
simplifiedControls: true,
|
||||
logAppDetails: true,
|
||||
defaultRegion: "us", // Local Store
|
||||
defaultPage: "failing", // Local Store
|
||||
...settings,
|
||||
};
|
||||
|
||||
const settingsUpdater = (oldState, storeUpdate) => {
|
||||
const settingsToUpdate = {};
|
||||
for (var k of settingsKeys) {
|
||||
settingsToUpdate[k] = oldState[k];
|
||||
if (storeUpdate[k] === undefined) continue;
|
||||
settingsToUpdate[k] = storeUpdate[k];
|
||||
}
|
||||
|
||||
localStorage.setItem("settings", JSON.stringify(settingsToUpdate));
|
||||
};
|
||||
|
||||
const reducer = (state, action) => {
|
||||
|
@ -76,6 +102,7 @@ const reducer = (state, action) => {
|
|||
// Actions
|
||||
switch (action.type) {
|
||||
case ACTIONS.UPDATE:
|
||||
settingsUpdater(state, store);
|
||||
return { ...state, ...store };
|
||||
default:
|
||||
return state;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue