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.
[Search] [Onboarding] With Data View (elastic#193121)
## Summary Adds the document view tab when the index has documents ![image](https://github.com/user-attachments/assets/37efbd78-9fae-465b-a3ab-2803a8858285) ### Checklist Delete any items that are not applicable to this PR. - [ ] 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) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit 2d78f23)
- Loading branch information
1 parent
647ac36
commit ccd9ada
Showing
10 changed files
with
274 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
*/ | ||
|
||
export { Result } from './result'; | ||
export { resultMetaData, resultToField } from './result_metadata'; |
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
23 changes: 23 additions & 0 deletions
23
...k/plugins/search_indices/public/components/index_documents/add_documents_code_example.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,23 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
import { EuiPanel } from '@elastic/eui'; | ||
|
||
export const AddDocumentsCodeExample: React.FC = () => { | ||
return ( | ||
<EuiPanel | ||
hasBorder={false} | ||
hasShadow={false} | ||
paddingSize="none" | ||
data-test-subj="SearchIndicesAddDocumentsCode" | ||
> | ||
TODO: WITHOUT DATA TICKET | ||
</EuiPanel> | ||
); | ||
}; |
114 changes: 114 additions & 0 deletions
114
x-pack/plugins/search_indices/public/components/index_documents/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,114 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
import { Result, resultToField, resultMetaData } from '@kbn/search-index-documents'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiIcon, | ||
EuiLink, | ||
EuiPanel, | ||
EuiProgress, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import { useIndexDocumentSearch } from '../../hooks/api/use_document_search'; | ||
import { useIndexMapping } from '../../hooks/api/use_index_mappings'; | ||
import { useKibana } from '../../hooks/use_kibana'; | ||
import { AddDocumentsCodeExample } from './add_documents_code_example'; | ||
|
||
interface IndexDocumentsProps { | ||
indexName: string; | ||
} | ||
|
||
interface RecentDocsActionMessageProps { | ||
indexName: string; | ||
} | ||
|
||
const DEFAULT_PAGE_SIZE = 50; | ||
|
||
const RecentDocsActionMessage: React.FC<RecentDocsActionMessageProps> = ({ indexName }) => { | ||
const { | ||
services: { share }, | ||
} = useKibana(); | ||
|
||
const discoverLocator = share.url.locators.get('DISCOVER_APP_LOCATOR'); | ||
|
||
const onClick = async () => { | ||
await discoverLocator?.navigate({ dataViewSpec: { title: indexName } }); | ||
}; | ||
|
||
return ( | ||
<EuiPanel hasBorder={false} hasShadow={false} color="subdued" borderRadius="none"> | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={false}> | ||
<EuiIcon type="calendar" /> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<p> | ||
{i18n.translate('xpack.searchIndices.indexDocuments.recentDocsActionMessage', { | ||
defaultMessage: | ||
'You are viewing the {pageSize} most recently ingested documents in this index. To see all documents, view in', | ||
values: { | ||
pageSize: DEFAULT_PAGE_SIZE, | ||
}, | ||
})}{' '} | ||
<EuiLink onClick={onClick}> | ||
{i18n.translate('xpack.searchIndices.indexDocuments.recentDocsActionMessageLink', { | ||
defaultMessage: 'Discover.', | ||
})} | ||
</EuiLink> | ||
</p> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
}; | ||
|
||
export const IndexDocuments: React.FC<IndexDocumentsProps> = ({ indexName }) => { | ||
const { data: indexDocuments, isInitialLoading } = useIndexDocumentSearch(indexName, { | ||
pageSize: DEFAULT_PAGE_SIZE, | ||
pageIndex: 0, | ||
}); | ||
|
||
const { data: mappingData } = useIndexMapping(indexName); | ||
|
||
const docs = indexDocuments?.results?.data ?? []; | ||
const mappingProperties = mappingData?.mappings?.properties ?? {}; | ||
|
||
return ( | ||
<EuiPanel hasBorder={false} hasShadow={false} paddingSize="none"> | ||
<EuiSpacer /> | ||
<EuiFlexGroup direction="column"> | ||
<EuiFlexItem> | ||
{isInitialLoading && <EuiProgress size="xs" color="primary" />} | ||
{docs.length === 0 && <AddDocumentsCodeExample />} | ||
{docs.length > 0 && ( | ||
<> | ||
<RecentDocsActionMessage indexName={indexName} /> | ||
<EuiSpacer size="m" /> | ||
{docs.map((doc) => { | ||
return ( | ||
<React.Fragment key={doc._id}> | ||
<Result | ||
fields={resultToField(doc, mappingProperties)} | ||
metaData={resultMetaData(doc)} | ||
/> | ||
<EuiSpacer size="s" /> | ||
</React.Fragment> | ||
); | ||
})} | ||
</> | ||
)} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
}; |
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
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/search_indices/public/hooks/api/use_document_search.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,53 @@ | ||
/* | ||
* 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 { useKibana } 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, | ||
}; | ||
const pollingInterval = 5 * 1000; | ||
export const useIndexDocumentSearch = ( | ||
indexName: string, | ||
pagination: Omit<Pagination, 'totalItemCount'>, | ||
searchQuery?: string | ||
) => { | ||
const { | ||
services: { http }, | ||
} = useKibana(); | ||
const response = useQuery({ | ||
queryKey: ['fetchIndexDocuments', pagination, searchQuery], | ||
refetchInterval: pollingInterval, | ||
refetchIntervalInBackground: true, | ||
refetchOnWindowFocus: 'always', | ||
queryFn: async () => | ||
http.post<IndexDocuments>(`/internal/serverless_search/indices/${indexName}/search`, { | ||
body: JSON.stringify({ | ||
searchQuery, | ||
}), | ||
query: { | ||
page: pagination.pageIndex, | ||
size: pagination.pageSize, | ||
}, | ||
}), | ||
}); | ||
return { | ||
...response, | ||
meta: pageToPagination(response?.data?.results?._meta?.page ?? DEFAULT_PAGINATION), | ||
}; | ||
}; |
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.