-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Stack Monitoring] fix useTable sorting and pagination #113563
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
| */ | ||
|
|
||
| import { useState, useCallback } from 'react'; | ||
| import { EUI_SORT_ASCENDING } from '../../../common/constants'; | ||
| import { euiTableStorageGetter, euiTableStorageSetter } from '../../components/table'; | ||
| import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; | ||
|
|
||
|
|
@@ -83,22 +82,18 @@ export function useTable(storageKey: string) { | |
|
|
||
| // get initial state from localStorage | ||
| const [sorting, setSorting] = useState<Sorting>(storageData.sort || { sort: {} }); | ||
| const cleanSortingData = (sortData: Sorting) => { | ||
| const sort = sortData || { sort: {} }; | ||
|
|
||
| if (!sort.sort.field) { | ||
| sort.sort.field = 'name'; | ||
| } | ||
| if (!sort.sort.direction) { | ||
| sort.sort.direction = EUI_SORT_ASCENDING; | ||
| } | ||
|
|
||
| return sort; | ||
| }; | ||
|
|
||
| const [query, setQuery] = useState(''); | ||
|
|
||
| const onTableChange = ({ page, sort }: { page: Page; sort: Sorting['sort'] }) => { | ||
| const onTableChange = ({ | ||
| page, | ||
| sort, | ||
| queryText, | ||
| }: { | ||
| page: Page; | ||
| sort: Sorting['sort']; | ||
| queryText: string; | ||
| }) => { | ||
| setPagination({ | ||
| ...pagination, | ||
| ...{ | ||
|
|
@@ -109,11 +104,14 @@ export function useTable(storageKey: string) { | |
| pageSizeOptions: PAGE_SIZE_OPTIONS, | ||
| }, | ||
| }); | ||
| setSorting(cleanSortingData({ sort })); | ||
| setSorting({ sort }); | ||
| setLocalStorageData(storage, { | ||
| page, | ||
| sort: { sort }, | ||
| sort: { | ||
| sort, | ||
| }, | ||
| }); | ||
| setQuery(queryText); | ||
| }; | ||
|
|
||
| const getPaginationRouteOptions = useCallback(() => { | ||
|
|
@@ -136,33 +134,6 @@ export function useTable(storageKey: string) { | |
| sorting, | ||
| pagination, | ||
| onTableChange, | ||
| fetchMoreData: ({ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This used to have the async |
||
| page, | ||
| sort, | ||
| queryText, | ||
| }: { | ||
| page: Page; | ||
| sort: Sorting; | ||
| queryText: string; | ||
| }) => { | ||
| setPagination({ | ||
| ...pagination, | ||
| ...{ | ||
| initialPageSize: page.size, | ||
| pageSize: page.size, | ||
| initialPageIndex: page.index, | ||
| pageIndex: page.index, | ||
| pageSizeOptions: PAGE_SIZE_OPTIONS, | ||
| }, | ||
| }); | ||
| setSorting(cleanSortingData(sort)); | ||
| setQuery(queryText); | ||
|
|
||
| setLocalStorageData(storage, { | ||
| page, | ||
| sort, | ||
| }); | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,8 +298,7 @@ const getColumns = (showCgroupMetricsElasticsearch, setupMode, clusterUuid, aler | |
| }; | ||
|
|
||
| export function ElasticsearchNodes({ clusterStatus, showCgroupMetricsElasticsearch, ...props }) { | ||
| const { sorting, pagination, onTableChange, clusterUuid, setupMode, fetchMoreData, alerts } = | ||
| props; | ||
| const { sorting, pagination, onTableChange, clusterUuid, setupMode, alerts } = props; | ||
|
|
||
| const columns = getColumns(showCgroupMetricsElasticsearch, setupMode, clusterUuid, alerts); | ||
|
|
||
|
|
@@ -474,7 +473,7 @@ export function ElasticsearchNodes({ clusterStatus, showCgroupMetricsElasticsear | |
| }, | ||
| }} | ||
| onTableChange={onTableChange} | ||
| fetchMoreData={fetchMoreData} | ||
| {...props} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't look for fetchMoreData explicitly because its removed in the react version now |
||
| /> | ||
| </EuiPageContent> | ||
| </EuiPageBody> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,7 +129,7 @@ export class PipelineListing extends Component { | |
| } | ||
|
|
||
| render() { | ||
| const { data, sorting, pagination, onTableChange, fetchMoreData, upgradeMessage, className } = | ||
| const { data, sorting, pagination, onTableChange, upgradeMessage, className, ...props } = | ||
| this.props; | ||
|
|
||
| const sortingOptions = sorting || { field: 'id', direction: 'asc' }; | ||
|
|
@@ -159,7 +159,6 @@ export class PipelineListing extends Component { | |
| sorting={sortingOptions} | ||
| message={upgradeMessage} | ||
| pagination={pagination} | ||
| fetchMoreData={fetchMoreData} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't look for fetchMoreData explicitly because its removed in the react version now |
||
| search={{ | ||
| box: { | ||
| placeholder: i18n.translate( | ||
|
|
@@ -171,6 +170,7 @@ export class PipelineListing extends Component { | |
| }, | ||
| }} | ||
| onTableChange={onTableChange} | ||
| {...props} | ||
| /> | ||
| </EuiPageContent> | ||
| </EuiPageBody> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,8 @@ export function EuiMonitoringSSPTable({ | |
| onTableChange, | ||
| setupMode, | ||
| productName, | ||
| fetchMoreData, | ||
| ...props | ||
| }) { | ||
| const [isLoading, setIsLoading] = React.useState(false); | ||
| const [queryText, setQueryText] = React.useState(''); | ||
| const [page, setPage] = React.useState({ | ||
| index: pagination.pageIndex, | ||
|
|
@@ -72,19 +70,28 @@ export function EuiMonitoringSSPTable({ | |
| const onChange = async ({ page, sort }) => { | ||
| setPage(page); | ||
| setSort({ sort }); | ||
| setIsLoading(true); | ||
| await fetchMoreData({ page, sort: { sort }, queryText }); | ||
| setIsLoading(false); | ||
| onTableChange({ page, sort }); | ||
| // angular version | ||
| if (props.fetchMoreData) { | ||
| await props.fetchMoreData({ page, sort: { sort }, queryText }); | ||
| onTableChange({ page, sort }); | ||
| } | ||
| // react version | ||
| else { | ||
| onTableChange({ page, sort, queryText }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fetchMoreData isn't needed in React version because we get data in the ElasticsearchTemplate |
||
| } | ||
| }; | ||
|
|
||
| const onQueryChange = async ({ queryText }) => { | ||
| const newPage = { ...page, index: 0 }; | ||
| setPage(newPage); | ||
| setQueryText(queryText); | ||
| setIsLoading(true); | ||
| await fetchMoreData({ page: newPage, sort, queryText }); | ||
| setIsLoading(false); | ||
| // angular version | ||
| if (props.fetchMoreData) { | ||
| await props.fetchMoreData({ page: newPage, sort, queryText }); | ||
| } else { | ||
| // react version | ||
| onTableChange({ page, sort: sort.sort, queryText }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
|
|
@@ -97,7 +104,6 @@ export function EuiMonitoringSSPTable({ | |
| items={items} | ||
| pagination={pagination} | ||
| onChange={onChange} | ||
| loading={isLoading} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No loading visual was happening in Angular version so I removed it. Would need to pass this down from parent component at some point. |
||
| columns={columns} | ||
| /> | ||
| {footerContent} | ||
|
|
||
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.
this new function was causing the sorting to store itself incorrectly. it doesn't exist in the angular version and after removal it stopped breaking