Skip to content

Commit b6e3058

Browse files
[BUG] Edit detector rules table paging goes to page the first page if… (#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]>
1 parent 8c5246c commit b6e3058

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { CriteriaWithPagination, EuiInMemoryTable } from '@elastic/eui';
7-
import React from 'react';
7+
import React, { useState } from 'react';
88
import { RuleItem } from './types/interfaces';
99
import { getRulesColumns } from './utils/constants';
1010
import { Search } from '@opensearch-project/oui/src/eui_components/basic_table';
@@ -70,12 +70,17 @@ export const DetectionRulesTable: React.FC<DetectionRulesTableProps> = ({
7070
},
7171
],
7272
};
73-
73+
const [pagination, setPagination] = useState({ pageIndex: pageIndex || 0 });
7474
const allRulesEnabled = ruleItems.every((item) => item.active);
7575
ruleItems.sort((a, b) => {
7676
return (rulePriorityBySeverity[a.severity] || 6) - (rulePriorityBySeverity[b.severity] || 6);
7777
});
7878

79+
const onTableChangeHandler = (pagination: CriteriaWithPagination<T>) => {
80+
setPagination({ pageIndex: pagination.page.index });
81+
onTableChange && onTableChange(pagination);
82+
};
83+
7984
return (
8085
<div style={{ padding: 10 }}>
8186
<EuiInMemoryTable
@@ -88,14 +93,8 @@ export const DetectionRulesTable: React.FC<DetectionRulesTableProps> = ({
8893
items={ruleItems}
8994
itemId={(item: RuleItem) => `${item.name}`}
9095
search={search}
91-
pagination={
92-
pageIndex !== undefined
93-
? {
94-
pageIndex,
95-
}
96-
: true
97-
}
98-
onTableChange={onTableChange}
96+
pagination={pagination}
97+
onTableChange={onTableChangeHandler}
9998
loading={loading}
10099
data-test-subj={'edit-detector-rules-table'}
101100
/>

0 commit comments

Comments
 (0)