-
Notifications
You must be signed in to change notification settings - Fork 916
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
Improve the perceived performance of Discover #6599
Merged
ashwin-pc
merged 1 commit into
opensearch-project:main
from
AMoo-Miki:discover-performance
Apr 24, 2024
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- Improve the perceived performance of Discover when using the default tabular renderer ([#6599](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6599)) |
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
153 changes: 153 additions & 0 deletions
153
src/plugins/discover/public/application/components/data_grid/data_grid.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,153 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import './_data_grid_table.scss'; | ||
|
||
import React, { useMemo, useCallback } from 'react'; | ||
import { EuiDataGrid, EuiDataGridSorting } from '@elastic/eui'; | ||
import { IndexPattern, getServices } from '../../../opensearch_dashboards_services'; | ||
import { fetchTableDataCell } from './data_grid_table_cell_value'; | ||
import { buildDataGridColumns, computeVisibleColumns } from './data_grid_table_columns'; | ||
import { DocViewInspectButton } from './data_grid_table_docview_inspect_button'; | ||
import { OpenSearchSearchHit } from '../../doc_views/doc_views_types'; | ||
import { usePagination } from '../utils/use_pagination'; | ||
import { buildColumns } from '../../utils/columns'; | ||
import { DOC_HIDE_TIME_COLUMN_SETTING, SAMPLE_SIZE_SETTING } from '../../../../common'; | ||
import { UI_SETTINGS } from '../../../../../data/common'; | ||
import { SortOrder } from '../../../saved_searches/types'; | ||
import { useToolbarOptions } from './data_grid_toolbar'; | ||
|
||
export interface DataGridProps { | ||
columns: string[]; | ||
indexPattern: IndexPattern; | ||
onSort: (s: SortOrder[]) => void; | ||
rows: OpenSearchSearchHit[]; | ||
onSetColumns: (columns: string[]) => void; | ||
sort: SortOrder[]; | ||
isToolbarVisible?: boolean; | ||
isContextView?: boolean; | ||
} | ||
|
||
const DataGridUI = ({ | ||
columns, | ||
indexPattern, | ||
onSetColumns, | ||
onSort, | ||
sort, | ||
rows, | ||
isToolbarVisible = true, | ||
isContextView = false, | ||
}: DataGridProps) => { | ||
const services = getServices(); | ||
const rowCount = useMemo(() => (rows ? rows.length : 0), [rows]); | ||
AMoo-Miki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { toolbarOptions, lineCount } = useToolbarOptions(); | ||
const [pageSizeLimit, isShortDots] = useMemo(() => { | ||
return [ | ||
services.uiSettings.get(SAMPLE_SIZE_SETTING), | ||
services.uiSettings.get(UI_SETTINGS.SHORT_DOTS_ENABLE), | ||
]; | ||
}, [services.uiSettings]); | ||
const displayTimeColumn = useMemo( | ||
() => | ||
!services.uiSettings.get(DOC_HIDE_TIME_COLUMN_SETTING, false) && indexPattern?.isTimeBased(), | ||
[indexPattern, services.uiSettings] | ||
); | ||
const pagination = usePagination({ rowCount, pageSizeLimit }); | ||
|
||
let adjustedColumns = buildColumns(columns); | ||
AMoo-Miki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// handle case where the user removes selected filed and leaves only time column | ||
if ( | ||
adjustedColumns.length === 1 && | ||
indexPattern && | ||
adjustedColumns[0] === indexPattern.timeFieldName | ||
) { | ||
adjustedColumns = [...adjustedColumns, '_source']; | ||
} | ||
|
||
const includeSourceInColumns = adjustedColumns.includes('_source'); | ||
const sortingColumns = useMemo(() => sort.map(([id, direction]) => ({ id, direction })), [sort]); | ||
const rowHeightsOptions = useMemo( | ||
() => ({ | ||
defaultHeight: { | ||
lineCount: lineCount || (includeSourceInColumns ? 3 : 1), | ||
}, | ||
}), | ||
[includeSourceInColumns, lineCount] | ||
); | ||
|
||
const onColumnSort = useCallback( | ||
(cols: EuiDataGridSorting['columns']) => { | ||
onSort(cols.map(({ id, direction }) => [id, direction])); | ||
}, | ||
[onSort] | ||
); | ||
|
||
const renderCellValue = useMemo(() => fetchTableDataCell(indexPattern, rows, isShortDots), [ | ||
indexPattern, | ||
isShortDots, | ||
rows, | ||
]); | ||
|
||
const displayedTableColumns = useMemo( | ||
() => | ||
buildDataGridColumns( | ||
adjustedColumns, | ||
indexPattern, | ||
displayTimeColumn, | ||
includeSourceInColumns, | ||
isContextView | ||
), | ||
[adjustedColumns, indexPattern, displayTimeColumn, includeSourceInColumns, isContextView] | ||
); | ||
|
||
const dataGridTableColumnsVisibility = useMemo( | ||
() => ({ | ||
visibleColumns: computeVisibleColumns( | ||
adjustedColumns, | ||
indexPattern, | ||
displayTimeColumn | ||
) as string[], | ||
setVisibleColumns: (cols: string[]) => { | ||
onSetColumns(cols); | ||
}, | ||
}), | ||
[adjustedColumns, indexPattern, displayTimeColumn, onSetColumns] | ||
); | ||
|
||
const sorting: EuiDataGridSorting = useMemo( | ||
() => ({ columns: sortingColumns, onSort: onColumnSort }), | ||
[sortingColumns, onColumnSort] | ||
); | ||
|
||
const leadingControlColumns = useMemo(() => { | ||
return [ | ||
{ | ||
id: 'inspectCollapseColumn', | ||
headerCellRender: () => null, | ||
rowCellRender: DocViewInspectButton, | ||
width: 40, | ||
}, | ||
]; | ||
}, []); | ||
AMoo-Miki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<EuiDataGrid | ||
aria-labelledby="aria-labelledby" | ||
columns={displayedTableColumns} | ||
columnVisibility={dataGridTableColumnsVisibility} | ||
leadingControlColumns={leadingControlColumns} | ||
data-test-subj="docTable" | ||
pagination={pagination} | ||
renderCellValue={renderCellValue} | ||
rowCount={rowCount} | ||
sorting={sorting} | ||
toolbarVisibility={isToolbarVisible ? toolbarOptions : false} | ||
rowHeightsOptions={rowHeightsOptions} | ||
className="discoverDataGrid" | ||
/> | ||
); | ||
}; | ||
|
||
export const DataGrid = React.memo(DataGridUI); |
Oops, something went wrong.
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.
Does the css get imported twice or is it deduplicated? (not sure if the dedupe option is turned on for the loader)
Given this will be removed, feel free to ignore if this ends up having no real impact.
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.
You are right. The other one needs to go. Will add it to s subsequent PR.