Skip to content

Commit aa4af5f

Browse files
committed
added buckets info to existing return objec per feedback
1 parent 84b7fef commit aa4af5f

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

x-pack/plugins/security_solution/public/common/containers/matrix_histogram/index.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export interface UseMatrixHistogramArgs {
3232
inspect: InspectResponse;
3333
refetch: inputsModel.Refetch;
3434
totalCount: number;
35+
buckets: Array<{
36+
key: string;
37+
doc_count: number;
38+
}>;
3539
}
3640

3741
const ID = 'matrixHistogramQuery';
@@ -45,14 +49,7 @@ export const useMatrixHistogram = ({
4549
stackByField,
4650
startDate,
4751
threshold,
48-
}: MatrixHistogramQueryProps): [
49-
boolean,
50-
UseMatrixHistogramArgs,
51-
Array<{
52-
key: string;
53-
doc_count: number;
54-
}>
55-
] => {
52+
}: MatrixHistogramQueryProps): [boolean, UseMatrixHistogramArgs] => {
5653
const { data, notifications } = useKibana().services;
5754
const refetch = useRef<inputsModel.Refetch>(noop);
5855
const abortCtrl = useRef(new AbortController());
@@ -82,13 +79,8 @@ export const useMatrixHistogram = ({
8279
},
8380
refetch: refetch.current,
8481
totalCount: -1,
82+
buckets: [],
8583
});
86-
const [matrixHistogramBuckets, setMatrixHistogramBuckets] = useState<
87-
Array<{
88-
key: string;
89-
doc_count: number;
90-
}>
91-
>([]);
9284

9385
const hostsSearch = useCallback(
9486
(request: MatrixHistogramRequestOptions) => {
@@ -117,8 +109,8 @@ export const useMatrixHistogram = ({
117109
inspect: getInspectResponse(response, prevResponse.inspect),
118110
refetch: refetch.current,
119111
totalCount: response.totalCount,
112+
buckets: histogramBuckets,
120113
}));
121-
setMatrixHistogramBuckets(histogramBuckets);
122114
}
123115
searchSubscription$.unsubscribe();
124116
} else if (isErrorResponse(response)) {
@@ -177,5 +169,5 @@ export const useMatrixHistogram = ({
177169
hostsSearch(matrixHistogramRequest);
178170
}, [matrixHistogramRequest, hostsSearch]);
179171

180-
return [loading, matrixHistogramResponse, matrixHistogramBuckets];
172+
return [loading, matrixHistogramResponse];
181173
};

x-pack/plugins/security_solution/public/detections/components/rules/query_preview/threshold_histogram.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const PreviewThresholdQueryHistogram = ({
3636
}: PreviewThresholdQueryHistogramProps) => {
3737
const { setQuery, isInitializing } = useGlobalTime();
3838

39-
const [isLoading, { inspect, refetch }, buckets] = useMatrixHistogram({
39+
const [isLoading, { inspect, refetch, buckets }] = useMatrixHistogram({
4040
errorMessage: i18n.PREVIEW_QUERY_ERROR,
4141
endDate: from,
4242
startDate: to,
@@ -54,21 +54,14 @@ export const PreviewThresholdQueryHistogram = ({
5454
}, [setQuery, inspect, isLoading, isInitializing, refetch]);
5555

5656
const { data, totalCount } = useMemo(() => {
57-
if (buckets != null) {
58-
return {
59-
data: buckets.map<{ x: string; y: number; g: string }>(({ key, doc_count: docCount }) => ({
60-
x: key,
61-
y: docCount,
62-
g: key,
63-
})),
64-
totalCount: buckets.length,
65-
};
66-
} else {
67-
return {
68-
data: [],
69-
totalCount: 0,
70-
};
71-
}
57+
return {
58+
data: buckets.map<{ x: string; y: number; g: string }>(({ key, doc_count: docCount }) => ({
59+
x: key,
60+
y: docCount,
61+
g: key,
62+
})),
63+
totalCount: buckets.length,
64+
};
7265
}, [buckets]);
7366

7467
return (

0 commit comments

Comments
 (0)