Skip to content

Commit

Permalink
solid changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller committed Apr 9, 2020
1 parent 3d9e34c commit c12e150
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@
* 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';
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;
Expand Down Expand Up @@ -52,5 +51,12 @@ export const EventingCheckbox = React.memo(function<
[dispatch, os, policyDetailsConfig, protectionEvent, protectionField]
);

return <EuiCheckbox id={id} label={name} checked={selected} onChange={handleCheckboxChange} />;
return (
<EuiCheckbox
id={useMemo(() => htmlIdGenerator()(), [])}
label={name}
checked={selected}
onChange={handleCheckboxChange}
/>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const WindowsEventing = React.memo(() => {
[]
);

const renderCheckboxes = () => {
const renderCheckboxes = useMemo(() => {
return (
<>
<EuiTitle size="xxs">
Expand All @@ -63,7 +63,6 @@ export const WindowsEventing = React.memo(() => {
{checkboxes.map((item, index) => {
return (
<EventingCheckbox
id={`eventing${item.name}`}
name={item.name}
key={index}
os={item.os}
Expand All @@ -74,9 +73,9 @@ export const WindowsEventing = React.memo(() => {
})}
</>
);
};
}, [checkboxes]);

const collectionsEnabled = () => {
const collectionsEnabled = useMemo(() => {
return (
<EuiText size="s" color="subdued">
<FormattedMessage
Expand All @@ -86,19 +85,22 @@ export const WindowsEventing = React.memo(() => {
/>
</EuiText>
);
};
}, [selected, total]);

return (
<ConfigForm
type={i18n.translate('xpack.endpoint.policy.details.eventCollection', {
defaultMessage: 'Event Collection',
})}
supportedOss={[
i18n.translate('xpack.endpoint.policy.details.windows', { defaultMessage: 'Windows' }),
]}
supportedOss={useMemo(
() => [
i18n.translate('xpack.endpoint.policy.details.windows', { defaultMessage: 'Windows' }),
],
[]
)}
id="windowsEventingForm"
rightCorner={collectionsEnabled()}
children={renderCheckboxes()}
children={renderCheckboxes}
/>
);
});

0 comments on commit c12e150

Please sign in to comment.