Skip to content

Commit

Permalink
[Security Solution][Data Quality Dashboard] fix pattern state reset o…
Browse files Browse the repository at this point in the history
…n ilm phase filter change

addresses #196523
  • Loading branch information
kapral18 committed Nov 4, 2024
1 parent 73a4d6a commit 5169e4d
Show file tree
Hide file tree
Showing 7 changed files with 882 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { useEffect, useState } from 'react';
import { IToasts } from '@kbn/core-notifications-browser';
import { HttpHandler } from '@kbn/core-http-browser';
import { isEmpty } from 'lodash/fp';

import { DataQualityCheckResult } from '../../../../types';
import { formatResultFromStorage, getStorageResults } from '../../utils/storage';

export const useStoredPatternResults = (
patterns: string[],
toasts: IToasts,
httpFetch: HttpHandler
) => {
const [storedPatternResults, setStoredPatternResults] = useState<
Array<{ pattern: string; results: Record<string, DataQualityCheckResult> }>
>([]);

useEffect(() => {
if (isEmpty(patterns)) {
return;
}

let ignore = false;
const abortController = new AbortController();
const fetchStoredPatternResults = async () => {
const requests = patterns.map((pattern) =>
getStorageResults({ pattern, httpFetch, abortController, toasts }).then((results = []) => ({
pattern,
results: Object.fromEntries(
results.map((storageResult) => [
storageResult.indexName,
formatResultFromStorage({ storageResult, pattern }),
])
),
}))
);
const patternResults = await Promise.all(requests);
if (patternResults?.length && !ignore) {
setStoredPatternResults(patternResults);
}
};

fetchStoredPatternResults();
return () => {
ignore = true;
};
}, [httpFetch, patterns, toasts]);

return storedPatternResults;
};
Loading

0 comments on commit 5169e4d

Please sign in to comment.