-
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
turning it all into one React app #35185
Changes from 2 commits
048b7e7
65a4606
38f50e5
beda17d
645203c
40b8ee0
7dd479e
a2dc9e7
430a69a
8c3f9da
4ba88ba
35dc179
b6130f6
b94ec53
97a4a99
efa89e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<kbn-management-app section="elasticsearch/watcher"> | ||
<div id="watchReactRoot"></div> | ||
</kbn-management-app> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { HashRouter, Switch, Route, Redirect } from 'react-router-dom'; | ||
import { WatchStatus } from './sections/watch_status/watch_status'; | ||
import { WatchEdit } from './sections/watch_edit/components/watch_edit'; | ||
import { WatchList } from './sections/watch_list/components/watch_list'; | ||
import { registerRouter } from './lib/navigation'; | ||
import { BASE_PATH } from './constants'; | ||
|
||
class ShareRouter extends Component { | ||
static contextTypes = { | ||
router: PropTypes.shape({ | ||
history: PropTypes.shape({ | ||
push: PropTypes.func.isRequired, | ||
createHref: PropTypes.func.isRequired | ||
}).isRequired | ||
}).isRequired | ||
} | ||
constructor(...args) { | ||
super(...args); | ||
this.registerRouter(); | ||
} | ||
|
||
registerRouter() { | ||
// Share the router with the app without requiring React or context. | ||
const { router } = this.context; | ||
registerRouter(router); | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
export const App = () => { | ||
return ( | ||
<HashRouter> | ||
<ShareRouter> | ||
<AppWithoutRouter /> | ||
</ShareRouter> | ||
</HashRouter> | ||
); | ||
}; | ||
|
||
// Export this so we can test it with a different router. | ||
export const AppWithoutRouter = () => ( | ||
<Switch> | ||
<Redirect exact from={`${BASE_PATH}`} to={`${BASE_PATH}watches`} /> | ||
<Route exact path={`${BASE_PATH}watches`} component={WatchList} /> | ||
<Route exact path={`${BASE_PATH}watches/watch/:id/status`} component={WatchStatus} /> | ||
<Route exact path={`${BASE_PATH}watches/watch/:id/edit`} component={WatchEdit} /> | ||
<Route exact path={`${BASE_PATH}watches/new-watch/:type`} component={WatchEdit} /> | ||
</Switch> | ||
); |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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: no new line