-
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.
Add registerProfileProviders and new example profiles
- Loading branch information
1 parent
ad83b20
commit 831f324
Showing
11 changed files
with
204 additions
and
127 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
9 changes: 9 additions & 0 deletions
9
.../discover/public/context_awareness/profile_providers/example_data_source_profile/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,9 @@ | ||
/* | ||
* 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 { exampleDataSourceProfileProvider } from './profile'; |
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
9 changes: 9 additions & 0 deletions
9
...ins/discover/public/context_awareness/profile_providers/example_document_profile/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,9 @@ | ||
/* | ||
* 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 { exampleDocumentProfileProvider } from './profile'; |
32 changes: 32 additions & 0 deletions
32
...s/discover/public/context_awareness/profile_providers/example_document_profile/profile.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,32 @@ | ||
/* | ||
* 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 { DataTableRecord } from '@kbn/discover-utils'; | ||
import { DocumentProfileProvider, DocumentType } from '../../profiles'; | ||
|
||
export const exampleDocumentProfileProvider: DocumentProfileProvider = { | ||
profileId: 'example-document-profile', | ||
profile: {}, | ||
resolve: (params) => { | ||
if (getFieldValue(params.record, 'data_stream.type') !== 'logs') { | ||
return { isMatch: false }; | ||
} | ||
|
||
return { | ||
isMatch: true, | ||
context: { | ||
type: DocumentType.Log, | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
const getFieldValue = (record: DataTableRecord, field: string) => { | ||
const value = record.flattened[field]; | ||
return Array.isArray(value) ? value[0] : value; | ||
}; |
9 changes: 9 additions & 0 deletions
9
src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/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,9 @@ | ||
/* | ||
* 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 { exampleRootProfileProvider } from './profile'; |
37 changes: 37 additions & 0 deletions
37
...ugins/discover/public/context_awareness/profile_providers/example_root_pofile/profile.tsx
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,37 @@ | ||
/* | ||
* 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 { EuiBadge } from '@elastic/eui'; | ||
import type { DataTableRecord } from '@kbn/discover-utils'; | ||
import React from 'react'; | ||
import { RootProfileProvider, SolutionType } from '../../profiles'; | ||
|
||
export const exampleRootProfileProvider: RootProfileProvider = { | ||
profileId: 'example-root-profile', | ||
profile: { | ||
getCellRenderers: (prev) => () => ({ | ||
...prev(), | ||
'@timestamp': (props) => { | ||
const timestamp = getFieldValue(props.row, '@timestamp'); | ||
return ( | ||
<EuiBadge color="hollow" title={timestamp} data-test-subj="exampleRootProfileTimestamp"> | ||
{timestamp} | ||
</EuiBadge> | ||
); | ||
}, | ||
}), | ||
}, | ||
resolve: () => { | ||
return { isMatch: true, context: { solutionType: SolutionType.Default } }; | ||
}, | ||
}; | ||
|
||
const getFieldValue = (record: DataTableRecord, field: string) => { | ||
const value = record.flattened[field]; | ||
return Array.isArray(value) ? value[0] : value; | ||
}; |
9 changes: 9 additions & 0 deletions
9
src/plugins/discover/public/context_awareness/profile_providers/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,9 @@ | ||
/* | ||
* 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 { registerProfileProviders } from './register_profile_providers'; |
70 changes: 70 additions & 0 deletions
70
...plugins/discover/public/context_awareness/profile_providers/register_profile_providers.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,70 @@ | ||
/* | ||
* 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 { | ||
DataSourceProfileService, | ||
DocumentProfileService, | ||
RootProfileService, | ||
} from '../profiles'; | ||
import type { BaseProfileProvider, BaseProfileService } from '../profile_service'; | ||
import { exampleDataSourceProfileProvider } from './example_data_source_profile'; | ||
import { exampleDocumentProfileProvider } from './example_document_profile'; | ||
import { exampleRootProfileProvider } from './example_root_pofile'; | ||
|
||
export const registerProfileProviders = ({ | ||
rootProfileService, | ||
dataSourceProfileService, | ||
documentProfileService, | ||
enabledProfileIds, | ||
}: { | ||
rootProfileService: RootProfileService; | ||
dataSourceProfileService: DataSourceProfileService; | ||
documentProfileService: DocumentProfileService; | ||
enabledProfileIds: string[]; | ||
}) => { | ||
const rootProfileProviders = [exampleRootProfileProvider]; | ||
const dataSourceProfileProviders = [exampleDataSourceProfileProvider]; | ||
const documentProfileProviders = [exampleDocumentProfileProvider]; | ||
|
||
registerEnabledProfileProviders({ | ||
profileService: rootProfileService, | ||
availableProviders: rootProfileProviders, | ||
enabledProfileIds, | ||
}); | ||
|
||
registerEnabledProfileProviders({ | ||
profileService: dataSourceProfileService, | ||
availableProviders: dataSourceProfileProviders, | ||
enabledProfileIds, | ||
}); | ||
|
||
registerEnabledProfileProviders({ | ||
profileService: documentProfileService, | ||
availableProviders: documentProfileProviders, | ||
enabledProfileIds, | ||
}); | ||
}; | ||
|
||
const registerEnabledProfileProviders = < | ||
TProvider extends BaseProfileProvider<{}>, | ||
TService extends BaseProfileService<TProvider, {}> | ||
>({ | ||
profileService, | ||
availableProviders, | ||
enabledProfileIds, | ||
}: { | ||
profileService: TService; | ||
availableProviders: TProvider[]; | ||
enabledProfileIds: string[]; | ||
}) => { | ||
for (const profile of availableProviders) { | ||
if (enabledProfileIds.includes(profile.profileId)) { | ||
profileService.registerProvider(profile); | ||
} | ||
} | ||
}; |
28 changes: 0 additions & 28 deletions
28
src/plugins/discover/public/context_awareness/register_enabled_profiles.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.