From e11e19f394510972163f320d6ff9a2a4653bcd63 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Mon, 6 Apr 2020 13:24:38 -0400 Subject: [PATCH 1/9] wip fixing checkbox types --- .../store/policy_details/selectors.ts | 26 +++++ .../public/applications/endpoint/types.ts | 6 ++ .../endpoint/view/policy/policy_details.tsx | 4 +- .../policy/policy_forms/eventing/checkbox.tsx | 25 ++--- .../policy/policy_forms/eventing/index.tsx | 8 ++ .../view/policy/policy_forms/eventing/mac.tsx | 101 ++++++++++++++++++ .../policy/policy_forms/eventing/windows.tsx | 4 +- 7 files changed, 159 insertions(+), 15 deletions(-) create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/index.tsx create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts index 0d505931c9ec5..17a89d7ff525b 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts @@ -105,6 +105,32 @@ export const selectedWindowsEventing = (state: PolicyDetailsState): number => { return 0; }; +/** Returns an object of all the mac eventing configurations */ +export const macEventing = (state: PolicyDetailsState) => { + const config = policyConfig(state); + return config && config.mac.events; +}; + +/** Returns the total number of possible mac eventing configurations */ +export const totalMacEventing = (state: PolicyDetailsState): number => { + const config = policyConfig(state); + if (config) { + return Object.keys(config.mac.events).length; + } + return 0; +}; + +/** Returns the number of selected mac eventing configurations */ +export const selectedMacEventing = (state: PolicyDetailsState): number => { + const config = policyConfig(state); + if (config) { + return Object.values(config.mac.events).reduce((count, event) => { + return event === true ? count + 1 : count; + }, 0); + } + return 0; +}; + /** is there an api call in flight */ export const isLoading = (state: PolicyDetailsState) => state.isLoading; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index d4f6d2457254e..9d901232d66e5 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -133,7 +133,9 @@ export interface PolicyConfig { }; mac: { events: { + file: boolean; process: boolean; + network: boolean; }; malware: MalwareFields; logging: { @@ -144,7 +146,9 @@ export interface PolicyConfig { }; linux: { events: { + file: boolean; process: boolean; + network: boolean; }; logging: { stdout: string; @@ -191,6 +195,7 @@ export interface UIPolicyConfig { mac: MacPolicyConfig; linux: LinuxPolicyConfig; } +export type nerds = keyof UIPolicyConfig[t]['events']; /** OS used in Policy */ export enum OS { @@ -203,6 +208,7 @@ export enum OS { export enum EventingFields { process = 'process', network = 'network', + file = 'file', } /** diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx index 2dba301bf4537..eb444e40ea4dd 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx @@ -29,12 +29,12 @@ import { isLoading, apiError, } from '../../store/policy_details/selectors'; -import { WindowsEventing } from './policy_forms/eventing/windows'; import { PageView, PageViewHeaderTitle } from '../../components/page_view'; import { AppAction } from '../../types'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { AgentsSummary } from './agents_summary'; import { VerticalDivider } from './vertical_divider'; +import { WindowsEventing, MacEventing } from './policy_forms/eventing'; import { MalwareProtections } from './policy_forms/protections/malware'; export const PolicyDetails = React.memo(() => { @@ -203,6 +203,8 @@ export const PolicyDetails = React.memo(() => { + + ); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx index 8b7fb89ed1646..abb1dd53a290b 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx @@ -10,28 +10,29 @@ import { useDispatch } from 'react-redux'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { policyConfig, windowsEventing } from '../../../../store/policy_details/selectors'; import { PolicyDetailsAction } from '../../../../store/policy_details'; -import { OS, EventingFields } from '../../../../types'; +import { OS, UIPolicyConfig, nerds } from '../../../../types'; import { clone } from '../../../../models/policy_details_config'; -export const EventingCheckbox: React.FC<{ +export const EventingCheckbox = React.memo(function({ + id, + name, + os, + protectionField, +}: { id: string; name: string; - os: OS; - protectionField: EventingFields; -}> = React.memo(({ id, name, os, protectionField }) => { + os: T; + protectionField: nerds; +}) { const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); const eventing = usePolicyDetailsSelector(windowsEventing); const dispatch = useDispatch<(action: PolicyDetailsAction) => void>(); - const handleRadioChange = useCallback( + const handleCheckboxChange = useCallback( (event: React.ChangeEvent) => { if (policyDetailsConfig) { const newPayload = clone(policyDetailsConfig); - if (os === OS.linux || os === OS.mac) { - newPayload[os].events.process = event.target.checked; - } else { - newPayload[os].events[protectionField] = event.target.checked; - } + newPayload[os].events[protectionField] = event.target.checked; dispatch({ type: 'userChangedPolicyConfig', @@ -47,7 +48,7 @@ export const EventingCheckbox: React.FC<{ id={id} label={name} checked={eventing && eventing[protectionField]} - onChange={handleRadioChange} + onChange={handleCheckboxChange} /> ); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/index.tsx new file mode 100644 index 0000000000000..58b4af46c6e34 --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/index.tsx @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { WindowsEventing } from './windows'; +export { MacEventing } from './mac'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx new file mode 100644 index 0000000000000..b373dd6b32782 --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx @@ -0,0 +1,101 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { useMemo } from 'react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { htmlIdGenerator } from '@elastic/eui'; +import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; +import { EventingCheckbox } from './checkbox'; +import { OS, EventingFields } from '../../../../types'; +import { usePolicyDetailsSelector } from '../../policy_hooks'; +import { selectedMacEventing, totalMacEventing } from '../../../../store/policy_details/selectors'; +import { ConfigForm } from '../config_form'; + +export const MacEventing = React.memo(() => { + const selected = usePolicyDetailsSelector(selectedMacEventing); + const total = usePolicyDetailsSelector(totalMacEventing); + + const checkboxes = useMemo( + () => [ + { + name: i18n.translate('xpack.endpoint.policyDetailsConfig.mac.events.file', { + defaultMessage: 'File', + }), + os: OS.mac, + protectionField: EventingFields.file, + }, + { + name: i18n.translate('xpack.endpoint.policyDetailsConfig.mac.events.process', { + defaultMessage: 'Process', + }), + os: OS.mac, + protectionField: EventingFields.process, + }, + { + name: i18n.translate('xpack.endpoint.policyDetailsConfig.mac.events.network', { + defaultMessage: 'Network', + }), + os: OS.mac, + protectionField: EventingFields.network, + }, + ], + [] + ); + + const renderCheckboxes = () => { + return ( + <> + +
+ +
+
+ + {checkboxes.map((item, index) => { + return ( + htmlIdGenerator()(), [])} + name={item.name} + key={index} + os={item.os} + protectionField={item.protectionField} + /> + ); + })} + + ); + }; + + const collectionsEnabled = () => { + return ( + + + + ); + }; + + return ( + + ); +}); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx index 7bec2c4c742d2..3585407011a57 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx @@ -24,14 +24,14 @@ export const WindowsEventing = React.memo(() => { const checkboxes = useMemo( () => [ { - name: i18n.translate('xpack.endpoint.policyDetailsConfig.eventingProcess', { + name: i18n.translate('xpack.endpoint.policyDetailsConfig.windows.events.process', { defaultMessage: 'Process', }), os: OS.windows, protectionField: EventingFields.process, }, { - name: i18n.translate('xpack.endpoint.policyDetailsConfig.eventingNetwork', { + name: i18n.translate('xpack.endpoint.policyDetailsConfig.windows.events.network', { defaultMessage: 'Network', }), os: OS.windows, From 43c6a107ce3abfdf16393af340b77a5f6e77d357 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 6 Apr 2020 16:15:21 -0400 Subject: [PATCH 2/9] this --- .../public/applications/endpoint/models/policy.ts | 8 ++++++++ .../endpoint/public/applications/endpoint/types.ts | 1 - .../view/policy/policy_forms/eventing/checkbox.tsx | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts index 9ac53f9be609f..cfd8313338c1a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts @@ -42,6 +42,10 @@ export const generatePolicy = (): PolicyConfig => { mac: { events: { process: true, + // TODO, is this right? + file: true, + // TODO, is this right? + network: true, }, malware: { mode: ProtectionModes.detect, @@ -67,6 +71,10 @@ export const generatePolicy = (): PolicyConfig => { linux: { events: { process: true, + // TODO, is this right? + file: true, + // TODO, is this right? + network: true, }, logging: { stdout: 'debug', diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index 9d901232d66e5..5caab1450b2b6 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -195,7 +195,6 @@ export interface UIPolicyConfig { mac: MacPolicyConfig; linux: LinuxPolicyConfig; } -export type nerds = keyof UIPolicyConfig[t]['events']; /** OS used in Policy */ export enum OS { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx index abb1dd53a290b..cd46af222d076 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx @@ -10,7 +10,7 @@ import { useDispatch } from 'react-redux'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { policyConfig, windowsEventing } from '../../../../store/policy_details/selectors'; import { PolicyDetailsAction } from '../../../../store/policy_details'; -import { OS, UIPolicyConfig, nerds } from '../../../../types'; +import { UIPolicyConfig } from '../../../../types'; import { clone } from '../../../../models/policy_details_config'; export const EventingCheckbox = React.memo(function({ @@ -22,7 +22,7 @@ export const EventingCheckbox = React.memo(function; + protectionField: keyof UIPolicyConfig[T]['events']; }) { const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); const eventing = usePolicyDetailsSelector(windowsEventing); @@ -31,7 +31,7 @@ export const EventingCheckbox = React.memo(function) => { if (policyDetailsConfig) { - const newPayload = clone(policyDetailsConfig); + const newPayload: UIPolicyConfig = clone(policyDetailsConfig); newPayload[os].events[protectionField] = event.target.checked; dispatch({ From 3d9e34ca51a7a1bacf1a3633690646a0ad4b410e Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 8 Apr 2020 16:27:05 -0400 Subject: [PATCH 3/9] added setIn, still got some type errors tho --- .../endpoint/models/policy_details_config.ts | 33 +++++++++++++++++ .../policy/policy_forms/eventing/checkbox.tsx | 36 ++++++++++--------- .../view/policy/policy_forms/eventing/mac.tsx | 19 +++++++--- .../policy/policy_forms/eventing/windows.tsx | 16 ++++++--- 4 files changed, 78 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts index 1145d1d19242a..0d6b6096a430c 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts @@ -43,3 +43,36 @@ export function clone(policyDetailsConfig: UIPolicyConfig): UIPolicyConfig { */ return clonedConfig as UIPolicyConfig; } + +/** + * Returns cloned `configuration` with `value` set by the `keyPath`. + */ + +export function setIn< + K1 extends keyof UIPolicyConfig, + K2 extends keyof UIPolicyConfig[K1], + K3 extends keyof UIPolicyConfig[K1][K2] +>(configuration: UIPolicyConfig, keyPath: [K1, K2, K3], value: boolean | string): UIPolicyConfig; +export function setIn( + configuration: UIPolicyConfig, + keyPath: [K1, K2], + value: UIPolicyConfig[K1][K2] +): UIPolicyConfig; +export function setIn( + configuration: UIPolicyConfig, + keyPath: [K1], + value: UIPolicyConfig[K1] +): UIPolicyConfig; +export function setIn( + configuration: UIPolicyConfig, + keyPath: string[], + value: boolean | string +): UIPolicyConfig { + const payload = clone(configuration); + let current: any = payload; + while (keyPath.length > 1) { + current = current[keyPath.shift()!]; + } + current[keyPath[0]] = value; + return payload; +} diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx index cd46af222d076..54065b0b36233 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx @@ -7,48 +7,50 @@ import React, { useCallback } from 'react'; import { EuiCheckbox } from '@elastic/eui'; import { useDispatch } from 'react-redux'; +import { setIn } from '../../../../models/policy_details_config'; import { usePolicyDetailsSelector } from '../../policy_hooks'; -import { policyConfig, windowsEventing } from '../../../../store/policy_details/selectors'; +import { policyConfig } from '../../../../store/policy_details/selectors'; import { PolicyDetailsAction } from '../../../../store/policy_details'; import { UIPolicyConfig } from '../../../../types'; -import { clone } from '../../../../models/policy_details_config'; -export const EventingCheckbox = React.memo(function({ +export const EventingCheckbox = React.memo(function< + T extends keyof UIPolicyConfig, + TT extends keyof UIPolicyConfig[T], + TTT extends keyof UIPolicyConfig[T][TT] +>({ id, name, os, + protectionEvent, protectionField, }: { id: string; name: string; os: T; - protectionField: keyof UIPolicyConfig[T]['events']; + protectionEvent: TT; + protectionField: TTT; }) { const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); - const eventing = usePolicyDetailsSelector(windowsEventing); + const selected = policyDetailsConfig[os][protectionEvent][protectionField]; const dispatch = useDispatch<(action: PolicyDetailsAction) => void>(); const handleCheckboxChange = useCallback( (event: React.ChangeEvent) => { if (policyDetailsConfig) { - const newPayload: UIPolicyConfig = clone(policyDetailsConfig); - newPayload[os].events[protectionField] = event.target.checked; + const payload = setIn( + policyDetailsConfig, + [os, protectionEvent, protectionField], + event.target.checked + ); dispatch({ type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload }, + payload: { policyConfig: payload }, }); } }, - [dispatch, os, policyDetailsConfig, protectionField] + [dispatch, os, policyDetailsConfig, protectionEvent, protectionField] ); - return ( - - ); + return ; }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx index b373dd6b32782..d832eed378643 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx @@ -10,7 +10,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { htmlIdGenerator } from '@elastic/eui'; import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; import { EventingCheckbox } from './checkbox'; -import { OS, EventingFields } from '../../../../types'; +import { OS, UIPolicyConfig } from '../../../../types'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { selectedMacEventing, totalMacEventing } from '../../../../store/policy_details/selectors'; import { ConfigForm } from '../config_form'; @@ -19,28 +19,36 @@ export const MacEventing = React.memo(() => { const selected = usePolicyDetailsSelector(selectedMacEventing); const total = usePolicyDetailsSelector(totalMacEventing); - const checkboxes = useMemo( + const checkboxes: Array<{ + name: string; + os: 'mac'; + protectionEvent: keyof UIPolicyConfig['mac']; + protectionField: keyof UIPolicyConfig['mac']['events']; + }> = useMemo( () => [ { name: i18n.translate('xpack.endpoint.policyDetailsConfig.mac.events.file', { defaultMessage: 'File', }), os: OS.mac, - protectionField: EventingFields.file, + protectionEvent: 'events', + protectionField: 'file', }, { name: i18n.translate('xpack.endpoint.policyDetailsConfig.mac.events.process', { defaultMessage: 'Process', }), os: OS.mac, - protectionField: EventingFields.process, + protectionEvent: 'events', + protectionField: 'process', }, { name: i18n.translate('xpack.endpoint.policyDetailsConfig.mac.events.network', { defaultMessage: 'Network', }), os: OS.mac, - protectionField: EventingFields.network, + protectionEvent: 'events', + protectionField: 'network', }, ], [] @@ -65,6 +73,7 @@ export const MacEventing = React.memo(() => { name={item.name} key={index} os={item.os} + protectionEvent={item.protectionEvent} protectionField={item.protectionField} /> ); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx index 3585407011a57..e2728bee682f4 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; import { EventingCheckbox } from './checkbox'; -import { OS, EventingFields } from '../../../../types'; +import { OS, UIPolicyConfig } from '../../../../types'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { selectedWindowsEventing, @@ -21,21 +21,28 @@ export const WindowsEventing = React.memo(() => { const selected = usePolicyDetailsSelector(selectedWindowsEventing); const total = usePolicyDetailsSelector(totalWindowsEventing); - const checkboxes = useMemo( + const checkboxes: Array<{ + name: string; + os: 'windows'; + protectionEvent: keyof UIPolicyConfig['windows']; + protectionField: keyof UIPolicyConfig['windows']['events']; + }> = useMemo( () => [ { name: i18n.translate('xpack.endpoint.policyDetailsConfig.windows.events.process', { defaultMessage: 'Process', }), os: OS.windows, - protectionField: EventingFields.process, + protectionEvent: 'events', + protectionField: 'process', }, { name: i18n.translate('xpack.endpoint.policyDetailsConfig.windows.events.network', { defaultMessage: 'Network', }), os: OS.windows, - protectionField: EventingFields.network, + protectionEvent: 'events', + protectionField: 'network', }, ], [] @@ -60,6 +67,7 @@ export const WindowsEventing = React.memo(() => { name={item.name} key={index} os={item.os} + protectionEvent={item.protectionEvent} protectionField={item.protectionField} /> ); From c12e1509c20ed1e559f9aaaa02cf63fdeccda68d Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 9 Apr 2020 11:36:28 -0400 Subject: [PATCH 4/9] solid changes --- .../policy/policy_forms/eventing/checkbox.tsx | 20 ++++++++++++------- .../policy/policy_forms/eventing/windows.tsx | 20 ++++++++++--------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx index 54065b0b36233..3da3f4daffe33 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx @@ -4,9 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useCallback } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { EuiCheckbox } from '@elastic/eui'; import { useDispatch } from 'react-redux'; +import { htmlIdGenerator } from '@elastic/eui'; import { setIn } from '../../../../models/policy_details_config'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { policyConfig } from '../../../../store/policy_details/selectors'; @@ -14,17 +15,15 @@ import { PolicyDetailsAction } from '../../../../store/policy_details'; import { UIPolicyConfig } from '../../../../types'; export const EventingCheckbox = React.memo(function< - T extends keyof UIPolicyConfig, - TT extends keyof UIPolicyConfig[T], - TTT extends keyof UIPolicyConfig[T][TT] + T extends keyof UIPolicyConfig & string, + TT extends keyof UIPolicyConfig[T] & string, + TTT extends keyof UIPolicyConfig[T][TT] & string >({ - id, name, os, protectionEvent, protectionField, }: { - id: string; name: string; os: T; protectionEvent: TT; @@ -52,5 +51,12 @@ export const EventingCheckbox = React.memo(function< [dispatch, os, policyDetailsConfig, protectionEvent, protectionField] ); - return ; + return ( + htmlIdGenerator()(), [])} + label={name} + checked={selected} + onChange={handleCheckboxChange} + /> + ); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx index e2728bee682f4..ee7ce56391b7c 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx @@ -48,7 +48,7 @@ export const WindowsEventing = React.memo(() => { [] ); - const renderCheckboxes = () => { + const renderCheckboxes = useMemo(() => { return ( <> @@ -63,7 +63,6 @@ export const WindowsEventing = React.memo(() => { {checkboxes.map((item, index) => { return ( { })} ); - }; + }, [checkboxes]); - const collectionsEnabled = () => { + const collectionsEnabled = useMemo(() => { return ( { /> ); - }; + }, [selected, total]); return ( [ + i18n.translate('xpack.endpoint.policy.details.windows', { defaultMessage: 'Windows' }), + ], + [] + )} id="windowsEventingForm" rightCorner={collectionsEnabled()} - children={renderCheckboxes()} + children={renderCheckboxes} /> ); }); From 9fdfe773c9966ed7e7efdf65864474a03c60b4ac Mon Sep 17 00:00:00 2001 From: oatkiller Date: Thu, 9 Apr 2020 12:47:54 -0400 Subject: [PATCH 5/9] fixed up stuff, but reducer is still having a hard time --- .../endpoint/models/policy_details_config.ts | 55 +++++++------- .../public/applications/endpoint/types.ts | 73 +++++++++---------- .../policy/policy_forms/eventing/checkbox.tsx | 29 ++------ .../view/policy/policy_forms/eventing/mac.tsx | 14 ++-- .../policy/policy_forms/eventing/windows.tsx | 13 ++-- 5 files changed, 78 insertions(+), 106 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts index 0d6b6096a430c..bf96942e83a91 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy_details_config.ts @@ -45,34 +45,31 @@ export function clone(policyDetailsConfig: UIPolicyConfig): UIPolicyConfig { } /** - * Returns cloned `configuration` with `value` set by the `keyPath`. + * Returns value from `configuration` */ +export const getIn = (a: UIPolicyConfig) => (key: Key) => < + subKey extends keyof UIPolicyConfig[Key] +>( + subKey: subKey +) => ( + leafKey: LeafKey +): UIPolicyConfig[Key][subKey][LeafKey] => { + return a[key][subKey][leafKey]; +}; -export function setIn< - K1 extends keyof UIPolicyConfig, - K2 extends keyof UIPolicyConfig[K1], - K3 extends keyof UIPolicyConfig[K1][K2] ->(configuration: UIPolicyConfig, keyPath: [K1, K2, K3], value: boolean | string): UIPolicyConfig; -export function setIn( - configuration: UIPolicyConfig, - keyPath: [K1, K2], - value: UIPolicyConfig[K1][K2] -): UIPolicyConfig; -export function setIn( - configuration: UIPolicyConfig, - keyPath: [K1], - value: UIPolicyConfig[K1] -): UIPolicyConfig; -export function setIn( - configuration: UIPolicyConfig, - keyPath: string[], - value: boolean | string -): UIPolicyConfig { - const payload = clone(configuration); - let current: any = payload; - while (keyPath.length > 1) { - current = current[keyPath.shift()!]; - } - current[keyPath[0]] = value; - return payload; -} +/** + * Returns cloned `configuration` with `value` set by the `keyPath`. + */ +export const setIn = (a: UIPolicyConfig) => (key: Key) => < + subKey extends keyof UIPolicyConfig[Key] +>( + subKey: subKey +) => (leafKey: LeafKey) => < + V extends UIPolicyConfig[Key][subKey][LeafKey] +>( + v: V +): UIPolicyConfig => { + const c = clone(a); + c[key][subKey][leafKey] = v; + return c; +}; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index 5caab1450b2b6..dda50847169e7 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -118,38 +118,21 @@ export interface PolicyDetailsState { * Endpoint Policy configuration */ export interface PolicyConfig { - windows: { - events: { - process: boolean; - network: boolean; - }; - /** malware mode can be off, detect, prevent or prevent and notify user */ - malware: MalwareFields; + windows: UIPolicyConfig['windows'] & { logging: { stdout: string; file: string; }; advanced: PolicyConfigAdvancedOptions; }; - mac: { - events: { - file: boolean; - process: boolean; - network: boolean; - }; - malware: MalwareFields; + mac: UIPolicyConfig['mac'] & { logging: { stdout: string; file: string; }; advanced: PolicyConfigAdvancedOptions; }; - linux: { - events: { - file: boolean; - process: boolean; - network: boolean; - }; + linux: UIPolicyConfig['linux'] & { logging: { stdout: string; file: string; @@ -172,29 +155,39 @@ interface PolicyConfigAdvancedOptions { }; } -/** - * Windows-specific policy configuration that is supported via the UI - */ -type WindowsPolicyConfig = Pick; - -/** - * Mac-specific policy configuration that is supported via the UI - */ -type MacPolicyConfig = Pick; - -/** - * Linux-specific policy configuration that is supported via the UI - */ -type LinuxPolicyConfig = Pick; - /** * The set of Policy configuration settings that are show/edited via the UI */ -export interface UIPolicyConfig { - windows: WindowsPolicyConfig; - mac: MacPolicyConfig; - linux: LinuxPolicyConfig; -} +/* eslint-disable @typescript-eslint/consistent-type-definitions */ +export type UIPolicyConfig = { + windows: { + events: { + process: boolean; + network: boolean; + }; + /** malware mode can be off, detect, prevent or prevent and notify user */ + malware: MalwareFields; + }; + mac: { + events: { + file: boolean; + process: boolean; + network: boolean; + }; + malware: MalwareFields; + }; + + /** + * Linux-specific policy configuration that is supported via the UI + */ + linux: { + events: { + file: boolean; + process: boolean; + network: boolean; + }; + }; +}; /** OS used in Policy */ export enum OS { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx index 3da3f4daffe33..5cae342e25ab5 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx @@ -8,47 +8,34 @@ import React, { useCallback, useMemo } from 'react'; import { EuiCheckbox } from '@elastic/eui'; import { useDispatch } from 'react-redux'; import { htmlIdGenerator } from '@elastic/eui'; -import { setIn } from '../../../../models/policy_details_config'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { policyConfig } from '../../../../store/policy_details/selectors'; import { PolicyDetailsAction } from '../../../../store/policy_details'; import { UIPolicyConfig } from '../../../../types'; -export const EventingCheckbox = React.memo(function< - T extends keyof UIPolicyConfig & string, - TT extends keyof UIPolicyConfig[T] & string, - TTT extends keyof UIPolicyConfig[T][TT] & string ->({ +export const EventingCheckbox = React.memo(function({ name, - os, - protectionEvent, - protectionField, + setter, + getter, }: { name: string; - os: T; - protectionEvent: TT; - protectionField: TTT; + setter: (config: UIPolicyConfig, checked: boolean) => UIPolicyConfig; + getter: (config: UIPolicyConfig) => boolean; }) { const policyDetailsConfig = usePolicyDetailsSelector(policyConfig); - const selected = policyDetailsConfig[os][protectionEvent][protectionField]; + const selected = getter(policyDetailsConfig); const dispatch = useDispatch<(action: PolicyDetailsAction) => void>(); const handleCheckboxChange = useCallback( (event: React.ChangeEvent) => { if (policyDetailsConfig) { - const payload = setIn( - policyDetailsConfig, - [os, protectionEvent, protectionField], - event.target.checked - ); - dispatch({ type: 'userChangedPolicyConfig', - payload: { policyConfig: payload }, + payload: { policyConfig: setter(policyDetailsConfig, event.target.checked) }, }); } }, - [dispatch, os, policyDetailsConfig, protectionEvent, protectionField] + [dispatch, policyDetailsConfig, setter] ); return ( diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx index d832eed378643..e652b47edca7a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx @@ -7,13 +7,13 @@ import React, { useMemo } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { htmlIdGenerator } from '@elastic/eui'; import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; import { EventingCheckbox } from './checkbox'; import { OS, UIPolicyConfig } from '../../../../types'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { selectedMacEventing, totalMacEventing } from '../../../../store/policy_details/selectors'; import { ConfigForm } from '../config_form'; +import { getIn, setIn } from '../../../../models/policy_details_config'; export const MacEventing = React.memo(() => { const selected = usePolicyDetailsSelector(selectedMacEventing); @@ -22,7 +22,6 @@ export const MacEventing = React.memo(() => { const checkboxes: Array<{ name: string; os: 'mac'; - protectionEvent: keyof UIPolicyConfig['mac']; protectionField: keyof UIPolicyConfig['mac']['events']; }> = useMemo( () => [ @@ -31,7 +30,6 @@ export const MacEventing = React.memo(() => { defaultMessage: 'File', }), os: OS.mac, - protectionEvent: 'events', protectionField: 'file', }, { @@ -39,7 +37,6 @@ export const MacEventing = React.memo(() => { defaultMessage: 'Process', }), os: OS.mac, - protectionEvent: 'events', protectionField: 'process', }, { @@ -47,7 +44,6 @@ export const MacEventing = React.memo(() => { defaultMessage: 'Network', }), os: OS.mac, - protectionEvent: 'events', protectionField: 'network', }, ], @@ -69,12 +65,12 @@ export const MacEventing = React.memo(() => { {checkboxes.map((item, index) => { return ( htmlIdGenerator()(), [])} name={item.name} key={index} - os={item.os} - protectionEvent={item.protectionEvent} - protectionField={item.protectionField} + setter={(config, checked) => + setIn(config)(item.os)('events')(item.protectionField)(checked) + } + getter={config => getIn(config)(item.os)('events')(item.protectionField)} /> ); })} diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx index ee7ce56391b7c..1ab0434fcc378 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx @@ -16,6 +16,7 @@ import { totalWindowsEventing, } from '../../../../store/policy_details/selectors'; import { ConfigForm } from '../config_form'; +import { setIn, getIn } from '../../../../models/policy_details_config'; export const WindowsEventing = React.memo(() => { const selected = usePolicyDetailsSelector(selectedWindowsEventing); @@ -24,7 +25,6 @@ export const WindowsEventing = React.memo(() => { const checkboxes: Array<{ name: string; os: 'windows'; - protectionEvent: keyof UIPolicyConfig['windows']; protectionField: keyof UIPolicyConfig['windows']['events']; }> = useMemo( () => [ @@ -33,7 +33,6 @@ export const WindowsEventing = React.memo(() => { defaultMessage: 'Process', }), os: OS.windows, - protectionEvent: 'events', protectionField: 'process', }, { @@ -41,7 +40,6 @@ export const WindowsEventing = React.memo(() => { defaultMessage: 'Network', }), os: OS.windows, - protectionEvent: 'events', protectionField: 'network', }, ], @@ -65,9 +63,10 @@ export const WindowsEventing = React.memo(() => { + setIn(config)(item.os)('events')(item.protectionField)(checked) + } + getter={config => getIn(config)(item.os)('events')(item.protectionField)} /> ); })} @@ -99,7 +98,7 @@ export const WindowsEventing = React.memo(() => { [] )} id="windowsEventingForm" - rightCorner={collectionsEnabled()} + rightCorner={collectionsEnabled} children={renderCheckboxes} /> ); From 817c4bb18e7ab946ab45b7559d00af7a8954936c Mon Sep 17 00:00:00 2001 From: Candace Park Date: Thu, 9 Apr 2020 17:01:58 -0400 Subject: [PATCH 6/9] reason any --- .../applications/endpoint/store/policy_details/reducer.ts | 2 +- x-pack/plugins/endpoint/public/applications/endpoint/types.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts index fb3e26157ef32..3931f4b10af99 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts @@ -90,7 +90,7 @@ export const policyDetailsReducer: Reducer = ( if (action.type === 'userChangedPolicyConfig') { const newState = { ...state, policyItem: { ...(state.policyItem as PolicyData) } }; - const newPolicy = (newState.policyItem.inputs[0].config.policy.value = { + const newPolicy: any = (newState.policyItem.inputs[0].config.policy.value = { ...fullPolicy(state), }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index dda50847169e7..c7a29f03d1b5a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -97,7 +97,7 @@ export interface PolicyListState { /** * Policy details store state */ -export interface PolicyDetailsState { +export type PolicyDetailsState = Immutable<{ /** A single policy item */ policyItem?: PolicyData; /** API error if loading data failed */ @@ -112,7 +112,7 @@ export interface PolicyDetailsState { success: boolean; error?: ServerApiError; }; -} +}>; /** * Endpoint Policy configuration From bf6541156480dcfddfa22862c2aa46391c0edde1 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Fri, 10 Apr 2020 11:44:08 -0400 Subject: [PATCH 7/9] changed eventing to events, removed unnecessary things --- .../applications/endpoint/models/policy.ts | 4 ---- .../store/policy_details/index.test.ts | 5 +++-- .../endpoint/store/policy_details/reducer.ts | 12 ++++++----- .../store/policy_details/selectors.ts | 20 ++++--------------- .../public/applications/endpoint/types.ts | 4 ++-- .../endpoint/view/policy/policy_details.tsx | 6 +++--- .../{eventing => events}/checkbox.tsx | 2 +- .../{eventing => events}/index.tsx | 4 ++-- .../policy_forms/{eventing => events}/mac.tsx | 12 +++++------ .../{eventing => events}/windows.tsx | 14 ++++++------- 10 files changed, 35 insertions(+), 48 deletions(-) rename x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/{eventing => events}/checkbox.tsx (96%) rename x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/{eventing => events}/index.tsx (74%) rename x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/{eventing => events}/mac.tsx (89%) rename x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/{eventing => events}/windows.tsx (92%) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts index cfd8313338c1a..30f45e54c2005 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/models/policy.ts @@ -42,9 +42,7 @@ export const generatePolicy = (): PolicyConfig => { mac: { events: { process: true, - // TODO, is this right? file: true, - // TODO, is this right? network: true, }, malware: { @@ -71,9 +69,7 @@ export const generatePolicy = (): PolicyConfig => { linux: { events: { process: true, - // TODO, is this right? file: true, - // TODO, is this right? network: true, }, logging: { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts index cf14092953227..ffce38344f993 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts @@ -7,7 +7,7 @@ import { PolicyDetailsState } from '../../types'; import { createStore, Dispatch, Store } from 'redux'; import { policyDetailsReducer, PolicyDetailsAction } from './index'; -import { policyConfig, windowsEventing } from './selectors'; +import { policyConfig } from './selectors'; import { clone } from '../../models/policy_details_config'; import { generatePolicy } from '../../models/policy'; @@ -72,7 +72,8 @@ describe('policy details: ', () => { }); it('windows process eventing is enabled', async () => { - expect(windowsEventing(getState())!.process).toEqual(true); + const config = policyConfig(getState()); + expect(config!.windows.events.process).toEqual(true); }); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts index 3931f4b10af99..fb0f371cdae0d 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts @@ -5,7 +5,7 @@ */ import { Reducer } from 'redux'; -import { PolicyData, PolicyDetailsState, UIPolicyConfig } from '../../types'; +import { PolicyDetailsState, UIPolicyConfig } from '../../types'; import { AppAction } from '../action'; import { fullPolicy, isOnPolicyDetailsPage } from './selectors'; @@ -89,10 +89,12 @@ export const policyDetailsReducer: Reducer = ( } if (action.type === 'userChangedPolicyConfig') { - const newState = { ...state, policyItem: { ...(state.policyItem as PolicyData) } }; - const newPolicy: any = (newState.policyItem.inputs[0].config.policy.value = { - ...fullPolicy(state), - }); + if (!state.policyItem) { + return state; + } + const newState = { ...state, policyItem: { ...state.policyItem } }; + const newPolicy: any = { ...fullPolicy(state) }; + newState.policyItem.inputs[0].config.policy.value = newPolicy; Object.entries(action.payload.policyConfig).forEach(([section, newSettings]) => { newPolicy[section as keyof UIPolicyConfig] = { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts index 17a89d7ff525b..4b4dc9d9bee43 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts @@ -79,14 +79,8 @@ export const policyConfig: (s: PolicyDetailsState) => UIPolicyConfig = createSel } ); -/** Returns an object of all the windows eventing configuration */ -export const windowsEventing = (state: PolicyDetailsState) => { - const config = policyConfig(state); - return config && config.windows.events; -}; - /** Returns the total number of possible windows eventing configurations */ -export const totalWindowsEventing = (state: PolicyDetailsState): number => { +export const totalWindowsEvents = (state: PolicyDetailsState): number => { const config = policyConfig(state); if (config) { return Object.keys(config.windows.events).length; @@ -95,7 +89,7 @@ export const totalWindowsEventing = (state: PolicyDetailsState): number => { }; /** Returns the number of selected windows eventing configurations */ -export const selectedWindowsEventing = (state: PolicyDetailsState): number => { +export const selectedWindowsEvents = (state: PolicyDetailsState): number => { const config = policyConfig(state); if (config) { return Object.values(config.windows.events).reduce((count, event) => { @@ -105,14 +99,8 @@ export const selectedWindowsEventing = (state: PolicyDetailsState): number => { return 0; }; -/** Returns an object of all the mac eventing configurations */ -export const macEventing = (state: PolicyDetailsState) => { - const config = policyConfig(state); - return config && config.mac.events; -}; - /** Returns the total number of possible mac eventing configurations */ -export const totalMacEventing = (state: PolicyDetailsState): number => { +export const totalMacEvents = (state: PolicyDetailsState): number => { const config = policyConfig(state); if (config) { return Object.keys(config.mac.events).length; @@ -121,7 +109,7 @@ export const totalMacEventing = (state: PolicyDetailsState): number => { }; /** Returns the number of selected mac eventing configurations */ -export const selectedMacEventing = (state: PolicyDetailsState): number => { +export const selectedMacEvents = (state: PolicyDetailsState): number => { const config = policyConfig(state); if (config) { return Object.values(config.mac.events).reduce((count, event) => { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index c7a29f03d1b5a..dda50847169e7 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -97,7 +97,7 @@ export interface PolicyListState { /** * Policy details store state */ -export type PolicyDetailsState = Immutable<{ +export interface PolicyDetailsState { /** A single policy item */ policyItem?: PolicyData; /** API error if loading data failed */ @@ -112,7 +112,7 @@ export type PolicyDetailsState = Immutable<{ success: boolean; error?: ServerApiError; }; -}>; +} /** * Endpoint Policy configuration diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx index 92afa06ebe9b3..1e723e32615eb 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx @@ -34,7 +34,7 @@ import { AppAction } from '../../types'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { AgentsSummary } from './agents_summary'; import { VerticalDivider } from './vertical_divider'; -import { WindowsEventing, MacEventing } from './policy_forms/eventing'; +import { WindowsEvents, MacEvents } from './policy_forms/events'; import { MalwareProtections } from './policy_forms/protections/malware'; export const PolicyDetails = React.memo(() => { @@ -206,9 +206,9 @@ export const PolicyDetails = React.memo(() => { - + - + ); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/checkbox.tsx similarity index 96% rename from x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx rename to x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/checkbox.tsx index 5cae342e25ab5..bec6b33b85c7f 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/checkbox.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/checkbox.tsx @@ -13,7 +13,7 @@ import { policyConfig } from '../../../../store/policy_details/selectors'; import { PolicyDetailsAction } from '../../../../store/policy_details'; import { UIPolicyConfig } from '../../../../types'; -export const EventingCheckbox = React.memo(function({ +export const EventsCheckbox = React.memo(function({ name, setter, getter, diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/index.tsx similarity index 74% rename from x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/index.tsx rename to x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/index.tsx index 58b4af46c6e34..44716d8183041 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/index.tsx @@ -4,5 +4,5 @@ * you may not use this file except in compliance with the Elastic License. */ -export { WindowsEventing } from './windows'; -export { MacEventing } from './mac'; +export { WindowsEvents } from './windows'; +export { MacEvents } from './mac'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/mac.tsx similarity index 89% rename from x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx rename to x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/mac.tsx index e652b47edca7a..3b69c21d2b150 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/mac.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/mac.tsx @@ -8,16 +8,16 @@ import React, { useMemo } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; -import { EventingCheckbox } from './checkbox'; +import { EventsCheckbox } from './checkbox'; import { OS, UIPolicyConfig } from '../../../../types'; import { usePolicyDetailsSelector } from '../../policy_hooks'; -import { selectedMacEventing, totalMacEventing } from '../../../../store/policy_details/selectors'; +import { selectedMacEvents, totalMacEvents } from '../../../../store/policy_details/selectors'; import { ConfigForm } from '../config_form'; import { getIn, setIn } from '../../../../models/policy_details_config'; -export const MacEventing = React.memo(() => { - const selected = usePolicyDetailsSelector(selectedMacEventing); - const total = usePolicyDetailsSelector(totalMacEventing); +export const MacEvents = React.memo(() => { + const selected = usePolicyDetailsSelector(selectedMacEvents); + const total = usePolicyDetailsSelector(totalMacEvents); const checkboxes: Array<{ name: string; @@ -64,7 +64,7 @@ export const MacEventing = React.memo(() => { {checkboxes.map((item, index) => { return ( - diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/windows.tsx similarity index 92% rename from x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx rename to x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/windows.tsx index 1ab0434fcc378..63a140912437d 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/eventing/windows.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_forms/events/windows.tsx @@ -8,19 +8,19 @@ import React, { useMemo } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; -import { EventingCheckbox } from './checkbox'; +import { EventsCheckbox } from './checkbox'; import { OS, UIPolicyConfig } from '../../../../types'; import { usePolicyDetailsSelector } from '../../policy_hooks'; import { - selectedWindowsEventing, - totalWindowsEventing, + selectedWindowsEvents, + totalWindowsEvents, } from '../../../../store/policy_details/selectors'; import { ConfigForm } from '../config_form'; import { setIn, getIn } from '../../../../models/policy_details_config'; -export const WindowsEventing = React.memo(() => { - const selected = usePolicyDetailsSelector(selectedWindowsEventing); - const total = usePolicyDetailsSelector(totalWindowsEventing); +export const WindowsEvents = React.memo(() => { + const selected = usePolicyDetailsSelector(selectedWindowsEvents); + const total = usePolicyDetailsSelector(totalWindowsEvents); const checkboxes: Array<{ name: string; @@ -60,7 +60,7 @@ export const WindowsEventing = React.memo(() => { {checkboxes.map((item, index) => { return ( - From 47ac6306c18a48a03c3a28cae3708a2e15ba7f02 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Fri, 10 Apr 2020 13:10:45 -0400 Subject: [PATCH 8/9] added a mac events unit test --- .../store/policy_details/index.test.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts index ffce38344f993..d98e37685a2a5 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts @@ -71,9 +71,31 @@ describe('policy details: ', () => { }); }); - it('windows process eventing is enabled', async () => { + it('windows process events is enabled', () => { const config = policyConfig(getState()); expect(config!.windows.events.process).toEqual(true); }); }); + + describe('when the user has enabled mac file events', () => { + beforeEach(() => { + const config = policyConfig(getState()); + if (!config) { + throw new Error(); + } + + const newPayload1 = clone(config); + newPayload1.mac.events.file = true; + + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload1 }, + }); + }); + + it('windows process eventing is enabled', () => { + const config = policyConfig(getState()); + expect(config!.mac.events.file).toEqual(true); + }); + }); }); From 2e636cec4707368480bddb1f64be0d2afeb2334b Mon Sep 17 00:00:00 2001 From: Candace Park Date: Fri, 10 Apr 2020 13:26:08 -0400 Subject: [PATCH 9/9] lol typos --- .../applications/endpoint/store/policy_details/index.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts index d98e37685a2a5..e09a62b235e35 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.test.ts @@ -55,7 +55,7 @@ describe('policy details: ', () => { }); }); - describe('when the user has enabled windows process eventing', () => { + describe('when the user has enabled windows process events', () => { beforeEach(() => { const config = policyConfig(getState()); if (!config) { @@ -93,7 +93,7 @@ describe('policy details: ', () => { }); }); - it('windows process eventing is enabled', () => { + it('mac file events is enabled', () => { const config = policyConfig(getState()); expect(config!.mac.events.file).toEqual(true); });