Skip to content

Commit

Permalink
renderCustomActionsRow with named params instead of args (#149304)
Browse files Browse the repository at this point in the history
## Summary

Closes #149303

## QA

Run the alerts table and check that the actions cell is working. 


https://user-images.githubusercontent.com/17549662/214009339-afc1fe7f-fb2a-4461-aec9-70a2335a875b.mov
  • Loading branch information
jcger authored Jan 24, 2023
1 parent afb84dc commit 611e5af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import React from 'react';
import { EcsFieldsResponse } from '@kbn/rule-registry-plugin/common/search_strategy';
import { RenderCustomActionsRowArgs } from '@kbn/triggers-actions-ui-plugin/public/types';
import { ObservabilityRuleTypeRegistry } from '../../../../rules/create_observability_rule_type_registry';
import { ObservabilityActions } from '../../components/observability_actions';
import type { ObservabilityActionsProps } from '../../components/observability_actions';
Expand All @@ -22,11 +23,7 @@ export const getRowActions = (
config: ConfigSchema
) => {
return () => ({
renderCustomActionsRow: (
alert: EcsFieldsResponse,
setFlyoutAlert: (data: unknown, id?: string) => void,
id?: string
) => {
renderCustomActionsRow: ({ alert, setFlyoutAlert, id }: RenderCustomActionsRowArgs) => {
return (
<ObservabilityActions
data={buildData(alert)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('AlertsTable', () => {
fireEvent.click((await screen.findAllByTestId('testActionColumn'))[0]);

// the callback given to our clients to run when they want to update the loading state
mockedFn.mock.calls[0][3](true);
mockedFn.mock.calls[0][0].setIsActionLoading(true);

expect(await screen.findAllByTestId('row-loader')).toHaveLength(1);
const selectedOptions = await screen.findAllByTestId('dataGridRowCell');
Expand Down Expand Up @@ -351,7 +351,7 @@ describe('AlertsTable', () => {
fireEvent.click((await screen.findAllByTestId('testActionColumn'))[0]);

// the callback given to our clients to run when they want to update the loading state
mockedFn.mock.calls[0][3](false);
mockedFn.mock.calls[0][0].setIsActionLoading(false);

expect(screen.queryByTestId('row-loader')).not.toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ const AlertsTable: React.FunctionComponent<AlertsTableProps> = (props: AlertsTab
)}
{renderCustomActionsRow &&
alerts[visibleRowIndex] &&
renderCustomActionsRow(
alerts[visibleRowIndex],
handleFlyoutAlert,
props.id,
getSetIsActionLoadingCallback(visibleRowIndex)
)}
renderCustomActionsRow({
alert: alerts[visibleRowIndex],
setFlyoutAlert: handleFlyoutAlert,
id: props.id,
setIsActionLoading: getSetIsActionLoadingCallback(visibleRowIndex),
})}
</EuiFlexGroup>
);
},
Expand Down
14 changes: 8 additions & 6 deletions x-pack/plugins/triggers_actions_ui/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,15 @@ export interface BulkActionsConfig {
) => void;
}

export interface RenderCustomActionsRowArgs {
alert: EcsFieldsResponse;
setFlyoutAlert: (data: unknown) => void;
id?: string;
setIsActionLoading?: (isLoading: boolean) => void;
}

export type UseActionsColumnRegistry = () => {
renderCustomActionsRow: (
alert: EcsFieldsResponse,
setFlyoutAlert: (data: unknown) => void,
id?: string,
setIsActionLoading?: (isLoading: boolean) => void
) => JSX.Element;
renderCustomActionsRow: (args: RenderCustomActionsRowArgs) => JSX.Element;
width?: number;
};

Expand Down

0 comments on commit 611e5af

Please sign in to comment.