Skip to content

Commit

Permalink
Add host checks selection saga
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Jul 11, 2023
1 parent 0e97c78 commit 9d52fb9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
41 changes: 41 additions & 0 deletions assets/js/state/sagas/hosts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { delay, put, race, call, take, takeEvery } from 'redux-saga/effects';
import { post } from '@lib/network';

import {
CHECK_HOST_IS_DEREGISTERABLE,
CANCEL_CHECK_HOST_IS_DEREGISTERABLE,
HOST_DEREGISTERED,
removeHost,
setHostListDeregisterable,
updateSelectedChecks,
} from '@state/hosts';
import {
setChecksSelectionSavingSuccess,
startSavingChecksSelection,
stopSavingChecksSelection,
CHECKS_SELECTED,
} from '@state/checksSelection';
import { notify } from '@state/actions/notifications';

export function* markDeregisterableHosts(hosts) {
Expand Down Expand Up @@ -43,10 +52,42 @@ export function* hostDeregistered({ payload }) {
);
}

function* checksSelected({ payload }) {
const { targetID, targetName } = payload;
yield put(startSavingChecksSelection());

try {
yield call(post, `/hosts/${targetID}/checks`, {
checks: payload.checks,
});

yield put(updateSelectedChecks(payload));
yield put(
notify({
text: `Checks selection for ${targetName} saved`,
icon: '💾',
})
);
yield put(setChecksSelectionSavingSuccess());
} catch (error) {
yield put(
notify({
text: `Unable to save selection for ${targetName}`,
icon: '❌',
})
);
}
yield put(stopSavingChecksSelection());
}

export function* watchHostDeregisterable() {
yield takeEvery(CHECK_HOST_IS_DEREGISTERABLE, checkHostDeregisterable);
}

export function* watchHostDeregistered() {
yield takeEvery(HOST_DEREGISTERED, hostDeregistered);
}

export function* watchHostChecksSelection() {
yield takeEvery(CHECKS_SELECTED, checksSelected);
}
6 changes: 4 additions & 2 deletions assets/js/state/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ import {
markDeregisterableHosts,
watchHostDeregistered,
watchHostDeregisterable,
watchHostChecksSelection,
} from '@state/sagas/hosts';
import {
watchClusterDeregistered,
watchChecksSelected,
watchClusterChecksSelection,
} from '@state/sagas/clusters';

import {
Expand Down Expand Up @@ -375,7 +376,8 @@ export default function* rootSaga() {
watchClusterCibLastWrittenUpdated(),
watchClusterDeregistered(),
watchNotifications(),
watchChecksSelected(),
watchClusterChecksSelection(),
watchHostChecksSelection(),
watchChecksExecutionStarted(),
watchChecksExecutionCompleted(),
watchChecksResultsUpdated(),
Expand Down

0 comments on commit 9d52fb9

Please sign in to comment.