From 86a55d3680f4f3193dda45f6f291a102335e9f34 Mon Sep 17 00:00:00 2001 From: Haitao Yue Date: Thu, 28 Jun 2018 10:38:09 +0800 Subject: [PATCH] [CE-399] Fix edit host error in operator dashboard Change host router in operator dashboard. Remove k8s_ssl when update type is not kubernetes. Change-Id: I408af8a594c1903bcbc2a5bba1e49d4b6ab6b937 Signed-off-by: Haitao Yue --- src/modules/host.py | 4 +-- src/static/dashboard/src/common/menu.js | 18 ++++++++---- src/static/dashboard/src/common/router.js | 4 +-- .../src/components/SiderMenu/SiderMenu.js | 6 +++- .../src/routes/Host/CreateHost/index.js | 29 +++++++++---------- src/static/dashboard/src/routes/Host/index.js | 4 +-- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/modules/host.py b/src/modules/host.py index 1fbd71b8..168a9eb9 100644 --- a/src/modules/host.py +++ b/src/modules/host.py @@ -232,9 +232,9 @@ def update(self, id, d): if "log_type" in d and d["log_type"] == CLUSTER_LOG_TYPES[0]: d["log_server"] = "" if "autofill" in d: - d["autofill"] = d["autofill"] == "true" + d["autofill"] = d["autofill"] == "on" if "schedulable" in d: - d["schedulable"] = d["schedulable"] == "true" + d["schedulable"] = d["schedulable"] == "on" self.db_set_by_id(id, **d) h_new = self.get_by_id(id) return self._schema(h_new) diff --git a/src/static/dashboard/src/common/menu.js b/src/static/dashboard/src/common/menu.js index e6a2fb37..5da4728a 100644 --- a/src/static/dashboard/src/common/menu.js +++ b/src/static/dashboard/src/common/menu.js @@ -42,12 +42,18 @@ const menuData = [ name: intl.formatMessage(messages.menus.host), icon: 'laptop', path: 'host', - }, - { - name: 'Create Host', - path: 'host-create', - hideInMenu: true, - hideInBreadcrumb: false, + children: [ + { + name: intl.formatMessage(messages.menus.host), + path: 'index', + }, + { + name: 'Create Host', + path: 'create', + hideInMenu: true, + hideInBreadcrumb: false, + } + ], }, { name: intl.formatMessage(messages.menus.chain), diff --git a/src/static/dashboard/src/common/router.js b/src/static/dashboard/src/common/router.js index 0e6728f4..47ffb869 100644 --- a/src/static/dashboard/src/common/router.js +++ b/src/static/dashboard/src/common/router.js @@ -78,10 +78,10 @@ export const getRouterData = app => { '/overview': { component: dynamicWrapper(app, ['overview'], () => import('../routes/Overview')), }, - '/host': { + '/host/index': { component: dynamicWrapper(app, ['host'], () => import('../routes/Host')), }, - '/create-host': { + '/host/create': { component: dynamicWrapper(app, ['host'], () => import('../routes/Host/CreateHost')), }, '/chain': { diff --git a/src/static/dashboard/src/components/SiderMenu/SiderMenu.js b/src/static/dashboard/src/components/SiderMenu/SiderMenu.js index d7fe221a..8ca65827 100644 --- a/src/static/dashboard/src/components/SiderMenu/SiderMenu.js +++ b/src/static/dashboard/src/components/SiderMenu/SiderMenu.js @@ -115,7 +115,11 @@ export default class SiderMenu extends PureComponent { * get SubMenu or Item */ getSubMenuOrItem = item => { - if (item.children && item.children.some(child => child.name)) { + let shownChildrenLen = 1; + if (item.children) { + shownChildrenLen = item.children.filter(subItem => typeof subItem.hideInMenu === 'undefined').length; + } + if (item.children && item.children.some(child => child.name) && shownChildrenLen > 1) { const childrenItems = this.getNavMenuItems(item.children); // 当无子菜单时就不展示菜单 if (childrenItems && childrenItems.length > 0) { diff --git a/src/static/dashboard/src/routes/Host/CreateHost/index.js b/src/static/dashboard/src/routes/Host/CreateHost/index.js index 6342c2b8..03d6f0a9 100644 --- a/src/static/dashboard/src/routes/Host/CreateHost/index.js +++ b/src/static/dashboard/src/routes/Host/CreateHost/index.js @@ -287,29 +287,26 @@ class CreateHost extends PureComponent { this.setState({ submitting: true, }); + let data = { + ...values, + schedulable: schedulable ? 'on' : 'off', + autofill: autofill ? 'on' : 'off', + callback: this.submitCallback, + }; + if (values.host_type === 'kubernetes') { + data.k8s_ssl = k8sUseSSL ? 'on' : 'off'; + } if (action === 'create') { this.props.dispatch({ type: 'host/createHost', - payload: { - ...values, - schedulable: schedulable ? 'on' : 'off', - autofill: autofill ? 'on' : 'off', - k8s_ssl: k8sUseSSL ? 'on' : 'off', - callback: this.submitCallback, - }, + payload: data, }); } else { - delete values.host_type; + data.id = hostId; + delete data.host_type; this.props.dispatch({ type: 'host/updateHost', - payload: { - ...values, - schedulable: schedulable ? 'true' : 'false', - autofill: autofill ? 'true' : 'false', - k8s_ssl: k8sUseSSL ? 'on' : 'off', - id: hostId, - callback: this.submitCallback, - }, + payload: data, }); } } diff --git a/src/static/dashboard/src/routes/Host/index.js b/src/static/dashboard/src/routes/Host/index.js index 0ab22d5e..5347d404 100644 --- a/src/static/dashboard/src/routes/Host/index.js +++ b/src/static/dashboard/src/routes/Host/index.js @@ -88,7 +88,7 @@ class Host extends PureComponent { onClickAddHost = () => { this.props.dispatch( routerRedux.push({ - pathname: '/create-host', + pathname: '/host/create', }) ); }; @@ -129,7 +129,7 @@ class Host extends PureComponent { editHost = host => { this.props.dispatch( routerRedux.push({ - pathname: '/create-host', + pathname: '/host/create', search: stringify({ id: host.id, action: 'update',