Skip to content

Commit cb914d4

Browse files
authored
[SIEM] [Detection Engine] Fixes all rules sorting (#62039)
* 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
1 parent b1a39ce commit cb914d4

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/columns.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export const getColumns = ({
144144
</LocalizedDateTooltip>
145145
);
146146
},
147-
sortable: true,
148147
truncateText: true,
149148
width: '20%',
150149
},
@@ -180,7 +179,7 @@ export const getColumns = ({
180179
},
181180
{
182181
align: 'center',
183-
field: 'activate',
182+
field: 'enabled',
184183
name: i18n.COLUMN_ACTIVATE,
185184
render: (value: Rule['enabled'], item: Rule) => (
186185
<RuleSwitch
@@ -283,7 +282,6 @@ export const getMonitoringColumns = (): RulesStatusesColumns[] => {
283282
</LocalizedDateTooltip>
284283
);
285284
},
286-
sortable: true,
287285
truncateText: true,
288286
width: '20%',
289287
},

x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ import { showRulesTable } from './helpers';
4141
import { allRulesReducer, State } from './reducer';
4242
import { RulesTableFilters } from './rules_table_filters/rules_table_filters';
4343

44+
const SORT_FIELD = 'enabled';
4445
const initialState: State = {
4546
exportRuleIds: [],
4647
filterOptions: {
4748
filter: '',
48-
sortField: 'enabled',
49+
sortField: SORT_FIELD,
4950
sortOrder: 'desc',
5051
},
5152
loadingRuleIds: [],
@@ -127,9 +128,7 @@ export const AllRules = React.memo<AllRulesProps>(
127128
});
128129

129130
const sorting = useMemo(
130-
() => ({
131-
sort: { field: 'enabled', direction: filterOptions.sortOrder },
132-
}),
131+
() => ({ sort: { field: 'enabled', direction: filterOptions.sortOrder } }),
133132
[filterOptions.sortOrder]
134133
);
135134

@@ -171,7 +170,7 @@ export const AllRules = React.memo<AllRulesProps>(
171170
dispatch({
172171
type: 'updateFilterOptions',
173172
filterOptions: {
174-
sortField: 'enabled', // Only enabled is supported for sorting currently
173+
sortField: SORT_FIELD, // Only enabled is supported for sorting currently
175174
sortOrder: sort?.direction ?? 'desc',
176175
},
177176
pagination: { page: page.index + 1, perPage: page.size },

x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/reducer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export const allRulesReducer = (
6666
tableRef.current != null &&
6767
tableRef.current.changeSelection != null
6868
) {
69-
tableRef.current.changeSelection([]);
69+
// for future devs: eui basic table is not giving us a prop to set the value, so
70+
// we are using the ref in setTimeout to reset on the next loop so that we
71+
// do not get a warning telling us we are trying to update during a render
72+
window.setTimeout(() => tableRef?.current?.changeSelection([]), 0);
7073
}
7174

7275
return {

x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/all_rules_tables/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const AllRulesTablesComponent: React.FC<AllRulesTablesProps> = ({
9797
onChange={tableOnChangeCallback}
9898
pagination={paginationMemo}
9999
ref={tableRef}
100-
{...sorting}
100+
sorting={sorting}
101101
selection={hasNoPermissions ? undefined : euiBasicTableSelectionProps}
102102
/>
103103
)}
@@ -111,7 +111,7 @@ const AllRulesTablesComponent: React.FC<AllRulesTablesProps> = ({
111111
noItemsMessage={emptyPrompt}
112112
onChange={tableOnChangeCallback}
113113
pagination={paginationMemo}
114-
{...sorting}
114+
sorting={sorting}
115115
/>
116116
)}
117117
</>

0 commit comments

Comments
 (0)