Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Jul 9, 2020
1 parent 163701d commit 4262c59
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface AddExceptionModalProps {
nonEcsData: TimelineNonEcsData[];
};
onCancel: () => void;
onConfirm: (didCloseAlert?: boolean) => void;
onConfirm: (didCloseAlert: boolean) => void;
}

const Modal = styled(EuiModal)`
Expand Down Expand Up @@ -222,14 +222,18 @@ export const AddExceptionModal = memo(function AddExceptionModal({
);

const retrieveAlertOsTypes = useCallback(() => {
const osTypes = getMappedNonEcsValue({
data: alertData.nonEcsData,
fieldName: 'host.os.family',
});
if (osTypes.length === 0) {
return ['windows', 'macos', 'linux'];
const osDefaults = ['windows', 'macos', 'linux'];
if (alertData) {
const osTypes = getMappedNonEcsValue({
data: alertData.nonEcsData,
fieldName: 'host.os.family',
});
if (osTypes.length === 0) {
return osDefaults;
}
return osTypes;
}
return osTypes;
return osDefaults;
}, [alertData]);

const enrichExceptionItems = useCallback(() => {
Expand All @@ -239,11 +243,11 @@ export const AddExceptionModal = memo(function AddExceptionModal({
? enrichExceptionItemsWithComments(exceptionItemsToAdd, [{ comment }])
: exceptionItemsToAdd;
if (exceptionListType === 'endpoint') {
const osTypes = alertData ? retrieveAlertOsTypes() : ['windows', 'macos', 'linux'];
const osTypes = retrieveAlertOsTypes();
enriched = enrichExceptionItemsWithOS(enriched, osTypes);
}
return enriched;
}, [comment, exceptionItemsToAdd, exceptionListType, alertData, retrieveAlertOsTypes]);
}, [comment, exceptionItemsToAdd, exceptionListType, retrieveAlertOsTypes]);

const onAddExceptionConfirm = useCallback(() => {
if (addOrUpdateExceptionItems !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,30 @@ describe('Exception helpers', () => {
});

describe('#getOperatingSystems', () => {
test('it returns null if no operating system tag specified', () => {
const result = getOperatingSystems(['some tag', 'some other tag']);

expect(result).toEqual('');
});

test('it returns null if operating system tag malformed', () => {
const result = getOperatingSystems(['some tag', 'jibberos:mac,windows', 'some other tag']);

expect(result).toEqual('');
});

test('it returns operating systems if space included in os tag', () => {
const result = getOperatingSystems(['some tag', 'os: macos', 'some other tag']);
expect(result).toEqual(['macos']);
});

test('it returns operating systems if multiple os tags specified', () => {
const result = getOperatingSystems(['some tag', 'os: macos', 'some other tag', 'os:windows']);
expect(result).toEqual(['macos', 'windows']);
});
});

describe('#formatOperatingSystems', () => {
test('it returns null if no operating system tag specified', () => {
const result = formatOperatingSystems(getOperatingSystems(['some tag', 'some other tag']));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,27 +453,27 @@ export const entryHasNonEcsType = (
exceptionItems: Array<ExceptionListItemSchema | CreateExceptionListItemSchema>,
indexPatterns: IIndexPattern
): boolean => {
const doesFieldNameExist = (exceptionEntry: Entry): boolean => {
return indexPatterns.fields.some(({ name }) => name === exceptionEntry.field);
};

if (exceptionItems.length === 0) {
return false;
}
for (const { entries } of exceptionItems) {
for (const exceptionEntry of entries ?? []) {
if (exceptionEntry.type === 'nested') {
for (const nestedExceptionEntry of exceptionEntry.entries) {
if (doesFieldNameExist(nestedExceptionEntry) === true) {
if (doesFieldNameExist(nestedExceptionEntry) === false) {
return true;
}
}
} else if (doesFieldNameExist(exceptionEntry) === true) {
} else if (doesFieldNameExist(exceptionEntry) === false) {
return true;
}
}
}
return false;

function doesFieldNameExist(exceptionEntry: Entry) {
return indexPatterns.fields.find(({ name }) => name === exceptionEntry.field) === undefined;
}
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export const getAlertActions = ({
}
},
id: 'addEndpointException',
isActionDisabled: () => !canUserCRUD || !hasIndexWrite || isEndpointAlert() === false,
isActionDisabled: () => !canUserCRUD || !hasIndexWrite || !isEndpointAlert(),
dataTestSubj: 'add-endpoint-exception-menu-item',
ariaLabel: 'Add Endpoint Exception',
content: <EuiText size="m">{i18n.ACTION_ADD_ENDPOINT_EXCEPTION}</EuiText>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
}, [closeAddExceptionModal]);

const onAddExceptionConfirm = useCallback(
(didCloseAlert?: boolean) => {
(didCloseAlert: boolean) => {
closeAddExceptionModal();
},
[closeAddExceptionModal]
Expand Down

0 comments on commit 4262c59

Please sign in to comment.