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

feat(md): New option to display environments side by side #9269

Merged
merged 2 commits into from
Jun 4, 2021

Conversation

ranihorev
Copy link
Contributor

To better utilize large screens, I'm trying to display environments side by side. We might want to make it the default but, for now, users can pick their preferred view.

image

@ranihorev ranihorev changed the title feat(md): show envs side by side feat(md): New option to display environments side by side Jun 1, 2021
@ranihorev ranihorev force-pushed the md/side-by-side branch 4 times, most recently from 0187438 to 2762c60 Compare June 3, 2021 03:37
Comment on lines 7 to 23
React.useLayoutEffect(() => {
const debouncedResizeHandler = debounce(() => {
setDimension({ width: window.innerWidth, height: window.innerHeight });
}, delay);
if (isActive) {
window.addEventListener('resize', debouncedResizeHandler);
return () => window.removeEventListener('resize', debouncedResizeHandler);
} else {
return () => {};
}
}, [delay, isActive]);

React.useLayoutEffect(() => {
if (isActive) {
setDimension({ width: window.innerWidth, height: window.innerHeight });
}
}, [isActive]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to add comments describing what is going on here. Why are there two uses of useLayoutEffect and what does each one of them do? Also describe the purpose of delay and isActive. I can't quite figure out what they do within the context of this file.

Copy link
Contributor

@vigneshm vigneshm Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirmed offline that this is NOT used at all. So going to ignore it and look at the rest. Please remove this part before merging the PR.

}, delay);

if (isActive && ref.current) {
const observer = new ResizeObserver(debouncedResizeHandler);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL ResizeObserver.

Copy link
Contributor

@vigneshm vigneshm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state management and resize handler bits look good to me.

@ranihorev ranihorev added the ready to merge Reviewed and ready for merge label Jun 4, 2021
@mergify mergify bot merged commit 4d689b5 into spinnaker:master Jun 4, 2021
ranihorev pushed a commit that referenced this pull request Jun 4, 2021
4d689b5 feat(md): New option to display environments side by side (#9269)
ae43ad0 fix(nav): fix unsubscribe on unmount (#9285)
d998362 fix(md): properly redirect the old ui links to the new ui (#9287)
mergify bot pushed a commit that referenced this pull request Jun 4, 2021
4d689b5 feat(md): New option to display environments side by side (#9269)
ae43ad0 fix(nav): fix unsubscribe on unmount (#9285)
d998362 fix(md): properly redirect the old ui links to the new ui (#9287)
Copy link
Contributor

@christopherthielen christopherthielen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

// The goal of this hook is to store the value in an atom to be shared across the app but also update the local storage
const useEnvironmentDirection = () => {
const [direction, setDirection] = useRecoilState(environmentsDirectionState);
React.useLayoutEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a reason why useLayoutEffect would be appropriate here (as opposed to regular old useEffect). Can you explain?

Copy link
Contributor Author

@ranihorev ranihorev Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't think of a reason because there is no reason :)
Probably a left over...

const getElementDimensions = (ref: React.RefObject<HTMLElement>) =>
ref.current ? { width: ref.current.offsetWidth, height: ref.current.offsetHeight } : { width: 0, height: 0 };

export const useElementDimensions = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the filename should probably match the name of the hook

ref.current ? { width: ref.current.offsetWidth, height: ref.current.offsetHeight } : { width: 0, height: 0 };

export const useElementDimensions = ({
ref,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a style preference comment, not feedback per se

When an arg is "required" I prefer to pass it as a parameter, not as part of an object. i.e., I would have probably written this as:

export const useElementDimension = (ref: ..., options: ...) => 

ranihorev pushed a commit to ranihorev/deck that referenced this pull request Jun 4, 2021
ranihorev pushed a commit to ranihorev/deck that referenced this pull request Jun 4, 2021
ranihorev pushed a commit that referenced this pull request Jun 4, 2021
33708ee feat(md): change the deploying state blinking green instead of teal (#9291)
995d622 feat(md): set the new UI as the default one, and allow users to opt out (#9290)
3bb4ffe feat(md): show delivery config yml in the configuration tab (#9286)
75a3a25 fix(md): minor improvements based on feedback from #9269 (#9289)
mergify bot pushed a commit that referenced this pull request Jun 4, 2021
33708ee feat(md): change the deploying state blinking green instead of teal (#9291)
995d622 feat(md): set the new UI as the default one, and allow users to opt out (#9290)
3bb4ffe feat(md): show delivery config yml in the configuration tab (#9286)
75a3a25 fix(md): minor improvements based on feedback from #9269 (#9289)
@ranihorev ranihorev deleted the md/side-by-side branch June 10, 2021 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Reviewed and ready for merge target-release/1.27
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants