Skip to content

Commit

Permalink
[SIEM] [Detection Engine] Fixes all rules sorting (elastic#62039)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dhurley14 committed Apr 1, 2020
1 parent 6214dbe commit d265460
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export const getColumns = ({
</LocalizedDateTooltip>
);
},
sortable: true,
truncateText: true,
width: '20%',
},
Expand Down Expand Up @@ -184,7 +183,7 @@ export const getColumns = ({
},
{
align: 'center',
field: 'activate',
field: 'enabled',
name: i18n.COLUMN_ACTIVATE,
render: (value: Rule['enabled'], item: Rule) => (
<RuleSwitch
Expand Down Expand Up @@ -287,7 +286,6 @@ export const getMonitoringColumns = (): RulesStatusesColumns[] => {
</LocalizedDateTooltip>
);
},
sortable: true,
truncateText: true,
width: '20%',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -127,9 +128,7 @@ export const AllRules = React.memo<AllRulesProps>(
});

const sorting = useMemo(
() => ({
sort: { field: 'enabled', direction: filterOptions.sortOrder },
}),
() => ({ sort: { field: 'enabled', direction: filterOptions.sortOrder } }),
[filterOptions.sortOrder]
);

Expand Down Expand Up @@ -171,7 +170,7 @@ export const AllRules = React.memo<AllRulesProps>(
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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const AllRulesTablesComponent: React.FC<AllRulesTablesProps> = ({
onChange={tableOnChangeCallback}
pagination={paginationMemo}
ref={tableRef}
{...sorting}
sorting={sorting}
selection={hasNoPermissions ? undefined : euiBasicTableSelectionProps}
/>
)}
Expand All @@ -111,7 +111,7 @@ const AllRulesTablesComponent: React.FC<AllRulesTablesProps> = ({
noItemsMessage={emptyPrompt}
onChange={tableOnChangeCallback}
pagination={paginationMemo}
{...sorting}
sorting={sorting}
/>
)}
</>
Expand Down

0 comments on commit d265460

Please sign in to comment.