Skip to content

Commit

Permalink
addresses comments and uses better types
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Jan 24, 2020
1 parent 38df02e commit 0d81354
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
24 changes: 21 additions & 3 deletions x-pack/plugins/endpoint/endpoint_app_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@
* you may not use this file except in compliance with the Elastic License.
*/

export interface AlertData {
/**
* A deep readonly type that will make all children of a given object readonly recursively
*/
export type Immutable<T> = T extends undefined | null | boolean | string | number
? T
: T extends Array<infer U>
? ImmutableArray<U>
: T extends Map<infer K, infer V>
? ImmutableMap<K, V>
: T extends Set<infer M>
? ImmutableSet<M>
: ImmutableObject<T>;

export type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
export type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
export type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
export type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };

export type AlertData = Immutable<{
value: {
source: {
endgame: {
Expand All @@ -26,11 +44,11 @@ export interface AlertData {
hostname: string;
ip: string;
os: {
name: string; // TODO Union types?
name: string;
};
};
};
};
}
}>;

export type PageId = 'alertsPage' | 'endpointListPage';
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertData } from '../../../../../endpoint_app_types';
import { AlertData, Immutable } from '../../../../../endpoint_app_types';

export interface AlertListState {
export type AlertListState = Immutable<{
alerts: AlertData[];
}
}>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { Reducer } from 'redux';
import { EndpointListState } from './types';
import { EndpointListAction } from './action';
import { AppAction } from '../action';

const initialState = (): EndpointListState => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import { memo, useState, useMemo } from 'react';
import React from 'react';
import { EuiDataGrid } from '@elastic/eui';
import { useDispatch, useSelector } from 'react-redux';
import { AlertAction } from '../../store/alerts/action';
import { useSelector } from 'react-redux';
import * as selectors from '../../store/selectors';
import { usePageId } from '../use_page_id';

Expand Down

0 comments on commit 0d81354

Please sign in to comment.