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

[7.9] [SECURITY] Bugs css/inspect (#74711) #74760

Merged
merged 1 commit into from
Aug 11, 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 @@ -42,6 +42,9 @@ const FormWrapper = styled.div`

padding-top: ${theme.eui.paddingSizes.xl};
padding-bottom: ${theme.eui.paddingSizes.xl};
.euiFlyout {
z-index: ${theme.eui.euiZNavigation + 1};
}
`}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ const FlexItem = styled(EuiFlexItem)`
`;
FlexItem.displayName = 'FlexItem';

const FlexGroup = styled(EuiFlexGroup)<{ $globalFullScreen: boolean }>`
${({ $globalFullScreen, theme }) => `
const FlexGroup = styled(EuiFlexGroup)<{ $globalFullScreen: boolean; $hasSibling: boolean }>`
${({ $globalFullScreen, $hasSibling, theme }) => `
border-bottom: ${theme.eui.euiBorderThin};
margin-bottom: 1px;
padding-bottom: 4px;
padding-left: ${theme.eui.paddingSizes.l};
padding-right: ${gutterTimeline};
${$globalFullScreen ? 'display: none;' : ''}
${$hasSibling ? `border-bottom: ${theme.eui.euiBorderThin};` : 'border-bottom-width: 0px;'}
`}
`;
FlexGroup.displayName = 'FlexGroup';
Expand All @@ -75,6 +76,7 @@ export const HeaderGlobal = React.memo<HeaderGlobalProps>(({ hideDetectionEngine
<FlexGroup
alignItems="center"
$globalFullScreen={globalFullScreen}
$hasSibling={globalHeaderPortalNode.hasChildNodes()}
justifyContent="spaceBetween"
wrap
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const StatefulTopNComponent: React.FC<Props> = ({
value,
}) => {
const kibana = useKibana();
const { from, deleteQuery, setQuery, to } = useGlobalTime();
const { from, deleteQuery, setQuery, to } = useGlobalTime(false);

const options = getOptions(
timelineId === TimelineId.active ? activeTimelineEventType : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import { act, renderHook } from '@testing-library/react-hooks';

import { useGlobalTime } from '.';

const mockDispatch = jest.fn();

jest.mock('react-redux', () => {
const originalModule = jest.requireActual('react-redux');

return {
...originalModule,
useDispatch: jest.fn().mockReturnValue(jest.fn()),
useDispatch: () => mockDispatch,
useSelector: jest.fn().mockReturnValue({ from: 0, to: 0 }),
};
});

describe('useGlobalTime', () => {
beforeEach(() => {
mockDispatch.mockReset();
});
test('returns memoized value', () => {
const { result, rerender } = renderHook(() => useGlobalTime());

Expand All @@ -30,4 +35,18 @@ describe('useGlobalTime', () => {
expect(result1.from).toBe(0);
expect(result1.to).toBe(0);
});

test('clear all queries at unmount', () => {
const { rerender } = renderHook(() => useGlobalTime());
act(() => rerender());
expect(mockDispatch.mock.calls[0][0].type).toEqual(
'x-pack/security_solution/local/inputs/DELETE_ALL_QUERY'
);
});

test('do NOT clear all queries at unmount', () => {
const { rerender } = renderHook(() => useGlobalTime(false));
act(() => rerender());
expect(mockDispatch.mock.calls.length).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { inputsSelectors } from '../../store';
import { inputsActions } from '../../store/actions';
import { SetQuery, DeleteQuery } from './types';

export const useGlobalTime = () => {
export const useGlobalTime = (clearAllQuery: boolean = true) => {
const dispatch = useDispatch();
const { from, to } = useSelector(inputsSelectors.globalTimeRangeSelector);
const [isInitializing, setIsInitializing] = useState(true);
Expand All @@ -32,9 +32,11 @@ export const useGlobalTime = () => {
setIsInitializing(false);
}
return () => {
dispatch(inputsActions.deleteAllQuery({ id: 'global' }));
if (clearAllQuery) {
dispatch(inputsActions.deleteAllQuery({ id: 'global' }));
}
};
}, [dispatch, isInitializing]);
}, [clearAllQuery, dispatch, isInitializing]);

const memoizedReturn = useMemo(
() => ({
Expand Down