Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const mockUserProfiles = [

const defaultProps: UseBulkAlertAssigneesItemsProps = {
onAssigneesUpdate: () => {},
alertAssignments: [],
};

const mockAssigneeItems = [
Expand Down Expand Up @@ -170,6 +171,66 @@ describe('useBulkAlertAssigneesItems', () => {
);
});

it('should set unnasign alert action to disabled if no assignees exist', () => {
const mockSetAlertAssignees = jest.fn();
(useSetAlertAssignees as jest.Mock).mockReturnValue(mockSetAlertAssignees);
const { result } = renderHook(
() =>
useBulkAlertAssigneesItems({
onAssigneesUpdate: () => {},
alertAssignments: [],
}),
{
wrapper: TestProviders,
}
);

expect(
(
result.current.alertAssigneesItems[0] as unknown as {
disable: boolean;
}
).disable
).toBeFalsy();
expect(
(
result.current.alertAssigneesItems[1] as unknown as {
disable: boolean;
}
).disable
).toBeTruthy();
});

it('should set unnasign alert action to enabled if assignees exist', () => {
const mockSetAlertAssignees = jest.fn();
(useSetAlertAssignees as jest.Mock).mockReturnValue(mockSetAlertAssignees);
const { result } = renderHook(
() =>
useBulkAlertAssigneesItems({
onAssigneesUpdate: () => {},
alertAssignments: ['user1'],
}),
{
wrapper: TestProviders,
}
);

expect(
(
result.current.alertAssigneesItems[0] as unknown as {
disable: boolean;
}
).disable
).toBeFalsy();
expect(
(
result.current.alertAssigneesItems[1] as unknown as {
disable: boolean;
}
).disable
).toBeFalsy();
});

it('should return 0 items for the VIEWER role', () => {
(useAlertsPrivileges as jest.Mock).mockReturnValue({ hasIndexWrite: false });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
RenderContentPanelProps,
} from '@kbn/triggers-actions-ui-plugin/public/types';

import { isEmpty } from 'lodash/fp';
import { useLicense } from '../../../hooks/use_license';
import { useAlertsPrivileges } from '../../../../detections/containers/detection_engine/alerts/use_alerts_privileges';
import { ASSIGNEES_PANEL_WIDTH } from '../../assignees/constants';
Expand All @@ -24,6 +25,7 @@ import { useSetAlertAssignees } from './use_set_alert_assignees';

export interface UseBulkAlertAssigneesItemsProps {
onAssigneesUpdate?: () => void;
alertAssignments?: string[];
}

export interface UseBulkAlertAssigneesPanel {
Expand All @@ -36,6 +38,7 @@ export interface UseBulkAlertAssigneesPanel {

export const useBulkAlertAssigneesItems = ({
onAssigneesUpdate,
alertAssignments,
}: UseBulkAlertAssigneesItemsProps) => {
const isPlatinumPlus = useLicense().isPlatinumPlus();

Expand Down Expand Up @@ -89,6 +92,7 @@ export const useBulkAlertAssigneesItems = ({
panel: 2,
label: i18n.ALERT_ASSIGNEES_CONTEXT_MENU_ITEM_TITLE,
disableOnQuery: true,
disable: false,
},
{
key: 'remove-all-alert-assignees',
Expand All @@ -97,10 +101,11 @@ export const useBulkAlertAssigneesItems = ({
label: i18n.REMOVE_ALERT_ASSIGNEES_CONTEXT_MENU_TITLE,
disableOnQuery: true,
onClick: onRemoveAllAssignees,
disable: alertAssignments ? isEmpty(alertAssignments) : false,
},
]
: [],
[hasIndexWrite, isPlatinumPlus, onRemoveAllAssignees]
[alertAssignments, hasIndexWrite, isPlatinumPlus, onRemoveAllAssignees]
);

const TitleContent = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export const useAlertAssigneesActions = ({
const { hasIndexWrite } = useAlertsPrivileges();

const alertId = ecsRowData._id;
const alertAssignments = useMemo(
() => ecsRowData?.kibana?.alert.workflow_assignee_ids ?? [],
[ecsRowData?.kibana?.alert.workflow_assignee_ids]
);

const alertAssigneeData = useMemo(() => {
return [
{
Expand All @@ -39,7 +44,7 @@ export const useAlertAssigneesActions = ({
data: [
{
field: ALERT_WORKFLOW_ASSIGNEE_IDS,
value: ecsRowData?.kibana?.alert.workflow_assignee_ids ?? [],
value: alertAssignments,
},
],
ecs: {
Expand All @@ -48,7 +53,7 @@ export const useAlertAssigneesActions = ({
},
},
];
}, [alertId, ecsRowData._index, ecsRowData?.kibana?.alert.workflow_assignee_ids]);
}, [alertId, ecsRowData._index, alertAssignments]);

const onAssigneesUpdate = useCallback(() => {
closePopover();
Expand All @@ -59,6 +64,7 @@ export const useAlertAssigneesActions = ({

const { alertAssigneesItems, alertAssigneesPanels } = useBulkAlertAssigneesItems({
onAssigneesUpdate,
alertAssignments,
});

const itemsToReturn: AlertTableContextMenuItem[] = useMemo(
Expand All @@ -69,6 +75,7 @@ export const useAlertAssigneesActions = ({
'data-test-subj': item['data-test-subj'],
key: item.key,
onClick: () => item.onClick?.(alertAssigneeData, false, noop, noop, noop),
disabled: item.disable,
})),
[alertAssigneeData, alertAssigneesItems]
);
Expand Down