Skip to content

Commit c76d52e

Browse files
committed
address comments
1 parent 7a8ab62 commit c76d52e

5 files changed

Lines changed: 34 additions & 7 deletions

File tree

x-pack/plugins/endpoint/public/applications/endpoint/mocks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ type DataMock = Omit<DataPublicStartMock, 'indexPatterns' | 'query'> & {
2727
};
2828
};
2929

30+
/**
31+
* Type for our app's depsStart (plugin start dependencies)
32+
*/
3033
export interface DepsStartMock {
3134
data: DataMock;
3235
}
3336

37+
/**
38+
* Returns a mock of our app's depsStart (plugin start dependencies)
39+
*/
3440
export const depsStartMock: () => DepsStartMock = () => {
3541
const dataMock: DataMock = (dataPluginMock.createStartContract() as unknown) as DataMock;
3642
dataMock.indexPatterns.getFieldsForWildcard = jest.fn();

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import { EndpointAppConstants } from '../../../../../common/types';
1515
export const alertMiddlewareFactory: MiddlewareFactory<AlertListState> = (coreStart, depsStart) => {
1616
async function fetchIndexPatterns(): Promise<IIndexPattern[]> {
1717
const { indexPatterns } = depsStart.data;
18-
// TODO: what's the best way to get the index pattern?
19-
// const pattern = await indexPatterns.get('287e7b60-4394-11ea-aaac-c76376668d76');
2018
const indexName = EndpointAppConstants.ALERT_INDEX_NAME;
2119
const fields = await indexPatterns.getFieldsForWildcard({ pattern: indexName });
2220
const indexPattern: IIndexPattern = {
@@ -31,7 +29,6 @@ export const alertMiddlewareFactory: MiddlewareFactory<AlertListState> = (coreSt
3129
next(action);
3230
const state = api.getState();
3331
if (action.type === 'userChangedUrl' && isOnAlertPage(state)) {
34-
// TODO: only fetch index pattern once when the page loads
3532
const patterns = await fetchIndexPatterns();
3633
api.dispatch({ type: 'serverReturnedSearchBarIndexPatterns', payload: patterns });
3734

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export const uiQueryParams: (
7878
}
7979
);
8080

81+
/**
82+
* Parses the ui query params and returns a object that represents the query used by the SearchBar component.
83+
* If the query url param is undefined, a default is returned.
84+
*/
8185
export const searchBarQuery: (state: AlertListState) => Query = createSelector(
8286
uiQueryParams,
8387
({ query }) => {
@@ -89,24 +93,35 @@ export const searchBarQuery: (state: AlertListState) => Query = createSelector(
8993
}
9094
);
9195

96+
/**
97+
* Parses the ui query params and returns a rison encoded string that represents the search bar's date range.
98+
* A default is provided if 'date_range' is not present in the url params.
99+
*/
92100
export const encodedSearchBarDateRange: (state: AlertListState) => string = createSelector(
93101
uiQueryParams,
94102
({ date_range: dateRange }) => {
95103
if (dateRange === undefined) {
96-
return encode({ from: 'now-15m', to: 'now' });
104+
return encode({ from: 'now-24h', to: 'now' });
97105
} else {
98106
return dateRange;
99107
}
100108
}
101109
);
102110

111+
/**
112+
* Parses the ui query params and returns a object that represents the dateRange used by the SearchBar component.
113+
*/
103114
export const searchBarDateRange: (state: AlertListState) => TimeRange = createSelector(
104115
encodedSearchBarDateRange,
105116
encodedDateRange => {
106117
return (decode(encodedDateRange) as unknown) as TimeRange;
107118
}
108119
);
109120

121+
/**
122+
* Parses the ui query params and returns an array of filters used by the SearchBar component.
123+
* If the 'filters' param is not present, a default is returned.
124+
*/
110125
export const searchBarFilters: (state: AlertListState) => Filter[] = createSelector(
111126
uiQueryParams,
112127
({ filters }) => {
@@ -118,6 +133,11 @@ export const searchBarFilters: (state: AlertListState) => Filter[] = createSelec
118133
}
119134
);
120135

136+
/**
137+
* Returns the indexPatterns used by the SearchBar component
138+
*/
139+
export const searchBarIndexPatterns = (state: AlertListState) => state.searchBar.patterns;
140+
121141
/**
122142
* query params to use when requesting alert data.
123143
*/
@@ -157,5 +177,3 @@ export const selectedAlertIsLegacyEndpointEvent: (
157177
}
158178
return 'endgame' in event;
159179
});
160-
161-
export const searchBarIndexPatterns = (state: AlertListState) => state.searchBar.patterns;

x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ export const substateMiddlewareFactory = <Substate>(
4949
};
5050
};
5151

52+
/**
53+
* @param middlewareDeps Optionally create the store without any middleware. This is useful for testing the store w/o side effects.
54+
*/
5255
export const appStoreFactory: (middlewareDeps?: {
5356
/**
5457
* Allow middleware to communicate with Kibana core.
5558
*/
5659
coreStart: CoreStart;
60+
/**
61+
* Give middleware access to plugin start dependencies.
62+
*/
5763
depsStart: EndpointPluginStartDependencies;
5864
}) => Store = middlewareDeps => {
5965
let middleware;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export interface AlertListState {
129129
/** Specific Alert data to be shown in the details view */
130130
readonly alertDetails?: Immutable<AlertData>;
131131

132-
/** Search bar filters, query, dateRange, and index */
132+
/** Search bar state including indexPatterns */
133133
readonly searchBar: AlertsSearchBarState;
134134
}
135135

0 commit comments

Comments
 (0)