-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Breezewish <[email protected]>
- Loading branch information
1 parent
cf6df9c
commit eb0a97a
Showing
20 changed files
with
1,294 additions
and
1,125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/utils/dashboard_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# This file contains a version number which will be used to release assets to | ||
# GitHub. To trigger a new asset release, simply increase this version number. | ||
20200108_2 | ||
20200109_1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import singleSpaReact from 'single-spa-react'; | ||
import RootComponent from './RootComponent.js'; | ||
|
||
const reactLifecycles = singleSpaReact({ | ||
React, | ||
ReactDOM, | ||
rootComponent: RootComponent, | ||
domElementGetter, | ||
}); | ||
|
||
export const bootstrap = [ | ||
reactLifecycles.bootstrap, | ||
]; | ||
export const mount = [ | ||
reactLifecycles.mount, | ||
]; | ||
export const unmount = [ | ||
reactLifecycles.unmount, | ||
]; | ||
|
||
function domElementGetter() { | ||
return document.getElementById('__spa_content__'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
id: 'demo', | ||
loader: () => import('./app.js'), | ||
routerPrefix: '/demo', | ||
icon: 'pie-chart', | ||
menuTitle: 'Demo 2', // TODO: I18N | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { Menu } from 'antd'; | ||
import { HashRouter as Router, Switch, Route, Link } from 'react-router-dom'; | ||
|
||
const App = () => ( | ||
<Router> | ||
<p>Hello World</p> | ||
<p>Sample child navigation</p> | ||
<Menu mode="horizontal"> | ||
<Menu.Item> | ||
<Link to="/home/">Home</Link> | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Link to="/home/about">Home/About</Link> | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Link to="/home/users">Home/Users</Link> | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Link to="/demo">Demo</Link> | ||
</Menu.Item> | ||
</Menu> | ||
<Switch> | ||
<Route path="/home/about"> | ||
<About /> | ||
</Route> | ||
<Route path="/home/users"> | ||
<Users /> | ||
</Route> | ||
<Route path="/demo"> | ||
<Home /> | ||
</Route> | ||
</Switch> | ||
</Router> | ||
); | ||
|
||
function Home() { | ||
return <h2>Home</h2>; | ||
} | ||
|
||
function About() { | ||
return <h2>About</h2>; | ||
} | ||
|
||
function Users() { | ||
return <h2>Users</h2>; | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import singleSpaReact from 'single-spa-react'; | ||
import RootComponent from './RootComponent.js'; | ||
|
||
const reactLifecycles = singleSpaReact({ | ||
React, | ||
ReactDOM, | ||
rootComponent: RootComponent, | ||
domElementGetter, | ||
}); | ||
|
||
export const bootstrap = [ | ||
reactLifecycles.bootstrap, | ||
]; | ||
export const mount = [ | ||
reactLifecycles.mount, | ||
]; | ||
export const unmount = [ | ||
reactLifecycles.unmount, | ||
]; | ||
|
||
function domElementGetter() { | ||
return document.getElementById('__spa_content__'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
id: 'home', | ||
loader: () => import('./app.js'), | ||
routerPrefix: '/home', | ||
icon: 'desktop', | ||
menuTitle: 'Demo 1', // TODO: I18N | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +0,0 @@ | ||
body { | ||
margin: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', | ||
monospace; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,99 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Menu, Icon } from 'antd'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import * as singleSpa from 'single-spa'; | ||
import * as LayoutSPA from '@/layout'; | ||
import './index.css'; | ||
import App from './App'; | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
import AppHome from '@/apps/home'; | ||
import AppDemo from '@/apps/demo'; | ||
|
||
// TODO: This part might be better in TS. | ||
class AppRegistry { | ||
constructor() { | ||
this.defaultRouter = ''; | ||
this.apps = {}; | ||
} | ||
|
||
/** | ||
* Register a TiDB Dashboard application. | ||
* | ||
* This function is a light encapsulation over single-spa's registerApplication | ||
* which provides some extra registry capabilities. | ||
* | ||
* @param {{ | ||
* id: string, | ||
* loader: Function, | ||
* routerPrefix: string, | ||
* indexRoute: string, | ||
* isDefaultRouter: boolean, | ||
* icon: string, | ||
* menuTitle: string, | ||
* }} app | ||
*/ | ||
register(app) { | ||
singleSpa.registerApplication(app.id, app.loader, (location) => { | ||
return location.hash.indexOf('#' + app.routerPrefix) === 0; | ||
}); | ||
if (!app.indexRoute) { | ||
app.indexRoute = app.routerPrefix; | ||
} | ||
if (!this.defaultRouter || app.isDefaultRouter) { | ||
this.defaultRouter = app.indexRoute; | ||
} | ||
this.apps[app.id] = app; | ||
return this; | ||
} | ||
|
||
/** | ||
* Get the default router for initial routing. | ||
*/ | ||
getDefaultRouter() { | ||
return this.defaultRouter || '/'; | ||
} | ||
|
||
/** | ||
* Get the registry of the current active app. | ||
*/ | ||
getActiveApp() { | ||
const mountedApps = singleSpa.getMountedApps(); | ||
for (let i = 0; i < mountedApps.length; i++) { | ||
const app = mountedApps[i]; | ||
if (this.apps[app] !== undefined) { | ||
return this.apps[app]; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Render an Antd menu item according to the app id. | ||
* | ||
* @param {string} appId | ||
*/ | ||
renderAppMenuItem(appId) { | ||
const app = this.apps[appId]; | ||
if (!app) { | ||
return null; | ||
} | ||
return ( | ||
<Menu.Item key={appId}> | ||
<Link to={app.indexRoute}> | ||
{ app.icon ? <Icon type={app.icon} /> : null } | ||
<span>{app.menuTitle}</span> | ||
</Link> | ||
</Menu.Item> | ||
); | ||
} | ||
} | ||
|
||
const registry = new AppRegistry(); | ||
|
||
singleSpa.registerApplication('layout', LayoutSPA, () => true, { registry }); | ||
registry | ||
.register(AppHome) | ||
.register(AppDemo) | ||
; | ||
singleSpa.start(); | ||
|
||
document.getElementById('dashboard_page_spinner').remove(); |
Oops, something went wrong.