-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
# Backport This will backport the following commits from `main` to `8.16`: - [[Entity Inventory] Add basic telemetry (#197055)](#197055) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Irene Blanco","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-25T14:49:49Z","message":"[Entity Inventory] Add basic telemetry (#197055)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/195608.\r\n\r\nIn this PR, we introduce basic telemetry tracking for the new Inventory\r\nplugin.\r\nThese events will help us gain insight into how users are interacting\r\nwith the Inventory feature, including the state of the views, search\r\nbehaviors, and entity type filtering.\r\n\r\n\r\n**New events**\r\n- Entity Inventory Viewed\r\n- Entity Inventory Search Query Submitted\r\n- Entity Inventory Entity Type Filtered\r\n- Entity View Clicked\r\n\r\n\r\n![Untitled-2024-07-24-1420](https://github.com/user-attachments/assets/6e85ea00-c626-4bc1-a4f8-9907674eb264)\r\n\r\n\r\n~**New attribute added to global context**~\r\n- ~eem_enabled~\r\n\r\n~It will only be populated if the Inventory plugin is accessible to\r\nusers and after they access the Observability solution.\r\nIf EEM is not enabled and the user enables it, the property will be\r\nupdated accordingly.~\r\n\r\nDetails about not implementing `eem_enabled` can be found in [this\r\ncomment](https://github.com/elastic/kibana/pull/197055#issuecomment-2432123047).","sha":"7d673b84c3ecec2f6da81b57196301c6e7fe384a","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport missing","v9.0.0","telemetry","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services","v8.16.0"],"number":197055,"url":"https://github.com/elastic/kibana/pull/197055","mergeCommit":{"message":"[Entity Inventory] Add basic telemetry (#197055)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/195608.\r\n\r\nIn this PR, we introduce basic telemetry tracking for the new Inventory\r\nplugin.\r\nThese events will help us gain insight into how users are interacting\r\nwith the Inventory feature, including the state of the views, search\r\nbehaviors, and entity type filtering.\r\n\r\n\r\n**New events**\r\n- Entity Inventory Viewed\r\n- Entity Inventory Search Query Submitted\r\n- Entity Inventory Entity Type Filtered\r\n- Entity View Clicked\r\n\r\n\r\n![Untitled-2024-07-24-1420](https://github.com/user-attachments/assets/6e85ea00-c626-4bc1-a4f8-9907674eb264)\r\n\r\n\r\n~**New attribute added to global context**~\r\n- ~eem_enabled~\r\n\r\n~It will only be populated if the Inventory plugin is accessible to\r\nusers and after they access the Observability solution.\r\nIf EEM is not enabled and the user enables it, the property will be\r\nupdated accordingly.~\r\n\r\nDetails about not implementing `eem_enabled` can be found in [this\r\ncomment](https://github.com/elastic/kibana/pull/197055#issuecomment-2432123047).","sha":"7d673b84c3ecec2f6da81b57196301c6e7fe384a"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197055","number":197055,"mergeCommit":{"message":"[Entity Inventory] Add basic telemetry (#197055)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/195608.\r\n\r\nIn this PR, we introduce basic telemetry tracking for the new Inventory\r\nplugin.\r\nThese events will help us gain insight into how users are interacting\r\nwith the Inventory feature, including the state of the views, search\r\nbehaviors, and entity type filtering.\r\n\r\n\r\n**New events**\r\n- Entity Inventory Viewed\r\n- Entity Inventory Search Query Submitted\r\n- Entity Inventory Entity Type Filtered\r\n- Entity View Clicked\r\n\r\n\r\n![Untitled-2024-07-24-1420](https://github.com/user-attachments/assets/6e85ea00-c626-4bc1-a4f8-9907674eb264)\r\n\r\n\r\n~**New attribute added to global context**~\r\n- ~eem_enabled~\r\n\r\n~It will only be populated if the Inventory plugin is accessible to\r\nusers and after they access the Observability solution.\r\nIf EEM is not enabled and the user enables it, the property will be\r\nupdated accordingly.~\r\n\r\nDetails about not implementing `eem_enabled` can be found in [this\r\ncomment](https://github.com/elastic/kibana/pull/197055#issuecomment-2432123047).","sha":"7d673b84c3ecec2f6da81b57196301c6e7fe384a"}},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Irene Blanco <[email protected]>
- Loading branch information
1 parent
6f333b8
commit 512cabc
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.