From e0829fee830c405dcaa360a357fbec21947ea47e Mon Sep 17 00:00:00 2001 From: Felix Perron-Brault Date: Wed, 7 Aug 2024 11:05:52 -0400 Subject: [PATCH] fix warning https://coveord.atlassian.net/browse/KIT-3455 --- .../product-utils.ts | 22 +++++-------------- packages/atomic/src/utils/result-utils.ts | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/atomic/src/components/commerce/product-template-components/product-utils.ts b/packages/atomic/src/components/commerce/product-template-components/product-utils.ts index 9efa559233a..300bc616798 100644 --- a/packages/atomic/src/components/commerce/product-template-components/product-utils.ts +++ b/packages/atomic/src/components/commerce/product-template-components/product-utils.ts @@ -28,7 +28,7 @@ export function buildStringTemplateFromProduct( if (!newValue) { bindings.engine.logger.warn( - `${key} used in the href template is undefined for this product: ${product.permanentid} and not found in the window object.` + `${key} used in the href template is undefined for this product: ${product.permanentid} and could not be found in the window object.` ); return ''; } @@ -37,20 +37,10 @@ export function buildStringTemplateFromProduct( }); } -function readFromObject( - object: T, - key: string -): string | undefined { - const keys = key.split('.'); - let current: unknown = object; - - for (const k of keys) { - if (current && typeof current === 'object' && k in current) { - current = (current as Record)[k]; - } else { - return undefined; - } +function readFromObject(object: T, key: string): string | undefined { + if (object && typeof object === 'object' && key in object) { + const value = (object as Record)[key]; + return typeof value === 'string' ? value : undefined; } - - return typeof current === 'string' ? current : undefined; + return undefined; } diff --git a/packages/atomic/src/utils/result-utils.ts b/packages/atomic/src/utils/result-utils.ts index a84fbec99aa..b67a37a46e2 100644 --- a/packages/atomic/src/utils/result-utils.ts +++ b/packages/atomic/src/utils/result-utils.ts @@ -64,7 +64,7 @@ export function buildStringTemplateFromResult( if (!newValue) { bindings.engine.logger.warn( - `${key} used in the href template is undefined for this result: ${result.uniqueId} and not found in the window object.` + `${key} used in the href template is undefined for this result: ${result.uniqueId} and could not be found in the window object.` ); return ''; }