Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding useMemo #63504

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +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 { ImmutableArray } from '../../../../../../../common/types';
import { getIn, setIn } from '../../../../models/policy_details_config';
import { EventsCheckbox } from './checkbox';
import { OS, UIPolicyConfig } from '../../../../types';
import { usePolicyDetailsSelector } from '../../policy_hooks';
import { selectedLinuxEvents, totalLinuxEvents } from '../../../../store/policy_details/selectors';
import { ConfigForm } from '../config_form';
import { getIn, setIn } from '../../../../models/policy_details_config';

export const LinuxEvents = React.memo(() => {
const selected = usePolicyDetailsSelector(selectedLinuxEvents);
const total = usePolicyDetailsSelector(totalLinuxEvents);

const checkboxes: Array<{
const checkboxes: ImmutableArray<{
name: string;
os: 'linux';
protectionField: keyof UIPolicyConfig['linux']['events'];
Expand Down Expand Up @@ -50,7 +51,7 @@ export const LinuxEvents = React.memo(() => {
[]
);

const renderCheckboxes = () => {
const renderCheckboxes = useMemo(() => {
return (
<>
<EuiTitle size="xxs">
Expand All @@ -76,9 +77,9 @@ export const LinuxEvents = React.memo(() => {
})}
</>
);
};
}, [checkboxes]);

const collectionsEnabled = () => {
const collectionsEnabled = useMemo(() => {
return (
<EuiText size="s" color="subdued">
<FormattedMessage
Expand All @@ -88,19 +89,20 @@ export const LinuxEvents = 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.linux', { defaultMessage: 'Linux' }),
]}
id="linuxEventingForm"
rightCorner={collectionsEnabled()}
children={renderCheckboxes()}
supportedOss={useMemo(
() => [i18n.translate('xpack.endpoint.policy.details.linux', { defaultMessage: 'Linux' })],
[]
)}
id="linuxEventsForm"
rightCorner={collectionsEnabled}
children={renderCheckboxes}
/>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +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 { ImmutableArray } from '../../../../../../../common/types';
import { getIn, setIn } from '../../../../models/policy_details_config';
import { EventsCheckbox } from './checkbox';
import { OS, UIPolicyConfig } from '../../../../types';
import { usePolicyDetailsSelector } from '../../policy_hooks';
import { selectedMacEvents, totalMacEvents } from '../../../../store/policy_details/selectors';
import { ConfigForm } from '../config_form';
import { getIn, setIn } from '../../../../models/policy_details_config';

export const MacEvents = React.memo(() => {
const selected = usePolicyDetailsSelector(selectedMacEvents);
const total = usePolicyDetailsSelector(totalMacEvents);

const checkboxes: Array<{
const checkboxes: ImmutableArray<{
name: string;
os: 'mac';
protectionField: keyof UIPolicyConfig['mac']['events'];
Expand Down Expand Up @@ -50,7 +51,7 @@ export const MacEvents = React.memo(() => {
[]
);

const renderCheckboxes = () => {
const renderCheckboxes = useMemo(() => {
return (
<>
<EuiTitle size="xxs">
Expand All @@ -76,9 +77,9 @@ export const MacEvents = React.memo(() => {
})}
</>
);
};
}, [checkboxes]);

const collectionsEnabled = () => {
const collectionsEnabled = useMemo(() => {
return (
<EuiText size="s" color="subdued">
<FormattedMessage
Expand All @@ -88,19 +89,20 @@ export const MacEvents = 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.mac', { defaultMessage: 'Mac' }),
]}
id="macEventingForm"
rightCorner={collectionsEnabled()}
children={renderCheckboxes()}
supportedOss={useMemo(
() => [i18n.translate('xpack.endpoint.policy.details.mac', { defaultMessage: 'Mac' })],
[]
)}
id="macEventsForm"
rightCorner={collectionsEnabled}
children={renderCheckboxes}
/>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import React, { useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui';
import { ImmutableArray } from '../../../../../../../common/types';
import { setIn, getIn } from '../../../../models/policy_details_config';
import { EventsCheckbox } from './checkbox';
import { OS, UIPolicyConfig } from '../../../../types';
import { usePolicyDetailsSelector } from '../../policy_hooks';
Expand All @@ -16,13 +18,12 @@ import {
totalWindowsEvents,
} from '../../../../store/policy_details/selectors';
import { ConfigForm } from '../config_form';
import { setIn, getIn } from '../../../../models/policy_details_config';

export const WindowsEvents = React.memo(() => {
const selected = usePolicyDetailsSelector(selectedWindowsEvents);
const total = usePolicyDetailsSelector(totalWindowsEvents);

const checkboxes: Array<{
const checkboxes: ImmutableArray<{
name: string;
os: 'windows';
protectionField: keyof UIPolicyConfig['windows']['events'];
Expand Down Expand Up @@ -132,7 +133,7 @@ export const WindowsEvents = React.memo(() => {
],
[]
)}
id="windowsEventingForm"
id="windowsEventsForm"
rightCorner={collectionsEnabled}
children={renderCheckboxes}
/>
Expand Down