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

Hide the active workspace when moving a folder #2853

Merged

Conversation

gravyboat
Copy link
Contributor

Closes #2849

Before:
before

After:
after

This uses a flatMap which should have minimal impact on performance. I didn't see any tests for this specific component. If I missed them let me know and I can add some.

Copy link
Contributor

@develohpanda develohpanda left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! A couple of comments. 🎉

Comment on lines 95 to 103
{workspaces.flatMap(w =>
w._id === workspace._id ? (
[]
) : (
<option key={w._id} value={w._id}>
{w.name}
</option>
),
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing you didn't go down the workspaces.filter(...).map(...) route to avoid iterating through the array twice: 👏.

Is there a particular reason to use flatMap over map, though? If you use a map, you can simply return null in place of an empty array in the conditional.

Copy link
Contributor Author

@gravyboat gravyboat Nov 24, 2020

Choose a reason for hiding this comment

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

Is there a particular reason to use flatMap over map, though?

Not really other than personal preference. I don't like using null when I can avoid it and since it's already an array of workspaces here it seems more clear to provide an array. Performance wise it's nearly identical:
flatmap_v_map

Edit: If you prefer a map I can update it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's good to know! I don't really have a preference, I'm on board with avoiding null where possible, and I can see cases where flatMap will certainly be safer.

I feel that for the sake of consistency in this code-base (only one instance of flatMap), and the fact that React knows exactly what to do with a null, in this particular instance it might be better to stick with map. 🙂

Btw, what did you use to get that performance snapshot? Looks useful!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point about React knowing what to do with null for the conditional rendering. I didn't check to see if flatMap had been used elsewhere in the project and this being the only instance would be annoying for maintenance. I've updated the PR with this change. If things look good after that I'll squash the 3 commits in to one.

Btw, what did you use to get that performance snapshot? Looks useful!

It's https://jsbench.me, I wouldn't use it for anything large, but it's great for testing in these sorts of scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

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

We squash and merge PRs through GH, so no need to squash into a single commit 😊

@@ -12,6 +12,7 @@ import HelpTooltip from '../help-tooltip';

type Props = {
workspaces: Array<Workspace>,
workspace: Workspace,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this prop to be activeWorkspace to be clearer about what it represents. 🙂

Copy link
Contributor Author

@gravyboat gravyboat Nov 24, 2020

Choose a reason for hiding this comment

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

I considered this when making the PR but wasn't sure since it was labeled workspace in other instances, thanks for the clarification. This is now fixed for all references.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you're right, it is labeled simply workspace in other places. I don't know why... since it loses context. I'm not too concerned, but I think keeping context about what the workspace represents is useful for this particular case! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed!

Copy link
Contributor

@develohpanda develohpanda left a comment

Choose a reason for hiding this comment

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

Nicely done! 💯

@develohpanda develohpanda changed the title Hide the active workspace when moving a folder (#2849) Hide the active workspace when moving a folder Nov 24, 2020
@gravyboat
Copy link
Contributor Author

Did a quick merge in of the develop branch to get back up to date since I wasn't sure if you prefer that or a rebase since it will be squashed any way.

@develohpanda develohpanda merged commit c9173d3 into Kong:develop Nov 25, 2020
1 check passed
@gravyboat gravyboat deleted the feature/2849-hide-active-workspace branch November 25, 2020 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide the active workspace when moving a folder to a new workspace
3 participants