From 9fa88386025164548a6e508a79882952509ee544 Mon Sep 17 00:00:00 2001 From: Jovan Cvetkovic Date: Thu, 29 Dec 2022 13:57:15 +0100 Subject: [PATCH 1/2] [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 --- .../DetectionRules/DetectionRulesTable.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx index c80126b18..56ac1acdc 100644 --- a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx +++ b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx @@ -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'; @@ -70,12 +70,17 @@ export const DetectionRulesTable: React.FC = ({ }, ], }; - + const [pagination, setPagination] = useState({ 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) => { + setPagination({ pageIndex: pagination.page.index }); + onTableChange && onTableChange(pagination); + }; + return (
= ({ 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'} /> From aa1bec9720fa4f6708bf9d41e09bb792e2d06487 Mon Sep 17 00:00:00 2001 From: Jovan Cvetkovic Date: Thu, 29 Dec 2022 15:13:34 +0100 Subject: [PATCH 2/2] [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 --- .../components/DetectionRules/DetectionRulesTable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx index 56ac1acdc..c6be37e46 100644 --- a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx +++ b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx @@ -70,7 +70,7 @@ export const DetectionRulesTable: React.FC = ({ }, ], }; - const [pagination, setPagination] = useState({ pageIndex: 0 }); + 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);