From 9d52fb9c39b9323c6f3e7b703cfe68362367e6f5 Mon Sep 17 00:00:00 2001 From: Nelson Kopliku Date: Tue, 11 Jul 2023 16:08:06 +0200 Subject: [PATCH] Add host checks selection saga --- assets/js/state/sagas/hosts.js | 41 ++++++++++++++++++++++++++++++++++ assets/js/state/sagas/index.js | 6 +++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/assets/js/state/sagas/hosts.js b/assets/js/state/sagas/hosts.js index 9b9fa87e3c..a960348e79 100644 --- a/assets/js/state/sagas/hosts.js +++ b/assets/js/state/sagas/hosts.js @@ -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) { @@ -43,6 +52,34 @@ 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); } @@ -50,3 +87,7 @@ export function* watchHostDeregisterable() { export function* watchHostDeregistered() { yield takeEvery(HOST_DEREGISTERED, hostDeregistered); } + +export function* watchHostChecksSelection() { + yield takeEvery(CHECKS_SELECTED, checksSelected); +} diff --git a/assets/js/state/sagas/index.js b/assets/js/state/sagas/index.js index 4776c82eaf..cbdc527fc1 100644 --- a/assets/js/state/sagas/index.js +++ b/assets/js/state/sagas/index.js @@ -69,10 +69,11 @@ import { markDeregisterableHosts, watchHostDeregistered, watchHostDeregisterable, + watchHostChecksSelection, } from '@state/sagas/hosts'; import { watchClusterDeregistered, - watchChecksSelected, + watchClusterChecksSelection, } from '@state/sagas/clusters'; import { @@ -375,7 +376,8 @@ export default function* rootSaga() { watchClusterCibLastWrittenUpdated(), watchClusterDeregistered(), watchNotifications(), - watchChecksSelected(), + watchClusterChecksSelection(), + watchHostChecksSelection(), watchChecksExecutionStarted(), watchChecksExecutionCompleted(), watchChecksResultsUpdated(),