Skip to content

Commit

Permalink
appBootstrapper and routes .jsx->.tsx
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Abeshouse <abeshoua@mskcc.org>
  • Loading branch information
Adam Abeshouse committed Dec 23, 2021
1 parent 12421ad commit 403d7aa
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 76 deletions.
56 changes: 41 additions & 15 deletions src/appBootstrapper.jsx → src/appBootstrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
initializeAppStore,
initializeLoadConfiguration,
initializeServerConfiguration,
setConfigDefaults,
setServerConfig,
} from './config/config';

Expand All @@ -32,6 +31,23 @@ import { handleLongUrls } from 'shared/lib/handleLongUrls';
import 'shared/polyfill/canvasToBlob';
import { setCurrentURLHeader } from 'shared/lib/extraHeader';
import Container from 'appShell/App/Container';
import request from 'superagent';
import { IServerConfig } from 'config/IAppConfig';

export interface ICBioWindow {
globalStores: {
routing: ExtendedRoutingStore;
appStore: AppStore;
};
routingStore: ExtendedRoutingStore;
$: JQueryStatic;
jQuery: JQueryStatic;

e2etest: boolean;
FRONTEND_VERSION: string;
FRONTEND_COMMIT: string;
rawServerConfig: IServerConfig;
}

superagentCache(superagent);

Expand All @@ -53,14 +69,15 @@ handleLongUrls();
// YOU MUST RUN THESE initialize and then set the public path after
initializeLoadConfiguration();
// THIS TELLS WEBPACK BUNDLE LOADER WHERE TO LOAD SPLIT BUNDLES
//@ts-ignore
__webpack_public_path__ = getLoadConfig().frontendUrl;

if (!window.hasOwnProperty('$')) {
window.$ = $;
((window as any) as ICBioWindow).$ = $;
}

if (!window.hasOwnProperty('jQuery')) {
window.jQuery = $;
((window as any) as ICBioWindow).jQuery = $;
}

// write browser name, version to body tag
Expand All @@ -74,7 +91,7 @@ if (browser) {
if (getBrowserWindow().navigator.webdriver) {
$(document).ready(() => {
$('body').addClass('e2etest');
window.e2etest = true;
((window as any) as ICBioWindow).e2etest = true;
});
}

Expand All @@ -86,7 +103,7 @@ if (getBrowserWindow().navigator.webdriver || localStorage.recordAjaxQuiet) {
if (localStorage.getItem('timeElementVisible')) {
const interval = setInterval(() => {
const elementIsVisible = $(
localStorage.getItem('timeElementVisible')
localStorage.getItem('timeElementVisible')!
).is(':visible');
if (elementIsVisible) {
clearInterval(interval);
Expand All @@ -105,18 +122,20 @@ if (/cbioportal\.org/.test(getBrowserWindow().location.href)) {
}

// expose version on window
window.FRONTEND_VERSION = VERSION;
window.FRONTEND_COMMIT = COMMIT;
//@ts-ignore
((window as any) as ICBioWindow).FRONTEND_VERSION = VERSION;
//@ts-ignore
((window as any) as ICBioWindow).FRONTEND_COMMIT = COMMIT;

// this is special function allowing MSKCC CIS to hide login UI in
// portal header
window.postLoadForMskCIS = function() {
(window as any).postLoadForMskCIS = function() {
getLoadConfig().hide_login = true;
window.isMSKCIS = true;
(window as any).isMSKCIS = true;
};

// this is the only supported way to disable tracking for the $3Dmol.js
window.$3Dmol = { notrack: true };
(window as any).$3Dmol = { notrack: true };

// make sure lodash doesn't overwrite (or set) global underscore
_.noConflict();
Expand All @@ -135,14 +154,16 @@ const stores = {
appStore: new AppStore(),
};

window.globalStores = stores;
((window as any) as ICBioWindow).globalStores = stores;

//@ts-ignore
const end = superagent.Request.prototype.end;

let redirecting = false;

//@ts-ignore
superagent.Request.prototype.end = function(callback) {
return end.call(this, (error, response) => {
return end.call(this, (error: any, response: any) => {
if (redirecting) {
return;
}
Expand All @@ -152,6 +173,7 @@ superagent.Request.prototype.end = function(callback) {
localStorage.setItem(storageKey, window.location.href);

// build URL with a reference to storage key so that /restore route can restore it after login
//@ts-ignore because we're using buildCBioPortalPageUrl without a pathname, which is normally required
const loginUrl = buildCBioPortalPageUrl({
query: {
'spring-security-redirect': buildCBioPortalPageUrl({
Expand All @@ -169,27 +191,30 @@ superagent.Request.prototype.end = function(callback) {
});
};
//
window.routingStore = routingStore;
((window as any) as ICBioWindow).routingStore = routingStore;

let render = () => {
let render = (key?: number) => {
if (!getBrowserWindow().navigator.webdriver) initializeTracking();

const rootNode = document.getElementById('reactRoot');

ReactDOM.render(
<Provider {...stores}>
<Router history={syncedHistory}>
{/*@ts-ignore*/}
<Container location={routingStore.location} />
</Router>
</Provider>,
rootNode
);
};

//@ts-ignore
if (__DEBUG__ && module.hot) {
const renderApp = render;
render = () => renderApp(Math.random());

//@ts-ignore
module.hot.accept('./routes', () => render());
}

Expand All @@ -203,7 +228,8 @@ $(document).ready(async () => {
// or fetch from config service if not
// need to use jsonp, so use jquery
let initialServerConfig =
window.rawServerConfig || (await fetchServerConfig());
((window as any) as ICBioWindow).rawServerConfig ||
(await fetchServerConfig());

initializeServerConfiguration(initialServerConfig);

Expand Down
4 changes: 1 addition & 3 deletions src/appShell/App/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ export default class Container extends React.Component<IContainerProps, {}> {
</div>
</Then>
<Else>
<div className="contentWrapper">
{makeRoutes(this.routingStore)}
</div>
<div className="contentWrapper">{makeRoutes()}</div>
</Else>
</If>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/config/IAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IAppConfig {
export interface ILoadConfig {
apiRoot?: string;
baseUrl?: string;
basePath?: string;
configurationServiceUrl?: string;
frontendUrl?: string;
hide_login?: boolean;
Expand Down
Loading

0 comments on commit 403d7aa

Please sign in to comment.