From 0d97b10680d221d865b69b26b13d19c3014e09ae Mon Sep 17 00:00:00 2001 From: "Devin W. Hurley" Date: Wed, 1 Apr 2020 20:55:43 -0400 Subject: [PATCH] =?UTF-8?q?[7.x]=20[SIEM]=20[Detection=20Engine]=20Fixes?= =?UTF-8?q?=20all=20rules=20sorting=20(#6203=E2=80=A6=20(#62234)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixes sorting to what it was in 7.6.1 * removes sortable=true from non-sortable columns, fixes naming of sortable column field from activate to enabled to match the field eui expects to sort on, fixes react render warning due to resetting tableRef's current field during a render --- .../public/pages/detection_engine/rules/all/columns.tsx | 4 +--- .../public/pages/detection_engine/rules/all/index.tsx | 9 ++++----- .../public/pages/detection_engine/rules/all/reducer.ts | 5 ++++- .../rules/components/all_rules_tables/index.tsx | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/columns.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/columns.tsx index 6ee19ad51933..563acc20fe12 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/columns.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/columns.tsx @@ -148,7 +148,6 @@ export const getColumns = ({ ); }, - sortable: true, truncateText: true, width: '20%', }, @@ -184,7 +183,7 @@ export const getColumns = ({ }, { align: 'center', - field: 'activate', + field: 'enabled', name: i18n.COLUMN_ACTIVATE, render: (value: Rule['enabled'], item: Rule) => ( { ); }, - sortable: true, truncateText: true, width: '20%', }, diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx index 4003b71b95d7..1a9827254644 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx @@ -41,11 +41,12 @@ import { showRulesTable } from './helpers'; import { allRulesReducer, State } from './reducer'; import { RulesTableFilters } from './rules_table_filters/rules_table_filters'; +const SORT_FIELD = 'enabled'; const initialState: State = { exportRuleIds: [], filterOptions: { filter: '', - sortField: 'enabled', + sortField: SORT_FIELD, sortOrder: 'desc', }, loadingRuleIds: [], @@ -127,9 +128,7 @@ export const AllRules = React.memo( }); const sorting = useMemo( - () => ({ - sort: { field: 'enabled', direction: filterOptions.sortOrder }, - }), + () => ({ sort: { field: 'enabled', direction: filterOptions.sortOrder } }), [filterOptions.sortOrder] ); @@ -171,7 +170,7 @@ export const AllRules = React.memo( dispatch({ type: 'updateFilterOptions', filterOptions: { - sortField: 'enabled', // Only enabled is supported for sorting currently + sortField: SORT_FIELD, // Only enabled is supported for sorting currently sortOrder: sort?.direction ?? 'desc', }, pagination: { page: page.index + 1, perPage: page.size }, diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/reducer.ts b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/reducer.ts index 0a4d169d1315..bc5297e7628b 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/reducer.ts +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/reducer.ts @@ -66,7 +66,10 @@ export const allRulesReducer = ( tableRef.current != null && tableRef.current.changeSelection != null ) { - tableRef.current.changeSelection([]); + // for future devs: eui basic table is not giving us a prop to set the value, so + // we are using the ref in setTimeout to reset on the next loop so that we + // do not get a warning telling us we are trying to update during a render + window.setTimeout(() => tableRef?.current?.changeSelection([]), 0); } return { diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/all_rules_tables/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/all_rules_tables/index.tsx index 92ccbc864ab5..0fd07f30a00b 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/all_rules_tables/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/all_rules_tables/index.tsx @@ -97,7 +97,7 @@ const AllRulesTablesComponent: React.FC = ({ onChange={tableOnChangeCallback} pagination={paginationMemo} ref={tableRef} - {...sorting} + sorting={sorting} selection={hasNoPermissions ? undefined : euiBasicTableSelectionProps} /> )} @@ -111,7 +111,7 @@ const AllRulesTablesComponent: React.FC = ({ noItemsMessage={emptyPrompt} onChange={tableOnChangeCallback} pagination={paginationMemo} - {...sorting} + sorting={sorting} /> )}