-
Notifications
You must be signed in to change notification settings - Fork 8.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
[Canvas] Switch Canvas to use React Router #100579
Conversation
Pinging @elastic/kibana-presentation (Team:Presentation) |
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.
Approving the SCSS changes and noting that they're unrelated to the form layout issue. I'm not sure when that was broken, but the button and input are misaligned in that screenshot.
@ryankeairns yes thanks for pointing that out. I used the same layout as the AutorefreshControls, which is broken. I thought it might have just been Amsterdam related but it's broken on v7 theme as well. I'll make an issue to follow up on that. |
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.
Epic work, @crob611 ... some stuff I've mentioned I might leave to a follow-up, but just a stellar job. Let's get it in so we can iterate and avoid tie-ups in CI.
@@ -178,7 +170,4 @@ export const teardownCanvas = (coreStart: CoreStart, startPlugins: CanvasStartDe | |||
|
|||
coreStart.chrome.setBadge(undefined); | |||
coreStart.chrome.setHelpExtension(undefined); | |||
|
|||
destroyHistory(); | |||
stopRouter(); | |||
}; |
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 whole file makes me happy... and it's the first code file I'm reviewing. 🚀
import PropTypes from 'prop-types'; | ||
import { History } from 'history'; | ||
// @ts-expect-error | ||
import createHashStateHistory from 'history-extra/dist/createHashStateHistory'; |
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.
Um... we should replace this soon, too.
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.
Yep. I left this alone because we will have to switch from Hash routing because the HashHistory that comes from the history
package does not allow pushState, which is what the history-extra package allows. It should be a fairly straightforward switch, or we wait for the next version of history
which I believe is going to allow state on the hash.
import { shortcutManager } from '../../lib/shortcut_manager'; | ||
import { CanvasRouter } from '../../routes'; | ||
|
||
class ShortcutManagerContextWrapper extends React.Component { |
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 should be refactored soon, too.
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.
Yep, the ReactShortcuts
package we use uses the legacy context, hence the need for it here. That package is also not really maintained, so may want to look into other replacements that are more up to date.
import { EuiPanel, EuiLoadingChart, EuiSpacer, EuiText } from '@elastic/eui'; | ||
|
||
export const CanvasLoading = ({ msg }) => ( | ||
export const CanvasLoading: FC<{ msg?: string }> = ({ msg = 'Loading...' }) => ( |
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.
i18n?
<Link name="loadWorkpad" params={{ id }}> | ||
Edit Workpad | ||
</Link> | ||
<RoutingLink to={`/workpad/${id}`}>Edit Workpad</RoutingLink> |
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.
i18n?
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 on the PDF export page, so I don't think it really needs i18n since it's never actually going to be seen. Not sure why that link is even there really.
removeWorkpads={removeWorkpads} | ||
onClose={onClose} | ||
workpads={workpadsState} | ||
formatDate={formatDate} |
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 easier as:
const { workpadId, canUserWrite } = fromState;
<Component
downloadWorkpad={onDownloadWorkpad}
workpads={workpadsState}
{...{
workpadId,
canUserWrite,
cloneWorkpad,
createWorkpad,
findWorkpads,
removeWorkpads,
onClose,
formatDate,
}}
/>
I'd love to see consistency in event handlers, (e.g. downloadWorkpad
becomes onDownloadWorkpad
, createWorkpad
becomes onCreateWorkpad
, etc)
const { setFullscreen } = services.platform; | ||
|
||
useEffect(() => { | ||
const body = document.querySelector('body'); |
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.
Isn't this just document.body
with the potential of being undefined?
} | ||
|
||
useEffect(() => { | ||
if (pageIndex !== workpad.page) { |
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 should consider removing the param from the url if malformed. (follow-up)
path={'/workpad/:id'} | ||
exact={false} | ||
children={(route: WorkpadRouteProps) => { | ||
return [ |
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.
nit: can just return the array.
/> | ||
); | ||
|
||
export const ExportRouteManager: FC = ({ children }) => { |
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'd almost like to see this split out into individual files.
@elasticmachine merge upstream |
merge conflict between base and head |
@elasticmachine merge upstream |
|
||
const pageNumber = parseInt(params.pageNumber, 10); | ||
let pageIndex = workpad.page; | ||
if (!isNaN(pageNumber)) { |
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.
The comment below was actually for ^this line.
We should consider removing the param from the url if malformed. (follow-up)
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsReferences to deprecated APIs
History
To update your PR or re-run it, just comment with: |
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.
Approving to unblock! Tested workpads with embeddables and generated lots of PDFs!
Only issue I found was the "undo after fullscreen" issue
* Switch Canvas to use React Router * Fix typescript errors * Remove @scant/router from package.json * Fix tests * Fix functional test * Fix functional tests * Fix bad merge in package.json * Cleanup from code review comments * Fix double basepath append Co-authored-by: Kibana Machine <[email protected]>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
Thank you @crob611 and @poffdeluxe !! |
…sens/kibana into reporting/new-png-pdf-report-type * 'reporting/new-png-pdf-report-type' of github.com:jloleysens/kibana: (46 commits) [Security Solution] Add Ransomware canary advanced policy option (elastic#101068) [Exploratory view] Core web vitals (elastic#100320) [Security solution][Endpoint] Add unit tests for fleet event filters/trusted apps cards (elastic#101034) [Lens] Use a setter function for the dimension panel (elastic#101123) [Index Patterns] Fix return saved index pattern object (elastic#101051) [CI] For PRs, build TS refs before public api docs check (elastic#100791) [Maps] fix line and polygon label regression (elastic#101085) Migrate CCR to new ES JS client. (elastic#100131) [Canvas] Switch Canvas to use React Router (elastic#100579) [Expressions] Use table column ID instead of name when set (elastic#99724) [DOCS] Updates docs landing page (elastic#100749) [DOCS] Corrects typo in step 3 (elastic#101079) [DOCS] Updates runtime example in Discover (elastic#100926) Migrate kibana.autocomplete config to data plugin (elastic#100586) [Uptime] New width/delay definition for waterfall sidebar item tooltip (elastic#100147) [FTR] Use importExport for saved_object/basic archive (elastic#100244) [Fleet] Better input for multi text input in agent policy builder (elastic#101020) [CI] Buildkite support with Baseline pipeline (elastic#100492) [Reporting/Telemetry] Do not send telemetry if we are in screenshot mode (elastic#100388) Create API keys with metadata (elastic#100682) ...
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
2 similar comments
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
* Switch Canvas to use React Router * Fix typescript errors * Remove @scant/router from package.json * Fix tests * Fix functional test * Fix functional tests * Fix bad merge in package.json * Cleanup from code review comments * Fix double basepath append Co-authored-by: Kibana Machine <[email protected]> # Conflicts: # package.json
* Switch Canvas to use React Router * Fix typescript errors * Remove @scant/router from package.json * Fix tests * Fix functional test * Fix functional tests * Fix bad merge in package.json * Cleanup from code review comments * Fix double basepath append Co-authored-by: Kibana Machine <[email protected]> # Conflicts: # package.json
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
Summary
Closes #99815
Fixes #94575
This pull request switches Canvas to use React Router for its routing needs, and all that comes along with that.
Some key changes worth mentioning
Now, the url will always be the source of truth and we don't even sync that data to redux, opting instead to pass any kind of information or functionality related to routing around as a Context.
The view menu without "Stop/Start Autoplay"
Autoplay menu now has an X to disable autoplay, same as auto refresh
There is also a keyboard shortcut for disable autoplay. This would turn autoplay off and the url would be updated so there was no autoplay in it. I changed this slightly so that the keyboard shortcut internally pauses the autoplay, but nothing will be reflected in the url.
Testing
This touches a lot, so testing as much as possible is great. Anything that involves routing is going to be the most likely to be impacted, so I'll call out some of the important things
[ ] Undo/Redo on a workpad with Keyboard Shortcuts, Edit Menu links, and browser forward/back navigation
[ ] Changes to workpads that result in a change to the page number you are on. (adding a page, deleting a page, moving a page, etc)
[ ] Creating empty workpads and creating workpads from templates
[ ] Export