-
Notifications
You must be signed in to change notification settings - Fork 12k
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
AppPlugins: Expose react-router to apps #33775
Conversation
Lovely! The only nit I see is that if plugins start defining routes with the basename included, it will break if we move to rr6 and basename becomes not needed anymore. Not sure what we can do about it though |
@domasx2 not sure what and how would you accomplish anything with other routes not being exact. I mean - the App routes are rendered only under a/:pluginId segment which means you cannot use app route anywhere but under that segment. Wanna tell me something more about the use case you are describing? |
I think with this merged we'd be able to use One example use case: |
Ah, of course, this will be possible. I thought you were thinking of apps extending native routes. |
@domasx2 what do you mean? we do not use this for any routes currently. what is changing in v6? |
With this merged plugin devs will be able to use |
plugins-bundled/internal/plugin-catalog-app/src/components/Card.tsx
Outdated
Show resolved
Hide resolved
@ryantxu - have you seen https://github.com/grafana/marketplace-app/pull/4 ? It does exactly what you are trying to do in the last commit :) |
packages/grafana-ui/src/index.ts
Outdated
@@ -12,3 +12,4 @@ export * from './slate-plugins'; | |||
|
|||
// Exposes standard editors for registries of optionsUi config and panel options UI | |||
export { getStandardFieldConfigs, getStandardOptionEditors } from './utils/standardEditors'; | |||
export { Route, useLocation, useParams } from 'react-router-dom'; |
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.
Why export from here rather than just have people import directly? Is this to potentially help backwards compatibility? (if so, can you add a comment?)
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.
no exports anymore, we are exposing RR to plugins and updating the plugin starters now
@mckn I've tried. It's plenty of work that's too risky to do during beta. And, the current relwase of RR6 is a prelease(beta0) so I would wait for a stable. Regarding the support for RR6 -me and @torkelo talked about this and we think this approach should work OK with RR6 if we just change the root path passed to the app plugin from |
Ahh, perfect 👍 |
@@ -59,7 +59,7 @@ export class AppWrapper extends React.Component<AppWrapperProps, AppWrapperState | |||
|
|||
return ( | |||
<Route | |||
exact | |||
exact={route.exact === undefined ? true : route.exact} |
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.
One of the great newish js features, fyi 😸
exact={route.exact === undefined ? true : route.exact} | |
exact={route.exact ?? true} |
* Allow Route component usage in app plugins * i tried * fix catalog app * fix catalog app * remove catalog changes from this PR * remove extra files * feat(plugins): expose react-router to plugins rather than export via grafana-ui * Bring back query and pathname to AppRootPage and add deprecation notice Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Ok ok, sounds good! Will this also prevent users from registering routes outside of the plugin path? |
An alternative solution to #33759
This simply makes the core app route not to e exact, and allows app plugins to use react-router directly. This gives the app plugin authors max flexiility to define their routes in the app.
Tricky thing is the base path for an app. I've changed the AppRootProps to expose
basename
property for navigation and routes creation downstream.Note: react-router v6 will make the nested routes much easier. I did a quicl sketch of rr5 -> 6 update, but there is too big a risk to make this step right before v8 as there is plenty of changes to do. And RR6 is still in beta and learning from my previous experiences with RR they tend to change the APIs a lot before releasing stable.
See https://github.com/grafana/marketplace-app/pull/4 for a usage example.
TODO