Skip to content

Commit

Permalink
add predicate to convert alertdata to legacy endpoint event
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller committed Feb 28, 2020
1 parent 0626d65 commit d291a46
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
AlertsAPIQueryParams,
CreateStructuredSelector,
} from '../../types';
import { Immutable, LegacyEndpointEvent } from '../../../../../common/types';
import { Immutable, LegacyEndpointEvent, AlertEvent } from '../../../../../common/types';

const createStructuredSelector: CreateStructuredSelector = createStructuredSelectorWithBadType;
/**
Expand Down Expand Up @@ -93,14 +93,23 @@ export const hasSelectedAlert: (state: AlertListState) => boolean = createSelect
({ selected_alert: selectedAlert }) => selectedAlert !== undefined
);

/**
* Determine if the alert event is most likely compatible with LegacyEndpointEvent.
*/
function isAlertEventLegacyEndpointEvent(event: { endgame?: {} }): event is LegacyEndpointEvent {
return event.endgame !== undefined && 'unique_pid' in event.endgame;
}

export const selectedEvent: (
state: AlertListState
) => LegacyEndpointEvent | undefined = createSelector(
uiQueryParams,
alertListData,
({ selected_alert: selectedAlert }, alertList) => {
return (alertList.find(
alert => alert.event.id === selectedAlert
) as unknown) as LegacyEndpointEvent;
const found = alertList.find(alert => alert.event.id === selectedAlert);
if (!found) {
return found;
}
return isAlertEventLegacyEndpointEvent(found) ? found : undefined;
}
);

0 comments on commit d291a46

Please sign in to comment.