Skip to content

Commit 58f72c4

Browse files
authored
feat: empty table messages (#446)
* chore: empty table messages * chore(fix): fallback table messages * chore: updated changelog
1 parent 78df591 commit 58f72c4

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
## [3.7.6](https://github.com/eclipse-tractusx/portal-shared-components/compare/v3.7.5...v3.7.6) (2025-02-13)
3535

3636

37+
3738
### Bug Fixes
3839

3940
* upgrade storybook to version 8.5.3 ([4f4df10](https://github.com/eclipse-tractusx/portal-shared-components/commit/4f4df107bf6ca02ca959660c121f4dc18ac7b10a))
@@ -43,6 +44,9 @@
4344
* upgrade storybook to version 8.5.3 ([6cccaec](https://github.com/eclipse-tractusx/portal-shared-components/commit/6cccaec07fd20259fc9568ffc1e4a430203200e9))
4445

4546
## [3.7.5](https://github.com/eclipse-tractusx/portal-shared-components/compare/v3.7.4...v3.7.5) (2025-01-20)
47+
- **Table Empty Text** [4.0.3]
48+
- fixed empty table messages with consistency [#446](https://github.com/eclipse-tractusx/portal-shared-components/pull/446)
49+
4650

4751

4852
### Bug Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@catena-x/portal-shared-components",
3-
"version": "4.0.2",
3+
"version": "4.0.3",
44
"description": "Eclipse Tractus-X Portal Shared Components",
55
"author": "Eclipse Tractus-X Contributors",
66
"license": "Apache-2.0",

src/components/basic/Table/PageLoadingTable.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export interface PageLoadingTableProps<Row, Args>
5353
allItems?: Row[]
5454
callbackToPage?: (data: PaginResult<Row>) => void
5555
allItemsLoadedHint?: string
56+
emptyDataMsg?: string
57+
noSearchResultsMsg?: string
5658
}
5759

5860
const scrollOffset = 350 // Adjust this value for earlier load
@@ -65,6 +67,8 @@ export const PageLoadingTable = function <Row, Args>({
6567
allItems,
6668
callbackToPage,
6769
allItemsLoadedHint = 'All items have been loaded.',
70+
emptyDataMsg = 'No data found',
71+
noSearchResultsMsg = 'No search results found',
6872
...props
6973
}: PageLoadingTableProps<Row, Args>) {
7074
const [page, setPage] = useState(0)
@@ -79,12 +83,14 @@ export const PageLoadingTable = function <Row, Args>({
7983
},
8084
})
8185
const [loading, setLoading] = useState(true)
86+
const [noRowsMsg, setNoRowsMsg] = useState('')
8287

8388
function nextPage() {
8489
setPage(page + 1)
8590
}
8691
const hasMore = data ? hasMorePages(data) : false
8792
const maxRows = data ? getMaxRows(data) : 0
93+
const { searchExpr } = props
8894

8995
useEffect(() => {
9096
if (!allItems) {
@@ -130,6 +136,16 @@ export const PageLoadingTable = function <Row, Args>({
130136
}
131137
}, [isSuccess, isFetching, data, clear, loaded])
132138

139+
useEffect(() => {
140+
if (data) {
141+
if (!searchExpr && data.content.length === 0) {
142+
setNoRowsMsg(emptyDataMsg)
143+
} else if (searchExpr && data.content.length === 0) {
144+
setNoRowsMsg(noSearchResultsMsg)
145+
}
146+
}
147+
}, [data, searchExpr])
148+
133149
const handleScroll = useCallback(() => {
134150
const scrollableElement = document.documentElement
135151
if (
@@ -159,6 +175,7 @@ export const PageLoadingTable = function <Row, Args>({
159175
error={error}
160176
rows={items}
161177
reload={refetch}
178+
noRowsMsg={noRowsMsg}
162179
{...props}
163180
/>
164181
{/* Display loading spinner while fetching data */}

src/components/basic/Table/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,19 @@ export const Table = ({
195195

196196
const renderErrorMessage = () => {
197197
if (rowsCount === 0 || error == null) {
198-
return <Typography variant="body2">{noRowsMsg ?? 'No rows'}</Typography>
198+
if (noRowsMsg && noRowsMsg.includes('\n')) {
199+
const messageParts = noRowsMsg.split(/[\n|]/)
200+
return (
201+
<Stack spacing={1} alignItems="center">
202+
{messageParts.map((part, index) => (
203+
<Typography key={index} variant="body2" align="center">
204+
{part.trim()}
205+
</Typography>
206+
))}
207+
</Stack>
208+
)
209+
}
210+
return <></>
199211
}
200212
if (error.status >= 400 && error.status < 500) {
201213
return <Error400Overlay errorMessage4xx={error.message} />

0 commit comments

Comments
 (0)