Skip to content

Commit

Permalink
[7.x] Flatten child api response for resolver (#60810) (#61078)
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic authored Mar 24, 2020
1 parent 6bc866a commit 2221332
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ type MiddlewareFactory<S = ResolverState> = (
) => (
api: MiddlewareAPI<Dispatch<ResolverAction>, S>
) => (next: Dispatch<ResolverAction>) => (action: ResolverAction) => unknown;
interface Lifecycle {
lifecycle: ResolverEvent[];
}
type ChildResponse = [Lifecycle];

function flattenEvents(events: ChildResponse): ResolverEvent[] {
return events
.map((child: Lifecycle) => child.lifecycle)
.reduce(
(accumulator: ResolverEvent[], value: ResolverEvent[]) => accumulator.concat(value),
[]
);
}

export const resolverMiddlewareFactory: MiddlewareFactory = context => {
return api => next => async (action: ResolverAction) => {
Expand Down Expand Up @@ -47,7 +60,7 @@ export const resolverMiddlewareFactory: MiddlewareFactory = context => {
query: { legacyEndpointID },
}),
]);
childEvents = children.length > 0 ? children.map((child: any) => child.lifecycle) : [];
childEvents = children.length > 0 ? flattenEvents(children) : [];
} else {
const uniquePid = action.payload.selectedEvent.process.entity_id;
const ppid = action.payload.selectedEvent.process.parent?.entity_id;
Expand All @@ -67,7 +80,7 @@ export const resolverMiddlewareFactory: MiddlewareFactory = context => {
getAncestors(ppid),
]);
}
childEvents = children.length > 0 ? children.map((child: any) => child.lifecycle) : [];
childEvents = children.length > 0 ? flattenEvents(children) : [];
response = [...lifecycle, ...childEvents, ...relatedEvents, ...ancestors];
api.dispatch({
type: 'serverReturnedResolverData',
Expand Down

0 comments on commit 2221332

Please sign in to comment.