Skip to content

Commit

Permalink
Fixed due to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Nov 12, 2020
1 parent c7e6efc commit 5dae98a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

import { AlertType, ActionVariables } from '../../types';
import { actionVariablesFromAlertType } from './action_variables';
import { transformActionVariables } from './action_variables';
import { ALERTS_FEATURE_ID } from '../../../../alerts/common';

beforeEach(() => jest.resetAllMocks());

describe('actionVariablesFromAlertType', () => {
describe('transformActionVariables', () => {
test('should return correct variables when no state or context provided', async () => {
const alertType = getAlertType({ context: [], state: [], params: [] });
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('actionVariablesFromAlertType', () => {
state: [],
params: [],
});
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('actionVariablesFromAlertType', () => {
],
params: [],
});
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('actionVariablesFromAlertType', () => {
],
params: [{ name: 'fooP', description: 'fooP-description' }],
});
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n';
import { ActionVariable, ActionVariables } from '../../types';

// return a "flattened" list of action variables for an alertType
export function actionVariablesFromAlertType(actionVariables: ActionVariables): ActionVariable[] {
export function transformActionVariables(actionVariables: ActionVariables): ActionVariable[] {
const alwaysProvidedVars = getAlwaysProvidedActionVariables();
const contextVars = actionVariables.context
? prefixKeys(actionVariables.context, 'context.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { checkActionFormActionTypeEnabled } from '../../lib/check_action_type_enabled';
import { hasSaveActionsCapability } from '../../lib/capabilities';
import { ActionAccordionFormProps } from './action_form';
import { actionVariablesFromAlertType } from '../../lib/action_variables';
import { transformActionVariables } from '../../lib/action_variables';
import { resolvedActionGroupMessage } from '../../constants';

export type ActionTypeFormProps = {
Expand Down Expand Up @@ -110,7 +110,6 @@ export const ActionTypeForm = ({
? resolvedActionGroupMessage
: defaultActionMessage;
setAvailableDefaultActionMessage(res);
// setActionParamsProperty('message', res, index);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actionItem.group]);

Expand Down Expand Up @@ -375,7 +374,7 @@ function getAvailableActionVariables(
? { params: actionVariables.params, state: actionVariables.state }
: actionVariables;

return actionVariablesFromAlertType(filteredActionVariables).sort((a, b) =>
return transformActionVariables(filteredActionVariables).sort((a, b) =>
a.name.toUpperCase().localeCompare(b.name.toUpperCase())
);
}

0 comments on commit 5dae98a

Please sign in to comment.