-
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.
- Loading branch information
Showing
61 changed files
with
1,172 additions
and
175 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
id: sharedUX/ContentInsights | ||
slug: /shared-ux/content-insights | ||
title: Content Insights | ||
description: A set of Content Management services and component to provide insights on the content of Kibana. | ||
tags: ['shared-ux', 'component'] | ||
date: 2024-08-06 | ||
--- | ||
|
||
## Description | ||
|
||
The Content Insights is a set of Content Management services and components to provide insights on the content of Kibana. | ||
Currently, it allows to track the usage of your content and display the stats of it. | ||
|
||
- The service can count the following events: | ||
- `viewed` | ||
- It provides the api for registering the routes to increase the count and to get the stats. | ||
- It provides the client to increase the count and to get the stats. | ||
- It provides a flyout and a component to display the stats as a total count and a weekly chart. | ||
- Internally it uses the usage collection plugin to store and search the data. | ||
|
||
## API | ||
|
||
// server side | ||
|
||
```ts | ||
import { registerContentInsights } from '@kbn/content-management-content-insights-server'; | ||
|
||
if (plugins.usageCollection) { | ||
// Registers routes for tracking and fetching dashboard views | ||
registerContentInsights( | ||
{ | ||
usageCollection: plugins.usageCollection, | ||
http: core.http, | ||
getStartServices: () => | ||
core.getStartServices().then(([_, start]) => ({ | ||
usageCollection: start.usageCollection!, | ||
})), | ||
}, | ||
{ | ||
domainId: 'dashboard', | ||
// makes sure that only users with read/all access to dashboard app can access the routes | ||
routeTags: ['access:dashboardUsageStats'], | ||
} | ||
); | ||
} | ||
``` | ||
|
||
// client side | ||
|
||
```ts | ||
import { ContentInsightsClient } from '@kbn/content-management-content-insights-public'; | ||
|
||
const contentInsightsClient = new ContentInsightsClient( | ||
{ http: params.coreStart.http }, | ||
{ domainId: 'dashboard' } | ||
); | ||
|
||
contentInsightsClient.track(dashboardId, 'viewed'); | ||
|
||
// wrap component in `ContentInsightsProvider` and use the hook to open an insights flyout | ||
const openInsightsFlyout = useOpenInsightsFlyout(); | ||
openInsightsFlyout({ item }); | ||
``` |
3 changes: 3 additions & 0 deletions
3
packages/content-management/content_insights/content_insights_public/README.md
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,3 @@ | ||
# @kbn/content-management-content-insights-public | ||
|
||
Refer to [README](../README.mdx) |
21 changes: 21 additions & 0 deletions
21
packages/content-management/content_insights/content_insights_public/index.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,21 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { | ||
ContentInsightsProvider, | ||
type ContentInsightsServices, | ||
useServices as useContentInsightsServices, | ||
} from './src/services'; | ||
|
||
export { | ||
type ContentInsightsClientPublic, | ||
ContentInsightsClient, | ||
type ContentInsightsEventTypes, | ||
} from './src/client'; | ||
|
||
export { ActivityView, ViewsStats, type ActivityViewProps } from './src/components'; |
13 changes: 13 additions & 0 deletions
13
packages/content-management/content_insights/content_insights_public/jest.config.js
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,13 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../../..', | ||
roots: ['<rootDir>/packages/content-management/content_insights/content_insights_public'], | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/content-management/content_insights/content_insights_public/kibana.jsonc
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,5 @@ | ||
{ | ||
"type": "shared-browser", | ||
"id": "@kbn/content-management-content-insights-public", | ||
"owner": "@elastic/appex-sharedux" | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/content-management/content_insights/content_insights_public/package.json
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,6 @@ | ||
{ | ||
"name": "@kbn/content-management-content-insights-public", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/content-management/content_insights/content_insights_public/src/client.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,50 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { HttpStart } from '@kbn/core-http-browser'; | ||
import type { | ||
ContentInsightsStats, | ||
ContentInsightsStatsResponse, | ||
} from '@kbn/content-management-content-insights-server'; | ||
|
||
export type ContentInsightsEventTypes = 'viewed'; | ||
|
||
/** | ||
* Public interface of the Content Management Insights service. | ||
*/ | ||
export interface ContentInsightsClientPublic { | ||
track(id: string, eventType: ContentInsightsEventTypes): void; | ||
getStats(id: string, eventType: ContentInsightsEventTypes): Promise<ContentInsightsStats>; | ||
} | ||
|
||
/** | ||
* Client for the Content Management Insights service. | ||
*/ | ||
export class ContentInsightsClient implements ContentInsightsClientPublic { | ||
constructor( | ||
private readonly deps: { http: HttpStart }, | ||
private readonly config: { domainId: string } | ||
) {} | ||
|
||
track(id: string, eventType: ContentInsightsEventTypes) { | ||
this.deps.http | ||
.post(`/internal/content_management/insights/${this.config.domainId}/${id}/${eventType}`) | ||
.catch((e) => { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Could not track ${eventType} event for ${id}`, e); | ||
}); | ||
} | ||
|
||
async getStats(id: string, eventType: ContentInsightsEventTypes) { | ||
return this.deps.http | ||
.get<ContentInsightsStatsResponse>( | ||
`/internal/content_management/insights/${this.config.domainId}/${id}/${eventType}/stats` | ||
) | ||
.then((response) => response.result); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.