-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Feature: Confirm Dialog's content
prop can receive React.ReactNode
#5954
Feature: Confirm Dialog's content
prop can receive React.ReactNode
#5954
Conversation
...translateOptions, | ||
})} | ||
</DialogContentText> | ||
{isContentString ? ( |
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'm not handling this conditional logic in a very elegant way. I wasn't sure how best you'd like this done. The two solutions I have in mind are
-
Leave it as it is
-
Do somethng like this
import MUIContent from '@material-ui/blahblah`
function Content(props) {
if (typeof props.content === 'string') {
return (
<DialogContentText>
{translate(content, {
_: content,
...translateOptions,
})}
</DialogContentText>
}
return props.content
}
function Confirm() {
return (
<Dialog {..existingProps}>
{otherElements}
<Content />
{otherElements}
</Dialog>
)
}
Or any other suggestions you folks might have
I also didn't make a ticket for this, so I'm happy if you don't believe this fits with the repo |
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.
Hey and thanks for contributing. If think it would be easier to accept an optional children
prop which would take precedence over the content
prop when provided, wouldn'it?
I would be concerned that this would increase the component's complexity, and increase the cognitive overhead. e.g.
It also increases potential errors and gotchas. While we can make use of discriminated union types (i think) to ensure only one of the two props are passed through, it won't stop JavaScript users from getting themselves into this broken state. What do you think? |
I think the difference is that:
Besides, I would even deprecate the |
I agree that replacing One question that I have is how to handle translating the text in this case. It would like look we'd still need type guards. If it's a string, pass the value through the |
I think it's for the best, yes. Please make sure the warning is only displayed in development mode though. Thanks for taking the time to do this! |
Right, missed that one... We may have to keep both for a while, maybe providing a |
Hi, and thanks for your contribution. I don't understand the use case here. Can you describe why an end user would want to see something else than text there? Also, I don't want to change the way such a simple component behaves in v4, so I don't think we should add a deprecation warning. Let's keep that for important changes. |
One of the things I manage the chat thread. Each thread is a resource, and has its own |
Interesting. I don't think that's what the generic |
I'm not sure if this is something to consider, but if RA makes heavy use of Material UI to the point where having a basic understanding of MUI is beneficial to using RA, then it would make sense to try and keep the component interfaces similar. What I mean to say is in MUI's Dialog Component, the client can pass through children as the main content. For me at least, this seems more intuitive than having a The main challenge here is ensuring translation still works as expected |
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 change is benign and can help in some cases, so let's merge it.
Thanks! |
Amazing! I only noticed this went in as I read the release notes 😅 |
Makes the
Confirm
component more flexible while retaining existing behaviour,i.e.
if a string is passed through, the content is translated, otherwise simply render the component.The video demonstrates this behaviour in action.
content-is-react-delement.mov
Note: While I updated the all of the uses of
Content
within the React Admin codebase, please let me know if there's anything else I need to consider.I'll also be happy adding a cypress test too.