-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f172633
commit 199fbae
Showing
6 changed files
with
74 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { NoFilter, WithFilter } from './ListNoResults.stories'; | ||
|
||
describe('List?oResults', () => { | ||
it('should display no results found message when no filter', async () => { | ||
render(<NoFilter />); | ||
await screen.findByText('No results found.'); | ||
}); | ||
|
||
it('should display no results found message and a clear filter link when there is a filter', async () => { | ||
render(<WithFilter />); | ||
await screen.findByText('No results found with the current filters.'); | ||
screen.getByText('Clear filters').click(); | ||
await screen.findByText('{"id":1}'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/ra-ui-materialui/src/list/ListNoResults.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from 'react'; | ||
import { useList, ListContextProvider } from 'ra-core'; | ||
import { ListNoResults } from './ListNoResults'; | ||
|
||
export default { | ||
title: 'ra-ui-materialui/list/ListNoResults', | ||
}; | ||
|
||
export const NoFilter = () => { | ||
const context = useList<any>({ data: [] }); | ||
return ( | ||
<ListContextProvider value={context}> | ||
{context.data?.length === 0 && <ListNoResults />} | ||
</ListContextProvider> | ||
); | ||
}; | ||
|
||
export const WithFilter = () => { | ||
const context = useList<any>({ data: [{ id: 1 }], filter: { id: 2 } }); | ||
return ( | ||
<ListContextProvider value={context}> | ||
{context.data?.length === 0 ? ( | ||
<ListNoResults /> | ||
) : ( | ||
<ul> | ||
{context.data?.map(record => ( | ||
<li key={record.id}>{JSON.stringify(record)}</li> | ||
))} | ||
</ul> | ||
)} | ||
</ListContextProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,36 @@ | ||
import * as React from 'react'; | ||
import { memo } from 'react'; | ||
import CardContent from '@mui/material/CardContent'; | ||
import Typography from '@mui/material/Typography'; | ||
import { useListController, useResourceContext, useTranslate } from 'ra-core'; | ||
import { Link } from '@mui/material'; | ||
import { CardContent, Typography } from '@mui/material'; | ||
import { useListContext, useResourceContext, useTranslate } from 'ra-core'; | ||
|
||
export const ListNoResults = memo(() => { | ||
import { Button } from '../button'; | ||
|
||
export const ListNoResults = () => { | ||
const translate = useTranslate(); | ||
const resource = useResourceContext(); | ||
const { filterValues, setFilters } = useListController({ resource }); | ||
const { filterValues, setFilters } = useListContext(); | ||
return ( | ||
<CardContent> | ||
<Typography variant="body2"> | ||
{filterValues && Object.keys(filterValues).length > 0 ? ( | ||
<> | ||
{translate('ra.navigation.no_filtred_results', { | ||
{translate('ra.navigation.no_filtered_results', { | ||
resource, | ||
_: 'No results found with the current filters.', | ||
})}{' '} | ||
<Link | ||
component="button" | ||
<Button | ||
onClick={() => setFilters({}, [])} | ||
> | ||
{translate('ra.navigation.clear_filters')} | ||
</Link> | ||
label={translate('ra.navigation.clear_filters', { | ||
_: 'Clear filters', | ||
})} | ||
/> | ||
</> | ||
) : ( | ||
translate('ra.navigation.no_results', { resource }) | ||
translate('ra.navigation.no_results', { | ||
resource, | ||
_: 'No results found.', | ||
}) | ||
)} | ||
</Typography> | ||
</CardContent> | ||
); | ||
}); | ||
}; |