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.
[CM] Onboard
maps
to cross-type search (elastic#155148)
## Summary Part of elastic#152224 Follow up to elastic#153256 This PR onboards maps CM integration into the multi-type search (`msearch`). It isn't actually used anywhere in the user-facing UI yet, as first other types need to be migrated to CM. This PR also adds an example app to test the `msearch` end-to-end.
- Loading branch information
Showing
21 changed files
with
316 additions
and
23 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
9 changes: 9 additions & 0 deletions
9
examples/content_management_examples/public/examples/msearch/index.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,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 { MSearchApp } from './msearch_app'; |
42 changes: 42 additions & 0 deletions
42
examples/content_management_examples/public/examples/msearch/msearch_app.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,42 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { ContentClientProvider, type ContentClient } from '@kbn/content-management-plugin/public'; | ||
import { TableListViewKibanaProvider } from '@kbn/content-management-table-list'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import { toMountPoint } from '@kbn/kibana-react-plugin/public'; | ||
import { FormattedRelative, I18nProvider } from '@kbn/i18n-react'; | ||
import { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public'; | ||
import { MSearchTable } from './msearch_table'; | ||
|
||
export const MSearchApp = (props: { | ||
contentClient: ContentClient; | ||
core: CoreStart; | ||
savedObjectsTagging: SavedObjectTaggingOssPluginStart; | ||
}) => { | ||
return ( | ||
<ContentClientProvider contentClient={props.contentClient}> | ||
<I18nProvider> | ||
<TableListViewKibanaProvider | ||
core={{ | ||
application: props.core.application, | ||
notifications: props.core.notifications, | ||
overlays: props.core.overlays, | ||
http: props.core.http, | ||
}} | ||
toMountPoint={toMountPoint} | ||
FormattedRelative={FormattedRelative} | ||
savedObjectsTagging={props.savedObjectsTagging.getTaggingApi()} | ||
> | ||
<MSearchTable /> | ||
</TableListViewKibanaProvider> | ||
</I18nProvider> | ||
</ContentClientProvider> | ||
); | ||
}; |
62 changes: 62 additions & 0 deletions
62
examples/content_management_examples/public/examples/msearch/msearch_table.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,62 @@ | ||
/* | ||
* 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 { TableListView, UserContentCommonSchema } from '@kbn/content-management-table-list'; | ||
import { useContentClient } from '@kbn/content-management-plugin/public'; | ||
import React from 'react'; | ||
import { SavedObjectsFindOptionsReference } from '@kbn/core-saved-objects-api-browser'; | ||
|
||
const LISTING_LIMIT = 1000; | ||
|
||
export const MSearchTable = () => { | ||
const contentClient = useContentClient(); | ||
|
||
const findItems = async ( | ||
searchQuery: string, | ||
refs?: { | ||
references?: SavedObjectsFindOptionsReference[]; | ||
referencesToExclude?: SavedObjectsFindOptionsReference[]; | ||
} | ||
) => { | ||
const { hits, pagination } = await contentClient.mSearch<UserContentCommonSchema>({ | ||
query: { | ||
text: searchQuery, | ||
limit: LISTING_LIMIT, | ||
cursor: '1', | ||
tags: { | ||
included: refs?.references?.map((ref) => ref.id), | ||
excluded: refs?.referencesToExclude?.map((ref) => ref.id), | ||
}, | ||
}, | ||
contentTypes: [{ contentTypeId: 'map' }], // TODO: improve types to not require objects here? | ||
}); | ||
|
||
// TODO: needs to have logic of extracting common schema from an unknown mSearch hit: hits.map(hit => cm.convertToCommonSchema(hit)) | ||
// for now we just assume that mSearch hit satisfies UserContentCommonSchema | ||
|
||
return { hits, total: pagination.total }; | ||
}; | ||
|
||
return ( | ||
<TableListView | ||
id="cm-msearch-table" | ||
headingId="cm-msearch-table-heading" | ||
findItems={findItems} | ||
listingLimit={LISTING_LIMIT} | ||
initialPageSize={50} | ||
entityName={`ContentItem`} | ||
entityNamePlural={`ContentItems`} | ||
tableListTitle={`MSearch Demo`} | ||
urlStateEnabled={false} | ||
emptyPrompt={<>No data found. Try to install some sample data first.</>} | ||
onClickTitle={(item) => { | ||
alert(`Clicked item ${item.attributes.title} (${item.id})`); | ||
}} | ||
/> | ||
); | ||
}; |
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
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
Oops, something went wrong.