From 5ed7c7b815c797fa67a5844d1289eab426dcd93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chy=C5=82a?= Date: Tue, 24 Oct 2023 14:42:19 +0200 Subject: [PATCH] Remove ts utils and use function to check boolean --- .../views/ProductUpdate/handlers/data/attributes.ts | 9 ++++++--- src/products/views/ProductUpdate/handlers/utils.ts | 4 ++++ src/utils/ts.ts | 10 ---------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/products/views/ProductUpdate/handlers/data/attributes.ts b/src/products/views/ProductUpdate/handlers/data/attributes.ts index 82eb8e44fa1..2e2050589ff 100644 --- a/src/products/views/ProductUpdate/handlers/data/attributes.ts +++ b/src/products/views/ProductUpdate/handlers/data/attributes.ts @@ -10,7 +10,8 @@ import { getColumnAttribute, isCurrentRow, } from "@dashboard/products/utils/datagrid"; -import { nonNullable } from "@dashboard/utils/ts"; + +import { byAttributeName } from "../utils"; export function getAttributeData( data: DatagridChange[], @@ -134,7 +135,9 @@ export function getAttributeInput( if (inputType === AttributeInputTypeEnum.REFERENCE) { return { - references: values.map(({ reference }) => reference).filter(nonNullable), + references: values + .map(({ reference }) => reference) + .filter(byAttributeName), }; } @@ -151,7 +154,7 @@ export function getAttributeInput( } return { - values: values.map(({ name }) => name).filter(nonNullable), + values: values.map(({ name }) => name).filter(byAttributeName), }; } diff --git a/src/products/views/ProductUpdate/handlers/utils.ts b/src/products/views/ProductUpdate/handlers/utils.ts index e099791dd34..16ae327b77a 100644 --- a/src/products/views/ProductUpdate/handlers/utils.ts +++ b/src/products/views/ProductUpdate/handlers/utils.ts @@ -246,3 +246,7 @@ export function inferProductChannelsAfterUpdate( ...updatedChannelsIds, ]); } + +export function byAttributeName(x: string | null | undefined): x is string { + return typeof x === "string" && x.length > 0; +} diff --git a/src/utils/ts.ts b/src/utils/ts.ts index 6bdb1bf3c70..05ea1c1599c 100644 --- a/src/utils/ts.ts +++ b/src/utils/ts.ts @@ -6,13 +6,3 @@ src/orders/components/OrderGrantRefundPage/reducer.ts export function exhaustiveCheck(x: never) { return x; } - -export function nonNullable(value: T): value is NonNullable { - return value !== null && value !== undefined; -} - -type Truthy = T extends false | "" | 0 | null | undefined ? never : T; // from lodash - -export function truthy(value: T): value is Truthy { - return !!value; -}