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

(fix): set slugified title as permalink #5264

Merged
merged 8 commits into from Jul 26, 2019
Merged

Conversation

mpaktiti
Copy link
Contributor

@mpaktiti mpaktiti commented Jul 3, 2019

Resolves #4735
Impact: major
Type: bugfix

Issue

When you create a product, the permalink (handle) is set to a random ID instead of the slugified version of the title. This is happening because:

  • the code initially sets the handle to a random ID (in the meanwhile, the title is null)
  • when the title is set the handle is not updated because the condition doc.handle === doc._id is never true (the handle is set to a random ID, not the doc ID)

Steps to reproduce:

  1. Create a new product
  2. Observe that the handle is not a slugified version of the title
  3. Update the title -> the handle is not updated

Solution

I removed the doc.handle === doc._id condition. This way when the user sets a Title for the product, the handle is updated. I also removed the initial population with a random ID because I see no use for it.

Breaking changes

None

Testing

  1. Log in the Operator UI and create a product
  2. Both the Title and the Handle are null
  3. Set a Title for the product and tab to another field
  4. Notice how the Handle is updated to the title's slugified version
  5. Keep changing the Title and notice how the Handle keeps getting updated each time

@zenweasel
Copy link
Collaborator

@mpaktiti I think setting the handle temporarily is to handle the case where you would navigate out of the PDP and then click back again and the product you were editing would disappear because products are only accessible by handle so this newly created product would never be accessible. Can you double check that you haven't introduced a new bug around that scenario?

@mpaktiti
Copy link
Contributor Author

mpaktiti commented Jul 4, 2019

@zenweasel Steps followed:

  • Go to Products
  • Click Create product
  • Fill no info (both title and handle are null)
  • Click on Orders
  • Click back on Products -> I can see the product I created earlier (2nd row in the screenshot below)

Let me know if I didn't get the steps right.

Screenshot from 2019-07-04 15-42-59

@zenweasel
Copy link
Collaborator

Are you able to click back into that product? If so I think we're OK

@mpaktiti
Copy link
Contributor Author

mpaktiti commented Jul 5, 2019

@zenweasel Yes I can step back and edit it. The URL uses the product ID. For example, for an untitled product I created the URL is http://localhost:3000/operator/products/eMnJA25oWMGYP55zn and I can see in Mongo that eMnJA25oWMGYP55zn is the product's _id.

@zenweasel
Copy link
Collaborator

@mpaktiti You need to sign your commits when committing to the open source projects. Click on "details" next to the DCO check on how to rectify

@zenweasel
Copy link
Collaborator

@manueldelreal can you give this a quick test please?

Signed-off-by: Maria Paktiti <maria@reactioncommerce.com>
@@ -816,7 +814,7 @@ Meteor.methods({
// Should be a call similar to the line below.
[field]: createHandle(Reaction.getSlug(value), _id) // handle should be unique
};
} else if (field === "title" && doc.handle === doc._id) {
Copy link
Member

Choose a reason for hiding this comment

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

The purpose of this is to ensure that permalink isn't updated every time someone changes a title. With the removal of the ID being the default permalink, this is definitely less useful; however, there should be new check added for the existence of the permalink and block updates if it's set.

The permalink changing every time the title changes will cause broken links. If someone wants to break their permalink, they can do so from the field itself, and make whatever redirects they want in their storefront if necessary.

What I'd like to see from this is:

  • The permalink should be set the first time automatically based on the title.
  • The permalink doesn't update automatically with the title change if it's already set.
  • The permalink is manually updateable through the field, which it is now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @mikemurray , thanks for the feedback. One clarification about the first bullet point.

When we create a product the title is null. I'll have the permalink updated automatically only the first time the title is set by the user. Until then it will be null (and after the first update it will not be updated automatically again). Sounds good or should we populate it initially with a default value?

Copy link
Member

Choose a reason for hiding this comment

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

The permalink could be blank until the first update of the title. Products can't be published with a null title. Not sure about a null permalink, but the null title will make sure the permalink it set.

Copy link
Member

Choose a reason for hiding this comment

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

is this thread resolved? asking for a friend that needs to test this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@manueldelreal No it's not! I'll ping you once it's ready for testing.

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 changed this locally and this is the behavior I see:

  • Go to Products and create a new product. The title is not set yet and therefore the permalink is empty as well.

image

  • Set a value for title -> permalink is updated automatically

image

  • Update the title -> permalink is not updated automatically

image

  • Update the permalink manually -> update successful

image

However, if I delete the permalink manually and try to Publish, the system lets me do it. Should I add the same validation we have for Title and not allow them to publish if the permalink is null?
@mikemurray @zenweasel

Copy link
Contributor Author

@mpaktiti mpaktiti Jul 15, 2019

Choose a reason for hiding this comment

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

Actually the title validation is not on Publish, it doesn't let you delete it to start with:

image

Add the same for permalink?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to make the permalink required since it no-longer defaults to the product id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mikemurray Can you please review the changes I just pushed? Behaviour is the same as I described in my previous comment, plus if you try to delete the permalink you get this error:

image

@manueldelreal
Copy link
Member

@zenweasel @mpaktiti waiting on the conversation thread between @mikemurray and @mpaktiti to be resolved before testing this one with its final form.

cc @zenweasel

mpaktiti and others added 4 commits July 18, 2019 11:45
Signed-off-by: Maria Paktiti <maria.paktiti@gmail.com>
Signed-off-by: Maria Paktiti <maria.paktiti@gmail.com>
Signed-off-by: Maria Paktiti <maria.paktiti@gmail.com>
Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@manueldelreal manueldelreal left a comment

Choose a reason for hiding this comment

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

:shipit:

@mikemurray mikemurray merged commit 7662bab into develop Jul 26, 2019
@mikemurray mikemurray deleted the fix-4735-mpaktiti-catalog branch July 26, 2019 23:39
@kieckhafer kieckhafer mentioned this pull request Aug 2, 2019
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.

None yet

4 participants