[update] improved render methods for childrens with selectKey

This commit is contained in:
srgooglo 2020-10-07 11:16:26 +02:00
parent 9023493d02
commit 6454287277
9 changed files with 84 additions and 56 deletions

View File

@ -0,0 +1,14 @@
import React from 'react'
import settings from 'core/libs/settings'
const verbosity_enabled = settings('verbosity')
export default class Verbosity extends React.Component{
render(){
return(
<div>
verbosity => {verbosity_enabled ? "enabled" : "disabled"}
</div>
)
}
}

View File

@ -3,61 +3,68 @@ import { Menu } from 'antd'
import * as Icons from 'components/Icons' import * as Icons from 'components/Icons'
import styles from './index.less' import styles from './index.less'
import ApiDebug from './debuggers/api'
import AntdDebug from './debuggers/antd'
import CoreDebug from './debuggers/core'
import ThemeDebug from './debuggers/theme'
import SocketDebug from './debuggers/socket'
import VerbosityDebug from './debuggers/verbosity'
import ApiDebug from './api.js' const Debuggers = {
import AntdDebug from './antd.js' api: <ApiDebug />,
import CoreDebug from './core.js' antd: <AntdDebug />,
import ThemeDebug from './theme.js' core: <CoreDebug />,
import SocketDebug from './socket.js' theme: <ThemeDebug />,
socket: <SocketDebug />,
const debbugers = { verbosity: <VerbosityDebug />
apiDebug: <ApiDebug />,
antdDebug: <AntdDebug />,
coreDebug: <CoreDebug />,
themeDebug: <ThemeDebug />,
socketDebug: <SocketDebug />
} }
const { Item } = Menu const menuList = [
const menuMap = { {
apiDebug: ( key: "api",
<span> title: "API V3 Requester",
<Icons.Globe /> V3 Api icon: <Icons.Globe />,
</span> },
), {
antdDebug: ( key: "antd",
<span> title: "Antd",
<Icons.AntDesignOutlined /> Antd icon: <Icons.AntDesignOutlined />,
</span> require: "embedded"
), },
coreDebug: ( {
<span> key: "core",
<Icons.Box /> Core title: "Core",
</span> icon: <Icons.Box />
), },
themeDebug: ( {
<span> key: "theme",
<Icons.Image /> Theme title: "Theme",
</span> icon: <Icons.Image />
), },
socketDebug: ( {
<span> key: "socket",
<Icons.Box /> Socket title: "Socket",
</span> icon: <Icons.Box />
) },
} {
key: "verbosity",
title: "Verbosity",
icon: <Icons.Edit3 />
}
]
export default class Debug extends React.Component { export default class Debug extends React.Component {
constructor(props) { state = {
super(props) loading: true,
this.state = { selectKey: '',
selectKey: 'socketDebug', menus: []
}
} }
getMenu = () => { getMenu() {
return Object.keys(menuMap).map(item => ( return this.state.menus.map(item => (
<Item key={item}>{menuMap[item]}</Item> <Menu.Item key={item.key}>
<span>{item.icon} {item.title}</span>
</Menu.Item>
)) ))
} }
@ -68,17 +75,23 @@ export default class Debug extends React.Component {
} }
renderChildren = () => { renderChildren = () => {
try { let titlesArray = []
if (!this.state.selectKey) { this.state.menus.forEach(e => {
return <div>Select an debugger</div> titlesArray[e.key] = e
} })
return debbugers[this.state.selectKey] if(this.state.selectKey){
} catch (error) { return Debuggers[this.state.selectKey]
return <div>Select an debugger</div> }else{
<div> Select an Option </div>
} }
} }
componentDidMount(){
this.setState({ menus: menuList, loading: false })
}
render() { render() {
const { selectKey } = this.state const { selectKey } = this.state
return ( return (
<div className={styles.main}> <div className={styles.main}>

View File

@ -123,6 +123,7 @@ class GeneralSettings extends React.PureComponent {
</Menu.Item> </Menu.Item>
)) ))
} }
selectKey = key => { selectKey = key => {
this.setState({ this.setState({
selectKey: key, selectKey: key,