Skip to content

Commit

Permalink
extracted default page size to a constant for alerting UI as a whole
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Feb 13, 2020
1 parent ddeb7a3 commit 7930a7c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export enum SORT_ORDERS {
ASCENDING = 'asc',
DESCENDING = 'desc',
}

export const DEFAULT_SEARCH_PAGE_SIZE: number = 10;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ComponentOpts as AlertApis,
withBulkAlertOperations,
} from '../../common/components/with_bulk_alert_api_operations';
import { DEFAULT_SEARCH_PAGE_SIZE } from '../../../constants';

type AlertInstancesProps = {
alert: Alert;
Expand Down Expand Up @@ -135,7 +136,10 @@ export function AlertInstances({
unmuteAlertInstance,
requestRefresh,
}: AlertInstancesProps) {
const [pagination, setPagination] = useState<Pagination>({ index: 0, size: 10 });
const [pagination, setPagination] = useState<Pagination>({
index: 0,
size: DEFAULT_SEARCH_PAGE_SIZE,
});

const mergedAlertInstances = [
...Object.entries(alertInstances).map(([instanceId, instance]) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ActionTypeFilter } from './action_type_filter';
import { loadAlerts, loadAlertTypes } from '../../../lib/alert_api';
import { loadActionTypes } from '../../../lib/action_connector_api';
import { hasDeleteAlertsCapability, hasSaveAlertsCapability } from '../../../lib/capabilities';
import { routeToAlertDetails } from '../../../constants';
import { routeToAlertDetails, DEFAULT_SEARCH_PAGE_SIZE } from '../../../constants';

const ENTER_KEY = 13;

Expand Down Expand Up @@ -67,7 +67,7 @@ export const AlertsList: React.FunctionComponent = () => {
const [actionTypes, setActionTypes] = useState<ActionType[]>([]);
const [selectedIds, setSelectedIds] = useState<string[]>([]);
const [isPerformingAction, setIsPerformingAction] = useState<boolean>(false);
const [page, setPage] = useState<Pagination>({ index: 0, size: 10 });
const [page, setPage] = useState<Pagination>({ index: 0, size: DEFAULT_SEARCH_PAGE_SIZE });
const [searchText, setSearchText] = useState<string | undefined>();
const [inputText, setInputText] = useState<string | undefined>();
const [typesFilter, setTypesFilter] = useState<string[]>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
});

const PAGE_SIZE = 10;
it('renders the first page', async () => {
// Verify content
await testSubjects.existOrFail('alertInstancesList');

const { alertInstances } = await alerting.alerts.getAlertState(alert.id);

const [firstItem] = await pageObjects.alertDetailsUI.getAlertInstancesList();
const items = await pageObjects.alertDetailsUI.getAlertInstancesList();
expect(items.length).to.eql(PAGE_SIZE);

const [firstItem] = items;
expect(firstItem.instance).to.eql(Object.keys(alertInstances)[0]);
});

Expand All @@ -412,8 +416,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

await pageObjects.alertDetailsUI.clickPaginationNextPage();

const PAGE_SIZE = 10;

await retry.try(async () => {
const [firstItem] = await pageObjects.alertDetailsUI.getAlertInstancesList();
expect(firstItem.instance).to.eql(Object.keys(alertInstances)[PAGE_SIZE]);
Expand Down

0 comments on commit 7930a7c

Please sign in to comment.