Implemented: Added support for the Product Store selector from dxp-component and updated the package versions (#349)#359
Conversation
…xp-component(#dxp/193)
…lication if no product stores are fetched(#dxp/193)
…→ 1.22.1 and 1.14.0 → 1.20.0 respectively (hotwax#349) - Also removed fetchGoodIdentificationTypes from the app level and started using it from dxp-component.
…wax#349-product-store-identifier-fix
Summary of ChangesHello @R-Sourabh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors how product store information is managed and accessed throughout the application. By upgrading core dependencies and centralizing product store state management within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the application to use the @hotwax/dxp-components for product store selection and state management, which is a great improvement for code centralization and maintainability. The package versions have been updated accordingly, and redundant code has been removed.
My review includes a few suggestions to enhance type safety by avoiding the use of any, which is a recurring pattern in the changes, and to improve error handling. There's also a critical point about a potential runtime error in a new utility function that should be addressed.
| const getProductStoreId = () => { | ||
| const currentEComStore: any = useUserStore().getCurrentEComStore; | ||
| return currentEComStore.productStoreId | ||
| }; |
There was a problem hiding this comment.
The currentEComStore is typed as any, which bypasses TypeScript's type safety. It's better to use a proper type, which might be available from @hotwax/dxp-components. Additionally, currentEComStore could be null or undefined if no store is selected, which would cause a runtime error when accessing productStoreId. Using optional chaining (?.) will prevent this.
| const getProductStoreId = () => { | |
| const currentEComStore: any = useUserStore().getCurrentEComStore; | |
| return currentEComStore.productStoreId | |
| }; | |
| const getProductStoreId = () => { | |
| // TODO: Consider importing the actual type for currentEComStore from dxp-components | |
| const currentEComStore: any = useUserStore().getCurrentEComStore; | |
| return currentEComStore?.productStoreId | |
| }; |
| await useProductIdentificationStore().getIdentificationPref(this.currentEComStore?.productStoreId) | ||
| .catch((error) => console.error(error)); | ||
| if(this.userToken) { | ||
| const currentEComStore = useUserStore().getCurrentEComStore as any; |
There was a problem hiding this comment.
Casting useUserStore().getCurrentEComStore to any should be avoided as it suppresses type checking. It's better to import the specific type from @hotwax/dxp-components if available, or let TypeScript infer it. This improves maintainability and prevents potential runtime errors.
const currentEComStore = useUserStore().getCurrentEComStore;
| store && (preferredStore = store) | ||
| } | ||
| userProfile.stores = await useUserStore().getEComStores() | ||
| if(!userProfile.stores.length) throw "Unable to login. User is not associated with any product store" |
There was a problem hiding this comment.
Throwing a string literal is not a best practice. It's better to throw an Error object, as it provides a stack trace and can be handled more robustly by error handling mechanisms.
| if(!userProfile.stores.length) throw "Unable to login. User is not associated with any product store" | |
| if(!userProfile.stores.length) throw new Error("Unable to login. User is not associated with any product store"); |
| } | ||
| userProfile.stores = await useUserStore().getEComStores() | ||
| if(!userProfile.stores.length) throw "Unable to login. User is not associated with any product store" | ||
| const preferredStore: any = useUserStore().getCurrentEComStore |
There was a problem hiding this comment.
Using : any for preferredStore bypasses TypeScript's type safety. It's recommended to import the specific type for the store object from @hotwax/dxp-components to ensure type safety and improve code clarity.
| const preferredStore: any = useUserStore().getCurrentEComStore | |
| const preferredStore = useUserStore().getCurrentEComStore; |
Related Issues
#349
Short Description and Why It's Useful
Screenshots of Visual Changes before/after (If There Are Any)
Contribution and Currently Important Rules Acceptance