Skip to content

Commit

Permalink
Some TS runtime error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrsKondratjevs committed Sep 8, 2022
1 parent aea6e5c commit 5c5dd16
Show file tree
Hide file tree
Showing 29 changed files with 1,475 additions and 1,368 deletions.
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/da_DK.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/fa_IR.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/fi_FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/lv_LV.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/nb_NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/nl_NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/sl_SI.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/sv_SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/tr_TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
5 changes: 3 additions & 2 deletions packages/scandipwa/i18n/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@
"The requested qty is not available!": null,
"County": null,
"State/Province": null,
"Region": null
}
"Region": null,
"You %s the address": null
}
4 changes: 2 additions & 2 deletions packages/scandipwa/src/component/Header/Header.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class HeaderContainer extends NavigationAbstractContainer<HeaderContainer
getNavigationState(): NavigationState {
const { navigationState } = this.props;

const { location: { pathname, state } } = history || {};
const { location: { pathname, state = {} } } = history || {};

// TODO: something here breaks /<STORE CODE> from being opened, and / when, the url-based stores are enabled.

Expand All @@ -241,7 +241,7 @@ export class HeaderContainer extends NavigationAbstractContainer<HeaderContainer
}

getUserName(): string | undefined {
const { firstname } = BrowserDatabase.getItem(CUSTOMER) || {};
const { firstname }: { firstname?: string } = BrowserDatabase.getItem(CUSTOMER) || {};

return firstname;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class MyAccountCreateAccountContainer extends PureComponent<MyAccountCrea
lastname,
is_subscribed,
taxvat
} = transformToNameValuePair(fields);
} = transformToNameValuePair<Record<string, string | number | boolean>>(fields);

const customerData = {
customer: {
Expand All @@ -139,7 +139,7 @@ export class MyAccountCreateAccountContainer extends PureComponent<MyAccountCrea
} as CreateAccountOptions;

if (is_subscribed) {
customerData.customer.is_subscribed = is_subscribed;
customerData.customer.is_subscribed = !!is_subscribed;
}

if (isLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ ProductReviewFormContainerState
nickname,
title,
detail
} = transformToNameValuePair(fields as Record<string, FieldData>);
} = transformToNameValuePair<Record<string, string>>(fields as Record<string, FieldData>);

const { sku: product_sku = '' } = product;

Expand Down
4 changes: 2 additions & 2 deletions packages/scandipwa/src/query/ProductList.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ export class ProductListQuery {
type: 'ProductAttributeFilterInput!',
handler: (initialOptions = {}) => {
// add customer group by default to all requests
const { group_id } = BrowserDatabase.getItem(CUSTOMER) || {};
const { group_id }: { group_id?: number } = BrowserDatabase.getItem(CUSTOMER) || {};

const options: ProductAttributeFilterOptions = {
...initialOptions,
customerGroupId: group_id || '0'
customerGroupId: group_id || 0
};

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ PasswordChangePageContainerState
this.setState({ isLoading: true }, () => {
const { resetPassword } = this.props;
const { location } = history;
const { password, password_confirmation } = transformToNameValuePair(fields);
const { password, password_confirmation } = transformToNameValuePair<Record<string, string>>(fields);
const token = getQueryParam('token', location);
const customer_id = getQueryParam('id', location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ SendConfirmationPageContainerState

this.setState({ isLoading: true });

const { email } = transformToNameValuePair(fields);
const { email } = transformToNameValuePair<Record<string, string>>(fields);

try {
const data = await resendConfirmation({ email });
Expand Down
1 change: 1 addition & 0 deletions packages/scandipwa/src/store/Config/Config.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const filterStoreConfig = (config: StoreConfig): Partial<StoreConfig> =>
);

export const {
// @ts-ignore
countries, reviewRatings, storeConfig, currencyData, currency, cartDisplayConfig
} = BrowserDatabase.getItem('config') || {
countries: [],
Expand Down
1 change: 1 addition & 0 deletions packages/scandipwa/src/store/Config/Config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type ConfigStore = StoreConfig & {
category_url_suffix: string;
device: Device;
currency: Currencies;
storeConfig: StoreConfig;
};

declare module 'Util/Store/Store.type' {
Expand Down
4 changes: 4 additions & 0 deletions packages/scandipwa/src/store/Navigation/Navigation.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const NavigationReducer: Reducer<NavigationStore, NavigationAction> = (
) => {
const { navigationType, navigationState } = action;

if (!navigationType) {
return state;
}

const {
[navigationType]: {
navigationStateHistory,
Expand Down
6 changes: 4 additions & 2 deletions packages/scandipwa/src/util/Query/PrepareDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export const prepareRequest = <T>(fields: AbstractField<string, T, boolean>[], t
// go through argument accumulator collected in "prepareFieldString", join values
// into the format "$var:Type" and append variable value to variables field
const resolvedArgs = Object.entries(accArgs).reduce((acc, [name, dataArray]): string[] => {
(dataArray as Array<Omit<FieldArgument, 'name'>>).forEach((item, i: number) => {
(dataArray as Array<string[]>).forEach(([type, value], i: number) => {
const variable = `${name}_${i + 1}`;

acc.push(`$${variable}:${type}`);
variables[variable] = String(item.value);
variables[variable] = value;
});

return acc;
Expand All @@ -105,6 +105,8 @@ export const prepareRequest = <T>(fields: AbstractField<string, T, boolean>[], t
);
}

console.log(`${type}${formattedArgs}`, '***');

return {
// format like "query($var_1:String){test(arg: $var_1){id}}"
query: `${type}${formattedArgs}{${fieldStrings}}`,
Expand Down
28 changes: 14 additions & 14 deletions packages/scandipwa/src/util/Request/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,29 @@ export const executeGet = async <T>(
refreshUid();
}

// circumvention of the eslint rule that prohibits usage of let
const res: Response[] = [];

try {
res[0] = await getFetch(uri, name, signal);
} catch (err) {
if (res[0].status === HTTP_410_GONE) {
const result = await getFetch(uri, name, signal);

if (result.status === HTTP_410_GONE) {
const putResponse = await putPersistedQuery(getGraphqlEndpoint(), query, cacheTTL);

if (putResponse.status === HTTP_201_CREATED) {
res[0] = await getFetch(uri, name, signal);
return await parseResponse(await getFetch(uri, name, signal));
}
} else if (res[0].status === HTTP_503_SERVICE_UNAVAILABLE) {
handleConnectionError(err, 'Service unavailable!...');
}

throw new Error(err as string);
if (result.status === HTTP_503_SERVICE_UNAVAILABLE) {
handleConnectionError(result.status, result.statusText);
throw new Error(result.statusText);
}

handleConnectionError(err, 'executeGet failed');
throw new Error(err as string);
// Successful and all other http responses go here:
return await parseResponse(result);
} catch (error) {
// Network error
handleConnectionError(error, 'executeGet failed');
throw new Error(error as string);
}

return parseResponse(res[0]);
};
/**
* Make POST request to endpoint
Expand Down
Loading

0 comments on commit 5c5dd16

Please sign in to comment.