From 0a3c7b6f010210354895cb8b5f3e109dbc0504b0 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 30 Dec 2022 10:01:27 +0530 Subject: [PATCH] =?UTF-8?q?[BUG]=20Edit=20detector=20rules=20table=20pagin?= =?UTF-8?q?g=20goes=20to=20page=20the=20first=20page=20if=E2=80=A6=20(#270?= =?UTF-8?q?)=20(#277)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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 * [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 Signed-off-by: Jovan Cvetkovic (cherry picked from commit b6e305807c5fd8192b34e67c34c8b0b330753491) Co-authored-by: Jovan Cvetkovic Signed-off-by: AWSHurneyt --- .../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..c6be37e46 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: 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'} />