-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add category field dropdown field #34400
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
Conversation
273c3bc to
17508af
Compare
Test Results SummaryCommit SHA: 9f4db44
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
cf93f27 to
03cb71e
Compare
4cd9913 to
ae76d8d
Compare
| box-sizing: border-box; | ||
| display: none; | ||
| z-index: 10; | ||
| margin-top: $gap-smaller; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly spacing it seems from spaces to tabs, this is what my prettier did. The only addition is:
z-index: 10;
margin-top: $gap-smaller;
| ); | ||
| if ( clearSearchOnSelect ) { | ||
| onInputChange( '' ); | ||
| setInputValue( '' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionally clear the input value upon selection.
Not sure if we want to separate InputBlur from this, and do clear in for that? I guess play around with it and see what feels natural.
| isOpen: keepMenuOpenOnSelect ? true : false, | ||
| highlightedIndex: state.highlightedIndex, | ||
| inputValue: '', | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to handle the keepMenuOpenOnSelect option
| getMenuProps: getMenuPropsType; | ||
| getToggleButtonProps: getToggleButtonPropsType; | ||
| selectItem: ( item: ItemType ) => void; | ||
| setInputValue: ( value: string ) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposed these extra functions from downshifts library.
| UPDATE_ITEM_ERROR = 'UPDATE_ITEM_ERROR', | ||
| UPDATE_ITEM_SUCCESS = 'UPDATE_ITEM_SUCCESS', | ||
| GET_ITEMS_TOTAL_COUNT_SUCCESS = 'GET_ITEMS_TOTAL_COUNT_SUCCESS', | ||
| GET_ITEMS_TOTAL_COUNT_ERROR = 'GET_ITEMS_TOTAL_COUNT_ERROR', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes within the crud data store revolve around adding the getItemsTotalCount support, it should be more or less self explanatory.
| @@ -0,0 +1,43 @@ | |||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple component that shows the Create "new category" item in the list.
| ) } | ||
| > | ||
| { children.map( ( child ) => ( | ||
| <CategoryFieldItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We continue to nest this element as long as the categories contains more children.
Allowing us to form the tree like data structure.
| const selectedIds = value.map( ( item ) => item.id ); | ||
| let selectControlItems = categoriesSelectList; | ||
| // Add the add new button if search value does not exist. | ||
| if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic might be slightly dirty, I wasn't sure what the other easier method would be, but this only handles adding or removing the Create "new category" item from the list.
| const selected = ( value || [] ).map( ( cat ) => ( { | ||
| value: cat.id.toString(), | ||
| label: cat.name, | ||
| } ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the SelectControl doesn't allow us to pass in any kind of object yet, so have to convert it to the value/label object it prefers.
| categoryTreeKeyValues[ | ||
| parseInt( item.value, 10 ) | ||
| ]?.parentID === 0 || | ||
| item.value === 'add-new' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order for the selection to work well and the keyboard selection. We had to pass in the entire list of categories to the component, this includes all the children as well.
But
We don't want to display all of them in the top list, so we filter out all the children here.
You can see that for the CategoryFieldItem we actually pass in:
categoryTreeKeyValues[
parseInt(
item.value,
10
)
]
This is for the same reason as above, this actually returns us a tree like object that contains children.
| value={ categoryName } | ||
| onChange={ setCategoryName } | ||
| /> | ||
| <SelectControl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This SelectControl should follow a similar format as the way it's used in category-field.tsx.
There is one main difference that we make use of Popover here to display the menu. This is in order to display the dropdown without part of it being hidden by the modal window.
I had to make use of <Popover.Slot /> for this also, this is set in category-field.tsx under the Modal component.
| @@ -0,0 +1,286 @@ | |||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the function comments should explain what this is doing, but this is a custom category search hook to encapsulate most of the logic surround the tree generation of categories, which includes a recursive function that would retrieve any missing parents if necessary.
This hook is both used in category-field.tsx and create-category-modal.tsx.
ac47ff2 to
940af37
Compare
940af37 to
f2ac82f
Compare
plugins/woocommerce-admin/client/products/fields/category-field/category-field-item.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce-admin/client/products/fields/category-field/category-field.tsx
Outdated
Show resolved
Hide resolved
f2ac82f to
5ee1b23
Compare
|
@mdperez86 thanks for the initial look, this should be ready for a re-review. |
9aaf42d to
36820dc
Compare
Move search logic to useCategorySearch hook Add initial add new category logic Add parent category field to add new category modal Adding some debug changes Update category control to make use of internal selectItem function of select control Add changelogs Update pagesize back to 100 Add placeholder Empty placeholder Fix input and icon sizes Fix input underline Add max height and scroll to category dropdown Add sorting of category items Auto open parents when traversing up the tree using arrow keys Add several comments Add some initial unit tests for the category field component Add tests for useCategorySearch hook and fixed minor bug Update styling and autoselect parent if child is selected Fix styling issues for the select control dropdown inside a modal Fix issue with creating new category with parent Add function comment and fixed border styling Prune out create new category logic Fix minor css issue with border Revert some of the select control changes and make use of the custom type Fix up some styling changes
36820dc to
9f4db44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a hard work here. Great job!!!
|
Hi @louwie17, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
All Submissions:
Changes proposed in this Pull Request:
Adds a new Category dropdown field that includes a nested tree for the categories.
Changes done as part of this
getItemsTotalCountto the crud data store, allowing us to use it for categories -getProductCategoriesTotalCountAddresses: #34029
Kapture.2022-09-02.at.14.52.41.mp4
How to test the changes in this Pull Request:
Should match these designs: 5sAIeTRd9Yp7nSCT33BAWz-fi-5175%3A105193
new-product-management-experiencefeature flag by using the WCA Test Helper (Tools > WCA Test Helper > Features) and refresh the page.Other information:
pnpm changelog add --filter=<project>?FOR PR REVIEWER ONLY: