Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Jul 5, 2020
1 parent 38846b0 commit 31a991b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import React, { useCallback, useMemo } from 'react';
import { EuiFormRow, EuiFlexItem, EuiFlexGroup, EuiSuperSelectOption } from '@elastic/eui';
import styled from 'styled-components';

import { CaseField, ActionType, ThirdPartyField } from '../../../../../../../case/common/api';
import { FieldMappingRow } from './field_mapping_row';
import * as i18n from './translations';

import { setActionTypeToMapping, setThirdPartyToMapping } from './utils';
import {
ThirdPartyField as ConnectorConfigurationThirdPartyField,
AllThirdPartyFields,
} from './types';
import { ThirdPartyField as ConnectorConfigurationThirdPartyField } from './types';
import { CasesConfigurationMapping } from '../types';
import { connectorConfiguration } from '../config';
import { createDefaultMapping } from '../servicenow_connectors';
Expand All @@ -26,7 +22,7 @@ const FieldRowWrapper = styled.div`
font-size: 14px;
`;

const actionTypeOptions: Array<EuiSuperSelectOption<ActionType>> = [
const actionTypeOptions: Array<EuiSuperSelectOption<string>> = [
{
value: 'nothing',
inputDisplay: <>{i18n.FIELD_MAPPING_EDIT_NOTHING}</>,
Expand All @@ -45,12 +41,10 @@ const actionTypeOptions: Array<EuiSuperSelectOption<ActionType>> = [
];

const getThirdPartyOptions = (
caseField: CaseField,
caseField: string,
thirdPartyFields: Record<string, ConnectorConfigurationThirdPartyField>
): Array<EuiSuperSelectOption<AllThirdPartyFields>> =>
(Object.keys(thirdPartyFields) as AllThirdPartyFields[]).reduce<
Array<EuiSuperSelectOption<AllThirdPartyFields>>
>(
): Array<EuiSuperSelectOption<string>> =>
(Object.keys(thirdPartyFields) as string[]).reduce<Array<EuiSuperSelectOption<string>>>(
(acc, key) => {
if (thirdPartyFields[key].validSourceFields.includes(caseField)) {
return [
Expand Down Expand Up @@ -87,7 +81,7 @@ const FieldMappingComponent: React.FC<FieldMappingProps> = ({
connectorActionTypeId,
}) => {
const onChangeActionType = useCallback(
(caseField: CaseField, newActionType: ActionType) => {
(caseField: string, newActionType: string) => {
const myMapping = mapping ?? defaultMapping;
onChangeMapping(setActionTypeToMapping(caseField, newActionType, myMapping));
},
Expand All @@ -96,7 +90,7 @@ const FieldMappingComponent: React.FC<FieldMappingProps> = ({
);

const onChangeThirdParty = useCallback(
(caseField: CaseField, newThirdPartyField: ThirdPartyField) => {
(caseField: string, newThirdPartyField: string) => {
const myMapping = mapping ?? defaultMapping;
onChangeMapping(setThirdPartyToMapping(caseField, newThirdPartyField, myMapping));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ import {
} from '@elastic/eui';

import { capitalize } from 'lodash';
import { CaseField, ActionType, ThirdPartyField } from '../../../../../../../case/common/api/cases';
import { AllThirdPartyFields } from './types';

export interface RowProps {
id: string;
disabled: boolean;
securitySolutionField: CaseField;
thirdPartyOptions: Array<EuiSuperSelectOption<AllThirdPartyFields>>;
actionTypeOptions: Array<EuiSuperSelectOption<ActionType>>;
onChangeActionType: (caseField: CaseField, newActionType: ActionType) => void;
onChangeThirdParty: (caseField: CaseField, newThirdPartyField: ThirdPartyField) => void;
selectedActionType: ActionType;
selectedThirdParty: ThirdPartyField;
securitySolutionField: string;
thirdPartyOptions: Array<EuiSuperSelectOption<string>>;
actionTypeOptions: Array<EuiSuperSelectOption<string>>;
onChangeActionType: (caseField: string, newActionType: string) => void;
onChangeThirdParty: (caseField: string, newThirdPartyField: string) => void;
selectedActionType: string;
selectedThirdParty: string;
}

const FieldMappingRowComponent: React.FC<RowProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IErrorObject, ActionType } from '../../../../../types';
import { ActionType } from '../../../../../types';

import {
ActionType as ThirdPartySupportedActions,
CaseField,
} from '../../../../../../../case/common/api';

export { ThirdPartyField as AllThirdPartyFields } from '../../../../../../../case/common/api';

export { ActionType, CaseField };
export { ActionType };

export interface ThirdPartyField {
label: string;
validSourceFields: CaseField[];
defaultSourceField: CaseField;
defaultActionType: ThirdPartySupportedActions;
}

export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;

export interface ConnectorFlyoutFormProps<T> {
errors: IErrorObject;
action: T;
onChangeSecret: (key: string, value: string) => void;
onBlurSecret: (key: string) => void;
onChangeConfig: (key: string, value: string) => void;
onBlurConfig: (key: string) => void;
}

export interface ConnectorFlyoutHOCProps<T> {
ConnectorFormComponent: React.FC<ConnectorFlyoutFormProps<T>>;
connectorActionTypeId: string;
configKeys?: string[];
secretKeys?: string[];
validSourceFields: string[];
defaultSourceField: string;
defaultActionType: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { ActionType, ThirdPartyField } from '../../../../../../../case/common/api';
import { CaseField } from './types';
import { CasesConfigurationMapping } from '../types';

export const setActionTypeToMapping = (
caseField: CaseField,
newActionType: ActionType,
caseField: string,
newActionType: string,
mapping: CasesConfigurationMapping[]
): CasesConfigurationMapping[] => {
const findItemIndex = mapping.findIndex((item) => item.source === caseField);
Expand All @@ -26,8 +24,8 @@ export const setActionTypeToMapping = (
};

export const setThirdPartyToMapping = (
caseField: CaseField,
newThirdPartyField: ThirdPartyField,
caseField: string,
newThirdPartyField: string,
mapping: CasesConfigurationMapping[]
): CasesConfigurationMapping[] =>
mapping.map((item) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('ServiceNowActionConnectorFields renders', () => {
errors={{ apiUrl: [], username: [], password: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
editActionProperty={() => {}}
docLinks={deps!.docLinks}
/>
);
Expand Down Expand Up @@ -72,7 +71,6 @@ describe('ServiceNowActionConnectorFields renders', () => {
errors={{ apiUrl: [], username: [], password: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
editActionProperty={() => {}}
docLinks={deps!.docLinks}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@ import {
} from '@elastic/eui';

import { isEmpty } from 'lodash';
import { IErrorObject, ActionConnectorFieldsProps } from '../../../../types';
import { ActionConnectorFieldsProps } from '../../../../types';
import * as i18n from './translations';
import { ServiceNowActionConnector, CasesConfigurationMapping } from './types';
import { connectorConfiguration } from './config';
import { FieldMapping } from './case_mappings/field_mapping';

export interface ConnectorFlyoutFormProps<T> {
errors: IErrorObject;
action: T;
onChangeSecret: (key: string, value: string) => void;
onBlurSecret: (key: string) => void;
onChangeConfig: (key: string, value: string) => void;
onBlurConfig: (key: string) => void;
}

const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<
ServiceNowActionConnector
>> = ({ action, editActionSecrets, editActionConfig, errors, consumer }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

// to remove
import { CaseField, ThirdPartyField, ActionType } from '../../../../../../case/common/api';

export interface ServiceNowActionConnector {
config: ServiceNowConfig;
secrets: ServiceNowSecrets;
Expand Down Expand Up @@ -43,7 +40,7 @@ interface ServiceNowSecrets {

// to remove
export interface CasesConfigurationMapping {
source: CaseField;
target: ThirdPartyField;
actionType: ActionType;
source: string;
target: string;
actionType: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export const ActionConnectorForm = ({
errors={errors}
editActionConfig={setActionConfigProperty}
editActionSecrets={setActionSecretsProperty}
editActionProperty={setActionProperty}
http={http}
docLinks={docLinks}
consumer={consumer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface AlertReducerAction {
key: string;
value: {};
index?: number;
subKey?: string;
};
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/triggers_actions_ui/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export interface ActionConnectorFieldsProps<TActionConnector> {
action: TActionConnector;
editActionConfig: (property: string, value: any) => void;
editActionSecrets: (property: string, value: any) => void;
editActionProperty?: (property: string, value: any) => void;
errors: IErrorObject;
docLinks: DocLinksStart;
http?: HttpSetup;
Expand Down Expand Up @@ -77,7 +76,6 @@ export interface ActionConnector {
referencedByCount?: number;
config: Record<string, any>;
isPreconfigured: boolean;
consumer?: string | null;
}

export type ActionConnectorWithoutId = Omit<ActionConnector, 'id'>;
Expand Down

0 comments on commit 31a991b

Please sign in to comment.