diff --git a/CHANGELOG.md b/CHANGELOG.md index bc47ee9d..6dd62cdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ ## [3.7.6](https://github.com/eclipse-tractusx/portal-shared-components/compare/v3.7.5...v3.7.6) (2025-02-13) + ### Bug Fixes * upgrade storybook to version 8.5.3 ([4f4df10](https://github.com/eclipse-tractusx/portal-shared-components/commit/4f4df107bf6ca02ca959660c121f4dc18ac7b10a)) @@ -43,6 +44,9 @@ * upgrade storybook to version 8.5.3 ([6cccaec](https://github.com/eclipse-tractusx/portal-shared-components/commit/6cccaec07fd20259fc9568ffc1e4a430203200e9)) ## [3.7.5](https://github.com/eclipse-tractusx/portal-shared-components/compare/v3.7.4...v3.7.5) (2025-01-20) +- **Table Empty Text** [4.0.3] + - fixed empty table messages with consistency [#446](https://github.com/eclipse-tractusx/portal-shared-components/pull/446) + ### Bug Fixes diff --git a/package.json b/package.json index a1a6b036..7ed5c643 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@catena-x/portal-shared-components", - "version": "4.0.2", + "version": "4.0.3", "description": "Eclipse Tractus-X Portal Shared Components", "author": "Eclipse Tractus-X Contributors", "license": "Apache-2.0", diff --git a/src/components/basic/Table/PageLoadingTable.tsx b/src/components/basic/Table/PageLoadingTable.tsx index 8dac8310..a7d69c3d 100644 --- a/src/components/basic/Table/PageLoadingTable.tsx +++ b/src/components/basic/Table/PageLoadingTable.tsx @@ -53,6 +53,8 @@ export interface PageLoadingTableProps allItems?: Row[] callbackToPage?: (data: PaginResult) => void allItemsLoadedHint?: string + emptyDataMsg?: string + noSearchResultsMsg?: string } const scrollOffset = 350 // Adjust this value for earlier load @@ -65,6 +67,8 @@ export const PageLoadingTable = function ({ allItems, callbackToPage, allItemsLoadedHint = 'All items have been loaded.', + emptyDataMsg = 'No data found', + noSearchResultsMsg = 'No search results found', ...props }: PageLoadingTableProps) { const [page, setPage] = useState(0) @@ -79,12 +83,14 @@ export const PageLoadingTable = function ({ }, }) const [loading, setLoading] = useState(true) + const [noRowsMsg, setNoRowsMsg] = useState('') function nextPage() { setPage(page + 1) } const hasMore = data ? hasMorePages(data) : false const maxRows = data ? getMaxRows(data) : 0 + const { searchExpr } = props useEffect(() => { if (!allItems) { @@ -130,6 +136,16 @@ export const PageLoadingTable = function ({ } }, [isSuccess, isFetching, data, clear, loaded]) + useEffect(() => { + if (data) { + if (!searchExpr && data.content.length === 0) { + setNoRowsMsg(emptyDataMsg) + } else if (searchExpr && data.content.length === 0) { + setNoRowsMsg(noSearchResultsMsg) + } + } + }, [data, searchExpr]) + const handleScroll = useCallback(() => { const scrollableElement = document.documentElement if ( @@ -159,6 +175,7 @@ export const PageLoadingTable = function ({ error={error} rows={items} reload={refetch} + noRowsMsg={noRowsMsg} {...props} /> {/* Display loading spinner while fetching data */} diff --git a/src/components/basic/Table/index.tsx b/src/components/basic/Table/index.tsx index 0f22ebd8..b8aebfd6 100644 --- a/src/components/basic/Table/index.tsx +++ b/src/components/basic/Table/index.tsx @@ -195,7 +195,19 @@ export const Table = ({ const renderErrorMessage = () => { if (rowsCount === 0 || error == null) { - return {noRowsMsg ?? 'No rows'} + if (noRowsMsg && noRowsMsg.includes('\n')) { + const messageParts = noRowsMsg.split(/[\n|]/) + return ( + + {messageParts.map((part, index) => ( + + {part.trim()} + + ))} + + ) + } + return <> } if (error.status >= 400 && error.status < 500) { return