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

Added real swatch color resolves #1633 #2151

Merged
merged 10 commits into from
May 7, 2020

Conversation

deiserh
Copy link
Contributor

@deiserh deiserh commented Feb 8, 2020

Description

Changed the random color of the swatch to the real one.

Related Issue

Closes #1633 .

Verification Steps

  1. Go to a configurable product.
  2. The colors of the swatches are the real ones.

Checklist

  • I have updated tests to cover my changes.

Compatibility

With Magento 2.3.5 or higher

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Feb 8, 2020

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).

Generated by 🚫 dangerJS against 409787c

@deiserh
Copy link
Contributor Author

deiserh commented Feb 8, 2020

What should I do regarding node failed?

Copy link
Member

@larsroettig larsroettig left a comment

Choose a reason for hiding this comment

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

@zetlen looks very nice

@m2-community-project m2-community-project bot moved this from Ready for Review to Reviewer Approved in Pull Request Progress Feb 8, 2020
@jimbo
Copy link
Contributor

jimbo commented Feb 11, 2020

Awesome. Looks like a good, straightforward implementation.

Does GQL always return a single hex color? Can it return multiple colors or an image?

@sirugh
Copy link
Contributor

sirugh commented Feb 11, 2020

What should I do regarding node failed?

Run the validate-queries script locally. See if the output indicates the failure reason. If you need help after that, let us know.

That said, it seems like the deployed version does not have a swatch property on graphql. Has that feature been released?

@larsroettig
Copy link
Member

larsroettig commented Feb 11, 2020

Awesome. Looks like a good, straightforward implementation.

Does GQL always return a single hex color? Can it return multiple colors or an image?

Hi @jimbo,
your are correct image is allowed see: https://docs.magento.com/m2/ce/user_guide/catalog/swatch-create.html

For Hex color you can only have one by default.

I will test this Ticket tomorrow with an image swatch and update this comment if it is
working.

@jimbo you are correct can be also a string of the image

                {
                  "default_label": "Latte",
                  "label": "Latte",
                  "store_label": "Latte",
                  "use_default_value": true,
                  "value_index": 15,
                  "swatch_data": {
                    "value": "#C0a890"
                  }
                },
                {
                  "default_label": "Jeans",
                  "label": "Jeans",
                  "store_label": "Jeans",
                  "use_default_value": true,
                  "value_index": 66,
                  "swatch_data": {
                    "value": "/j/e/jeans.jpg"
                  }

What I recommend making sure if a picture does not break the logic and create new ticket in the backlog

best regards,

Lars

Copy link
Member

@larsroettig larsroettig left a comment

Choose a reason for hiding this comment

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

Image swatch can break this logic see my comment

Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

Please try to resolve the error that is thrown on the deployed PR page:

https://pr-2151.pwa-venia.com/venia-dresses.html

@m2-community-project m2-community-project bot moved this from Reviewer Approved to Changes Requested in Pull Request Progress Feb 18, 2020
@deiserh
Copy link
Contributor Author

deiserh commented Feb 18, 2020

I Updated the Pull Request the error of validate-queries is that some functions are depricated and the Magento Version should be between 2.3.3-2.3.4 but the swatch graphql api was introduced in 2.3.5.

I also added a fallback to empty if no swatch is available.

@sirugh
Copy link
Contributor

sirugh commented Feb 20, 2020

the swatch graphql api was introduced in 2.3.5.

Ah, there is the problem. We develop against the latest released version ie 2.3.4, so this will cause our CI to start failing if we merge it as is.

This may be a good use case for the new extensibility framework though I don't think we have published our docs for it. If you urgently need this feature in your own line of work I would suggest making the change on your own fork for now.

If you want to see how we implemented page builder as an extension, check out the packages/pagebuilder directory, specifically the intercept file and how it taps into richContentRenderers. I'd love to hear your thoughts on how we might approach implementing a 2.3.5 feature as an extension.

@zetlen
Copy link
Contributor

zetlen commented Mar 2, 2020

I think this PR is absolutely a candidate for core functionality; it should be our default swatch implementation, instead of the one that uses random colors!

This kind of thing can be implemented as an extension, but I think this changeset in particular should be merged (once 2.3.5 is out).

In the meantime, @deiserh, please maintain this code in your own fork and we'll merge it as soon as our CI is rebased on to 2.3.5.

larsroettig
larsroettig previously approved these changes Mar 31, 2020
Copy link
Member

@larsroettig larsroettig left a comment

Choose a reason for hiding this comment

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

As mentions from the code side, it looks we need to wait for
2.3.5 should be released on April 28, 2020. I maintain this branch regularly

@sirugh sirugh added the hold On hold until another condition is fulfilled. label Apr 20, 2020
@larsroettig larsroettig removed the hold On hold until another condition is fulfilled. label Apr 30, 2020
sirugh
sirugh previously requested changes May 4, 2020
Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

The selected image is broken. On develop the check appears over the color but on this branch the color turns white.

Image from Gyazo

Image from Gyazo

@@ -1,6 +1,6 @@
.root {
composes: root from './tile.css';
background-color: rgb(var(--venia-swatch-bg));
background: var(--venia-swatch-bg);
Copy link
Contributor

Choose a reason for hiding this comment

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

The background property is shorthand and allows us to use a single variable to provide either the URL or the color.

Signed-off-by: sirugh <rugh@adobe.com>
@@ -21,7 +21,8 @@ const joinUrls = (base, url) =>

const mediaBases = new Map()
.set('image-product', 'catalog/product/')
.set('image-category', 'catalog/category/');
.set('image-category', 'catalog/category/')
.set('image-swatch', 'attribute/swatch');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this where swatch images are served? I'd have to test this but I don't have a magento instance configured to try it out. @dpatil-magento do you know how to test this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've confirmed on my local that both image swatch value and thumbnail are in this path. value returns a relative path, while thumbnail returns an absolute path (which I think is less fragile to bad config).

Copy link
Contributor

@tjwiebell tjwiebell left a comment

Choose a reason for hiding this comment

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

The actual scope of this issue looks perfect 👌

The scope creep of image swatch is my only hang up. I would be willing to accept with some minor tweaks that would only really support square images. HMU if you need help getting your local setup with some swatches!

@@ -49,6 +49,9 @@ fragment ProductDetails on ProductInterface {
store_label
use_default_value
value_index
swatch_data {
value
Copy link
Contributor

@tjwiebell tjwiebell May 5, 2020

Choose a reason for hiding this comment

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

Magento already has an optimized thumbnail which I think would be better to use; this also gives you better indicator that its an image instead of color swatch. Apply same to other query.

Suggested change
value
... on ImageSwatchData {
thumbnail
}
value

@@ -21,7 +21,8 @@ const joinUrls = (base, url) =>

const mediaBases = new Map()
.set('image-product', 'catalog/product/')
.set('image-category', 'catalog/category/');
.set('image-category', 'catalog/category/')
.set('image-swatch', 'attribute/swatch');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.set('image-swatch', 'attribute/swatch');
.set('image-swatch', 'attribute/swatch/');

@@ -21,7 +21,8 @@ const joinUrls = (base, url) =>

const mediaBases = new Map()
.set('image-product', 'catalog/product/')
.set('image-category', 'catalog/category/');
.set('image-category', 'catalog/category/')
.set('image-swatch', 'attribute/swatch');
Copy link
Contributor

Choose a reason for hiding this comment

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

I've confirmed on my local that both image swatch value and thumbnail are in this path. value returns a relative path, while thumbnail returns an absolute path (which I think is less fragile to bad config).

// https://github.com/magento/pwa-studio/issues/1633
const randomColor = memoizedGetRandomColor(value_index);
let swatchValue;
const isImage = swatch_data && swatch_data.value.charAt(0) !== '#';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const isImage = swatch_data && swatch_data.value.charAt(0) !== '#';
const isImage = swatch_data && swatch_data.thumbnail;

const isImage = swatch_data && swatch_data.value.charAt(0) !== '#';

if (isImage) {
const imagePath = generateUrlFromContainerWidth(
Copy link
Contributor

@tjwiebell tjwiebell May 5, 2020

Choose a reason for hiding this comment

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

So, having provided feedback on image swatch, I'm a bit apprehensive to include it in this scope. If I use one of our 4x5 images this is the result as-is:
Screen Shot 2020-05-05 at 4 26 07 PM

This is the result if I use the optimized thumbnail from GraphQL:
Screen Shot 2020-05-05 at 4 26 53 PM

And finally if I change the implementation to hard-code width/height to the exact dimensions of these tiles (3rem/3rem or 48px/48px):
Screen Shot 2020-05-05 at 4 27 12 PM

We're making progress on not assuming every images aspect ratio, but a square box now forces us to actually support this natively. Would like the team's thoughts on this; but I'm going to propose we remove support for image swatch until we can support different aspect ratios.

I would be willing to accept this if we put in a comment that says you must upload swatch images with a 1x1 aspect ratio, and change implementation to this (only way I could get images to render correctly):

const imagePath = generateUrl(swatch_data.thumbnail, 'image-swatch')(48);

Screen Shot 2020-05-05 at 4 46 45 PM

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 going to propose we remove support for image swatch until we can support different aspect ratios.

I think that is fair. The initial scope of this ticket was to replace random color with the actual color.

However it does seem like swatch_data.value can be an image url. We still need to have a fall-back thing to display.

@sirugh
Copy link
Contributor

sirugh commented May 6, 2020

Upon further review it looks like this needs some more work to get the color filter swatches and the product edit swatches functional.

@sirugh
Copy link
Contributor

sirugh commented May 6, 2020

That said, we may have to remove the filter swatches because the aggregation response from the server does not include color values:

Image from Gyazo

Image from Gyazo

sirugh added 2 commits May 6, 2020 11:00
…ons from graphql do not include swatch values

Signed-off-by: sirugh <rugh@adobe.com>
@tjwiebell tjwiebell added the version: Minor This changeset includes functionality added in a backwards compatible manner. label May 6, 2020
Copy link
Contributor

@tjwiebell tjwiebell left a comment

Choose a reason for hiding this comment

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

Minor cleanup since you moved some logic around, but code works 👍

One small problem found testing; the selected state for images doesn't overlay the same as color. Please investigate.

Unselected:
Screen Shot 2020-05-06 at 3 03 35 PM
Selected:
Screen Shot 2020-05-06 at 2 47 07 PM

@@ -21,6 +21,9 @@ import { useSwatch } from '@magento/peregrine/lib/talons/ProductOptions/useSwatc
const getClassName = (name, isSelected, hasFocus) =>
`${name}${isSelected ? '_selected' : ''}${hasFocus ? '_focused' : ''}`;

// Swatches _must_ have a 1x1 aspect ratio to match the UI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Man, it'd be real cool if comments supported markdown 😂

} else {
swatchValue = swatch_data.value;
let finalStyle = style;
let swatchValue = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to inside the scope of if (swatch_data)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh oops :D

Copy link
Contributor

Choose a reason for hiding this comment

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

let finalStyle = style;
let swatchValue = '';
if (swatch_data) {
const isImage = swatch_data && swatch_data.thumbnail;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicky cleanup since you wrapped in if, sorry 😬I would almost try to simplify init of swatchValue to ternary if it doesn't look too gnarly.

Suggested change
const isImage = swatch_data && swatch_data.thumbnail;
const {thumbnail, value} = swatch_data;
if (thumbnail) { ... }

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea I can clean this up :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Err swatch_data could be undefined so I'll just try to handle this gracefully.

Copy link
Contributor

Choose a reason for hiding this comment

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

Resolved in 69386ab

Signed-off-by: sirugh <rugh@adobe.com>
Copy link
Contributor

@tjwiebell tjwiebell 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, looks great! And thank you @deiserh for the original contribution, sorry for the delay 🙂

@dpatil-magento dpatil-magento requested a review from sirugh May 7, 2020 18:31
@dpatil-magento dpatil-magento merged commit 76cf84b into magento:develop May 7, 2020
@m2-community-project m2-community-project bot moved this from Changes Requested to Done in Pull Request Progress May 7, 2020
@deiserh
Copy link
Contributor Author

deiserh commented May 8, 2020

Thank you for finalizing the pr 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Partner: TechDivision partners-contribution pkg:peregrine pkg:venia-ui version: Minor This changeset includes functionality added in a backwards compatible manner.
Development

Successfully merging this pull request may close these issues.

[feature]: Utilize graphql returned color for swatches
9 participants