Fix: Use basepath from state for socket path (#24369)

Closes https://github.com/elastic/kibana/issues/23168

This PR uses the `basePath` constant from Angular to mount the client socket instance, allowing it to connect correctly even in when using a Space.

### Workpad correctly loading in a Space
![screenshot 2018-10-22 15 57 00](https://user-images.githubusercontent.com/404731/47324055-251a3f80-d613-11e8-9fb0-0b0eaa3b974d.png)

### List of workpads restricted to a space
![screenshot 2018-10-22 13 49 54](https://user-images.githubusercontent.com/404731/47319741-50496280-d604-11e8-8966-83ef3a9fb320.png)

### List of workpads restricted to default space
![screenshot 2018-10-22 13 50 37](https://user-images.githubusercontent.com/404731/47319747-593a3400-d604-11e8-960d-385c80c7638a.png)
This commit is contained in:
Joe Fleming 2018-10-23 09:56:42 -07:00 committed by GitHub
parent 9b78cfd4b9
commit f894f0ea62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View file

@ -8,7 +8,7 @@ import { connect } from 'react-redux';
import { compose, withProps } from 'recompose';
import { createSocket } from '../../socket';
import { initialize as initializeInterpreter } from '../../lib/interpreter';
import { getAppReady } from '../../state/selectors/app';
import { getAppReady, getBasePath } from '../../state/selectors/app';
import { appReady, appError } from '../../state/actions/app';
import { trackRouteChange } from './track_route_change';
import { App as Component } from './app';
@ -19,13 +19,15 @@ const mapStateToProps = state => {
return {
appState: typeof appState === 'object' ? appState : { ready: appState },
basePath: getBasePath(state),
};
};
const mapDispatchToProps = dispatch => ({
setAppReady: async () => {
// TODO: the correct socket path should come from upstream, using the constant here is not ideal
setAppReady: basePath => async () => {
// initialize the socket and interpreter
createSocket();
createSocket(basePath);
await initializeInterpreter();
// set app state to ready
@ -34,10 +36,20 @@ const mapDispatchToProps = dispatch => ({
setAppError: payload => dispatch(appError(payload)),
});
const mergeProps = (stateProps, dispatchProps, ownProps) => {
return {
...ownProps,
...stateProps,
...dispatchProps,
setAppReady: dispatchProps.setAppReady(stateProps.basePath),
};
};
export const App = compose(
connect(
mapStateToProps,
mapDispatchToProps
mapDispatchToProps,
mergeProps
),
withProps(() => ({
onRouteChange: trackRouteChange,

View file

@ -4,15 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/
import chrome from 'ui/chrome';
import io from 'socket.io-client';
import { functionsRegistry } from '../common/lib/functions_registry';
import { loadBrowserPlugins } from './lib/load_browser_plugins';
let socket;
export function createSocket() {
const basePath = chrome.getBasePath();
export function createSocket(basePath) {
socket = io(undefined, { path: `${basePath}/socket.io` });
socket.on('getFunctionList', () => {