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

CustomSelectControlV2: Rename for consistency #60178

Merged
merged 6 commits into from Mar 27, 2024
Merged

Conversation

mirka
Copy link
Member

@mirka mirka commented Mar 25, 2024

Part of #55023

What?

Renames CustomSelect and CustomSelectItem to the names we actually want to ship with:

  • CustomSelectControlV2
  • CustomSelectControlV2.Item

Why?

I have been discussing this with @ciampo and @brookewp, and we now have the guidelines documented in the Contributing guide.

We chose dot notation (Component.Subcomponent) over flat namespacing (ComponentSubcomponent) for better ergonomics on the consumer side, when doing things like unlocking private APIs and importing components with multiple subcomponents.

Testing Instructions

✅ Internal naming makes sense
✅ Documentation (readme and Storybook) is consistent

@mirka mirka added [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components labels Mar 25, 2024
@mirka mirka self-assigned this Mar 25, 2024
@mirka mirka requested a review from ajitbohra as a code owner March 25, 2024 17:00
@@ -26,4 +26,6 @@ export function CustomSelectItem( {
);
}

CustomSelectItem.displayName = 'CustomSelectControlV2.Item';
Copy link
Member Author

Choose a reason for hiding this comment

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

This was necessary to ensure that React devtools and the Storybook code snippet generator displays the intended name.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this shouldn't be necessary if we exported them like this (untested):

const CustomSelectControlV2 = CustomSelect;
CustomSelectControlV2.Item = Item;
export default CustomSelectControlV2;

which would be something similar to what we're doing with Tabs right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't seem to work, it looks like it just uses the name of the initial function no matter what.

And your comment made me realize that the Tabs subcomponents aren't showing the correct display names either 😅 I'll fix that.

Copy link

github-actions bot commented Mar 25, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@mirka mirka requested a review from a team March 25, 2024 17:04
packages/components/src/custom-select-control-v2/README.md Outdated Show resolved Hide resolved
packages/components/src/custom-select-control-v2/README.md Outdated Show resolved Hide resolved
packages/components/src/custom-select-control-v2/README.md Outdated Show resolved Hide resolved
packages/components/src/custom-select-control-v2/README.md Outdated Show resolved Hide resolved
@@ -1,5 +1,9 @@
/**
* Internal dependencies
*/
export { default as CustomSelect } from './default-component';
export { default as CustomSelectItem } from './custom-select-item';
import CustomSelect from './default-component';
Copy link
Member

Choose a reason for hiding this comment

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

Should we also use CustomSelectControlV2 here for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in 7b678d4

import CustomSelect from './default-component';
import Item from './item';

const CustomSelectControlV2 = Object.assign( CustomSelect, { Item } );
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to use Object.assign() rather than just do a direct assignment?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is necessary for TypeScript reasons because here the component is already exported once and "sealed" to new keys.

But I moved the assignment to the default-component file so it's a bit simpler and doesn't require the Object.assign (7b678d4).

@@ -26,4 +26,6 @@ export function CustomSelectItem( {
);
}

CustomSelectItem.displayName = 'CustomSelectControlV2.Item';
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this shouldn't be necessary if we exported them like this (untested):

const CustomSelectControlV2 = CustomSelect;
CustomSelectControlV2.Item = Item;
export default CustomSelectControlV2;

which would be something similar to what we're doing with Tabs right now.

@@ -12,7 +12,7 @@ import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import { CustomSelect as UncontrolledCustomSelect, CustomSelectItem } from '..';
import UncontrolledCustomSelectControl from '..';
Copy link
Member

Choose a reason for hiding this comment

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

Should we use UncontrolledCustomSelectControlV2 instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in bf056b6 👍

mirka and others added 4 commits March 27, 2024 06:14
# Conflicts:
#	packages/components/src/custom-select-control-v2/stories/legacy.story.tsx
Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
@mirka mirka requested a review from tyxla March 26, 2024 21:42
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! 🚀

@mirka mirka merged commit ab708fd into trunk Mar 27, 2024
60 checks passed
@mirka mirka deleted the rename-custom-select-v2 branch March 27, 2024 11:37
@github-actions github-actions bot added this to the Gutenberg 18.1 milestone Mar 27, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Mar 27, 2024
* CustomSelectControlV2: Rename for consistency

* Add changelog

* Improve naming consistency in tests

* Simply subcomponent composition and exports

* Apply suggestions to readme

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
cbravobernal pushed a commit to garridinsi/gutenberg that referenced this pull request Apr 9, 2024
* CustomSelectControlV2: Rename for consistency

* Add changelog

* Improve naming consistency in tests

* Simply subcomponent composition and exports

* Apply suggestions to readme

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants