-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add invite to create the first record when the list is empty #4113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d65ca67
Improve empty state page
m4theushw 7e0614c
Add tests
m4theushw 1b3a5b8
Add docs about List's empty prop
m4theushw 9602baf
Update french translations
m4theushw bd30d10
Rename <EmptyState /> to <Empty />
m4theushw 04aa790
Update docs
m4theushw 6d49a60
Fix styles
m4theushw aab6cb8
Rename prop
m4theushw 1459c6d
Allow users to override messages in specific resources
m4theushw ed15d76
Fix typo
m4theushw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,62 @@ | ||
import React from 'react'; | ||
import Inbox from '@material-ui/icons/Inbox'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { makeStyles } from '@material-ui/styles'; | ||
import { useTranslate } from 'ra-core'; | ||
import { CreateButton } from '../button'; | ||
import inflection from 'inflection'; | ||
|
||
const useStyles = makeStyles({ | ||
message: { | ||
textAlign: 'center', | ||
opacity: 0.5, | ||
margin: '0 1em', | ||
}, | ||
icon: { | ||
width: '9em', | ||
height: '9em', | ||
}, | ||
toolbar: { | ||
textAlign: 'center', | ||
marginTop: '2em', | ||
}, | ||
}); | ||
|
||
const Empty = ({ resource, basePath }) => { | ||
const classes = useStyles(); | ||
const translate = useTranslate(); | ||
|
||
const resourceName = inflection.humanize( | ||
translate(`resources.${resource}.name`, { | ||
smart_count: 0, | ||
_: inflection.pluralize(resource), | ||
}), | ||
true | ||
); | ||
|
||
const emptyMessage = translate('ra.page.empty', { name: resourceName }); | ||
const inviteMessage = translate('ra.page.invite'); | ||
|
||
return ( | ||
<> | ||
<div className={classes.message}> | ||
<Inbox className={classes.icon} /> | ||
<Typography variant="h4" paragraph> | ||
{translate(`resources.${resource}.empty`, { | ||
_: emptyMessage, | ||
})} | ||
</Typography> | ||
<Typography variant="body1"> | ||
{translate(`resources.${resource}.invite`, { | ||
_: inviteMessage, | ||
})} | ||
</Typography> | ||
</div> | ||
<div className={classes.toolbar}> | ||
<CreateButton variant="contained" basePath={basePath} /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Empty; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause bad wording when the resource name is feminine (ex: promotion). But I don't see an easy way to fix that, so we'll go with that translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could leave to user to override the empty text, by looking for a
resources.foobar.empty
key. If there's no such key we use the default onera.page.empty
.The invite key could also be customizable, like
resources.foobar.invite
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. Would you mind adding that feature to your PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll work on it