Skip to content

Commit

Permalink
Made ServerApiError a default error type for data binding.
Browse files Browse the repository at this point in the history
  • Loading branch information
efreeti committed Sep 3, 2020
1 parent 7072df7 commit 7e998f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/

import { Immutable } from '../../../../../common/endpoint/types';
import { ServerApiError } from '../../../../common/types';

export interface UninitialisedAsyncBinding {
type: 'UninitialisedAsyncBinding';
}

export interface InProgressAsyncBinding<T, E> {
export interface InProgressAsyncBinding<T, E = ServerApiError> {
type: 'InProgressAsyncBinding';
previousBinding: StaleAsyncBinding<T, E>;
}
Expand All @@ -20,18 +21,18 @@ export interface PresentAsyncBinding<T> {
data: T;
}

export interface FailedAsyncBinding<T, E> {
export interface FailedAsyncBinding<T, E = ServerApiError> {
type: 'FailedAsyncBinding';
error: E;
lastPresentBinding?: PresentAsyncBinding<T>;
}

export type StaleAsyncBinding<T, E> =
export type StaleAsyncBinding<T, E = ServerApiError> =
| UninitialisedAsyncBinding
| PresentAsyncBinding<T>
| FailedAsyncBinding<T, E>;

export type AsyncDataBinding<T, E> =
export type AsyncDataBinding<T, E = ServerApiError> =
| UninitialisedAsyncBinding
| InProgressAsyncBinding<T, E>
| PresentAsyncBinding<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { TrustedApp } from '../../../../../common/endpoint/types/trusted_apps';
import { ServerApiError } from '../../../../common/types';
import { AsyncDataBinding } from './async_data_binding';

export interface PaginationInfo {
Expand All @@ -21,7 +20,7 @@ export interface TrustedAppsListData {

export interface TrustedAppsListPageState {
listView: {
currentListData: AsyncDataBinding<TrustedAppsListData, ServerApiError>;
currentListData: AsyncDataBinding<TrustedAppsListData>;
currentPaginationInfo: PaginationInfo;
};
active: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ServerApiError } from '../../../../common/types';
import { AsyncDataBinding } from '../state/async_data_binding';
import { TrustedAppsListData } from '../state/trusted_apps_list_page_state';

export interface TrustedAppsListDataBindingChanged {
type: 'trustedAppsListDataBindingChanged';
payload: {
newBinding: AsyncDataBinding<TrustedAppsListData, ServerApiError>;
newBinding: AsyncDataBinding<TrustedAppsListData>;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ServerApiError } from '../../../../common/types';
import { Immutable } from '../../../../../common/endpoint/types';
import { ImmutableMiddlewareAPI, ImmutableMiddlewareFactory } from '../../../../common/store';
import { AppAction } from '../../../../common/store/actions';
Expand All @@ -22,7 +21,7 @@ import { needsRefreshOfListData } from './selectors';
import { TrustedAppsListDataBindingChanged } from './action';

const createListDataBindingChangedAction = (
newBinding: Immutable<AsyncDataBinding<TrustedAppsListData, ServerApiError>>
newBinding: Immutable<AsyncDataBinding<TrustedAppsListData>>
): Immutable<TrustedAppsListDataBindingChanged> => ({
type: 'trustedAppsListDataBindingChanged',
payload: { newBinding },
Expand All @@ -38,9 +37,7 @@ const refreshList = async (
createListDataBindingChangedAction({
type: 'InProgressAsyncBinding',
// need to think on how to avoid the casting
previousBinding: list.currentListData as Immutable<
StaleAsyncBinding<TrustedAppsListData, ServerApiError>
>,
previousBinding: list.currentListData as Immutable<StaleAsyncBinding<TrustedAppsListData>>,
})
);

Expand Down

0 comments on commit 7e998f3

Please sign in to comment.