Skip to content

Conversation

@louwie17
Copy link
Contributor

@louwie17 louwie17 commented Oct 14, 2022

All Submissions:

Changes proposed in this Pull Request:

This allows users to create a new attribute if the name they are searching for doesn't exist within the attribute list.
This is currently dependent on #34999 to be merged, which is why it's pointing at that branch.

Kapture.2022-10-14.at.11.23.36.mp4

Address the creation part in #34331 .

How to test the changes in this Pull Request:

  1. Load this branch, build it, and make sure you have the new-product-management-experience feature flag enabled (you can do so using the latest version of the Beta tester within the mono repo).
  2. Go to Products > Add new (MVP) and fill out some of the initial details like name and price
  3. Scroll down and click Add first attribute in the attributes section
  4. Now write a random name in the attribute search field in the table, of an attribute that doesn't exist.
  5. The 'Create "your new attribute name"' should show as an option
  6. Click that and the new item should show as selected and the term field should focus
  7. With localStorage.setItem( 'debug', 'wc-admin:*' ); run prior, it should show that a product_attribute_add_custom_attribute has been fired.
  8. Start adding attribute terms, this dropdown should initial be blank and any text you put in will show up as a Create "text" option, allowing you to add several new items.
  9. Click Add the custom attribute should show correctly in the main list, now hit Update or Publish
  10. Go to old product editor and load the same product you just saved, check the attributes tab and make sure the custom one's show up correctly.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> run changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added focus: react admin release: highlight Issues that have a high user impact and need to be discussed/paid attention to. labels Oct 14, 2022
: null;

return (
<SelectControl< Pick< QueryProductAttribute, 'id' | 'name' > >
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just indented as I had to add a Fragment around this in order to add the create modal

@github-actions
Copy link
Contributor

github-actions bot commented Oct 14, 2022

Test Results Summary

Commit SHA: 9a7f07b

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests26000202620m 54s
E2E Tests186006019215m 28s

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.

@louwie17 louwie17 marked this pull request as ready for review October 17, 2022 16:23
@louwie17 louwie17 requested a review from a team October 17, 2022 16:23
@louwie17 louwie17 force-pushed the add/34331_add_attributes_modal branch from 8d5ce35 to 7420a10 Compare October 18, 2022 20:22
Base automatically changed from add/34331_add_attributes_modal to trunk October 19, 2022 19:28
@louwie17 louwie17 force-pushed the add/34331_create_attribute branch from 9f67bfd to 24d1302 Compare October 20, 2022 12:19
@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. and removed release: highlight Issues that have a high user impact and need to be discussed/paid attention to. labels Oct 20, 2022
@louwie17 louwie17 force-pushed the add/34331_create_attribute branch from 24d1302 to a27aec1 Compare November 1, 2022 18:59
@louwie17 louwie17 force-pushed the add/34331_create_attribute branch from 02a8b3f to db5bea2 Compare November 15, 2022 14:34
joshuatf
joshuatf previously approved these changes Nov 16, 2022
Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Very nice work, Lourens! Testing well on my end; left a few minor comments, but nothing blocking and pre-approving this PR.

Not a result of this PR, but I noticed a couple of oddities around styling:

  1. The modal appears off when editing an existing attribute

Screen Shot 2022-11-16 at 7 44 44 AM

  1. The loading indicator is slightly disorienting and jumpy, making it challenging to click an item while loading occurs. This loading indicator might be better as the select control's icon instead of in the list (cc @jarekmorawski). Though this may already be planned and blocked by the select control icon issue.

Screen Shot 2022-11-16 at 7 43 45 AM

};

function isEmptyItem(
item: HydratedAttributeType | { id: undefined }
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a partial of HydratedAttributeType or does it need to have a separate { id: undefined }?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to have a clear differentiator between when a attribute was set and when it wasn't. Using a Partial of HydratedAttributeType would make that a bit more difficult and we did have to manually check if all the attributes exist on that property to deem it as the HydratedAttributeType in several places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could potentially just try null, let me see if that works well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated it to using HydratedAttributeType | null so that things are more clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome!

options:
undefined,
}
typeof val ===
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 great to have this as a util method so we could also test it.

E.g., parseAttribute( val: string | Attribute )

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 suggestion, I did do this as part of the fd8af0d commit (it includes the other changes as well)

name: attribute.name,
options: [],
} );
if ( attribute.id === -99 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To reduce the number of attribute.id === -99 checks, maybe we could create a util method isNewAttribute( attribute ) that handles this check for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done as part of: 2dcbcd5

index +
'].terms',
{ isEmptyItem(
formAttr
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that formAttr was not added in this PR, but this confused me for a minute as I thought it was a "form attribute." Would attribute be a more accurate name? Or is there something special about these that is related to the form?

@jarekmorawski
Copy link

The loading indicator is slightly disorienting and jumpy, making it challenging to click an item while loading occurs. This loading indicator might be better as the select control's icon instead of in the list (cc @jarekmorawski). Though this may already be planned and blocked by the select control icon issue.

Definitely. The latest approach is to replace the search icon with a loading indicator, but we'll work on that as part of another issue.

@louwie17
Copy link
Contributor Author

@joshuatf this should be ready for re-review, I addressed all your changes.
Also in relation to the two issues you found:

The modal appears off when editing an existing attribute

This should be fixed now after the rebase as I fixed this as part of the create attribute PR -> #35132 (at-least I can't reproduce it anymore)

The loading indicator is slightly disorienting and jumpy, making it challenging to click an item while loading occurs. This loading indicator might be better as the select control's icon instead of in the list (cc @jarekmorawski). Though this may already be planned and blocked by the select control icon issue.

As @jarekmorawski mentioned this is blocked by the other issue in flight to allow us to move the loading indicator within the input field.

@louwie17 louwie17 requested a review from joshuatf November 17, 2022 12:27
joshuatf
joshuatf previously approved these changes Nov 18, 2022
Copy link
Contributor

@joshuatf joshuatf 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 changes, @louwie17! This is still testing well for me and changes look great.

Left one more comment about using refs instead of dom selectors for a possible follow-up issue. Otherwise, LGTM! 🚢

getItemProps={ getItemProps }
>
{ item.name }
{ item.id === -99 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

This could also use the new isNewAttributeListItem right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, not sure how I missed that, fixed here: 9a7f07b

setTimeout( () => {
setTimeout( () => {
const valueInputField: HTMLInputElement | null =
document.querySelector(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think ideally we could use a ref here instead of dom selectors, but we can save that for a follow-up issue as I know that wasn't really a part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah currently the SelectControl component doesn't allow us to pass in a ref, I could definitely add that though as a separate PR

};

function isEmptyItem(
item: HydratedAttributeType | { id: undefined }
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome!

@louwie17
Copy link
Contributor Author

@joshuatf could I get a re-review/approval I just updated the one last spot that needed to use the helper function.

Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Changes look good! LGTM :shipit:

@louwie17 louwie17 merged commit 7ec3210 into trunk Nov 21, 2022
@louwie17 louwie17 deleted the add/34331_create_attribute branch November 21, 2022 14:56
@github-actions github-actions bot added this to the 7.3.0 milestone Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants