Skip to content

Commit

Permalink
fix page size issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed May 19, 2020
1 parent 71420ff commit 72ec35e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EuiPanel,
EuiSpacer,
} from '@elastic/eui';
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import styled from 'styled-components';
import { HistogramPoint } from '../../../../common/runtime_types';
import { MonitorSummary } from '../../../../common/runtime_types';
Expand Down Expand Up @@ -43,27 +43,13 @@ const TruncatedEuiLink = styled(EuiLink)`
text-overflow: ellipsis;
`;

const DEFAULT_PAGE_SIZE = 10;
const LOCAL_STORAGE_KEY = 'xpack.uptime.monitorList.pageSize';
const getPageSizeValue = () => {
const value = parseInt(localStorage.getItem(LOCAL_STORAGE_KEY) ?? '', 10);
if (isNaN(value)) {
return DEFAULT_PAGE_SIZE;
}
return value;
};

export const MonitorListComponent: React.FC<Props> = ({
filters,
monitorList: { list, error, loading },
linkParameters,
pageSize,
setPageSize,
}) => {
useEffect(() => {
setPageSize(getPageSizeValue());
}, [setPageSize]);

const [drawerIds, updateDrawerIds] = useState<string[]>([]);

const items = list.summaries ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ export interface MonitorListProps {
linkParameters?: string;
}

const DEFAULT_PAGE_SIZE = 10;
const LOCAL_STORAGE_KEY = 'xpack.uptime.monitorList.pageSize';
const getPageSizeValue = () => {
const value = parseInt(localStorage.getItem(LOCAL_STORAGE_KEY) ?? '', 10);
if (isNaN(value)) {
return DEFAULT_PAGE_SIZE;
}
return value;
};

export const MonitorList: React.FC<MonitorListProps> = props => {
const { filters } = props;

const [pageSize, setPageSize] = useState<number>(10);
const [pageSize, setPageSize] = useState<number>(getPageSizeValue);

const dispatch = useDispatch();

Expand Down

0 comments on commit 72ec35e

Please sign in to comment.