-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move data changes to a plugin for better readability
- Loading branch information
1 parent
be6c5e1
commit 63657b1
Showing
6 changed files
with
34 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
...uct-configurable/components/ConfigurableShortDescription/ConfigurableShortDescription.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/magento-product-configurable/components/ConfigurableShortDescription/index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/magento-product-configurable/plugins/ConfigurableProductShortDescription.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { ProductShortDescriptionProps } from '@graphcommerce/magento-product' | ||
import type { PluginProps } from '@graphcommerce/next-config' | ||
import { ConfigurableOptionsFragment } from '../graphql/ConfigurableOptions.gql' | ||
import { useConfigurableOptionsSelection } from '../hooks' | ||
|
||
export const component = 'ProductShortDescription' | ||
export const exported = '@graphcommerce/magento-product' | ||
|
||
function ConfigurableProductShortDescription( | ||
props: PluginProps< | ||
ProductShortDescriptionProps & { product?: ConfigurableOptionsFragment; index?: number } | ||
>, | ||
) { | ||
const { Prev, product, index = 0, short_description, ...rest } = props | ||
const { configured } = useConfigurableOptionsSelection({ url_key: product?.url_key, index }) | ||
|
||
const isConfigurable = product?.__typename === 'ConfigurableProduct' | ||
|
||
const getConfigurableShortDescription = | ||
configured?.configurable_product_options_selection?.variant?.short_description | ||
const configurableShortDescription = | ||
isConfigurable && getConfigurableShortDescription?.html.length | ||
? getConfigurableShortDescription | ||
: short_description | ||
|
||
return <Prev {...rest} short_description={configurableShortDescription} /> | ||
} | ||
export const Plugin = ConfigurableProductShortDescription |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters