Skip to content

Commit

Permalink
Address review nits
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed Dec 29, 2019
1 parent 8dcb268 commit ebde655
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ export interface CapabilitiesStart {
*/
export class CapabilitiesService {
public async start({ appIds, http }: StartDeps): Promise<CapabilitiesStart> {
const capabilities = await http.post<Capabilities>(
`/api/core/capabilities${
http.anonymousPaths.isAnonymous(window.location.pathname) ? '/defaults' : ''
}`,
{ body: JSON.stringify({ applications: appIds }) }
);
const route = http.anonymousPaths.isAnonymous(window.location.pathname) ? '/defaults' : '';
const capabilities = await http.post<Capabilities>(`/api/core/capabilities${route}`, {
body: JSON.stringify({ applications: appIds }),
});

return {
capabilities: deepFreeze(capabilities),
Expand Down
32 changes: 17 additions & 15 deletions src/core/public/application/integration_tests/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@
* under the License.
*/

import React, { Component, ReactNode } from 'react';
import { mount, ReactWrapper } from 'enzyme';
import React, { ReactElement } from 'react';
import { mount } from 'enzyme';

import { I18nProvider } from '@kbn/i18n/react';

import { App, LegacyApp, AppMountParameters } from '../types';
import { MockedMounter, MockedMounterTuple } from '../test_types';

type Renderer = (
item: string
) => Promise<ReactWrapper<any, Readonly<{}>, Component<{}, {}, any>> | null>;
type Dom = ReturnType<typeof mount> | null;
type Renderer = (item: string) => Dom | Promise<Dom>;

export const createRenderer = (
node: ReactNode | null,
callback: (item: string) => void
element: ReactElement | null,
callback?: (item: string) => void | Promise<void>
): Renderer => {
const dom = node !== null ? mount(<I18nProvider>{node}</I18nProvider>) : node;
const dom: Dom = element && mount(<I18nProvider>{element}</I18nProvider>);

return (item: string) => {
callback(item);
if (dom) {
dom.update();
}
return new Promise(resolve => setImmediate(() => resolve(dom))); // flushes any pending promises
};
return item =>
new Promise(async resolve => {
if (callback) {
await callback(item);
}
if (dom) {
dom.update();
}
setImmediate(() => resolve(dom)); // flushes any pending promises
});
};

export const createAppMounter = (
Expand Down
8 changes: 4 additions & 4 deletions src/core/public/application/ui/app_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import React, { Fragment, FunctionComponent } from 'react';
import React, { FunctionComponent } from 'react';
import { History } from 'history';
import { Router, Route, RouteComponentProps } from 'react-router-dom';
import { Router, Route, RouteComponentProps, Switch } from 'react-router-dom';

import { Mounter } from '../types';
import { AppContainer } from './app_container';
Expand All @@ -35,7 +35,7 @@ interface Params {

export const AppRouter: FunctionComponent<Props> = ({ history, mounters }) => (
<Router history={history}>
<Fragment>
<Switch>
{[...mounters].flatMap(([appId, mounter]) =>
// Remove /app paths from the routes as they will be handled by the
// "named" route parameter `:appId` below
Expand Down Expand Up @@ -64,6 +64,6 @@ export const AppRouter: FunctionComponent<Props> = ({ history, mounters }) => (
return <AppContainer mounter={mounter} appId={id} />;
}}
/>
</Fragment>
</Switch>
</Router>
);

0 comments on commit ebde655

Please sign in to comment.