-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathapp.tsx
128 lines (106 loc) · 3.73 KB
/
app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import './styles/style.scss';
import 'cloudify-ui-common-frontend/styles/font-cloudify.css';
// Import semantic ui styles and themes
import 'semantic-ui-less/semantic.less';
// Import react grid
import 'react-grid-layout/css/styles.css';
import 'react-resizable/css/styles.css';
// Import leaflet
import 'leaflet/dist/leaflet.css';
import 'react-leaflet-markercluster/dist/styles.min.css';
import * as Leaflet from 'leaflet';
import 'leaflet.markercluster';
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import log from 'loglevel';
import moment from 'moment';
import * as ReactQuery from 'react-query';
import { pick } from 'lodash';
import * as ReactRedux from 'react-redux';
import { createBrowserHistory } from 'history';
import { ConnectedRouter, push, replace } from 'connected-react-router';
import { Switch } from 'react-router-dom';
import i18n from 'i18next';
import type { ReduxStore } from './configureStore';
import configureStore from './configureStore';
import { createToolbox } from './utils/Toolbox';
import ConfigLoader from './utils/ConfigLoader';
import EventBus from './utils/EventBus';
import Consts from './utils/consts';
import StatusPoller from './utils/StatusPoller';
import UserAppDataAutoSaver from './utils/UserAppDataAutoSaver';
import widgetDefinitionLoader from './utils/widgetDefinitionsLoader';
import Interceptor from './utils/Interceptor';
import Routes from './components/routes';
import translation from './translations/en.json';
import LoaderUtils from './utils/LoaderUtils';
const browserHistory = createBrowserHistory({
basename: Consts.CONTEXT_PATH
});
const queryClient = new ReactQuery.QueryClient({
defaultOptions: {
queries: {
retry: false
}
}
});
export function initAppContext() {
i18n.init({
resources: {
en: {
translation
}
},
lng: 'en',
fallbackLng: 'en'
});
window.React = React;
window.ReactDOM = ReactDOM;
window.PropTypes = PropTypes;
window.L = Leaflet;
window.log = log;
window.connectToStore = ReactRedux.connect;
window.moment = moment;
window.ReactRedux = pick(ReactRedux, ['useSelector', 'useDispatch']);
window.ReactRouter = { push, replace };
window.ReactQuery = ReactQuery;
log.setLevel(log.levels.WARN);
window.onerror = (message, source, lineno, colno, error) => {
EventBus.trigger('window:error', message, source, lineno, colno, error);
};
widgetDefinitionLoader.init();
}
export default class app {
static load() {
initAppContext();
return Promise.all([
ConfigLoader.load().then(result => {
const store = configureStore(browserHistory, result);
createToolbox(store);
StatusPoller.create(store);
UserAppDataAutoSaver.create(store);
Interceptor.create(store);
return store;
}),
LoaderUtils.fetchResource('overrides.json', true).then(overrides =>
i18n.addResourceBundle('en', 'translation', overrides, true, true)
)
]).then(results => results[0]);
}
static start(store: ReduxStore) {
const { Provider } = ReactRedux;
ReactDOM.render(
<Provider store={store}>
<ReactQuery.QueryClientProvider client={queryClient}>
<ConnectedRouter history={browserHistory}>
<Switch>
<Routes />
</Switch>
</ConnectedRouter>
</ReactQuery.QueryClientProvider>
</Provider>,
document.getElementById('app')
);
}
}