From 96b17ed5af0c90b049bca30a8645c73beb8ab25c Mon Sep 17 00:00:00 2001 From: Uyen Doan Date: Thu, 19 Sep 2024 13:28:39 -0500 Subject: [PATCH 1/6] added warning when both subRows and subComponent are passed --- packages/itwinui-react/src/core/Table/Table.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/itwinui-react/src/core/Table/Table.tsx b/packages/itwinui-react/src/core/Table/Table.tsx index 8bbe3feb639..98f9f0af06f 100644 --- a/packages/itwinui-react/src/core/Table/Table.tsx +++ b/packages/itwinui-react/src/core/Table/Table.tsx @@ -656,6 +656,12 @@ export const Table = < } } + if (data.some((item) => (item.subRows as T[]).length > 0) && subComponent) { + logWarning( + `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`, + ); + } + const ariaDataAttributes = Object.entries(rest).reduce( (result, [key, value]) => { if (key.startsWith('data-') || key.startsWith('aria-')) { From aed5616e4a59a602f349c8de833c7a12dc089064 Mon Sep 17 00:00:00 2001 From: Uyen Doan Date: Mon, 7 Oct 2024 12:30:05 -0500 Subject: [PATCH 2/6] checked if in dev environment --- packages/itwinui-react/src/core/Table/Table.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/itwinui-react/src/core/Table/Table.tsx b/packages/itwinui-react/src/core/Table/Table.tsx index 98f9f0af06f..9cd37fae77c 100644 --- a/packages/itwinui-react/src/core/Table/Table.tsx +++ b/packages/itwinui-react/src/core/Table/Table.tsx @@ -657,9 +657,11 @@ export const Table = < } if (data.some((item) => (item.subRows as T[]).length > 0) && subComponent) { - logWarning( - `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`, - ); + if (process.env.NODE_ENV === 'development') { + logWarning( + `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`, + ); + } } const ariaDataAttributes = Object.entries(rest).reduce( From 5fcaca44d20fafd6b522099785a5f9ad0d7d168f Mon Sep 17 00:00:00 2001 From: Uyen Doan Date: Mon, 7 Oct 2024 14:24:47 -0500 Subject: [PATCH 3/6] checked if in dev environment --- packages/itwinui-react/src/core/Table/Table.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/itwinui-react/src/core/Table/Table.tsx b/packages/itwinui-react/src/core/Table/Table.tsx index 9cd37fae77c..c0e8928b0da 100644 --- a/packages/itwinui-react/src/core/Table/Table.tsx +++ b/packages/itwinui-react/src/core/Table/Table.tsx @@ -656,12 +656,14 @@ export const Table = < } } - if (data.some((item) => (item.subRows as T[]).length > 0) && subComponent) { - if (process.env.NODE_ENV === 'development') { - logWarning( - `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`, - ); - } + if ( + data.some((item) => (item.subRows as T[]).length > 0) && + subComponent && + process.env.NODE_ENV === 'development' + ) { + logWarning( + `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`, + ); } const ariaDataAttributes = Object.entries(rest).reduce( From fcb4b327adeef7ec99770169db95488f348393f5 Mon Sep 17 00:00:00 2001 From: Uyen Doan Date: Mon, 7 Oct 2024 14:45:40 -0500 Subject: [PATCH 4/6] checked if in dev environment --- packages/itwinui-react/src/core/Table/Table.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/itwinui-react/src/core/Table/Table.tsx b/packages/itwinui-react/src/core/Table/Table.tsx index c0e8928b0da..2fdab63e4cf 100644 --- a/packages/itwinui-react/src/core/Table/Table.tsx +++ b/packages/itwinui-react/src/core/Table/Table.tsx @@ -657,9 +657,9 @@ export const Table = < } if ( + process.env.NODE_ENV === 'development' && data.some((item) => (item.subRows as T[]).length > 0) && - subComponent && - process.env.NODE_ENV === 'development' + subComponent ) { logWarning( `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`, From 0df551ec26b8469e8e7297b6631348316a223f56 Mon Sep 17 00:00:00 2001 From: Uyen Doan Date: Mon, 7 Oct 2024 15:12:45 -0500 Subject: [PATCH 5/6] added changeset --- .changeset/cuddly-gorillas-type.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cuddly-gorillas-type.md diff --git a/.changeset/cuddly-gorillas-type.md b/.changeset/cuddly-gorillas-type.md new file mode 100644 index 00000000000..3bfa4f4912c --- /dev/null +++ b/.changeset/cuddly-gorillas-type.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': patch +--- + +Added warning log in browser when both `subRows` and `subComponent` are passed into `Table`. From 2bae264280dce5f9492f39563ba1796c3cf3fc6d Mon Sep 17 00:00:00 2001 From: Uyen Doan Date: Mon, 7 Oct 2024 16:26:01 -0500 Subject: [PATCH 6/6] made sure item.subRows exist before getting its length --- packages/itwinui-react/src/core/Table/Table.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/itwinui-react/src/core/Table/Table.tsx b/packages/itwinui-react/src/core/Table/Table.tsx index 2fdab63e4cf..e48d97e53af 100644 --- a/packages/itwinui-react/src/core/Table/Table.tsx +++ b/packages/itwinui-react/src/core/Table/Table.tsx @@ -658,8 +658,8 @@ export const Table = < if ( process.env.NODE_ENV === 'development' && - data.some((item) => (item.subRows as T[]).length > 0) && - subComponent + subComponent && + data.some((item) => !!(item.subRows as T[] | undefined)?.length) ) { logWarning( `Passing both \`subComponent\` and \`data\` with \`subRows\` is not supported. There are features designed for \`subRows\` that are not compatible with \`subComponent\` and vice versa.`,