Skip to content

Commit 3b78e30

Browse files
committed
chore: empty table messages
1 parent d33f8df commit 3b78e30

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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,
71+
noSearchResultsMsg,
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)