-
-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: show all envs in project tables unless you've explicitly hidden …
…some (#6812) This PR changes the behavior of the project tables' environment columns based on input from customers. Up until now, you have been shown either the first project or the first three projects in the list of the project's environment. The decision on whether to show one or three is based on screen size. The breakpoint appears to be about 1280px. Above that you get three, below it you get one. With this PR, we'll show you *all* environments by default, regardless of screen size. However, that's just for the default values. If you manually change column visibility, those changes will of course be respected. I've used a new package, `css-mediaquery`, to test that all screen sizes show all envs.
- Loading branch information
1 parent
1a05bda
commit c9beb86
Showing
4 changed files
with
87 additions
and
3 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
74 changes: 74 additions & 0 deletions
74
.../project/Project/PaginatedProjectFeatureToggles/hooks/useDefaultColumnVisibility.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,74 @@ | ||
import theme from 'themes/theme'; | ||
import { screen } from '@testing-library/react'; | ||
import { useDefaultColumnVisibility } from './useDefaultColumnVisibility'; | ||
import { render } from 'utils/testRenderer'; | ||
import { ThemeProvider } from 'themes/ThemeProvider'; | ||
import mediaQuery from 'css-mediaquery'; | ||
|
||
const createMatchMedia = (width: number) => { | ||
return (query: string) => { | ||
return { | ||
matches: mediaQuery.match(query, { width }), | ||
media: '', | ||
addListener: () => {}, | ||
removeListener: () => {}, | ||
onchange: () => {}, | ||
addEventListener: () => {}, | ||
removeEventListener: () => {}, | ||
dispatchEvent: () => true, | ||
}; | ||
}; | ||
}; | ||
|
||
const resizeScreen = (width: number) => { | ||
window.matchMedia = createMatchMedia(width); | ||
}; | ||
|
||
const columnIds = [ | ||
'select', | ||
'favorite', | ||
'name', | ||
'createdAt', | ||
'lastSeenAt', | ||
'environment:development', | ||
'environment:production', | ||
'environment:dev2', | ||
'environment:prod2', | ||
'environment:staging', | ||
'environment:test', | ||
'actions', | ||
]; | ||
|
||
const TestComponent: React.FC = () => { | ||
const columns = useDefaultColumnVisibility(columnIds); | ||
|
||
return ( | ||
<ThemeProvider> | ||
<ul data-testid='wrapper'> | ||
{Object.keys(columns).map((column) => ( | ||
<li key={column}>{column}</li> | ||
))} | ||
</ul> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
test.each(Object.keys(theme.breakpoints.values))( | ||
'it renders all envs on %s screens', | ||
(screenSize) => { | ||
resizeScreen( | ||
theme.breakpoints.values[ | ||
screenSize as keyof typeof theme.breakpoints.values | ||
] + 1, | ||
); | ||
render(<TestComponent />); | ||
|
||
const allEnvs = columnIds.filter((column) => | ||
column.startsWith('environment:'), | ||
); | ||
|
||
for (const env of allEnvs) { | ||
screen.getByText(env); | ||
} | ||
}, | ||
); |
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
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 |
---|---|---|
|
@@ -2250,6 +2250,11 @@ | |
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5" | ||
integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA== | ||
|
||
"@types/css-mediaquery@^0.1.4": | ||
version "0.1.4" | ||
resolved "https://registry.yarnpkg.com/@types/css-mediaquery/-/css-mediaquery-0.1.4.tgz#8efbebbc0cebaf34c77db2b63892711e19143c63" | ||
integrity sha512-DZyHAz716ZUctpqkUU2COwUoZ4gI6mZK2Q1oIz/fvNS6XHVpKSJgDnE7vRxZUBn9vjJHDVelCVW0dkshKOLFsA== | ||
|
||
"@types/[email protected]": | ||
version "1.2.4" | ||
resolved "https://registry.yarnpkg.com/@types/debounce/-/debounce-1.2.4.tgz#cb7e85d9ad5ababfac2f27183e8ac8b576b2abb3" | ||
|
@@ -3366,6 +3371,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.3: | |
shebang-command "^2.0.0" | ||
which "^2.0.1" | ||
|
||
css-mediaquery@^0.1.2: | ||
version "0.1.2" | ||
resolved "https://registry.yarnpkg.com/css-mediaquery/-/css-mediaquery-0.1.2.tgz#6a2c37344928618631c54bd33cedd301da18bea0" | ||
integrity sha512-COtn4EROW5dBGlE/4PiKnh6rZpAPxDeFLaEEwt4i10jpDMFt2EhQGS79QmmrO+iKCHv0PU/HrOWEhijFd1x99Q== | ||
|
||
css-tree@^2.3.1: | ||
version "2.3.1" | ||
resolved "https://registry.yarnpkg.com/css-tree/-/css-tree-2.3.1.tgz#10264ce1e5442e8572fc82fbe490644ff54b5c20" | ||
|