forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Entity Inventory] Add basic telemetry (elastic#197055)
## Summary Closes elastic#195608. In this PR, we introduce basic telemetry tracking for the new Inventory plugin. These events will help us gain insight into how users are interacting with the Inventory feature, including the state of the views, search behaviors, and entity type filtering. **New events** - Entity Inventory Viewed - Entity Inventory Search Query Submitted - Entity Inventory Entity Type Filtered - Entity View Clicked ![Untitled-2024-07-24-1420](https://github.com/user-attachments/assets/6e85ea00-c626-4bc1-a4f8-9907674eb264) ~**New attribute added to global context**~ - ~eem_enabled~ ~It will only be populated if the Inventory plugin is accessible to users and after they access the Observability solution. If EEM is not enabled and the user enables it, the property will be updated accordingly.~ Details about not implementing `eem_enabled` can be found in [this comment](elastic#197055 (comment)).
- Loading branch information
Showing
16 changed files
with
549 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
x-pack/plugins/observability_solution/inventory/public/hooks/use_is_loading_complete.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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 { renderHook } from '@testing-library/react-hooks'; | ||
import { useIsLoadingComplete } from './use_is_loading_complete'; | ||
|
||
describe('useIsLoadingComplete', () => { | ||
describe('initialization', () => { | ||
it('should initialize with undefined', () => { | ||
const { result } = renderHook(() => useIsLoadingComplete({ loadingStates: [false, false] })); | ||
expect(result.current).toBeUndefined(); | ||
}); | ||
|
||
it('should handle an empty array of loadingStates', () => { | ||
const { result } = renderHook(() => useIsLoadingComplete({ loadingStates: [] })); | ||
expect(result.current).toBeUndefined(); | ||
}); | ||
|
||
it('should handle a single loading state that is false', () => { | ||
const { result } = renderHook(() => useIsLoadingComplete({ loadingStates: [false] })); | ||
expect(result.current).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('loading states', () => { | ||
it('should set isLoadingComplete to false when some loadingStates are true', () => { | ||
const { result } = renderHook(() => useIsLoadingComplete({ loadingStates: [true, false] })); | ||
expect(result.current).toBe(false); | ||
}); | ||
|
||
it('should set isLoadingComplete to false when all loadingStates are true', () => { | ||
const { result } = renderHook(() => useIsLoadingComplete({ loadingStates: [true, true] })); | ||
expect(result.current).toBe(false); | ||
}); | ||
|
||
it('should handle a single loading state that is true', () => { | ||
const { result } = renderHook(() => useIsLoadingComplete({ loadingStates: [true] })); | ||
expect(result.current).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('loading completion', () => { | ||
it('should set isLoadingComplete to true when all loadingStates are false after being true', () => { | ||
const { result, rerender } = renderHook( | ||
({ loadingStates }) => useIsLoadingComplete({ loadingStates }), | ||
{ | ||
initialProps: { loadingStates: [true, false] }, | ||
} | ||
); | ||
|
||
expect(result.current).toBe(false); | ||
|
||
rerender({ loadingStates: [false, false] }); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it('should set isLoadingComplete to true when all loadingStates are false after being mixed', () => { | ||
const { result, rerender } = renderHook( | ||
({ loadingStates }) => useIsLoadingComplete({ loadingStates }), | ||
{ | ||
initialProps: { loadingStates: [true, false] }, | ||
} | ||
); | ||
|
||
expect(result.current).toBe(false); | ||
|
||
rerender({ loadingStates: [false, false] }); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('mixed states', () => { | ||
it('should not change isLoadingComplete if loadingStates are mixed', () => { | ||
const { result, rerender } = renderHook( | ||
({ loadingStates }) => useIsLoadingComplete({ loadingStates }), | ||
{ | ||
initialProps: { loadingStates: [true, true] }, | ||
} | ||
); | ||
|
||
expect(result.current).toBe(false); | ||
|
||
rerender({ loadingStates: [true, false] }); | ||
|
||
expect(result.current).toBe(false); | ||
}); | ||
|
||
it('should not change isLoadingComplete if loadingStates change from all true to mixed', () => { | ||
const { result, rerender } = renderHook( | ||
({ loadingStates }) => useIsLoadingComplete({ loadingStates }), | ||
{ | ||
initialProps: { loadingStates: [true, true] }, | ||
} | ||
); | ||
|
||
expect(result.current).toBe(false); | ||
|
||
rerender({ loadingStates: [true, false] }); | ||
|
||
expect(result.current).toBe(false); | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/observability_solution/inventory/public/hooks/use_is_loading_complete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 { useState, useEffect } from 'react'; | ||
|
||
interface UseIsLoadingCompleteProps { | ||
loadingStates: boolean[]; | ||
} | ||
|
||
export const useIsLoadingComplete = ({ loadingStates }: UseIsLoadingCompleteProps) => { | ||
const [isLoadingComplete, setIsLoadingComplete] = useState<boolean | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
const someLoading = loadingStates.some((loading) => loading); | ||
const allLoaded = loadingStates.every((loading) => !loading); | ||
|
||
if (isLoadingComplete === undefined && someLoading) { | ||
setIsLoadingComplete(false); | ||
} else if (isLoadingComplete === false && allLoaded) { | ||
setIsLoadingComplete(true); | ||
} | ||
}, [isLoadingComplete, loadingStates]); | ||
|
||
return isLoadingComplete; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.