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

Migrate ProductProjection model #738

Merged
merged 6 commits into from
Jan 14, 2025

Conversation

CarlosCortizasCT
Copy link
Contributor

The ProductProjection model was one of the first ones we created when we started the initiative to remove local test data models from the MC frontend monorepo but we never got to actually use it.

Now that I was reviewing the pending work we have, I noticed we had this PR that was trying to address some issues related to this model but that was something we tried before the introduction of the new implementation patterns so I took the opportunity to start cleaning up the model and migrate it to the new patterns.

The main compatibility issue for this model to be usable was it had an incorrect preset name.

Copy link

changeset-bot bot commented Jan 8, 2025

🦋 Changeset detected

Latest commit: bfa97b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 47 packages
Name Type
@commercetools-test-data/product Patch
@commercetools-test-data/commons Patch
@commercetools-test-data/product-projection Patch
@commercetools-test-data/cart Patch
@commercetools-test-data/inventory-entry Patch
@commercetools-test-data/standalone-price Patch
@commercetools-test-data/associate-role Patch
@commercetools-test-data/attribute-group Patch
@commercetools-test-data/business-unit Patch
@commercetools-test-data/cart-discount Patch
@commercetools-test-data/category Patch
@commercetools-test-data/channel Patch
@commercetools-test-data/custom-application Patch
@commercetools-test-data/custom-object Patch
@commercetools-test-data/custom-view Patch
@commercetools-test-data/customer-group Patch
@commercetools-test-data/customer Patch
@commercetools-test-data/customers-search-list-my-view Patch
@commercetools-test-data/discount-code Patch
@commercetools-test-data/discounts-custom-view Patch
@commercetools-test-data/order Patch
@commercetools-test-data/organization Patch
@commercetools-test-data/payment Patch
@commercetools-test-data/platform-limits Patch
@commercetools-test-data/product-discount Patch
@commercetools-test-data/product-selection Patch
@commercetools-test-data/product-type Patch
@commercetools-test-data/quote-request Patch
@commercetools-test-data/quote Patch
@commercetools-test-data/review Patch
@commercetools-test-data/shipping-method Patch
@commercetools-test-data/shopping-list Patch
@commercetools-test-data/staged-quote Patch
@commercetools-test-data/state Patch
@commercetools-test-data/store Patch
@commercetools-test-data/tax-category Patch
@commercetools-test-data/type Patch
@commercetools-test-data/user Patch
@commercetools-test-data/zone Patch
@commercetools-test-data/organization-extension Patch
@commercetools-test-data/project-extension Patch
@commercetools-test-data/core Patch
@commercetools-test-data/graphql-types Patch
@commercetools-test-data/filter-values Patch
@commercetools-test-data/project Patch
@commercetools-test-data/utils Patch
@commercetools-test-data/generators Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CarlosCortizasCT CarlosCortizasCT added 🚧 Status: WIP fe-chapter-rotation Tasks coming from frontend chapter work labels Jan 8, 2025
@CarlosCortizasCT CarlosCortizasCT self-assigned this Jan 8, 2025
Comment on lines +13 to +20
buildFields: ['obj'],
replaceFields: ({ fields }) => {
return {
...fields,
obj:
(fields.obj as TExpandedReferenceObject) || omit(fields, ['typeId']),
};
},
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 so we can forward to the obj object all the properties we potentially have received so, in case the model was populated with a reference object, the model instance has its properties.


it(
...createBuilderSpec<TProductProjection, TProductProjectionRest>(
...createBuilderSpec<TProductProjectionRest, TProductProjectionRest>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the default type test as we don't have it anymore.

@@ -0,0 +1,25 @@
import { createSpecializedBuilder } from '@commercetools-test-data/core';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Part of the migration of this model to use the new implementation patterns.

@@ -0,0 +1,131 @@
import { LocalizedString, Reference } from '@commercetools-test-data/commons';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Part of the migration of this model to use the new implementation patterns.

@@ -1,4 +1,14 @@
export { default as random } from './builder';
export { default as presets } from './presets';
import * as modelBuilders from './builders';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this model was not used yet, I'm not including the compat builder.

@@ -0,0 +1,52 @@
import { LocalizedString, Reference } from '@commercetools-test-data/commons';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Part of the migration of this model to use the new implementation patterns.

import type { TBuilder } from '@commercetools-test-data/core';
import { TState } from '@commercetools-test-data/state';
import { TTaxCategory } from '@commercetools-test-data/tax-category';
import type { TCtpProductProjection } from '@commercetools-test-data/graphql-types';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified the types by leveraging the generated GraphQL ones.

@@ -45,6 +45,7 @@ const transformers = {
(category) => ({
id: category.id,
typeId: 'category',
obj: category,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consumers (MC in the case I detected) were expecting the obj to be populated, which makes sense.

Copy link
Contributor

@kark kark left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me 👍
We need to add the changeset, right?

@CarlosCortizasCT
Copy link
Contributor Author

Thanks, looks good to me 👍 We need to add the changeset, right?

Thanks for the reminder, Kacper 🙇

Changesets added here: bfa97b0

@CarlosCortizasCT CarlosCortizasCT merged commit e374c6f into main Jan 14, 2025
4 checks passed
@CarlosCortizasCT CarlosCortizasCT deleted the cm/product-projection-migration branch January 14, 2025 16:40
@ct-changesets ct-changesets bot mentioned this pull request Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fe-chapter-rotation Tasks coming from frontend chapter work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants