-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Portal toasters into app provider + Fix toaster hrefs to include path prefix. #16696
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
28 changes: 28 additions & 0 deletions
28
js_modules/dagster-ui/packages/ui-core/src/app/AppToasterPortalProvider.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,28 @@ | ||
import {registerPortalProvider} from '@dagster-io/ui-components/src/components/createToaster'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import {useHref} from 'react-router-dom-v5-compat'; | ||
|
||
// A hook that makes toaster elements render inside of our React router dom hook and that fixes their hrefs | ||
// to take --path-prefix into account | ||
export const AppToasterPortalProvider = () => { | ||
const [portaledElements, setPortalElements] = React.useState< | ||
[React.ReactNode, HTMLElement, string | undefined][] | ||
>([]); | ||
const baseHref = useHref('/'); | ||
React.useLayoutEffect(() => { | ||
registerPortalProvider((node, container, key) => { | ||
setPortalElements((elements) => { | ||
return [...elements, [node, container, key]]; | ||
}); | ||
}, baseHref); | ||
}, [baseHref]); | ||
|
||
return ( | ||
<> | ||
{portaledElements.map(([node, container, key], index) => | ||
ReactDOM.createPortal(node, container, key ?? String(index)), | ||
)} | ||
</> | ||
); | ||
}; |
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 is an interesting fix but I am worried this behavior is inconsistent with the rest of the UI kit -- if you make an
<a href=
or awindow.open(href)
call, you have to pass the correct href. Why should toaster let you pass an incorrect href and fix it for you?We have some places like
RunUtils.tsx
where we already pass the href correctly built fromhistory.createHref
. Can you update the callsites that are doing it incorrectly to do it right instead?I'm worried that these places that ARE doing it right will have the href "double prepended" with the path prefix now.
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.
Alternatively, we could extend the Toaster data to let you specify
action: {text: string, to: string}
and then have the toaster transform the "to" into an href. I think that'd be consistent with how<Link
works and would be nice!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.
Yeah I was considering doing that too but the utilities creating the href aren't hooks so they can't access
createHref
. I guess I can update their callsites to pass the history object fromuseHistory
to them. We could also check if it already has the prefix and if so skip adding it.