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.
[Serverless Search] Index documents can be browsed in index management (
elastic#172635) This PR adds functionality to browse index documents in a index management app. ## Screen Recording https://github.com/elastic/kibana/assets/55930906/d7e565b4-f893-4c56-8e51-3a535cea09ff ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- Loading branch information
1 parent
594731d
commit 543a047
Showing
14 changed files
with
300 additions
and
35 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
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/serverless_search/public/application/components/index_documents/documents.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,76 @@ | ||
/* | ||
* 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 React, { useEffect, useState } from 'react'; | ||
|
||
import { | ||
DocumentList, | ||
DocumentsOverview, | ||
INDEX_DOCUMENTS_META_DEFAULT, | ||
} from '@kbn/search-index-documents'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { useIndexDocumentSearch } from '../../hooks/api/use_index_documents'; | ||
import { useIndexMappings } from '../../hooks/api/use_index_mappings'; | ||
|
||
const DEFAULT_PAGINATION = { | ||
pageIndex: INDEX_DOCUMENTS_META_DEFAULT.pageIndex, | ||
pageSize: INDEX_DOCUMENTS_META_DEFAULT.pageSize, | ||
totalItemCount: INDEX_DOCUMENTS_META_DEFAULT.totalItemCount, | ||
}; | ||
|
||
interface IndexDocumentsProps { | ||
indexName: string; | ||
} | ||
|
||
export const IndexDocuments: React.FC<IndexDocumentsProps> = ({ indexName }) => { | ||
const [pagination, setPagination] = useState(DEFAULT_PAGINATION); | ||
const [searchQuery, setSearchQuery] = useState(''); | ||
const searchQueryCallback = (query: string) => { | ||
setSearchQuery(query); | ||
}; | ||
const { results: indexDocuments, meta: documentsMeta } = useIndexDocumentSearch( | ||
indexName, | ||
pagination, | ||
searchQuery | ||
); | ||
|
||
const { data: mappingData } = useIndexMappings(indexName); | ||
|
||
const docs = indexDocuments?.data ?? []; | ||
|
||
useEffect(() => { | ||
setSearchQuery(''); | ||
setPagination(DEFAULT_PAGINATION); | ||
}, [indexName]); | ||
return ( | ||
<DocumentsOverview | ||
dataTelemetryIdPrefix="serverless-view-index-documents" | ||
searchQueryCallback={searchQueryCallback} | ||
documentComponent={ | ||
<> | ||
{docs.length === 0 && | ||
i18n.translate('xpack.serverlessSearch.indexManagementTab.documents.noMappings', { | ||
defaultMessage: 'No documents found for index', | ||
})} | ||
{docs?.length > 0 && ( | ||
<DocumentList | ||
dataTelemetryIdPrefix="serverless-view-index-documents" | ||
docs={docs} | ||
docsPerPage={pagination.pageSize ?? 10} | ||
isLoading={false} | ||
mappings={mappingData?.mappings?.properties ?? {}} | ||
meta={documentsMeta ?? DEFAULT_PAGINATION} | ||
onPaginate={(pageIndex) => setPagination({ ...pagination, pageIndex })} | ||
setDocsPerPage={(pageSize) => setPagination({ ...pagination, pageSize })} | ||
/> | ||
)} | ||
</> | ||
} | ||
/> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
...plugins/serverless_search/public/application/components/index_documents/documents_tab.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,43 @@ | ||
/* | ||
* 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 { IndexDetailsTab } from '@kbn/index-management-plugin/common/constants'; | ||
import React from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { CoreStart } from '@kbn/core-lifecycle-browser'; | ||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; | ||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public'; | ||
import { ServerlessSearchPluginStartDependencies } from '../../../types'; | ||
import { IndexDocuments } from './documents'; | ||
|
||
export const createIndexOverviewContent = ( | ||
core: CoreStart, | ||
services: ServerlessSearchPluginStartDependencies | ||
): IndexDetailsTab => { | ||
return { | ||
id: 'documents', | ||
name: ( | ||
<FormattedMessage | ||
defaultMessage="Documents" | ||
id="xpack.serverlessSearch.indexManagementTab.documents" | ||
/> | ||
), | ||
order: 11, | ||
renderTabContent: ({ index }) => { | ||
const queryClient = new QueryClient(); | ||
return ( | ||
<KibanaContextProvider services={{ ...core, ...services }}> | ||
<QueryClientProvider client={queryClient}> | ||
<ReactQueryDevtools initialIsOpen={false} /> | ||
<IndexDocuments indexName={index.name} /> | ||
</QueryClientProvider> | ||
</KibanaContextProvider> | ||
); | ||
}, | ||
}; | ||
}; |
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/serverless_search/public/application/hooks/api/use_index_documents.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,47 @@ | ||
/* | ||
* 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 { Pagination } from '@elastic/eui'; | ||
import { SearchHit } from '@kbn/es-types'; | ||
import { pageToPagination, Paginate } from '@kbn/search-index-documents'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useKibanaServices } from '../use_kibana'; | ||
|
||
interface IndexDocuments { | ||
meta: Pagination; | ||
results: Paginate<SearchHit>; | ||
} | ||
const DEFAULT_PAGINATION = { | ||
from: 0, | ||
has_more_hits_than_total: false, | ||
size: 10, | ||
total: 0, | ||
}; | ||
export const useIndexDocumentSearch = ( | ||
indexName: string, | ||
pagination: Omit<Pagination, 'totalItemCount'>, | ||
searchQuery?: string | ||
) => { | ||
const { http } = useKibanaServices(); | ||
const response = useQuery({ | ||
queryKey: ['fetchIndexDocuments', pagination, searchQuery], | ||
queryFn: async () => | ||
http.post<IndexDocuments>(`/internal/serverless_search/indices/${indexName}/search`, { | ||
body: JSON.stringify({ | ||
searchQuery, | ||
}), | ||
query: { | ||
page: pagination.pageIndex, | ||
size: pagination.pageSize, | ||
}, | ||
}), | ||
}); | ||
return { | ||
results: response?.data?.results, | ||
meta: pageToPagination(response?.data?.results?._meta?.page ?? DEFAULT_PAGINATION), | ||
}; | ||
}; |
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/serverless_search/public/application/hooks/api/use_index_mappings.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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IndicesGetMappingIndexMappingRecord } from '@elastic/elasticsearch/lib/api/types'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useKibanaServices } from '../use_kibana'; | ||
|
||
export const useIndexMappings = (indexName: string) => { | ||
const { http } = useKibanaServices(); | ||
return useQuery({ | ||
queryKey: ['fetchIndexMappings'], | ||
queryFn: async () => | ||
http.fetch<IndicesGetMappingIndexMappingRecord>( | ||
`/internal/serverless_search/mappings/${indexName}` | ||
), | ||
}); | ||
}; |
Oops, something went wrong.