From 0f788dc2cbdadb49d269e735ad53b47070d1008b Mon Sep 17 00:00:00 2001 From: zhangjingwei Date: Mon, 9 Aug 2021 08:20:37 +0800 Subject: [PATCH] fix: Fix inspect error message 1. Update error message display: auto parse json str 2. Disable inspect when baremetail's driver is ipmi Change-Id: I81ec6271b2eac779c9308c2e4a169b72b38d76de --- src/components/CodeEditor/index.jsx | 18 +++++++++++++----- .../BareMetalNode/actions/Inspect.jsx | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/CodeEditor/index.jsx b/src/components/CodeEditor/index.jsx index 0fe97a19..4192f162 100644 --- a/src/components/CodeEditor/index.jsx +++ b/src/components/CodeEditor/index.jsx @@ -20,24 +20,32 @@ import { isString } from 'lodash'; import styles from './index.less'; import AceEditor from './AceEditor'; -const parseHtml = (value) => { - if (isString(value) && value.includes('')) { +const parseValue = (value) => { + if (!isString(value)) { + return value; + } + if (value.includes('')) { const reg = /<\/h1>[\r\n]([\s\S]*)

/; const results = reg.exec(value); if (results) { return results[1]; } } - return value; + try { + const result = JSON.parse(value); + return result; + } catch (e) { + return value; + } }; const getCodeValue = (value, mode) => { if (isString(value)) { - return parseHtml(value); + return parseValue(value); } Object.keys(value).forEach((key) => { if (isString(value[key])) { - value[key] = parseHtml(value[key]); + value[key] = parseValue(value[key]); } }); if (mode === 'json') { diff --git a/src/pages/compute/containers/BareMetalNode/actions/Inspect.jsx b/src/pages/compute/containers/BareMetalNode/actions/Inspect.jsx index 328779dc..f46f8073 100644 --- a/src/pages/compute/containers/BareMetalNode/actions/Inspect.jsx +++ b/src/pages/compute/containers/BareMetalNode/actions/Inspect.jsx @@ -33,7 +33,8 @@ export default class Inspect extends ConfirmAction { getItemId = (data) => data.uuid; - allowedCheckFunc = (item) => item.provision_state === 'manageable'; + allowedCheckFunc = (item) => + item.provision_state === 'manageable' && item.driver !== 'ipmi'; confirmContext = (data) => { const name = this.getName(data);