Skip to content

Commit

Permalink
fix issue with reftech all timeline query
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Apr 27, 2020
1 parent 292c35e commit f106ff4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,21 @@ export const StatefulOpenTimelineComponent = React.memo<OpenTimelineOwnProps>(
);

const deleteTimelines: DeleteTimelines = useCallback(
(timelineIds: string[], variables?: AllTimelinesVariables) => {
async (timelineIds: string[], variables?: AllTimelinesVariables) => {
if (timelineIds.includes(timeline.savedObjectId || '')) {
createNewTimeline({ id: 'timeline-1', columns: defaultHeaders, show: false });
}
apolloClient.mutate<DeleteTimelineMutation.Mutation, DeleteTimelineMutation.Variables>({
await apolloClient.mutate<
DeleteTimelineMutation.Mutation,
DeleteTimelineMutation.Variables
>({
mutation: deleteTimelineMutation,
fetchPolicy: 'no-cache',
variables: { id: timelineIds },
refetchQueries: [
{
query: allTimelinesQuery,
variables,
},
],
});
refetch();
},
[apolloClient, createNewTimeline, timeline]
[apolloClient, createNewTimeline, refetch, timeline]
);

useEffect(() => {
Expand Down
47 changes: 31 additions & 16 deletions x-pack/legacy/plugins/siem/public/store/timeline/epic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@ import {
} from 'rxjs/operators';

import { esFilters, Filter, MatchAllFilter } from '../../../../../../../src/plugins/data/public';
// import { persistTimelineMutation } from '../../containers/timeline/persist.gql_query';
import {
// PersistTimelineMutation,
TimelineInput,
ResponseTimeline,
TimelineResult,
} from '../../graphql/types';
import { TimelineInput, ResponseTimeline, TimelineResult } from '../../graphql/types';
import { AppApolloClient } from '../../lib/lib';
import { addError } from '../app/actions';
import { NotesById } from '../app/model';
import { TimeRange, GlobalQuery } from '../inputs/model';
import { inputsModel } from '../inputs';

import {
applyKqlFilterQuery,
Expand Down Expand Up @@ -75,17 +69,15 @@ import { epicPersistPinnedEvent, timelinePinnedEventActionsType } from './epic_p
import { epicPersistTimelineFavorite, timelineFavoriteActionsType } from './epic_favorite';
import { isNotNull } from './helpers';
import { dispatcherTimelinePersistQueue } from './epic_dispatcher_timeline_persistence_queue';
// import { refetchQueries } from './refetch_queries';
import { myEpicTimelineId } from './my_epic_timeline_id';
import { ActionTimeline, TimelineById } from './types';
import { persistTimeline } from '../../containers/timeline/api';
import { ALL_TIMELINE_QUERY_ID } from '../../containers/timeline/all';
import { inputsModel } from '../inputs';

interface TimelineEpicDependencies<State> {
timelineByIdSelector: (state: State) => TimelineById;
timelineTimeRangeSelector: (state: State) => TimeRange;
selectAllTimelineQuery: () => (state: State, id: string) => GlobalQuery;
timelineTimeRangeSelector: (state: State) => inputsModel.TimeRange;
selectAllTimelineQuery: () => (state: State, id: string) => inputsModel.GlobalQuery;
selectNotesByIdSelector: (state: State) => NotesById;
apolloClient$: Observable<AppApolloClient>;
}
Expand Down Expand Up @@ -186,11 +178,34 @@ export const createTimelineEpic = <State>(): Epic<
const version = myEpicTimelineId.getTimelineVersion();

if (timelineNoteActionsType.includes(action.type)) {
return epicPersistNote(apolloClient, action, timeline, notes, action$, timeline$, notes$);
return epicPersistNote(
apolloClient,
action,
timeline,
notes,
action$,
timeline$,
notes$,
allTimelineQuery$
);
} else if (timelinePinnedEventActionsType.includes(action.type)) {
return epicPersistPinnedEvent(apolloClient, action, timeline, action$, timeline$);
return epicPersistPinnedEvent(
apolloClient,
action,
timeline,
action$,
timeline$,
allTimelineQuery$
);
} else if (timelineFavoriteActionsType.includes(action.type)) {
return epicPersistTimelineFavorite(apolloClient, action, timeline, action$, timeline$);
return epicPersistTimelineFavorite(
apolloClient,
action,
timeline,
action$,
timeline$,
allTimelineQuery$
);
} else if (timelineActionsType.includes(action.type)) {
return from(
persistTimeline({
Expand Down Expand Up @@ -275,7 +290,7 @@ const timelineInput: TimelineInput = {

export const convertTimelineAsInput = (
timeline: TimelineModel,
timelineTimeRange: TimeRange
timelineTimeRange: inputsModel.TimeRange
): TimelineInput =>
Object.keys(timelineInput).reduce<TimelineInput>((acc, key) => {
if (has(key, timeline)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { dispatcherTimelinePersistQueue } from './epic_dispatcher_timeline_persi
import { refetchQueries } from './refetch_queries';
import { myEpicTimelineId } from './my_epic_timeline_id';
import { ActionTimeline, TimelineById } from './types';
import { inputsModel } from '../inputs';

export const timelineFavoriteActionsType = [updateIsFavorite.type];

Expand All @@ -34,7 +35,8 @@ export const epicPersistTimelineFavorite = (
action: ActionTimeline,
timeline: TimelineById,
action$: Observable<Action>,
timeline$: Observable<TimelineById>
timeline$: Observable<TimelineById>,
allTimelineQuery$: Observable<inputsModel.GlobalQuery>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Observable<any> =>
from(
Expand All @@ -50,12 +52,16 @@ export const epicPersistTimelineFavorite = (
refetchQueries,
})
).pipe(
withLatestFrom(timeline$),
mergeMap(([result, recentTimelines]) => {
withLatestFrom(timeline$, allTimelineQuery$),
mergeMap(([result, recentTimelines, allTimelineQuery]) => {
const savedTimeline = recentTimelines[action.payload.id];
const response: ResponseFavoriteTimeline = get('data.persistFavorite', result);
const callOutMsg = response.code === 403 ? [showCallOutUnauthorizedMsg()] : [];

if (allTimelineQuery.refetch != null) {
(allTimelineQuery.refetch as inputsModel.Refetch)();
}

return [
...callOutMsg,
updateTimeline({
Expand Down
12 changes: 9 additions & 3 deletions x-pack/legacy/plugins/siem/public/store/timeline/epic_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { persistTimelineNoteMutation } from '../../containers/timeline/notes/per
import { PersistTimelineNoteMutation, ResponseNote } from '../../graphql/types';
import { updateNote, addError } from '../app/actions';
import { NotesById } from '../app/model';
import { inputsModel } from '../inputs';

import {
addNote,
Expand All @@ -39,7 +40,8 @@ export const epicPersistNote = (
notes: NotesById,
action$: Observable<Action>,
timeline$: Observable<TimelineById>,
notes$: Observable<NotesById>
notes$: Observable<NotesById>,
allTimelineQuery$: Observable<inputsModel.GlobalQuery>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Observable<any> =>
from(
Expand All @@ -61,12 +63,16 @@ export const epicPersistNote = (
refetchQueries,
})
).pipe(
withLatestFrom(timeline$, notes$),
mergeMap(([result, recentTimeline, recentNotes]) => {
withLatestFrom(timeline$, notes$, allTimelineQuery$),
mergeMap(([result, recentTimeline, recentNotes, allTimelineQuery]) => {
const noteIdRedux = action.payload.noteId;
const response: ResponseNote = get('data.persistNote', result);
const callOutMsg = response.code === 403 ? [showCallOutUnauthorizedMsg()] : [];

if (allTimelineQuery.refetch != null) {
(allTimelineQuery.refetch as inputsModel.Refetch)();
}

return [
...callOutMsg,
recentTimeline[action.payload.id].savedObjectId == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { filter, mergeMap, startWith, withLatestFrom, takeUntil } from 'rxjs/ope
import { persistTimelinePinnedEventMutation } from '../../containers/timeline/pinned_event/persist.gql_query';
import { PersistTimelinePinnedEventMutation, PinnedEvent } from '../../graphql/types';
import { addError } from '../app/actions';
import { inputsModel } from '../inputs';

import {
pinEvent,
endTimelineSaving,
Expand All @@ -35,7 +37,8 @@ export const epicPersistPinnedEvent = (
action: ActionTimeline,
timeline: TimelineById,
action$: Observable<Action>,
timeline$: Observable<TimelineById>
timeline$: Observable<TimelineById>,
allTimelineQuery$: Observable<inputsModel.GlobalQuery>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Observable<any> =>
from(
Expand All @@ -57,12 +60,16 @@ export const epicPersistPinnedEvent = (
refetchQueries,
})
).pipe(
withLatestFrom(timeline$),
mergeMap(([result, recentTimeline]) => {
withLatestFrom(timeline$, allTimelineQuery$),
mergeMap(([result, recentTimeline, allTimelineQuery]) => {
const savedTimeline = recentTimeline[action.payload.id];
const response: PinnedEvent = get('data.persistPinnedEventOnTimeline', result);
const callOutMsg = response && response.code === 403 ? [showCallOutUnauthorizedMsg()] : [];

if (allTimelineQuery.refetch != null) {
(allTimelineQuery.refetch as inputsModel.Refetch)();
}

return [
response != null
? updateTimeline({
Expand Down

0 comments on commit f106ff4

Please sign in to comment.