From 0d895e766f52f1f842f46091741f5b3eea466ab1 Mon Sep 17 00:00:00 2001 From: a-honey Date: Wed, 15 Jan 2025 02:27:11 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20hasValidChildren=EC=9D=84=20?= =?UTF-8?q?=ED=86=B5=ED=95=9C=20List=20=EB=82=B4=EB=B6=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20Blank=20=EB=A0=8C=EB=8D=94=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/List/RowContainer/index.tsx | 9 ++++++++- src/lib/node.utils.ts | 10 ++++++++++ src/pages/user/List.tsx | 8 +++----- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 src/lib/node.utils.ts diff --git a/src/components/List/RowContainer/index.tsx b/src/components/List/RowContainer/index.tsx index a1b8f9a..315b677 100644 --- a/src/components/List/RowContainer/index.tsx +++ b/src/components/List/RowContainer/index.tsx @@ -1,5 +1,8 @@ -import { PropsWithChildren } from "react"; +import React, { PropsWithChildren } from "react"; + +import Blank from "../../fallback/Blank"; import { cn } from "../../../lib/utils"; +import { hasValidChildren } from "../../../lib/node.utils"; type RowContainerProps = { row: number; @@ -11,6 +14,10 @@ export default function RowContainer({ className, children, }: RowContainerProps) { + if (!hasValidChildren(children)) { + return ; + } + return (
{children}
); diff --git a/src/lib/node.utils.ts b/src/lib/node.utils.ts new file mode 100644 index 0000000..9ea4706 --- /dev/null +++ b/src/lib/node.utils.ts @@ -0,0 +1,10 @@ +import React from "react"; + +export function hasValidChildren(children: React.ReactNode): boolean { + return React.Children.toArray(children).some( + (child) => + React.isValidElement(child) || + typeof child === "string" || + typeof child === "number" + ); +} diff --git a/src/pages/user/List.tsx b/src/pages/user/List.tsx index 30c3c86..f5b52b9 100644 --- a/src/pages/user/List.tsx +++ b/src/pages/user/List.tsx @@ -80,11 +80,9 @@ const UserListContent = () => { - {!data.users || data.users.length === 0 ? ( - - ) : ( - data.users.map((user) => ) - )} + {data.users.map((user) => ( + + ))} Date: Wed, 15 Jan 2025 02:30:57 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20List=20=EC=8A=A4=ED=86=A0=EB=A6=AC?= =?UTF-8?q?=20Blank=20=EB=B2=84=EC=A0=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/List/RowContainer/index.tsx | 3 +-- src/components/List/index.stories.tsx | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/List/RowContainer/index.tsx b/src/components/List/RowContainer/index.tsx index 315b677..6ff03eb 100644 --- a/src/components/List/RowContainer/index.tsx +++ b/src/components/List/RowContainer/index.tsx @@ -1,6 +1,5 @@ -import React, { PropsWithChildren } from "react"; - import Blank from "../../fallback/Blank"; +import { PropsWithChildren } from "react"; import { cn } from "../../../lib/utils"; import { hasValidChildren } from "../../../lib/node.utils"; diff --git a/src/components/List/index.stories.tsx b/src/components/List/index.stories.tsx index be4f872..efe8bae 100644 --- a/src/components/List/index.stories.tsx +++ b/src/components/List/index.stories.tsx @@ -23,6 +23,20 @@ export const Default = { ), }; +export const Blank = { + render: () => ( + + + + + {no_books.map((book) => ( + + ))} + + + ), +}; + type BookItemType = { id: string; title: string; @@ -105,6 +119,8 @@ const books: BookItemType[] = [ }, ]; +const no_books: BookItemType[] = []; + const ListItemStory = ({ id, title, author, publisher, etc }: BookItemType) => { return (
From 7abeee5b956d0dae631fc2485631bbd055651616 Mon Sep 17 00:00:00 2001 From: a-honey Date: Wed, 15 Jan 2025 02:33:19 +0900 Subject: [PATCH 3/3] =?UTF-8?q?test:=20hasValidChildren=20=EC=9C=A0?= =?UTF-8?q?=EB=8B=9B=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/node.spec.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/lib/node.spec.tsx diff --git a/src/lib/node.spec.tsx b/src/lib/node.spec.tsx new file mode 100644 index 0000000..d7b7e23 --- /dev/null +++ b/src/lib/node.spec.tsx @@ -0,0 +1,11 @@ +import { hasValidChildren } from "./node.utils"; + +test("return true for valid children case", () => { + const children = [
Valid
, "Text"]; + expect(hasValidChildren(children)).toBe(true); +}); + +test("return false for invalid or empty children case", () => { + const children = [null, undefined, false]; + expect(hasValidChildren(children)).toBe(false); +});