-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Search] [Onboarding] With Data View #193121
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d32d191
WIP
joemcelroy 8e86f71
WIP
joemcelroy 00c213d
WIP
joemcelroy b477f40
Merge remote-tracking branch 'upstream/main' into connection-details
joemcelroy efe73d0
Merge remote-tracking branch 'upstream/main' into connection-details
joemcelroy f7ffbc1
WIP
joemcelroy 47996ce
WIP
joemcelroy 4e65546
WIP
joemcelroy 42172c4
merge main
joemcelroy b2c1120
add tests + cleanup refactor
joemcelroy f6d7609
update to initial loading
joemcelroy d31de6b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 0b042cc
fix types / eslint issues
joemcelroy c8cb4ad
Merge branch 'connection-details' of github.com:joemcelroy/kibana int…
joemcelroy e3f37e8
fix types
joemcelroy 4f59c8e
Merge remote-tracking branch 'upstream/main' into with-data-view
joemcelroy ad40771
merge
joemcelroy 20b7106
add data view + tests
joemcelroy 629ef95
Merge remote-tracking branch 'upstream/main' into connection-details
joemcelroy c2b02bb
revert enterprise-search changes
joemcelroy 3b03da7
revert
joemcelroy 92c5730
Merge branch 'connection-details' into with-data-view
joemcelroy f8830b4
update WIP example
joemcelroy 86d5b88
Merge remote-tracking branch 'upstream/main' into with-data-view
joemcelroy 39eb7e3
update localisation string
joemcelroy cfac4ee
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll adjust this in my PR for no data