Skip to content

Commit

Permalink
changed eventing to events, removed unnecessary things
Browse files Browse the repository at this point in the history
  • Loading branch information
parkiino committed Apr 10, 2020
1 parent 817c4bb commit bf65411
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -89,10 +89,12 @@ export const policyDetailsReducer: Reducer<PolicyDetailsState, AppAction> = (
}

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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) => {
Expand All @@ -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;
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/endpoint/public/applications/endpoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -112,7 +112,7 @@ export type PolicyDetailsState = Immutable<{
success: boolean;
error?: ServerApiError;
};
}>;
}

/**
* Endpoint Policy configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -206,9 +206,9 @@ export const PolicyDetails = React.memo(() => {
</h4>
</EuiText>
<EuiSpacer size="xs" />
<WindowsEventing />
<WindowsEvents />
<EuiSpacer size="l" />
<MacEventing />
<MacEvents />
</PageView>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +64,7 @@ export const MacEventing = React.memo(() => {
<EuiSpacer size="s" />
{checkboxes.map((item, index) => {
return (
<EventingCheckbox
<EventsCheckbox
name={item.name}
key={index}
setter={(config, checked) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,7 +60,7 @@ export const WindowsEventing = React.memo(() => {
<EuiSpacer size="s" />
{checkboxes.map((item, index) => {
return (
<EventingCheckbox
<EventsCheckbox
name={item.name}
key={index}
setter={(config, checked) =>
Expand Down

0 comments on commit bf65411

Please sign in to comment.