Skip to content

Commit

Permalink
[Security Solution] Invalid kql query timeline refresh bug (elastic#1…
Browse files Browse the repository at this point in the history
…05525)

* poc test

* adds disable for refresh button

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
dplumlee and kibanamachine committed Jul 20, 2021
1 parent 630330b commit ccbf04b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
timelineId,
toStr,
updateReduxTime,
disabled,
}) => {
const [recentlyUsedRanges, setRecentlyUsedRanges] = useState<EuiSuperDatePickerRecentRange[]>(
[]
Expand Down Expand Up @@ -201,6 +202,7 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
refreshInterval={duration}
showUpdateButton={true}
start={startDate}
isDisabled={disabled}
/>
);
},
Expand All @@ -216,6 +218,7 @@ export const SuperDatePickerComponent = React.memo<SuperDatePickerProps>(
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) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,21 @@ export const QueryTabContentComponent: React.FC<Props> = ({
});

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;
Expand Down Expand Up @@ -264,7 +271,7 @@ export const QueryTabContentComponent: React.FC<Props> = ({
limit: itemsPerPage,
filterQuery: combinedQueries?.filterQuery,
startDate: start,
skip: !canQueryTimeline() || combinedQueries?.filterQuery === undefined,
skip: !canQueryTimeline,
sort: timelineQuerySortField,
timerangeKind,
});
Expand All @@ -290,6 +297,10 @@ export const QueryTabContentComponent: React.FC<Props> = ({
);
}, [loadingSourcerer, timelineId, isQueryLoading, dispatch]);

const isDatePickerDisabled = useMemo(() => {
return (combinedQueries && combinedQueries.kqlError != null) || false;
}, [combinedQueries]);

const leadingControlColumns: ControlColumnProps[] = [defaultControlColumn];
const trailingControlColumns: ControlColumnProps[] = [];

Expand All @@ -304,6 +315,7 @@ export const QueryTabContentComponent: React.FC<Props> = ({
inspect={inspect}
loading={isQueryLoading}
refetch={refetch}
skip={!canQueryTimeline}
/>
<FullWidthFlexGroup gutterSize="none">
<ScrollableFlexItem grow={2}>
Expand All @@ -323,7 +335,11 @@ export const QueryTabContentComponent: React.FC<Props> = ({
/>
)}
<DatePicker grow={1}>
<SuperDatePicker id="timeline" timelineId={timelineId} />
<SuperDatePicker
id="timeline"
timelineId={timelineId}
disabled={isDatePickerDisabled}
/>
</DatePicker>
<EuiFlexItem grow={false}>
<TimelineDatePickerLock />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TimelineRefetchProps {
inspect: inputsModel.InspectQuery | null;
loading: boolean;
refetch: inputsModel.Refetch;
skip?: boolean;
}

const TimelineRefetchComponent: React.FC<TimelineRefetchProps> = ({
Expand All @@ -26,12 +27,15 @@ const TimelineRefetchComponent: React.FC<TimelineRefetchProps> = ({
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;
};
Expand Down

0 comments on commit ccbf04b

Please sign in to comment.