-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WebUILink and WebUINavigate component
- Loading branch information
Showing
4 changed files
with
170 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import { Link, LinkProps } from 'react-router-dom'; | ||
|
||
interface WebUILinkProps extends LinkProps { | ||
options?: { | ||
params?: any; | ||
}; | ||
} | ||
|
||
const WebUILink: React.FC<WebUILinkProps> = ({ options, ...props }) => { | ||
return ( | ||
<Link | ||
{...props} | ||
onClick={(e) => { | ||
props.onClick?.(e); | ||
const pathName = _.isString(props.to) | ||
? props.to | ||
: props.to.pathname || ''; | ||
document.dispatchEvent( | ||
new CustomEvent('move-to-from-react', { | ||
detail: { | ||
path: pathName, | ||
params: options?.params, | ||
}, | ||
}), | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default WebUILink; |
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,29 @@ | ||
import { useSuspendedBackendaiClient } from '../hooks'; | ||
import _ from 'lodash'; | ||
import React, { useEffect } from 'react'; | ||
import { Navigate, NavigateProps } from 'react-router-dom'; | ||
|
||
interface WebUINavigateProps extends NavigateProps { | ||
options?: { | ||
params?: any; | ||
}; | ||
} | ||
const WebUINavigate: React.FC<WebUINavigateProps> = ({ options, ...props }) => { | ||
useSuspendedBackendaiClient(); | ||
const pathName = _.isString(props.to) ? props.to : props.to.pathname || ''; | ||
useEffect(() => { | ||
document.dispatchEvent( | ||
new CustomEvent('move-to-from-react', { | ||
detail: { | ||
path: pathName, | ||
params: options?.params, | ||
}, | ||
}), | ||
); | ||
// Don't need to consider options.params | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [pathName]); | ||
return <Navigate {...props} />; | ||
}; | ||
|
||
export default WebUINavigate; |