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
This commit is contained in:
zhangjingwei 2021-08-09 08:20:37 +08:00 committed by Jingwei.Zhang
parent eff7345154
commit 0f788dc2cb
2 changed files with 15 additions and 6 deletions

View File

@ -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('<html>')) {
const parseValue = (value) => {
if (!isString(value)) {
return value;
}
if (value.includes('<html>')) {
const reg = /<\/h1>[\r\n]([\s\S]*)<br \/><br \/>/;
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') {

View File

@ -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);