mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
(cherry picked from commit 2a1df2dd7b
)
Co-authored-by: Jan Monschke <jan.monschke@elastic.co>
This commit is contained in:
parent
1bb0d052c8
commit
c6eef453a2
3 changed files with 25 additions and 7 deletions
|
@ -116,7 +116,7 @@ describe('RelatedAlertsByProcessAncestry', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('renders a special message when there are no alerts to display', async () => {
|
||||
it('renders a special message when there are no alerts to display (empty response)', async () => {
|
||||
mockUseAlertPrevalenceFromProcessTree.mockReturnValue({
|
||||
loading: false,
|
||||
error: false,
|
||||
|
@ -134,4 +134,23 @@ describe('RelatedAlertsByProcessAncestry', () => {
|
|||
expect(screen.getByText(PROCESS_ANCESTRY_EMPTY)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('renders a special message when there are no alerts to display (undefined case)', async () => {
|
||||
mockUseAlertPrevalenceFromProcessTree.mockReturnValue({
|
||||
loading: false,
|
||||
error: false,
|
||||
alertIds: undefined,
|
||||
});
|
||||
|
||||
render(
|
||||
<TestProviders>
|
||||
<RelatedAlertsByProcessAncestry {...props} />
|
||||
</TestProviders>
|
||||
);
|
||||
|
||||
userEvent.click(screen.getByText(PROCESS_ANCESTRY));
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(PROCESS_ANCESTRY_EMPTY)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -70,15 +70,12 @@ export const RelatedAlertsByProcessAncestry = React.memo<Props>(
|
|||
const [cache, setCache] = useState<Partial<Cache>>({});
|
||||
|
||||
const onToggle = useCallback((isOpen: boolean) => setShowContent(isOpen), []);
|
||||
const isEmpty = !!cache.alertIds && cache.alertIds.length === 0;
|
||||
|
||||
// Makes sure the component is not fetching data before the accordion
|
||||
// has been openend.
|
||||
const renderContent = useCallback(() => {
|
||||
if (!showContent) {
|
||||
return null;
|
||||
} else if (isEmpty) {
|
||||
return PROCESS_ANCESTRY_EMPTY;
|
||||
} else if (cache.alertIds) {
|
||||
return (
|
||||
<ActualRelatedAlertsByProcessAncestry
|
||||
|
@ -98,7 +95,7 @@ export const RelatedAlertsByProcessAncestry = React.memo<Props>(
|
|||
onCacheLoad={setCache}
|
||||
/>
|
||||
);
|
||||
}, [showContent, cache, data, eventId, timelineId, index, originalDocumentId, isEmpty]);
|
||||
}, [showContent, cache, data, eventId, timelineId, index, originalDocumentId]);
|
||||
|
||||
return (
|
||||
<InsightAccordion
|
||||
|
@ -143,7 +140,7 @@ const FetchAndNotifyCachedAlertsByProcessAncestry: React.FC<{
|
|||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (alertIds) {
|
||||
if (alertIds && alertIds.length !== 0) {
|
||||
onCacheLoad({ alertIds });
|
||||
}
|
||||
}, [alertIds, onCacheLoad]);
|
||||
|
@ -152,6 +149,8 @@ const FetchAndNotifyCachedAlertsByProcessAncestry: React.FC<{
|
|||
return <EuiLoadingSpinner />;
|
||||
} else if (error) {
|
||||
return <>{PROCESS_ANCESTRY_ERROR}</>;
|
||||
} else if (!alertIds || alertIds.length === 0) {
|
||||
return <>{PROCESS_ANCESTRY_EMPTY}</>;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -18,7 +18,7 @@ interface UserAlertPrevalenceFromProcessTreeResult {
|
|||
}
|
||||
|
||||
interface ProcessTreeAlertPrevalenceResponse {
|
||||
alertIds: string[];
|
||||
alertIds: string[] | undefined;
|
||||
}
|
||||
|
||||
interface EntityResponse {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue