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

feat: add product card [MONET-1338] #4534

Merged
merged 31 commits into from
Aug 30, 2023
Merged

Conversation

marcolink
Copy link
Member

@marcolink marcolink commented Aug 17, 2023

Purpose

Introduce a new design for the product card.

Approach

To not enforce this change from the start, we allow consumers to opt-in to the new version of the ProductCard.
Alternatively, we could release with a major version bump.

As foundation for the new ProductCard, the same component has been copied over from the ecommerce app, and changed to our needs.

We will also allow to render additional data (provider specific) from the consumer directly, by implementing an additionalDataRenderer Function on the Integration object.

We ship with two predefined renderer for additional data:

  • RawDataRenderer renders any object as JSON string
  • MetaDataRenderer renders a grey box with columns and data items

Testing steps

Since there is currently no consumer for this, but we build a new storybook instance on every build, a link can be found in the PR comments.

Screenshot 2023-08-17 at 18 02 08 Screenshot 2023-08-17 at 18 02 19 Screenshot 2023-08-17 at 18 02 29 Screenshot 2023-08-17 at 18 02 45

The screenshots are just meant to be examples. design is still changing - ideally, we deploy a PR based storybook instance on every push, to allow faster validations of changes.

How it works:

import {Integration, MetaDataRenderer, Product, setup} from '@contentful/ecommerce-app-base'

type CustomProduct = Product  & {
    productStatus: 'available' | 'out-of-stock'
}

const integration: Integration<CustomProduct> = {
    // the normal configuration here ...

    // opt-in to the new product card
    productCardVersion: 'v2',

    // implement your own renderer for additional data
    additionalDataRenderer: ({ product }) => {
        return <MetaDataRenderer columns={[{
                title: 'Additional product info',
                items: [ {
                    name: 'Status',
                    value: product.productStatus
                    }
                ]
            }
        ]} />
    }
}

// setup the app
setup(integration)

@marcolink marcolink changed the title feat/MONET 1338 add product card feat: add product card [MONET 1338] Aug 17, 2023
@marcolink marcolink changed the title feat: add product card [MONET 1338] feat: add product card [MONET-1338] Aug 17, 2023
@marcolink marcolink force-pushed the feat/MONET-1338-add-product-card branch from b65800b to bd09390 Compare August 17, 2023 17:22
Copy link
Contributor

@lilbitner lilbitner left a comment

Choose a reason for hiding this comment

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

Just some minor comments after reviewing the code! Looking great. For some odd reason when I spin up Storybook locally, it is only showing a handful of the components that you added (missing ProductCard etc). This could absolutely be a 'me' issue but wondering if I am missing a step (pulling down branch, install, and npm run storybook).

@marcolink marcolink force-pushed the feat/MONET-1338-add-product-card branch 2 times, most recently from 17e2655 to 1535b7e Compare August 22, 2023 05:58
@marcolink marcolink force-pushed the feat/MONET-1338-add-product-card branch from 1535b7e to e6d8a4d Compare August 22, 2023 06:02
@marcolink marcolink marked this pull request as ready for review August 22, 2023 06:42
@marcolink marcolink requested a review from a team as a code owner August 22, 2023 06:42
@marcolink marcolink requested a review from lilbitner August 22, 2023 06:42
@marcolink
Copy link
Member Author

Just some minor comments after reviewing the code! Looking great. For some odd reason when I spin up Storybook locally, it is only showing a handful of the components that you added (missing ProductCard etc). This could absolutely be a 'me' issue but wondering if I am missing a step (pulling down branch, install, and npm run storybook).

Thanks for your review 🙏
Did you try to delete your node_modules folders (git clean -dfx) ? This is what worked for me.

@marcolink marcolink requested a review from j-pea August 22, 2023 09:20
@netlify
Copy link

netlify bot commented Aug 22, 2023

Deploy Preview for ecommerce-app-base-components ready!

Name Link
🔨 Latest commit f5a4522
🔍 Latest deploy log https://app.netlify.com/sites/ecommerce-app-base-components/deploys/64eeee1683853c0008d2124e
😎 Deploy Preview https://deploy-preview-4534--ecommerce-app-base-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@marcolink marcolink force-pushed the feat/MONET-1338-add-product-card branch 2 times, most recently from f9b1512 to 828b5d0 Compare August 23, 2023 08:53
@marcolink marcolink force-pushed the feat/MONET-1338-add-product-card branch 2 times, most recently from e76a947 to 63951cf Compare August 23, 2023 10:04
@marcolink marcolink force-pushed the feat/MONET-1338-add-product-card branch from 63951cf to d279ea0 Compare August 23, 2023 13:07
Copy link
Contributor

@lilbitner lilbitner left a comment

Choose a reason for hiding this comment

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

This is looking great! Was able to look at everything in Storybook locally. Thank you for setting that up, as it makes for such easy visual and functional validation. I had a few minor comments and one more general question:

  1. What is the outlook on deprecating the v1 of the productCard? Are we looking to measure the success of v2 somehow and then deprecate the old one eventually? Just want to make sure we document this process if this falls to us to address eventually!
  2. Will there be documentation introduced within this package or the README to guide the user of the package for how to use v2 of the components?

packages/ecommerce-app-base/src/Editor/Field.tsx Outdated Show resolved Hide resolved
fireEvent(image, new Event('error'));
expect(image).not.toBeInTheDocument();
expect(getByTestId('asset-icon')).toBeInTheDocument();
});

it('should render successfully the error variation for missing product', async () => {
//
it.skip('should render successfully the error variation for missing product', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a specific reason that this test is skipped?

Copy link
Contributor

@anho anho left a comment

Choose a reason for hiding this comment

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

Great stuff, some minor comments+questions.

products: Product[];
};

export type ProductsFn = (
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
export type ProductsFn = (
export type FetchProductsFn = (

hasNextPage?: boolean;
};

type ProductsFnResponse = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to make this generic like this:

type FetchFnResponse<I> = {
  pagination: Pagination
  items: I[]
}

describe('A RawDataRenderer', () => {
it('provides a copy button', () => {
const { getByRole } = render(<RawDataRenderer value={VALUE} />);
const button = getByRole('button');
Copy link
Contributor

Choose a reason for hiding this comment

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

To make this more expressive this should include the a11y label besides the role.

products: P[];
};

export type ProductsFn<P extends Product = Product> = (
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
export type ProductsFn<P extends Product = Product> = (
export type FetchProductsFn<P extends Product = Product> = (

Comment on lines +22 to +25
type ProductsFnResponse<P extends Product = Product> = {
pagination: Pagination;
products: P[];
};
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
type ProductsFnResponse<P extends Product = Product> = {
pagination: Pagination;
products: P[];
};
type FetchFnResponse<Item = unknown> = {
pagination: Pagination;
items: Item[];
};

@marcolink marcolink requested a review from lilbitner August 25, 2023 14:23
Copy link
Contributor

@lilbitner lilbitner left a comment

Choose a reason for hiding this comment

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

Looks really great Marco! Thanks for putting so much thought and detail into this work, it really shows ✨ . Approving because code and local storybook looks awesome, but still curious about the following next-steps:

What is the outlook on deprecating the v1 of the productCard? Are we looking to measure the success of v2 somehow and then deprecate the old one eventually? Just want to make sure we document this process if this falls to us to address eventually!
Will there be documentation introduced within this package or the README to guide the user of the package for how to use v2 of the components?

Thanks in advance for final clarifications!

@marcolink
Copy link
Member Author

Looks really great Marco! Thanks for putting so much thought and detail into this work, it really shows ✨ . Approving because code and local storybook looks awesome, but still curious about the following next-steps:

What is the outlook on deprecating the v1 of the productCard? Are we looking to measure the success of v2 somehow and then deprecate the old one eventually? Just want to make sure we document this process if this falls to us to address eventually! Will there be documentation introduced within this package or the README to guide the user of the package for how to use v2 of the components?

Thanks in advance for final clarifications!

@lilbitner To have at least some visibility of the API changes, I have re-generated the local docs, and added a link to the storybook instance to the readme. For all other questions, we can use the doc I shared earlier with you :)

@marcolink marcolink merged commit 5e9fcf4 into master Aug 30, 2023
@marcolink marcolink deleted the feat/MONET-1338-add-product-card branch August 30, 2023 08:06
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.

3 participants