Skip to content

Commit

Permalink
ui/nodes: Auto formatting
Browse files Browse the repository at this point in the history
Refs: #2443
  • Loading branch information
ChengYanJin committed Apr 24, 2020
1 parent bc4a613 commit c8cb42d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
23 changes: 11 additions & 12 deletions ui/src/ducks/app/salt.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export default function reducer(state = defaultState, action = {}) {
case REMOVE_JOB:
return {
...state,
jobs: state.jobs.filter(job => job.jid !== action.payload.jid),
jobs: state.jobs.filter((job) => job.jid !== action.payload.jid),
};
case ADD_JOB_EVENT:
return {
...state,
jobs: state.jobs.map(job =>
jobs: state.jobs.map((job) =>
job.jid === action.payload.jid
? { ...job, events: [...job.events, action.payload.event] }
: job,
Expand All @@ -58,7 +58,7 @@ export default function reducer(state = defaultState, action = {}) {
case JOB_COMPLETED:
return {
...state,
jobs: state.jobs.map(job =>
jobs: state.jobs.map((job) =>
job.jid === action.payload.jid
? {
...job,
Expand All @@ -72,7 +72,7 @@ export default function reducer(state = defaultState, action = {}) {
case SET_JOB_STATUS:
return {
...state,
jobs: state.jobs.map(job =>
jobs: state.jobs.map((job) =>
job.jid === action.payload.jid
? { ...job, status: action.payload.status }
: job,
Expand Down Expand Up @@ -124,13 +124,13 @@ export function setJobStatusAction(jid, status) {
}

// Selectors
export const allJobsSelector = state => state.app.salt.jobs;
export const allJobsSelector = (state) => state.app.salt.jobs;

// Sagas
export function* initialize(payload) {
const savedJobs = listJobsFromLocalStorage();
yield all(savedJobs.map(job => put(addJobAction(job))));
yield all(savedJobs.map(job => call(refreshJobStatus, job)));
yield all(savedJobs.map((job) => put(addJobAction(job))));
yield all(savedJobs.map((job) => call(refreshJobStatus, job)));

// Once state is initialized from localStorage, we can start watching Salt
// Event bus (doing it before may loose some events since no job exists)
Expand Down Expand Up @@ -168,7 +168,6 @@ export function* manageLocalStorage() {

export function* refreshJobStatus(job) {
const result = yield call(ApiSalt.printJob, job.jid);
// TODO: error handling?
const status = getJobStatusFromPrintJob(result, job.jid);
yield call(updateJobStatus, job, status);
}
Expand Down Expand Up @@ -201,8 +200,8 @@ function* readJobEvent(job, event) {
}

export function createChannelFromSource(eventSrc) {
const subs = emitter => {
eventSrc.onmessage = msg => {
const subs = (emitter) => {
eventSrc.onmessage = (msg) => {
emitter(msg);
};
eventSrc.onerror = () => {
Expand All @@ -224,7 +223,7 @@ export function* watchSaltEvents({ payload: { url, token } }) {
const data = JSON.parse(event.data);

const jobs = yield select(allJobsSelector);
const relatedJob = jobs.find(job => data.tag.includes(job.jid));
const relatedJob = jobs.find((job) => data.tag.includes(job.jid));

if (relatedJob !== undefined) {
yield all([
Expand Down Expand Up @@ -252,7 +251,7 @@ export function* garbageCollectJobs() {
while (true) {
const jobs = yield select(allJobsSelector);
const toRemove = jobs.filter(checkJobExpiry);
yield all(toRemove.map(job => put(removeJobAction(job))));
yield all(toRemove.map((job) => put(removeJobAction(job))));
yield delay(JOB_GC_DELAY);
}
}
Expand Down
8 changes: 4 additions & 4 deletions ui/src/services/salt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function addJobToLocalStorage({
...props
}) {
const jobs = listJobsFromLocalStorage();
const job = jobs.find(item => item.jid === jid);
const job = jobs.find((item) => item.jid === jid);
if (!job) {
jobs.push({ jid, type, completedAt, ...props });
saveJobsToLocalStorage(jobs);
Expand All @@ -27,7 +27,7 @@ export function addJobToLocalStorage({

export function removeJobFromLocalStorage(jid) {
const existingJobs = listJobsFromLocalStorage();
const jobs = existingJobs.filter(job => job.jid !== jid);
const jobs = existingJobs.filter((job) => job.jid !== jid);
if (jobs.length) {
saveJobsToLocalStorage(jobs);
} else {
Expand All @@ -37,7 +37,7 @@ export function removeJobFromLocalStorage(jid) {

export function markJobCompleteInLocalStorage(jid, completedAt) {
const jobs = listJobsFromLocalStorage();
const job = jobs.find(item => item.jid === jid);
const job = jobs.find((item) => item.jid === jid);
if (job) {
job.completedAt = completedAt;
}
Expand All @@ -53,7 +53,7 @@ export function parseJobError(returner) {
const steps = Object.values(returner.return.data)[0];
let firstFailedStepIndex = Infinity;
let firstFailedStepKey;
Object.keys(steps).forEach(key => {
Object.keys(steps).forEach((key) => {
if (!steps[key].result && steps[key].__run_num__ < firstFailedStepIndex) {
firstFailedStepIndex = steps[key].__run_num__;
firstFailedStepKey = key;
Expand Down

0 comments on commit c8cb42d

Please sign in to comment.