Skip to content

Commit

Permalink
Merge branch 'ts-migration' of github.com:scandipwa/scandipwa into es…
Browse files Browse the repository at this point in the history
…lint-fixes
  • Loading branch information
alfredsgenkins committed Sep 30, 2022
2 parents b20f95b + 623ea9f commit c5ca60f
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 75 deletions.
2 changes: 0 additions & 2 deletions build-packages/webpack-i18n-runtime/src/plugin/App.plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import I18nComponent from '../component/I18n';

import '../util/propTypesFix';

/** Ensure full application remount on locale change */
const render = (args, callback) => (
<I18nComponent>
Expand Down
17 changes: 1 addition & 16 deletions build-packages/webpack-i18n-runtime/src/util/__.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ function getTranslatedStringWithInjectedValues(string, values) {
return injectValues(translateString(string), ...values);
}

export class TranslatedValue extends String {
// Translate and inject values during the initialization
constructor(value, args = []) {
super(getTranslatedStringWithInjectedValues(value, args));

this.value = value;
this.injectables = args;
}

// Reload the translation each time toString() is called
toString() {
return getTranslatedStringWithInjectedValues(this.value, this.injectables);
}
}

export default function __(string, ...values) {
return new TranslatedValue(string, values);
return getTranslatedStringWithInjectedValues(string, values);
}
19 changes: 0 additions & 19 deletions build-packages/webpack-i18n-runtime/src/util/propTypesFix.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class Product<P extends ProductComponentProps = ProductComponentProps> ex

renderConfigurableOptions(): ReactElement {
const {
// setActiveProduct,
setActiveProduct,
parameters,
product: { type_id: type, variants = [] },
inStock,
Expand All @@ -182,7 +182,7 @@ export class Product<P extends ProductComponentProps = ProductComponentProps> ex
mix={ { block: this.className, elem: 'Attributes' } }
parameters={ parameters }
variants={ variants }
// updateConfigurableVariant={ setActiveProduct }
updateConfigurableVariant={ setActiveProduct }
configurable_options={ this.getConfigurableAttributes() }
isContentExpanded
inStock={ inStock }
Expand Down
19 changes: 12 additions & 7 deletions packages/scandipwa/src/component/Product/Product.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ import { validateGroup } from 'Util/Validator';

import {
AdjustedPriceMap,
ProductComponentContainerFunctions,
ProductComponentContainerPropKeys,
ConfigurableProductSelectedVariantValue,
ProductComponentProps,
ProductContainerFunctions,
ProductContainerMapDispatchProps,
ProductContainerMapStateProps,
ProductContainerPropKeys,
ProductContainerProps,
ProductContainerState,
ProductOption,
Expand Down Expand Up @@ -87,7 +88,7 @@ S extends ProductContainerState = ProductContainerState,
cartId: '',
};

containerFunctions: ProductComponentContainerFunctions = {
containerFunctions: ProductContainerFunctions = {
addToCart: this.addToCart.bind(this),

// Used to update entered and selected state values
Expand Down Expand Up @@ -225,7 +226,7 @@ S extends ProductContainerState = ProductContainerState,
}
}

containerProps(): Pick<ProductComponentProps, ProductComponentContainerPropKeys> {
containerProps(): Pick<ProductComponentProps, ProductContainerPropKeys> {
const {
quantity,
parameters,
Expand Down Expand Up @@ -467,8 +468,8 @@ S extends ProductContainerState = ProductContainerState,
const { showError } = this.props;

if (
errorFields
|| errorMessages
errorFields.length
|| errorMessages.length
|| this.validateConfigurableProduct()
|| this.filterAddToCartFileErrors(values)
) {
Expand Down Expand Up @@ -496,7 +497,11 @@ S extends ProductContainerState = ProductContainerState,
* @param key
* @param value
*/
updateConfigurableVariant(key: string, value: string, checkEmptyValue = false): void {
updateConfigurableVariant(
key: string,
value: ConfigurableProductSelectedVariantValue,
checkEmptyValue = false,
): void {
const { parameters: prevParameters } = this.state;

const newParameters = getNewParameters(prevParameters, key, value);
Expand Down
10 changes: 6 additions & 4 deletions packages/scandipwa/src/component/Product/Product.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ export interface ProductContainerState {
activeProduct: IndexedProduct | null;
}

export interface ProductComponentContainerFunctions {
export interface ProductContainerFunctions {
setQuantity: (quantity: ProductQuantity) => void;
addToCart: (options?: AddProductToCartOptions) => Promise<void>;
updateSelectedValues: (data?: Partial<ProductOption>) => void;
setAdjustedPrice: (type: keyof AdjustedPriceMap, amount: number) => void;
setDownloadableLinks: (links: string[]) => void;
updateAddToCartTriggeredWithError: () => void;
getActiveProduct: () => IndexedProduct;
setActiveProduct: (key: string, value: string, checkEmptyValue?: boolean) => void;
setActiveProduct: (key: string, value: ConfigurableProductSelectedVariantValue, checkEmptyValue?: boolean) => void;
getMagentoProduct: () => ProductTransformData[];
setValidator: (elem: HTMLElement) => void;
scrollOptionsIntoView: () => void;
}

export interface ProductComponentProps extends ProductComponentContainerFunctions {
export interface ProductComponentProps extends ProductContainerFunctions {
isWishlistEnabled: boolean;
unselectedOptions: string[];
quantity: ProductQuantity;
Expand All @@ -87,7 +87,7 @@ export interface ProductComponentProps extends ProductComponentContainerFunction
productPrice: Partial<ProductExtractPrice>;
}

export type ProductComponentContainerPropKeys =
export type ProductContainerPropKeys =
| 'isWishlistEnabled'
| 'unselectedOptions'
| 'quantity'
Expand Down Expand Up @@ -127,3 +127,5 @@ export interface ProductPrice {
minimum_price: Partial<PriceRange>;
maximum_price: Partial<PriceRange>;
}

export type ConfigurableProductSelectedVariantValue = string | number | boolean;
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { RootState } from 'Util/Store/Store.type';

import ProductActions from './ProductActions.component';
import {
ProductActionsComponentContainerFunctions,
ProductActionsComponentContainerPropKeys,
ProductActionsComponentProps,
ProductActionsContainerFunctions,
ProductActionsContainerMapStateProps,
ProductActionsContainerPropKeys,
ProductActionsContainerProps,
ProductActionsContainerState,
} from './ProductActions.type';
Expand All @@ -48,12 +48,12 @@ ProductActionsContainerState
> {
static defaultProps: Partial<ProductActionsContainerProps> = ProductContainer.defaultProps;

containerFunctions: ProductActionsComponentContainerFunctions = {
containerFunctions: ProductActionsContainerFunctions = {
...this.containerFunctions,
showOnlyIfLoaded: this.showOnlyIfLoaded.bind(this),
};

containerProps(): Pick<ProductActionsComponentProps, ProductActionsComponentContainerPropKeys> {
containerProps(): Pick<ProductActionsComponentProps, ProductActionsContainerPropKeys> {
const {
areDetailsLoaded,
areReviewsEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*/

import {
ProductComponentContainerFunctions,
ProductComponentContainerPropKeys,
ProductComponentProps,
ProductContainerBaseProps,
ProductContainerFunctions,
ProductContainerMapDispatchProps,
ProductContainerMapStateProps,
ProductContainerPropKeys,
ProductContainerProps,
ProductContainerState,
} from 'Component/Product/Product.type';
Expand Down Expand Up @@ -49,7 +49,7 @@ export type ProductActionsContainerProps = ProductContainerProps

export type ProductActionsContainerState = ProductContainerState;

export interface ProductActionsComponentContainerFunctions extends ProductComponentContainerFunctions {
export interface ProductActionsContainerFunctions extends ProductContainerFunctions {
showOnlyIfLoaded: (expression: boolean, content: ReactElement, placeholder?: ReactElement) => ReactElement;
}

Expand All @@ -69,7 +69,7 @@ export interface ProductActionsComponentProps extends ProductComponentProps {
isPricePreview: boolean;
}

export type ProductActionsComponentContainerPropKeys = ProductComponentContainerPropKeys
export type ProductActionsContainerPropKeys = ProductContainerPropKeys
| 'areDetailsLoaded'
| 'areReviewsEnabled'
| 'displayProductStockStatus'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ReactElement } from 'Type/Common.type';
import { noopFn } from 'Util/Common';
import { getBooleanLabel } from 'Util/Product';

import { AttributeType, STRING_ONLY_ATTRIBUTE_CODES } from './ProductAttributeValue.config';
import { AttributeType, SelectAttributeType, STRING_ONLY_ATTRIBUTE_CODES } from './ProductAttributeValue.config';
import { ProductAttributeValueComponentProps, ProductAttributeValueOption } from './ProductAttributeValue.type';

import './ProductAttributeValue.style';
Expand Down Expand Up @@ -159,11 +159,11 @@ export class ProductAttributeValue extends PureComponent<ProductAttributeValueCo
const { value, type } = swatch_data;

switch (type) {
case '0':
case SelectAttributeType.STRING:
return this.renderStringValue(value, labelText, count);
case '1':
case SelectAttributeType.COLOR:
return this.renderColorValue(value, label);
case '2':
case SelectAttributeType.IMAGE:
return this.renderImageValue(value, label);
default:
return this.renderStringValue(labelText || __('N/A'), labelText, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ export enum AttributeType {
TEXTAREA = 'textarea',
WEIGHT = 'weight',
}

export enum SelectAttributeType {
STRING = '0',
COLOR = '1',
IMAGE = '2',
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import { appendWithStoreCode, objectToUri } from 'Util/Url';

import ProductCard from './ProductCard.component';
import {
ProductCardComponentContainerPropKeys,
ProductCardComponentProps,
ProductCardContainerFunctions,
ProductCardContainerMapDispatchProps,
ProductCardContainerMapStateProps,
ProductCardContainerPropKeys,
ProductCardContainerProps,
ProductCartComponentContainerFunctions,
} from './ProductCard.type';

export const CartDispatcher = import(
Expand Down Expand Up @@ -73,12 +73,12 @@ export class ProductCardContainer extends ProductContainer<ProductCardContainerP
layout: CategoryPageLayout.GRID,
};

containerFunctions: ProductCartComponentContainerFunctions = {
containerFunctions: ProductCardContainerFunctions = {
...this.containerFunctions,
showSelectOptionsNotification: this.showSelectOptionsNotification.bind(this),
};

containerProps(): Pick<ProductCardComponentProps, ProductCardComponentContainerPropKeys> {
containerProps(): Pick<ProductCardComponentProps, ProductCardContainerPropKeys> {
const {
children,
mix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import { RefObject } from 'react';

import {
ProductComponentContainerFunctions,
ProductComponentContainerPropKeys,
ProductComponentProps,
ProductContainerBaseProps,
ProductContainerFunctions,
ProductContainerMapDispatchProps,
ProductContainerMapStateProps,
ProductContainerPropKeys,
} from 'Component/Product/Product.type';
import { CategoryPageLayout } from 'Route/CategoryPage/CategoryPage.config';
import { NotificationType } from 'Store/Notification/Notification.type';
Expand Down Expand Up @@ -51,7 +51,7 @@ export type ProductCardContainerProps = ProductCardContainerMapStateProps
& ProductCardContainerMapDispatchProps
& ProductCartContainerBaseProps;

export interface ProductCartComponentContainerFunctions extends ProductComponentContainerFunctions {
export interface ProductCardContainerFunctions extends ProductContainerFunctions {
showSelectOptionsNotification: () => void;
}

Expand All @@ -70,7 +70,7 @@ export interface ProductCardComponentProps extends ProductComponentProps {
isPlp: boolean;
}

export type ProductCardComponentContainerPropKeys = ProductComponentContainerPropKeys
export type ProductCardContainerPropKeys = ProductContainerPropKeys
| 'children'
| 'hideCompareButton'
| 'hideWishlistButton'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import { AnimationEvent } from 'react';

import { ConfigurableProductSelectedVariantValue } from 'Component/Product/Product.type';
import { StockStatus } from 'Component/Product/Stock.config';
import { ProductListFilter } from 'Store/ProductListInfo/ProductListInfo.type';
import { Merge, Mix } from 'Type/Common.type';
Expand All @@ -19,7 +20,7 @@ import { IndexedConfigurableOption, IndexedVariant } from 'Util/Product/Product.
export interface ProductConfigurableAttributesContainerProps {
getLink: (filterKey: string, value: string) => string;
parameters: Record<string, string | string[]>;
updateConfigurableVariant?: (requestVar: string, value: string | number | boolean) => void;
updateConfigurableVariant?: (requestVar: string, value: ConfigurableProductSelectedVariantValue) => void;
isExpandable: boolean;
showProductAttributeAsLink: boolean;
variants: IndexedVariant[];
Expand Down Expand Up @@ -51,7 +52,7 @@ export interface ProductConfigurableAttributesComponentProps
numberOfPlaceholders: number[];
parameters: Record<string, string | string[]>;
showProductAttributeAsLink: boolean;
updateConfigurableVariant?: (requestVar: string, value: string | number | boolean) => void;
updateConfigurableVariant?: (requestVar: string, value: ConfigurableProductSelectedVariantValue) => void;
inStock: boolean;
isContentExpanded: boolean;
addToCartTriggeredWithError: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/scandipwa/src/store/Cart/Cart.dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class CartDispatcher {
} = {},
method_code = '',
} = {},
}] = [],
} = {}] = [],
} = {},
} = await fetchQuery(
CartQuery.getCartQuery(
Expand Down
5 changes: 3 additions & 2 deletions packages/scandipwa/src/util/Product/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @link https://github.com/scandipwa/scandipwa
*/

import { ConfigurableProductSelectedVariantValue } from 'Component/Product/Product.type';
import { REVIEW_POPUP_ID } from 'Component/ProductReviews/ProductReviews.config';
import {
AttributeWithValue,
Expand Down Expand Up @@ -429,15 +430,15 @@ export const sortBySortOrder = <T>(options: T[], sortKey?: keyof T): T[] => opti
export const getIsConfigurableParameterSelected = (
parameters: Record<string, string>,
key: string,
value: string,
value: ConfigurableProductSelectedVariantValue,
): boolean => Object.hasOwnProperty.call(parameters, key) && parameters[key] === value;

/** @namespace Util/Product/getNewParameters */
// eslint-disable-next-line max-len
export const getNewParameters = (
parameters: Record<string, string>,
key: string,
value = '',
value: ConfigurableProductSelectedVariantValue = '',
): Record<string, string> => {
// If value is already selected, than we remove the key to achieve deselection
if (getIsConfigurableParameterSelected(parameters, key, value)) {
Expand Down

0 comments on commit c5ca60f

Please sign in to comment.