Skip to content

Commit

Permalink
Remove ts utils and use function to check boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch committed Oct 24, 2023
1 parent b8c602a commit 5ed7c7b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
9 changes: 6 additions & 3 deletions src/products/views/ProductUpdate/handlers/data/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -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),
};
}

Expand All @@ -151,7 +154,7 @@ export function getAttributeInput(
}

return {
values: values.map(({ name }) => name).filter(nonNullable),
values: values.map(({ name }) => name).filter(byAttributeName),
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/products/views/ProductUpdate/handlers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 0 additions & 10 deletions src/utils/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@ src/orders/components/OrderGrantRefundPage/reducer.ts
export function exhaustiveCheck(x: never) {
return x;
}

export function nonNullable<T>(value: T): value is NonNullable<T> {
return value !== null && value !== undefined;
}

type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T; // from lodash

export function truthy<T>(value: T): value is Truthy<T> {
return !!value;
}

0 comments on commit 5ed7c7b

Please sign in to comment.