From a34a15ea3d380282132ce2d2f2914e7165ab50e8 Mon Sep 17 00:00:00 2001 From: Davis Plumlee <56367316+dplumlee@users.noreply.github.com> Date: Mon, 19 Jul 2021 22:37:42 -0600 Subject: [PATCH] [Security Solution] Invalid kql query timeline refresh bug (#105525) * poc test * adds disable for refresh button Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../components/super_date_picker/index.tsx | 3 ++ .../timeline/query_tab_content/index.tsx | 36 +++++++++++++------ .../components/timeline/refetch_timeline.tsx | 8 +++-- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.tsx b/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.tsx index c57ae1d11b8da..04e4203df1a99 100644 --- a/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.tsx @@ -91,6 +91,7 @@ export const SuperDatePickerComponent = React.memo( timelineId, toStr, updateReduxTime, + disabled, }) => { const [recentlyUsedRanges, setRecentlyUsedRanges] = useState( [] @@ -201,6 +202,7 @@ export const SuperDatePickerComponent = React.memo( refreshInterval={duration} showUpdateButton={true} start={startDate} + isDisabled={disabled} /> ); }, @@ -216,6 +218,7 @@ export const SuperDatePickerComponent = React.memo( prevProps.startAutoReload === nextProps.startAutoReload && prevProps.stopAutoReload === nextProps.stopAutoReload && prevProps.timelineId === nextProps.timelineId && + prevProps.disabled === nextProps.disabled && prevProps.toStr === nextProps.toStr && prevProps.updateReduxTime === nextProps.updateReduxTime && deepEqual(prevProps.kqlQuery, nextProps.kqlQuery) && diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx index c2e47edeae202..abbb991c274da 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_tab_content/index.tsx @@ -220,14 +220,21 @@ export const QueryTabContentComponent: React.FC = ({ }); const isBlankTimeline: boolean = - isEmpty(dataProviders) && isEmpty(filters) && isEmpty(kqlQuery.query); - - const canQueryTimeline = () => - combinedQueries != null && - loadingSourcerer != null && - !loadingSourcerer && - !isEmpty(start) && - !isEmpty(end); + isEmpty(dataProviders) && + isEmpty(filters) && + isEmpty(kqlQuery.query) && + combinedQueries?.filterQuery === undefined; + + const canQueryTimeline = useMemo( + () => + combinedQueries != null && + loadingSourcerer != null && + !loadingSourcerer && + !isEmpty(start) && + !isEmpty(end) && + combinedQueries?.filterQuery !== undefined, + [combinedQueries, end, loadingSourcerer, start] + ); const getTimelineQueryFields = () => { const columnsHeader = isEmpty(columns) ? defaultHeaders : columns; @@ -264,7 +271,7 @@ export const QueryTabContentComponent: React.FC = ({ limit: itemsPerPage, filterQuery: combinedQueries?.filterQuery, startDate: start, - skip: !canQueryTimeline() || combinedQueries?.filterQuery === undefined, + skip: !canQueryTimeline, sort: timelineQuerySortField, timerangeKind, }); @@ -290,6 +297,10 @@ export const QueryTabContentComponent: React.FC = ({ ); }, [loadingSourcerer, timelineId, isQueryLoading, dispatch]); + const isDatePickerDisabled = useMemo(() => { + return (combinedQueries && combinedQueries.kqlError != null) || false; + }, [combinedQueries]); + const leadingControlColumns: ControlColumnProps[] = [defaultControlColumn]; const trailingControlColumns: ControlColumnProps[] = []; @@ -304,6 +315,7 @@ export const QueryTabContentComponent: React.FC = ({ inspect={inspect} loading={isQueryLoading} refetch={refetch} + skip={!canQueryTimeline} /> @@ -323,7 +335,11 @@ export const QueryTabContentComponent: React.FC = ({ /> )} - + diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/refetch_timeline.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/refetch_timeline.tsx index 108013c906522..0b51f0183bbb4 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/refetch_timeline.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/refetch_timeline.tsx @@ -18,6 +18,7 @@ export interface TimelineRefetchProps { inspect: inputsModel.InspectQuery | null; loading: boolean; refetch: inputsModel.Refetch; + skip?: boolean; } const TimelineRefetchComponent: React.FC = ({ @@ -26,12 +27,15 @@ const TimelineRefetchComponent: React.FC = ({ inspect, loading, refetch, + skip, }) => { const dispatch = useDispatch(); useEffect(() => { - dispatch(inputsActions.setQuery({ id, inputId, inspect, loading, refetch })); - }, [dispatch, id, inputId, loading, refetch, inspect]); + if (!skip) { + dispatch(inputsActions.setQuery({ id, inputId, inspect, loading, refetch })); + } + }, [dispatch, id, inputId, loading, refetch, inspect, skip]); return null; };