forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 11
/
App.tsx
158 lines (143 loc) · 4.9 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { hot } from 'react-hot-loader/root';
import thunk from 'redux-thunk';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
import { initFeatureFlags } from 'src/featureFlags';
import { supersetTheme, ThemeProvider } from '@superset-ui/style';
import ErrorBoundary from 'src/components/ErrorBoundary';
import Menu from 'src/components/Menu/Menu';
import FlashProvider from 'src/components/FlashProvider';
import DashboardList from 'src/views/CRUD/dashboard/DashboardList';
import ChartList from 'src/views/CRUD/chart/ChartList';
import DatasetList from 'src/views/CRUD/data/dataset/DatasetList';
import DatasourceList from 'src/views/CRUD/data/database/DatabaseList';
import messageToastReducer from '../messageToasts/reducers';
import { initEnhancer } from '../reduxUtils';
import setupApp from '../setup/setupApp';
import setupPlugins from '../setup/setupPlugins';
import Welcome from './CRUD/welcome/Welcome';
import ToastPresenter from '../messageToasts/containers/ToastPresenter';
import {
MenuObjectProps,
MenuObjectChildProps,
} from '../components/Menu/MenuObject';
setupApp();
setupPlugins();
const container = document.getElementById('app');
const bootstrap = JSON.parse(container?.getAttribute('data-bootstrap') ?? '{}');
const user = { ...bootstrap.user };
const menu = { ...bootstrap.common.menu_data };
const common = { ...bootstrap.common };
initFeatureFlags(bootstrap.common.feature_flags);
const store = createStore(
combineReducers({
messageToasts: messageToastReducer,
}),
{},
compose(applyMiddleware(thunk), initEnhancer(false)),
);
// Menu items that should go into settings dropdown
const settingsMenus = {
Security: true,
Manage: true,
};
// Menu items that should be ignored
const ignore = {
'Import Dashboards': true,
};
// Cycle through menu.menu to build out cleanedMenu and settings
const cleanedMenu: object[] = [];
const settings: object[] = [];
menu.menu.forEach((item: any) => {
if (!item) {
return;
}
const children: (MenuObjectProps | string)[] = [];
const newItem = {
...item,
};
// Filter childs
if (item.childs) {
item.childs.forEach((child: MenuObjectChildProps | string) => {
if (typeof child === 'string') {
children.push(child);
} else if (
(child as MenuObjectChildProps).label &&
!ignore.hasOwnProperty(child.label)
) {
children.push(child);
}
});
newItem.childs = children;
}
if (!settingsMenus.hasOwnProperty(item.name)) {
cleanedMenu.push(newItem);
} else {
settings.push(newItem);
}
});
menu.menu = cleanedMenu;
menu.settings = settings;
const App = () => (
<Provider store={store}>
<ThemeProvider theme={supersetTheme}>
<FlashProvider common={common}>
<Router>
<QueryParamProvider ReactRouterRoute={Route}>
<Menu data={menu} />
<Switch>
<Route path="/superset/welcome/">
<ErrorBoundary>
<Welcome user={user} />
</ErrorBoundary>
</Route>
<Route path="/dashboard/list/">
<ErrorBoundary>
<DashboardList user={user} />
</ErrorBoundary>
</Route>
<Route path="/chart/list/">
<ErrorBoundary>
<ChartList user={user} />
</ErrorBoundary>
</Route>
<Route path="/tablemodelview/list/">
<ErrorBoundary>
<DatasetList user={user} />
</ErrorBoundary>
</Route>
<Route path="/databaseview/list/">
<ErrorBoundary>
<DatasourceList user={user} />
</ErrorBoundary>
</Route>
</Switch>
<ToastPresenter />
</QueryParamProvider>
</Router>
</FlashProvider>
</ThemeProvider>
</Provider>
);
export default hot(App);