Skip to content

Commit

Permalink
Fixed hard refresh bug and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igoristic committed Feb 4, 2020
1 parent d32856e commit 30f3dfc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jest.mock('../../np_imports/ui/chrome', () => {
});

// TODO: Skipping for now, seems flaky in New Platform (needs more investigation)
describe('Test legends to toggle series: ', () => {
describe.skip('Test legends to toggle series: ', () => {
const ids = props.series.map(item => item.id);

describe('props.series: ', () => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/monitoring/public/lib/route_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function routeInitProvider(Private, monitoringClusters, globalState, lice
return (
monitoringClusters(clusterUuid, undefined, codePaths)
// Set the clusters collection and current cluster in globalState
.then(async clusters => {
const inSetupMode = await isInSetupMode();
.then(clusters => {
const inSetupMode = isInSetupMode();
const cluster = getClusterFromClusters(clusters, globalState);
if (!cluster && !inSetupMode) {
return kbnUrl.redirect('/no-data');
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/monitoring/public/lib/setup_mode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ export const initSetupModeState = async ($scope: any, $injector: any, callback?:
}
};

export const isInSetupMode = async () => {
export const isInSetupMode = () => {
if (setupModeState.enabled) {
return true;
}

const $injector = angularState.injector || (await chrome.dangerouslyGetActiveInjector());
const $injector = angularState.injector || chrome.dangerouslyGetActiveInjector();
const globalState = $injector.get('globalState');
return globalState.inSetupMode;
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const configureAppAngularModule = (angularModule: IModule, newPlatform: L
.value('esUrl', getEsUrl(newPlatform))
.value('uiCapabilities', newPlatform.application.capabilities)
.config(setupCompileProvider(newPlatform))
.config(setupLocationProvider(newPlatform))
.config(setupLocationProvider())
.config($setupXsrfRequestInterceptor(newPlatform))
.run(capture$httpLoadingCount(newPlatform))
.run($setupUICapabilityRedirect(newPlatform));
Expand All @@ -65,9 +65,7 @@ const setupCompileProvider = (newPlatform: LegacyCoreStart) => (
}
};

const setupLocationProvider = (newPlatform: CoreStart) => (
$locationProvider: ILocationProvider
) => {
const setupLocationProvider = () => ($locationProvider: ILocationProvider) => {
$locationProvider.html5Mode({
enabled: false,
requireBase: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { AppMountContext, LegacyCoreStart } from 'kibana/public';
// @ts-ignore TODO: change to absolute path
import uiRoutes from 'plugins/monitoring/np_imports/ui/routes';
// @ts-ignore TODO: change to absolute path
import chrome from 'plugins/monitoring/np_imports/ui/chrome';
// @ts-ignore TODO: change to absolute path
import { uiModules } from 'plugins/monitoring/np_imports/ui/modules';
// @ts-ignore TODO: change to absolute path
import { registerTimefilterWithGlobalState } from 'plugins/monitoring/np_imports/ui/timefilter';
Expand All @@ -32,11 +34,10 @@ export class AngularApp {
registerTimefilterWithGlobalState(app);
const appElement = document.createElement('div');
appElement.setAttribute('style', 'height: 100%');
appElement.innerHTML = `<div ng-app="monitoring">
<div ng-view style="height: 100%" id="monitoring-angular-app"></div>
</div>`;
appElement.innerHTML = '<div ng-view style="height: 100%" id="monitoring-angular-app"></div>';
this.injector = angular.bootstrap(appElement, [appModuleName]);
element.appendChild(appElement);
chrome.setInjector(this.injector);
angular.element(element).append(appElement);
}

public destroy = () => {
Expand Down
27 changes: 6 additions & 21 deletions x-pack/legacy/plugins/monitoring/public/np_imports/ui/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,15 @@
import angular from 'angular';
import { npStart, npSetup } from '../legacy_imports';

type OptionalInjector = void | angular.auto.IInjectorService;

class Chrome {
private getRootElement = (): Promise<HTMLElement> => {
return new Promise(resolve => {
const element = document.getElementById('monitoring-angular-app');
if (element) {
resolve(element);
} else {
setTimeout(() => resolve(this.getRootElement()), 100);
}
});
};
private injector?: OptionalInjector;

public dangerouslyGetActiveInjector = async (): Promise<angular.auto.IInjectorService> => {
const targetDomElement: HTMLElement = await this.getRootElement();
const $injector = angular.element(targetDomElement).injector();
if (!$injector) {
return Promise.reject('targetDomElement had no angular context after bootstrapping');
}
return Promise.resolve($injector);
};
public setInjector = (injector: OptionalInjector): void => void (this.injector = injector);
public dangerouslyGetActiveInjector = (): OptionalInjector => this.injector;

public getBasePath = (): string => {
return npStart.core.http.basePath.get();
};
public getBasePath = (): string => npStart.core.http.basePath.get();

public getInjected = (name?: string, defaultValue?: any): string | unknown => {
const { getInjectedVar, getInjectedVars } = npSetup.core.injectedMetadata;
Expand Down

0 comments on commit 30f3dfc

Please sign in to comment.