Skip to content

Commit

Permalink
[Security Solution] [Grouping] Re-add support to custom Group By titl…
Browse files Browse the repository at this point in the history
…e in the useGetGroupSelector hook (#184165)

## Summary

This PR fixes a regression from PR #180016 where the support to the
custom title on the `useGetGroupSelector` hook was dropped and the
Findings DataTables was displaying "Group alerts by" instead of "Group
findings by". Unit tests were added to prevent further regressions.


## Screenshots


![image](https://github.com/elastic/kibana/assets/19270322/97ac29f7-d314-4df9-a4d8-9a11b198f021)


![image](https://github.com/elastic/kibana/assets/19270322/6e6a3eef-fd4e-4619-a460-a3b0fb46ec37)


![image](https://github.com/elastic/kibana/assets/19270322/e6bcd40c-45e6-4444-8905-7c7c2c900926)
  • Loading branch information
opauloh committed May 29, 2024
1 parent f2a4bba commit 12f35c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ describe('group selector', () => {
const { getByTestId } = render(<GroupSelector {...testProps} />);
expect(getByTestId('group-selector-dropdown').textContent).toBe('Group alerts by: Rule name');
});
it('Sets the Group by title from the title prop', () => {
const { getByTestId } = render(
<GroupSelector {...testProps} title="Group custom property by" />
);
expect(getByTestId('group-selector-dropdown').textContent).toBe(
'Group custom property by: Rule name'
);
});
it('Presents correct option when group selector dropdown is clicked', () => {
const { getByTestId } = render(<GroupSelector {...testProps} />);
fireEvent.click(getByTestId('group-selector-dropdown'));
Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-grouping/src/hooks/use_get_group_selector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,17 @@ describe('Group Selector Hooks', () => {
type: ActionType.updateGroupOptions,
});
});

it('Supports custom group by title', () => {
const result = renderHook(() =>
useGetGroupSelector({
...defaultArgs,
title: 'Group custom property by',
})
);

expect(result.result.current.props.title).toEqual('Group custom property by');
});
});

describe('useGetGroupSelectorStateless', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-grouping/src/hooks/use_get_group_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ export const useGetGroupSelector = ({
fields,
maxGroupingLevels,
options,
title,
}}
/>
);
}, [groupingId, fields, maxGroupingLevels, onChange, selectedGroups, options]);
}, [groupingId, fields, maxGroupingLevels, onChange, selectedGroups, options, title]);
};

0 comments on commit 12f35c9

Please sign in to comment.