-
Notifications
You must be signed in to change notification settings - Fork 83
feat(webui): Display search results in Presto UI. #1179
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
aca6241
latest
5eea062
latest
d23ba77
latest
af59d56
latest
f3dec72
Merge branch 'main' into datat
hoophalab 3a8caa0
Merge branch 'main' into datat
davemarco e969603
latest
d8bc69b
latest
3c639fb
latest
db8e2eb
fix lint
4e055f5
latest
5281937
latest
527cb19
latest
9cdcebb
Merge branch 'main' into datat
davemarco ddaba31
Merge branch 'main' into datat
hoophalab 085ba38
latest
12222c2
Merge branch 'main' into datat
davemarco 2118902
latest
90caa4e
latest
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
54 changes: 54 additions & 0 deletions
54
...es/SearchPage/SearchResults/SearchResultsTable/Presto/PrestoResultsVirtualTable/index.tsx
This file contains hidden or 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,54 @@ | ||
| import { | ||
| useEffect, | ||
| useMemo, | ||
| } from "react"; | ||
|
|
||
| import VirtualTable from "../../../../../../components/VirtualTable"; | ||
| import useSearchStore from "../../../../SearchState/index"; | ||
| import {PrestoSearchResult} from "./typings"; | ||
| import {usePrestoSearchResults} from "./usePrestoSearchResults"; | ||
| import {getPrestoSearchResultsTableColumns} from "./utils"; | ||
|
|
||
|
|
||
| interface PrestoResultsVirtualTableProps { | ||
| tableHeight: number; | ||
| } | ||
|
|
||
| /** | ||
| * Renders Presto search results in a virtual table. | ||
| * | ||
| * @param props | ||
| * @param props.tableHeight | ||
| * @return | ||
| */ | ||
| const PrestoResultsVirtualTable = ({tableHeight}: PrestoResultsVirtualTableProps) => { | ||
| const {updateNumSearchResultsTable} = useSearchStore(); | ||
| const prestoSearchResults = usePrestoSearchResults(); | ||
|
|
||
| const columns = useMemo( | ||
| () => getPrestoSearchResultsTableColumns(prestoSearchResults || []), | ||
| [prestoSearchResults] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| const num = prestoSearchResults ? | ||
| prestoSearchResults.length : | ||
| 0; | ||
|
|
||
| updateNumSearchResultsTable(num); | ||
| }, [ | ||
| prestoSearchResults, | ||
| updateNumSearchResultsTable, | ||
| ]); | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <VirtualTable<PrestoSearchResult> | ||
| columns={columns} | ||
| dataSource={prestoSearchResults || []} | ||
| pagination={false} | ||
| rowKey={(record) => record._id} | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| scroll={{y: tableHeight}}/> | ||
| ); | ||
| }; | ||
|
|
||
| export default PrestoResultsVirtualTable; | ||
13 changes: 13 additions & 0 deletions
13
.../SearchPage/SearchResults/SearchResultsTable/Presto/PrestoResultsVirtualTable/typings.tsx
This file contains hidden or 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,13 @@ | ||
| import {PRESTO_DATA_PROPERTY} from "../../../../../../../../common"; | ||
|
|
||
|
|
||
| /** | ||
| * Structure of dynamic Presto search results data. | ||
| */ | ||
| interface PrestoSearchResult { | ||
| _id: string; | ||
| [PRESTO_DATA_PROPERTY]: Record<string, unknown>; | ||
| } | ||
hoophalab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export type {PrestoSearchResult}; | ||
| export {getPrestoSearchResultsTableColumns} from "./utils"; | ||
|
||
48 changes: 48 additions & 0 deletions
48
...archResults/SearchResultsTable/Presto/PrestoResultsVirtualTable/usePrestoSearchResults.ts
This file contains hidden or 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,48 @@ | ||
| import MongoSocketCollection from "../../../../../../api/socket/MongoSocketCollection"; | ||
| import {useCursor} from "../../../../../../api/socket/useCursor"; | ||
| import useSearchStore, {SEARCH_STATE_DEFAULT} from "../../../../SearchState/index"; | ||
| import {SEARCH_MAX_NUM_RESULTS} from "../../typings"; | ||
| import {PrestoSearchResult} from "./typings"; | ||
hoophalab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| /** | ||
| * Custom hook to get Presto search results for the current searchJobId. | ||
| * | ||
| * @return | ||
| */ | ||
| const usePrestoSearchResults = () => { | ||
| const searchJobId = useSearchStore((state) => state.searchJobId); | ||
|
|
||
| const searchResultsCursor = useCursor<PrestoSearchResult>( | ||
| () => { | ||
| // If there is no active search job, there are no results to fetch. The cursor will | ||
| // return null. | ||
| if (searchJobId === SEARCH_STATE_DEFAULT.searchJobId) { | ||
| return null; | ||
| } | ||
|
|
||
| console.log( | ||
| `Subscribing to updates to Presto search results with job ID: ${searchJobId}` | ||
| ); | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Retrieve 1k most recent results. | ||
| const options = { | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sort: [ | ||
| [ | ||
| "_id", | ||
| "desc", | ||
| ], | ||
| ], | ||
| limit: SEARCH_MAX_NUM_RESULTS, | ||
| }; | ||
|
|
||
| const collection = new MongoSocketCollection(searchJobId); | ||
| return collection.find({}, options); | ||
| }, | ||
| [searchJobId] | ||
| ); | ||
|
|
||
| return searchResultsCursor; | ||
| }; | ||
|
|
||
| export {usePrestoSearchResults}; | ||
29 changes: 29 additions & 0 deletions
29
...ges/SearchPage/SearchResults/SearchResultsTable/Presto/PrestoResultsVirtualTable/utils.ts
This file contains hidden or 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,29 @@ | ||
| import {TableProps} from "antd"; | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import {PRESTO_DATA_PROPERTY} from "../../../../../../../../common"; | ||
| import {PrestoSearchResult} from "./typings"; | ||
hoophalab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| /** | ||
| * Generates dynamic columns configuration for Presto query engine. | ||
| * | ||
| * @param data Array of Presto search results | ||
| * @return | ||
| */ | ||
davemarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const getPrestoSearchResultsTableColumns = ( | ||
| data: PrestoSearchResult[] | ||
| ): NonNullable<TableProps<PrestoSearchResult>["columns"]> => { | ||
| if (0 === data.length || "undefined" === typeof data[0] || "undefined" === typeof data[0].row) { | ||
hoophalab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return []; | ||
| } | ||
|
|
||
| return Object.keys(data[0].row) | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .map((key) => ({ | ||
| dataIndex: [PRESTO_DATA_PROPERTY, | ||
| key], | ||
| key: key, | ||
| title: key, | ||
| })); | ||
hoophalab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export {getPrestoSearchResultsTableColumns}; | ||
48 changes: 48 additions & 0 deletions
48
...src/pages/SearchPage/SearchResults/SearchResultsTable/SearchResultsVirtualTable/index.tsx
This file contains hidden or 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,48 @@ | ||
| import {useEffect} from "react"; | ||
|
|
||
| import VirtualTable from "../../../../../components/VirtualTable"; | ||
| import useSearchStore from "../../../SearchState/index"; | ||
| import { | ||
| SearchResult, | ||
| searchResultsTableColumns, | ||
| } from "./typings"; | ||
| import {useSearchResults} from "./useSearchResults"; | ||
|
|
||
|
|
||
| interface SearchResultsVirtualTableProps { | ||
| tableHeight: number; | ||
| } | ||
|
|
||
| /** | ||
| * Renders search results in a virtual table. | ||
| * | ||
| * @param props | ||
| * @param props.tableHeight | ||
| * @return | ||
| */ | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const SearchResultsVirtualTable = ({tableHeight}: SearchResultsVirtualTableProps) => { | ||
| const {updateNumSearchResultsTable} = useSearchStore(); | ||
| const searchResults = useSearchResults(); | ||
|
|
||
| useEffect(() => { | ||
| const num = searchResults ? | ||
| searchResults.length : | ||
| 0; | ||
|
|
||
| updateNumSearchResultsTable(num); | ||
| }, [ | ||
| searchResults, | ||
| updateNumSearchResultsTable, | ||
| ]); | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <VirtualTable<SearchResult> | ||
| columns={searchResultsTableColumns} | ||
| dataSource={searchResults || []} | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pagination={false} | ||
| rowKey={(record) => record._id.toString()} | ||
| scroll={{y: tableHeight}}/> | ||
| ); | ||
| }; | ||
|
|
||
| export default SearchResultsVirtualTable; | ||
This file contains hidden or 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
12 changes: 5 additions & 7 deletions
12
...ts/SearchResultsTable/useSearchResults.ts → ...chResultsVirtualTable/useSearchResults.ts
This file contains hidden or 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 hidden or 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
14 changes: 14 additions & 0 deletions
14
components/webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.ts
This file contains hidden or 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,14 @@ | ||
| /** | ||
| * Padding for the table to the bottom of the page. | ||
| */ | ||
| const TABLE_BOTTOM_PADDING = 75; | ||
|
|
||
| /** | ||
| * The maximum number of results to retrieve for a search. | ||
| */ | ||
| const SEARCH_MAX_NUM_RESULTS = 1000; | ||
|
|
||
| export { | ||
| SEARCH_MAX_NUM_RESULTS, | ||
| TABLE_BOTTOM_PADDING, | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.