Skip to content

Commit

Permalink
Merge branch 'main' into kbn-134362-monitor-esclient-sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoldevila authored Oct 4, 2022
2 parents 63a4314 + 10884e6 commit 6718285
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* 2.0.
*/

import type { IHttpFetchError } from '@kbn/core-http-browser';
import { createAction } from '@reduxjs/toolkit';
import { StatesIndexStatus } from '../../../../../common/runtime_types';
import { IHttpSerializedFetchError } from '../utils/http_error';

export const getIndexStatus = createAction<void>('[INDEX STATUS] GET');
export const getIndexStatusSuccess = createAction<StatesIndexStatus>('[INDEX STATUS] GET SUCCESS');
export const getIndexStatusFail =
createAction<IHttpSerializedFetchError>('[INDEX STATUS] GET FAIL');
export const getIndexStatusFail = createAction<IHttpFetchError>('[INDEX STATUS] GET FAIL');
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { createReducer } from '@reduxjs/toolkit';
import { IHttpSerializedFetchError } from '../utils/http_error';
import { IHttpSerializedFetchError, serializeHttpFetchError } from '../utils/http_error';
import { StatesIndexStatus } from '../../../../../common/runtime_types';

import { getIndexStatus, getIndexStatusSuccess, getIndexStatusFail } from './actions';
Expand All @@ -33,7 +33,7 @@ export const indexStatusReducer = createReducer(initialState, (builder) => {
state.loading = false;
})
.addCase(getIndexStatusFail, (state, action) => {
state.error = action.payload;
state.error = serializeHttpFetchError(action.payload);
state.loading = false;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

import { IHttpFetchError, ResponseErrorBody } from '@kbn/core/public';
import { createReducer } from '@reduxjs/toolkit';
import { IHttpSerializedFetchError } from '../utils/http_error';
import { IHttpSerializedFetchError, serializeHttpFetchError } from '../utils/http_error';
import {
getMonitorRecentPingsAction,
setMonitorDetailsLocationAction,
Expand Down Expand Up @@ -46,7 +47,7 @@ export const monitorDetailsReducer = createReducer(initialState, (builder) => {
state.loading = false;
})
.addCase(getMonitorRecentPingsAction.fail, (state, action) => {
state.error = action.payload;
state.error = serializeHttpFetchError(action.payload as IHttpFetchError<ResponseErrorBody>);
state.loading = false;
})

Expand All @@ -58,7 +59,7 @@ export const monitorDetailsReducer = createReducer(initialState, (builder) => {
state.syntheticsMonitorLoading = false;
})
.addCase(getMonitorAction.fail, (state, action) => {
state.error = action.payload;
state.error = serializeHttpFetchError(action.payload as IHttpFetchError<ResponseErrorBody>);
state.syntheticsMonitorLoading = false;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* 2.0.
*/

import { IHttpFetchError } from '@kbn/core-http-browser';
import { createAction } from '@reduxjs/toolkit';
import {
EncryptedSyntheticsMonitor,
MonitorManagementListResult,
} from '../../../../../common/runtime_types';
import { createAsyncAction } from '../utils/actions';
import { IHttpSerializedFetchError } from '../utils/http_error';

import { MonitorListPageState } from './models';

Expand All @@ -29,8 +29,7 @@ export const fetchUpsertSuccessAction = createAction<{
id: string;
attributes: { enabled: boolean };
}>('fetchUpsertMonitorSuccess');
export const fetchUpsertFailureAction = createAction<{
id: string;
error: IHttpSerializedFetchError;
}>('fetchUpsertMonitorFailure');
export const fetchUpsertFailureAction = createAction<{ id: string; error: IHttpFetchError }>(
'fetchUpsertMonitorFailure'
);
export const clearMonitorUpsertStatus = createAction<string>('clearMonitorUpsertStatus');
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import { IHttpFetchError } from '@kbn/core-http-browser';
import { PayloadAction } from '@reduxjs/toolkit';
import { call, put, takeEvery, takeLeading } from 'redux-saga/effects';
import { fetchEffectFactory } from '../utils/fetch_effect';
import { serializeHttpFetchError } from '../utils/http_error';
import {
fetchMonitorListAction,
fetchUpsertFailureAction,
Expand Down Expand Up @@ -40,7 +40,7 @@ export function* upsertMonitorEffect() {
);
} catch (error) {
yield put(
fetchUpsertFailureAction({ id: action.payload.id, error: serializeHttpFetchError(error) })
fetchUpsertFailureAction({ id: action.payload.id, error: error as IHttpFetchError })
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FETCH_STATUS } from '@kbn/observability-plugin/public';

import { ConfigKey, MonitorManagementListResult } from '../../../../../common/runtime_types';

import { IHttpSerializedFetchError } from '../utils/http_error';
import { IHttpSerializedFetchError, serializeHttpFetchError } from '../utils/http_error';

import { MonitorListPageState } from './models';
import {
Expand Down Expand Up @@ -58,7 +58,7 @@ export const monitorListReducer = createReducer(initialState, (builder) => {
})
.addCase(fetchMonitorListAction.fail, (state, action) => {
state.loading = false;
state.error = action.payload;
state.error = serializeHttpFetchError(action.payload);
})
.addCase(fetchUpsertMonitorAction, (state, action) => {
state.monitorUpsertStatuses[action.payload.id] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createReducer } from '@reduxjs/toolkit';

import { MonitorOverviewResult, OverviewStatus } from '../../../../../common/runtime_types';

import { IHttpSerializedFetchError } from '../utils/http_error';
import { IHttpSerializedFetchError, serializeHttpFetchError } from '../utils/http_error';

import { MonitorOverviewPageState } from './models';
import {
Expand Down Expand Up @@ -60,13 +60,13 @@ export const monitorOverviewReducer = createReducer(initialState, (builder) => {
})
.addCase(fetchMonitorOverviewAction.fail, (state, action) => {
state.loading = false;
state.error = action.payload;
state.error = serializeHttpFetchError(action.payload);
})
.addCase(quietFetchOverviewAction.success, (state, action) => {
state.data = action.payload;
})
.addCase(quietFetchOverviewAction.fail, (state, action) => {
state.error = action.payload;
state.error = serializeHttpFetchError(action.payload);
})
.addCase(setOverviewPerPageAction, (state, action) => {
state.pageState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@

import { createAction } from '@reduxjs/toolkit';
import { ServiceLocations, ThrottlingOptions } from '../../../../../common/runtime_types';
import { IHttpSerializedFetchError } from '../utils/http_error';

export const getServiceLocations = createAction('[SERVICE LOCATIONS] GET');
export const getServiceLocationsSuccess = createAction<{
throttling: ThrottlingOptions | undefined;
locations: ServiceLocations;
}>('[SERVICE LOCATIONS] GET SUCCESS');
export const getServiceLocationsFailure = createAction<IHttpSerializedFetchError>(
'[SERVICE LOCATIONS] GET FAILURE'
);
export const getServiceLocationsFailure = createAction<Error>('[SERVICE LOCATIONS] GET FAILURE');
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
ServiceLocations,
ThrottlingOptions,
} from '../../../../../common/runtime_types';
import { IHttpSerializedFetchError } from '../utils/http_error';

import {
getServiceLocations,
Expand All @@ -23,7 +22,7 @@ export interface ServiceLocationsState {
locations: ServiceLocations;
throttling: ThrottlingOptions | null;
loading: boolean;
error: IHttpSerializedFetchError | null;
error: Error | null;
locationsLoaded?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@

import { createAction } from '@reduxjs/toolkit';
import { MonitorManagementEnablementResult } from '../../../../../common/runtime_types';
import { IHttpSerializedFetchError } from '../utils/http_error';

export const getSyntheticsEnablement = createAction('[SYNTHETICS_ENABLEMENT] GET');
export const getSyntheticsEnablementSuccess = createAction<MonitorManagementEnablementResult>(
'[SYNTHETICS_ENABLEMENT] GET SUCCESS'
);
export const getSyntheticsEnablementFailure = createAction<IHttpSerializedFetchError>(
export const getSyntheticsEnablementFailure = createAction<Error>(
'[SYNTHETICS_ENABLEMENT] GET FAILURE'
);

export const disableSynthetics = createAction('[SYNTHETICS_ENABLEMENT] DISABLE');
export const disableSyntheticsSuccess = createAction<{}>('[SYNTHETICS_ENABLEMENT] DISABLE SUCCESS');
export const disableSyntheticsFailure = createAction<IHttpSerializedFetchError>(
export const disableSyntheticsFailure = createAction<Error>(
'[SYNTHETICS_ENABLEMENT] DISABLE FAILURE'
);

export const enableSynthetics = createAction('[SYNTHETICS_ENABLEMENT] ENABLE');
export const enableSyntheticsSuccess = createAction<{}>('[SYNTHETICS_ENABLEMENT] ENABLE SUCCESS');
export const enableSyntheticsFailure = createAction<IHttpSerializedFetchError>(
export const enableSyntheticsFailure = createAction<Error>(
'[SYNTHETICS_ENABLEMENT] ENABLE FAILURE'
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import {
getSyntheticsEnablementFailure,
} from './actions';
import { MonitorManagementEnablementResult } from '../../../../../common/runtime_types';
import { IHttpSerializedFetchError } from '../utils/http_error';

export interface SyntheticsEnablementState {
loading: boolean;
error: IHttpSerializedFetchError | null;
error: Error | null;
enablement: MonitorManagementEnablementResult | null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import { createAction } from '@reduxjs/toolkit';
import type { IHttpSerializedFetchError } from './http_error';
import type { IHttpFetchError } from '@kbn/core-http-browser';

export function createAsyncAction<Payload, SuccessPayload>(actionStr: string) {
return {
get: createAction<Payload>(actionStr),
success: createAction<SuccessPayload>(`${actionStr}_SUCCESS`),
fail: createAction<IHttpSerializedFetchError>(`${actionStr}_FAIL`),
fail: createAction<IHttpFetchError>(`${actionStr}_FAIL`),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { call, put } from 'redux-saga/effects';
import { PayloadAction } from '@reduxjs/toolkit';
import type { IHttpFetchError } from '@kbn/core-http-browser';
import { IHttpSerializedFetchError, serializeHttpFetchError } from './http_error';

/**
* Factory function for a fetch effect. It expects three action creators,
Expand All @@ -24,7 +23,7 @@ import { IHttpSerializedFetchError, serializeHttpFetchError } from './http_error
export function fetchEffectFactory<T, R, S, F>(
fetch: (request: T) => Promise<R>,
success: (response: R) => PayloadAction<S>,
fail: (error: IHttpSerializedFetchError) => PayloadAction<F>
fail: (error: IHttpFetchError) => PayloadAction<F>
) {
return function* (action: PayloadAction<T>): Generator {
try {
Expand All @@ -33,14 +32,14 @@ export function fetchEffectFactory<T, R, S, F>(
// eslint-disable-next-line no-console
console.error(response);

yield put(fail(serializeHttpFetchError(response as IHttpFetchError)));
yield put(fail(response as IHttpFetchError));
} else {
yield put(success(response as R));
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
yield put(fail(serializeHttpFetchError(error)));
yield put(fail(error as IHttpFetchError));
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { IHttpFetchError, ResponseErrorBody } from '@kbn/core/public';
import { createReducer } from '@reduxjs/toolkit';
import { AgentPolicy } from '@kbn/fleet-plugin/common';
import { IHttpSerializedFetchError } from '../../../apps/synthetics/state';
import {
getAgentPoliciesAction,
setAddingNewPrivateLocation,
Expand All @@ -24,7 +24,7 @@ export interface AgentPoliciesList {
export interface AgentPoliciesState {
data: AgentPoliciesList | null;
loading: boolean;
error: IHttpSerializedFetchError | null;
error: IHttpFetchError<ResponseErrorBody> | null;
isManageFlyoutOpen?: boolean;
isAddingNewPrivateLocation?: boolean;
}
Expand All @@ -47,7 +47,7 @@ export const agentPoliciesReducer = createReducer(initialState, (builder) => {
state.loading = false;
})
.addCase(getAgentPoliciesAction.fail, (state, action) => {
state.error = action.payload;
state.error = action.payload as IHttpFetchError<ResponseErrorBody>;
state.loading = false;
})
.addCase(setManageFlyoutOpen, (state, action) => {
Expand Down
Loading

0 comments on commit 6718285

Please sign in to comment.