Skip to content

Commit

Permalink
Fixed click on customField
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Feb 6, 2023
1 parent 09cad3a commit d07948c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const none = i18n.translate('xpack.securitySolution.groupsSelector.noneGroupByOp
interface GroupSelectorProps {
fields: FieldSpec[];
groupSelected: string;
onClearSelected: () => void;
onGroupChange: (groupSelection: string) => void;
options: Array<{ key: string; label: string }>;
title?: string;
Expand All @@ -33,7 +32,6 @@ interface GroupSelectorProps {
const GroupsSelectorComponent = ({
fields,
groupSelected = 'none',
onClearSelected,
onGroupChange,
options,
title = '',
Expand All @@ -48,17 +46,14 @@ const GroupsSelectorComponent = ({
'data-test-subj': 'panel-none',
name: none,
icon: groupSelected === 'none' ? 'check' : 'empty',
onClick: onClearSelected,
onClick: () => onGroupChange('none'),
},
...options.map<EuiContextMenuPanelItemDescriptor>(
(o) =>
({
'data-test-subj': `panel-${o.key}`,
name: o.label,
onClick: () => onGroupChange(o.key),
icon: groupSelected === o.key ? 'check' : 'empty',
} as EuiContextMenuPanelItemDescriptor)
),
...options.map<EuiContextMenuPanelItemDescriptor>((o) => ({
'data-test-subj': `panel-${o.key}`,
name: o.label,
onClick: () => onGroupChange(o.key),
icon: groupSelected === o.key ? 'check' : 'empty',
})),
{
'data-test-subj': `panel-custom`,
name: i18n.translate('xpack.securitySolution.groupsSelector.customGroupByOptionName', {
Expand Down Expand Up @@ -86,7 +81,7 @@ const GroupsSelectorComponent = ({
),
},
],
[fields, groupSelected, onClearSelected, onGroupChange, options]
[fields, groupSelected, onGroupChange, options]
);
const selectedOption = useMemo(
() => options.filter((groupOption) => groupOption.key === groupSelected),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { NONE_GROUP_KEY } from './types';

export * from './container';
export * from './query';
export * from './groups_selector';
export * from './types';

export const isNoneGroup = (groupKey: string) => groupKey === NONE_GROUP_KEY;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { GenericBuckets } from '../../../../common/search_strategy/common';

export const DEFAULT_GROUPING_QUERY_ID = 'defaultGroupingQuery';

export const NONE_GROUP_KEY = 'none';

export type RawBucket = GenericBuckets & {
alertsCount?: {
value?: number | null; // Elasticsearch returns `null` when a sub-aggregation cannot be computed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import type {
GroupingTableAggregation,
RawBucket,
} from '../../../common/components/grouping';
import { GroupingContainer, GroupsSelector } from '../../../common/components/grouping';
import {
GroupingContainer,
GroupsSelector,
isNoneGroup,
} from '../../../common/components/grouping';
import { useGlobalTime } from '../../../common/containers/use_global_time';
import { combineQueries } from '../../../common/lib/kuery';
import type { AlertWorkflowStatus } from '../../../common/types';
Expand Down Expand Up @@ -313,11 +317,11 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
query: queryGroups,
indexName: signalIndexName,
queryName: ALERTS_QUERY_NAMES.ALERTS_GROUPING,
skip: selectedGroup === 'none',
skip: isNoneGroup(selectedGroup),
});

useEffect(() => {
if (selectedGroup !== 'none') {
if (!isNoneGroup(selectedGroup)) {
setAlertsQuery(queryGroups);
}
}, [queryGroups, selectedGroup, setAlertsQuery]);
Expand Down Expand Up @@ -345,7 +349,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
? defaultGroupingOptions
: [
...defaultGroupingOptions,
...(selectedGroup
...(!isNoneGroup(selectedGroup)
? [
{
key: selectedGroup,
Expand All @@ -362,10 +366,14 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
groupSelected={selectedGroup}
data-test-subj="alerts-table-group-selector"
onGroupChange={(groupSelection: string) => {
if (groupSelection === selectedGroup) {
return;
}
storage.set(`${ALERTS_TABLE_GROUPS_SELECTION_KEY}-${tableId}`, groupSelection);
setGroupsActivePage(0);
setSelectedGroup(groupSelection);
if (groupSelection !== 'none' && !options.find((o) => o.key === groupSelection)) {

if (!isNoneGroup(groupSelection) && !options.find((o) => o.key === groupSelection)) {
setOptions([
...defaultGroupingOptions,
{
Expand All @@ -377,12 +385,6 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
setOptions(defaultGroupingOptions);
}
}}
onClearSelected={() => {
setGroupsActivePage(0);
setSelectedGroup('none');
setOptions(defaultGroupingOptions);
storage.set(`${ALERTS_TABLE_GROUPS_SELECTION_KEY}-${tableId}`, 'none');
}}
fields={indexPatterns.fields}
options={options}
title={i18n.GROUP_ALERTS_SELECTOR}
Expand Down Expand Up @@ -426,13 +428,13 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
rowRenderers={defaultRowRenderers}
sourcererScope={SourcererScopeName.detections}
start={from}
additionalRightMenuOptions={selectedGroup === 'none' ? [groupsSelector] : []}
additionalRightMenuOptions={isNoneGroup(selectedGroup) ? [groupsSelector] : []}
/>
);

return (
<>
{selectedGroup === 'none' ? (
{isNoneGroup(selectedGroup) ? (
dataTable
) : (
<>
Expand All @@ -459,7 +461,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
rowRenderers={defaultRowRenderers}
sourcererScope={SourcererScopeName.detections}
start={from}
additionalRightMenuOptions={selectedGroup === 'none' ? [groupsSelector] : []}
additionalRightMenuOptions={isNoneGroup(selectedGroup) ? [groupsSelector] : []}
/>
)}
unit={defaultUnit}
Expand Down

0 comments on commit d07948c

Please sign in to comment.