Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 14 additions & 43 deletions x-pack/plugins/monitoring/public/application/hooks/use_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) => {
Copy link
Copy Markdown
Contributor Author

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

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,
...{
Expand All @@ -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(() => {
Expand All @@ -136,33 +134,6 @@ export function useTable(storageKey: string) {
sorting,
pagination,
onTableChange,
fetchMoreData: ({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to have the async updateData function in here (https://github.com/elastic/kibana/blob/master/x-pack/plugins/monitoring/public/views/base_eui_table_controller.js#L131). Now it does not and this already happens onTableChange

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,
});
},
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -474,7 +473,7 @@ export function ElasticsearchNodes({ clusterStatus, showCgroupMetricsElasticsear
},
}}
onTableChange={onTableChange}
fetchMoreData={fetchMoreData}
{...props}
Copy link
Copy Markdown
Contributor Author

@neptunian neptunian Sep 30, 2021

Choose a reason for hiding this comment

The 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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
Expand Down Expand Up @@ -159,7 +159,6 @@ export class PipelineListing extends Component {
sorting={sortingOptions}
message={upgradeMessage}
pagination={pagination}
fetchMoreData={fetchMoreData}
Copy link
Copy Markdown
Contributor Author

@neptunian neptunian Sep 30, 2021

Choose a reason for hiding this comment

The 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(
Expand All @@ -171,6 +170,7 @@ export class PipelineListing extends Component {
},
}}
onTableChange={onTableChange}
{...props}
/>
</EuiPageContent>
</EuiPageBody>
Expand Down
26 changes: 16 additions & 10 deletions x-pack/plugins/monitoring/public/components/table/eui_table_ssp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 });
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 (
Expand All @@ -97,7 +104,6 @@ export function EuiMonitoringSSPTable({
items={items}
pagination={pagination}
onChange={onChange}
loading={isLoading}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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}
Expand Down