-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Update useBreakpoints hook with EUI breakpoint deprecations
- since getBreakpoint is no longer an usable util - EUI's new breakpoint hooks already use/debounce window resize events, so we now get to skip all that custom logic by simply making custom EUI breakpoint overrides and using EUI breakpoint hooks - remove returned `breakpoint` and `width` keys - they weren't actually being used anywhere in APM that I could see and were causing type errors. - If someone wants to access them, they can use `useCurrentEuiBreakpoint` and `useWindowSize` individually instead
- Loading branch information
Showing
4 changed files
with
147 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 0 additions & 153 deletions
153
x-pack/plugins/apm/public/hooks/use_breakpoints.test.ts
This file was deleted.
Oops, something went wrong.
125 changes: 125 additions & 0 deletions
125
x-pack/plugins/apm/public/hooks/use_breakpoints.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { FC } from 'react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { EuiProvider } from '@elastic/eui'; | ||
import { useBreakpoints } from './use_breakpoints'; | ||
|
||
const wrapper: FC = ({ children }) => ( | ||
<EuiProvider | ||
modify={{ | ||
// set in apm/public/application/index.tsx | ||
breakpoint: { | ||
xxl: 1600, | ||
xxxl: 2000, | ||
}, | ||
}} | ||
> | ||
{children} | ||
</EuiProvider> | ||
); | ||
|
||
describe('useBreakpoints', () => { | ||
test('xs breakpoint', () => { | ||
window.innerWidth = 0; | ||
const { result } = renderHook(() => useBreakpoints(), { wrapper }); | ||
expect(result.current).toEqual({ | ||
isXSmall: true, | ||
isSmall: true, | ||
isMedium: true, | ||
isLarge: true, | ||
isXl: true, | ||
isXXL: true, | ||
isXXXL: false, | ||
}); | ||
}); | ||
|
||
test('s breakpoint', () => { | ||
window.innerWidth = 575; | ||
const { result } = renderHook(() => useBreakpoints(), { wrapper }); | ||
expect(result.current).toEqual({ | ||
isXSmall: false, | ||
isSmall: true, | ||
isMedium: true, | ||
isLarge: true, | ||
isXl: true, | ||
isXXL: true, | ||
isXXXL: false, | ||
}); | ||
}); | ||
|
||
test('m breakpoint', () => { | ||
window.innerWidth = 768; | ||
const { result } = renderHook(() => useBreakpoints(), { wrapper }); | ||
expect(result.current).toEqual({ | ||
isXSmall: false, | ||
isSmall: false, | ||
isMedium: true, | ||
isLarge: true, | ||
isXl: true, | ||
isXXL: true, | ||
isXXXL: false, | ||
}); | ||
}); | ||
|
||
test('l breakpoint', () => { | ||
window.innerWidth = 992; | ||
const { result } = renderHook(() => useBreakpoints(), { wrapper }); | ||
expect(result.current).toEqual({ | ||
isXSmall: false, | ||
isSmall: false, | ||
isMedium: false, | ||
isLarge: true, | ||
isXl: true, | ||
isXXL: true, | ||
isXXXL: false, | ||
}); | ||
}); | ||
|
||
test('xl breakpoint', () => { | ||
window.innerWidth = 1200; | ||
const { result } = renderHook(() => useBreakpoints(), { wrapper }); | ||
expect(result.current).toEqual({ | ||
isXSmall: false, | ||
isSmall: false, | ||
isMedium: false, | ||
isLarge: false, | ||
isXl: true, | ||
isXXL: true, | ||
isXXXL: false, | ||
}); | ||
}); | ||
|
||
test('xxl breakpoint', () => { | ||
window.innerWidth = 1600; | ||
const { result } = renderHook(() => useBreakpoints(), { wrapper }); | ||
expect(result.current).toEqual({ | ||
isXSmall: false, | ||
isSmall: false, | ||
isMedium: false, | ||
isLarge: false, | ||
isXl: false, | ||
isXXL: true, | ||
isXXXL: false, | ||
}); | ||
}); | ||
|
||
test('xxxl breakpoint', () => { | ||
window.innerWidth = 2000; | ||
const { result } = renderHook(() => useBreakpoints(), { wrapper }); | ||
expect(result.current).toEqual({ | ||
isXSmall: false, | ||
isSmall: false, | ||
isMedium: false, | ||
isLarge: false, | ||
isXl: false, | ||
isXXL: false, | ||
isXXXL: true, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters