Skip to content

Commit

Permalink
[BUG] Edit detector rules table paging goes to page the first page if… (
Browse files Browse the repository at this point in the history
#270)

* [BUG] Edit detector rules table paging goes to page the first page if rules on other pages are toggled #269

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [BUG] Edit detector rules table paging goes to page the first page if rules on other pages are toggled #269

Signed-off-by: Jovan Cvetkovic <[email protected]>

Signed-off-by: Jovan Cvetkovic <[email protected]>
(cherry picked from commit b6e3058)
  • Loading branch information
jovancvetkovic3006 authored and github-actions[bot] committed Dec 29, 2022
1 parent 51856ee commit a834cc6
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { CriteriaWithPagination, EuiInMemoryTable } from '@elastic/eui';
import React from 'react';
import React, { useState } from 'react';
import { RuleItem } from './types/interfaces';
import { getRulesColumns } from './utils/constants';
import { Search } from '@opensearch-project/oui/src/eui_components/basic_table';
Expand Down Expand Up @@ -70,12 +70,17 @@ export const DetectionRulesTable: React.FC<DetectionRulesTableProps> = ({
},
],
};

const [pagination, setPagination] = useState({ pageIndex: pageIndex || 0 });
const allRulesEnabled = ruleItems.every((item) => item.active);
ruleItems.sort((a, b) => {
return (rulePriorityBySeverity[a.severity] || 6) - (rulePriorityBySeverity[b.severity] || 6);
});

const onTableChangeHandler = (pagination: CriteriaWithPagination<T>) => {
setPagination({ pageIndex: pagination.page.index });
onTableChange && onTableChange(pagination);
};

return (
<div style={{ padding: 10 }}>
<EuiInMemoryTable
Expand All @@ -88,14 +93,8 @@ export const DetectionRulesTable: React.FC<DetectionRulesTableProps> = ({
items={ruleItems}
itemId={(item: RuleItem) => `${item.name}`}
search={search}
pagination={
pageIndex !== undefined
? {
pageIndex,
}
: true
}
onTableChange={onTableChange}
pagination={pagination}
onTableChange={onTableChangeHandler}
loading={loading}
data-test-subj={'edit-detector-rules-table'}
/>
Expand Down

0 comments on commit a834cc6

Please sign in to comment.