|
| 1 | +--- |
| 2 | +"@bigcommerce/catalyst-core": patch |
| 3 | +--- |
| 4 | + |
| 5 | +Fix WishlistDetails page from exceeding GraphQL complexity limit, and fix wishlist e2e tests. |
| 6 | + |
| 7 | +Additionally, add the `required` prop to `core/components/wishlist/modals/new.tsx` and `core/components/wishlist/modals/rename.tsx` |
| 8 | + |
| 9 | +## Migration |
| 10 | + |
| 11 | +### Step 1: Update wishlist GraphQL fragments |
| 12 | + |
| 13 | +In `core/components/wishlist/fragment.ts`, replace the `WishlistItemProductFragment` to use explicit fields instead of `ProductCardFragment`: |
| 14 | + |
| 15 | +```typescript |
| 16 | +export const WishlistItemProductFragment = graphql( |
| 17 | + ` |
| 18 | + fragment WishlistItemProductFragment on Product { |
| 19 | + entityId |
| 20 | + name |
| 21 | + defaultImage { |
| 22 | + altText |
| 23 | + url: urlTemplate(lossy: true) |
| 24 | + } |
| 25 | + path |
| 26 | + brand { |
| 27 | + name |
| 28 | + path |
| 29 | + } |
| 30 | + reviewSummary { |
| 31 | + numberOfReviews |
| 32 | + averageRating |
| 33 | + } |
| 34 | + sku |
| 35 | + showCartAction |
| 36 | + inventory { |
| 37 | + isInStock |
| 38 | + } |
| 39 | + availabilityV2 { |
| 40 | + status |
| 41 | + } |
| 42 | + ...PricingFragment |
| 43 | + } |
| 44 | + `, |
| 45 | + [PricingFragment], |
| 46 | +); |
| 47 | +``` |
| 48 | + |
| 49 | +Remove `ProductCardFragment` from all fragment dependencies in the same file. |
| 50 | + |
| 51 | +### Step 2: Update product card transformer |
| 52 | + |
| 53 | +In `core/data-transformers/product-card-transformer.ts`: |
| 54 | + |
| 55 | +1. Import the `WishlistItemProductFragment`: |
| 56 | + ```typescript |
| 57 | + import { WishlistItemProductFragment } from '~/components/wishlist/fragment'; |
| 58 | + ``` |
| 59 | + |
| 60 | +2. Update the `singleProductCardTransformer` function signature to accept both fragment types: |
| 61 | + ```typescript |
| 62 | + product: ResultOf<typeof ProductCardFragment | typeof WishlistItemProductFragment> |
| 63 | + ``` |
| 64 | + |
| 65 | +3. Add a conditional check for the `inventoryMessage` field: |
| 66 | + ```typescript |
| 67 | + inventoryMessage: |
| 68 | + 'variants' in product |
| 69 | + ? getInventoryMessage(product, outOfStockMessage, showBackorderMessage) |
| 70 | + : undefined, |
| 71 | + ``` |
| 72 | + |
| 73 | +4. Update the `productCardTransformer` function signature similarly: |
| 74 | + ```typescript |
| 75 | + products: Array<ResultOf<typeof ProductCardFragment | typeof WishlistItemProductFragment>> |
| 76 | + ``` |
| 77 | + |
| 78 | +### Step 3: Fix wishlist e2e tests |
| 79 | + |
| 80 | +In `core/tests/ui/e2e/account/wishlists.spec.ts`, update label selectors to use `{ exact: true }` for specificity: |
| 81 | + |
| 82 | +Update all locators for the wishlist name input selectors: |
| 83 | + ```diff |
| 84 | + - page.getByLabel(t('Form.nameLabel')) |
| 85 | + + page.getByLabel(t('Form.nameLabel'), { exact: true }) |
| 86 | + ``` |
| 87 | + |
| 88 | +### Step 4: Fix mobile wishlist e2e tests |
| 89 | + |
| 90 | +In `core/tests/ui/e2e/account/wishlists.mobile.spec.ts`, update translation calls to use namespace prefixes: |
| 91 | + |
| 92 | +1. Update the translation initialization: |
| 93 | + ```diff |
| 94 | + - const t = await getTranslations('Account.Wishlist'); |
| 95 | + + const t = await getTranslations(); |
| 96 | + ``` |
| 97 | + |
| 98 | +2. Update all translation keys to include the namespace: |
| 99 | + ```diff |
| 100 | + - await locator.getByRole('button', { name: t('actionsTitle') }).click(); |
| 101 | + - await page.getByRole('menuitem', { name: t('share') }).click(); |
| 102 | + + await locator.getByRole('button', { name: t('Wishlist.actionsTitle') }).click(); |
| 103 | + + await page.getByRole('menuitem', { name: t('Wishlist.share') }).click(); |
| 104 | + ``` |
| 105 | + |
| 106 | + ```diff |
| 107 | + - await expect(page.getByText(t('shareSuccess'))).toBeVisible(); |
| 108 | + + await expect(page.getByText(t('Wishlist.shareSuccess'))).toBeVisible(); |
| 109 | + ``` |
| 110 | + |
| 111 | +### Step 5: Add `required` prop to wishlist modals |
| 112 | + |
| 113 | +Update the modal forms to include the `required` prop on the name input field: |
| 114 | + |
| 115 | +In `core/components/wishlist/modals/new.tsx`: |
| 116 | +```diff |
| 117 | + <Input |
| 118 | + {...getInputProps(fields.wishlistName, { type: 'text' })} |
| 119 | + defaultValue={defaultValue.current} |
| 120 | + errors={fields.wishlistName.errors} |
| 121 | + key={fields.wishlistName.id} |
| 122 | + label={nameLabel} |
| 123 | + onChange={(e) => { |
| 124 | + defaultValue.current = e.target.value; |
| 125 | + }} |
| 126 | ++ required |
| 127 | + /> |
| 128 | +``` |
| 129 | + |
| 130 | +In `core/components/wishlist/modals/rename.tsx`: |
| 131 | +```diff |
| 132 | + <Input |
| 133 | + {...getInputProps(fields.wishlistName, { type: 'text' })} |
| 134 | + defaultValue={defaultValue.current} |
| 135 | + errors={fields.wishlistName.errors} |
| 136 | + key={fields.wishlistName.id} |
| 137 | + label={nameLabel} |
| 138 | + onChange={(e) => { |
| 139 | + defaultValue.current = e.target.value; |
| 140 | + }} |
| 141 | ++ required |
| 142 | + /> |
| 143 | +``` |
| 144 | + |
0 commit comments