Skip to content

Commit 919e304

Browse files
committed
addresses comments and uses better types
1 parent d8d5475 commit 919e304

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

x-pack/plugins/endpoint/endpoint_app_types.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,25 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export interface AlertData {
7+
/**
8+
* A deep readonly type that will make all children of a given object readonly recursively
9+
*/
10+
export type Immutable<T> = T extends undefined | null | boolean | string | number
11+
? T
12+
: T extends Array<infer U>
13+
? ImmutableArray<U>
14+
: T extends Map<infer K, infer V>
15+
? ImmutableMap<K, V>
16+
: T extends Set<infer M>
17+
? ImmutableSet<M>
18+
: ImmutableObject<T>;
19+
20+
export type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
21+
export type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
22+
export type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
23+
export type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
24+
25+
export type AlertData = Immutable<{
826
value: {
927
source: {
1028
endgame: {
@@ -26,11 +44,11 @@ export interface AlertData {
2644
hostname: string;
2745
ip: string;
2846
os: {
29-
name: string; // TODO Union types?
47+
name: string;
3048
};
3149
};
3250
};
3351
};
34-
}
52+
}>;
3553

3654
export type PageId = 'alertsPage' | 'endpointListPage';

x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { AlertData } from '../../../../../endpoint_app_types';
7+
import { AlertData, Immutable } from '../../../../../endpoint_app_types';
88

9-
export interface AlertListState {
9+
export type AlertListState = Immutable<{
1010
alerts: AlertData[];
11-
}
11+
}>;

x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { Reducer } from 'redux';
88
import { EndpointListState } from './types';
9-
import { EndpointListAction } from './action';
109
import { AppAction } from '../action';
1110

1211
const initialState = (): EndpointListState => {

x-pack/plugins/endpoint/public/applications/endpoint/view/alerts/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import { memo, useState, useMemo } from 'react';
88
import React from 'react';
99
import { EuiDataGrid } from '@elastic/eui';
10-
import { useDispatch, useSelector } from 'react-redux';
11-
import { AlertAction } from '../../store/alerts/action';
10+
import { useSelector } from 'react-redux';
1211
import * as selectors from '../../store/selectors';
1312
import { usePageId } from '../use_page_id';
1413

0 commit comments

Comments
 (0)