Skip to content

Implemented: Added support for the Product Store selector from dxp-component and updated the package versions (#349)#359

Open
R-Sourabh wants to merge 6 commits into
hotwax:mainfrom
R-Sourabh:#349-product-store-identifier-fix
Open

Implemented: Added support for the Product Store selector from dxp-component and updated the package versions (#349)#359
R-Sourabh wants to merge 6 commits into
hotwax:mainfrom
R-Sourabh:#349-product-store-identifier-fix

Conversation

@R-Sourabh
Copy link
Copy Markdown
Contributor

Related Issues

#349

Short Description and Why It's Useful

  • Updated the dxp-component and oms-api versions from 1.20.0 → 1.22.1 and 1.14.0 → 1.20.0 respectively.
  • Also removed fetchGoodIdentificationTypes from the app level and started using it from dxp-component.
  • Added support for using the productStore selector on the settings page from the dxp-component.
  • Replaced the app-level productStore state and updated the logic to use the dxp-component for productStore state management.
  • Removed code related to storing/fetching productStores and currentProductStore in the application.
  • Utilized getters from the user store in dxp-components across the entire application.

Screenshots of Visual Changes before/after (If There Are Any)

Contribution and Currently Important Rules Acceptance

…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.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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 @hotwax/dxp-components library, the changes aim to reduce boilerplate code, improve consistency, and leverage shared functionalities. This migration simplifies the application's internal logic related to product store selection and data retrieval, making the codebase more maintainable and aligned with component library best practices.

Highlights

  • Dependency Updates: Upgraded @hotwax/dxp-components from 1.20.0 to 1.22.1 and @hotwax/oms-api from 1.14.0 to 1.20.0 to leverage the latest features and improvements.
  • Centralized Product Store Management: Migrated product store state management and selection logic to utilize the @hotwax/dxp-components library, removing redundant application-level code and centralizing this functionality.
  • Component Reuse: Integrated the DxpProductStoreSelector component from dxp-components into the settings page, replacing a custom implementation for product store selection.
  • API Call Refactoring: Replaced direct calls to fetchGoodIdentificationTypes and getEComStores from local services with their counterparts provided by the updated @hotwax/oms-api and dxp-components.
  • Simplified State Access: Updated various modules (job, order, product, stock, user) to use a new getProductStoreId utility function, which in turn uses useUserStore().getCurrentEComStore from dxp-components, streamlining access to the current product store ID.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/utils/index.ts
Comment on lines +38 to +41
const getProductStoreId = () => {
const currentEComStore: any = useUserStore().getCurrentEComStore;
return currentEComStore.productStoreId
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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.

Suggested change
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
};

Comment thread src/App.vue
await useProductIdentificationStore().getIdentificationPref(this.currentEComStore?.productStoreId)
.catch((error) => console.error(error));
if(this.userToken) {
const currentEComStore = useUserStore().getCurrentEComStore as any;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
const preferredStore: any = useUserStore().getCurrentEComStore
const preferredStore = useUserStore().getCurrentEComStore;

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.

1 participant