Skip to content

Commit

Permalink
[Triggers Actions UI] hideBulkActions for AlertsTable (elastic#184877)
Browse files Browse the repository at this point in the history
I would like to be able to disable the bulk actions entirely for a new
Observability page. Maybe there's an existing or easier way but I
couldn't figure it out :) I also added the possibility to set the
`emptyStateHeight`.

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
dgieselaar and kibanamachine authored Jun 7, 2024
1 parent ac1b9d0 commit 1b82363
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ const AlertsTable: React.FunctionComponent<AlertsTableProps> = memo((props: Aler
useBulkActionsConfig: alertsTableConfiguration.useBulkActions,
refresh: alertsRefresh,
featureIds,
hideBulkActions: Boolean(alertsTableConfiguration.hideBulkActions),
};
}, [alerts, alertsTableConfiguration, query, alertsRefresh, featureIds]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type AlertsTableStateProps = {
dynamicRowHeight?: boolean;
lastReloadRequestTime?: number;
renderCellPopover?: AlertsTableProps['renderCellPopover'];
emptyStateHeight?: 'tall' | 'short';
} & Omit<Partial<EuiDataGridProps>, 'renderCellPopover'>;

export interface AlertsTableStorage {
Expand Down Expand Up @@ -214,6 +215,7 @@ const AlertsTableStateWithQueryProvider = memo(
shouldHighlightRow,
dynamicRowHeight,
lastReloadRequestTime,
emptyStateHeight,
}: AlertsTableStateProps) => {
const { cases: casesService, fieldFormats } = useKibana<{
cases?: CasesService;
Expand Down Expand Up @@ -530,6 +532,7 @@ const AlertsTableStateWithQueryProvider = memo(
controls={persistentControls}
getInspectQuery={getInspectQuery}
showInpectButton={showInspectButton}
height={emptyStateHeight}
/>
</InspectButtonContainer>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,42 @@ describe('bulk action hooks', () => {
const newBulkActions = result.current.bulkActions[0].items;
expect(initialBulkActions).toEqual(newBulkActions);
});

it('hides bulk actions if hideBulkActions == true', () => {
// make sure by default some actions are returned for this
// config
const { result: resultWithoutHideBulkActions } = renderHook(
() =>
useBulkActions({
alerts: [],
query: {},
casesConfig,
refresh,
featureIds: ['observability'],
}),
{
wrapper: appMockRender.AppWrapper,
}
);

expect(resultWithoutHideBulkActions.current.bulkActions.length).toBeGreaterThan(0);

const { result: resultWithHideBulkActions } = renderHook(
() =>
useBulkActions({
alerts: [],
query: {},
casesConfig,
refresh,
featureIds: ['observability'],
hideBulkActions: true,
}),
{
wrapper: appMockRender.AppWrapper,
}
);

expect(resultWithHideBulkActions.current.bulkActions.length).toBe(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface BulkActionsProps {
useBulkActionsConfig?: UseBulkActionsRegistry;
refresh: () => void;
featureIds?: ValidFeatureId[];
hideBulkActions?: boolean;
}

export interface UseBulkActions {
Expand Down Expand Up @@ -278,6 +279,7 @@ export function useBulkActions({
refresh,
useBulkActionsConfig = () => [],
featureIds,
hideBulkActions,
}: BulkActionsProps): UseBulkActions {
const {
bulkActions: [bulkActionsState, updateBulkActionsState],
Expand All @@ -302,17 +304,22 @@ export function useBulkActions({
featureIds,
isAllSelected: bulkActionsState.isAllSelected,
});

const initialItems = useMemo(() => {
return [...caseBulkActions, ...(featureIds?.includes('siem') ? [] : untrackBulkActions)];
}, [caseBulkActions, featureIds, untrackBulkActions]);
const bulkActions = useMemo(() => {
if (hideBulkActions) {
return [];
}

return initialItems.length
? addItemsToInitialPanel({
panels: configBulkActionPanels,
items: initialItems,
})
: configBulkActionPanels;
}, [configBulkActionPanels, initialItems]);
}, [configBulkActionPanels, initialItems, hideBulkActions]);

const isBulkActionsColumnActive = bulkActions.length !== 0;

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/triggers_actions_ui/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ export interface AlertsTableConfigurationRegistry {
};
useFieldBrowserOptions?: UseFieldBrowserOptions;
showInspectButton?: boolean;
hideBulkActions?: boolean;
ruleTypeIds?: string[];
useFetchPageContext?: PreFetchPageContext;
actions?: {
Expand Down

0 comments on commit 1b82363

Please sign in to comment.