mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 11:50:42 -03:30
remove output/stderr tabs from host detail modals when not present (#12064)
This commit is contained in:
parent
c93155132a
commit
526b1e692a
@ -1,7 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Modal, Tab, Tabs, TabTitleText } from '@patternfly/react-core';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { t } from '@lingui/macro';
|
||||
import { encode } from 'html-entities';
|
||||
import StatusLabel from '../../../components/StatusLabel';
|
||||
@ -37,10 +36,8 @@ const processEventStatus = (event) => {
|
||||
|
||||
const processCodeEditorValue = (value) => {
|
||||
let codeEditorValue;
|
||||
if (value === undefined) {
|
||||
codeEditorValue = false;
|
||||
} else if (value === '') {
|
||||
codeEditorValue = ' ';
|
||||
if (!value) {
|
||||
codeEditorValue = '';
|
||||
} else if (typeof value === 'string') {
|
||||
codeEditorValue = encode(value);
|
||||
} else {
|
||||
@ -49,8 +46,8 @@ const processCodeEditorValue = (value) => {
|
||||
return codeEditorValue;
|
||||
};
|
||||
|
||||
const processStdOutValue = (hostEvent) => {
|
||||
const taskAction = hostEvent?.event_data?.taskAction;
|
||||
const getStdOutValue = (hostEvent) => {
|
||||
const taskAction = hostEvent?.event_data?.task_action;
|
||||
const res = hostEvent?.event_data?.res;
|
||||
|
||||
let stdOut;
|
||||
@ -61,8 +58,8 @@ const processStdOutValue = (hostEvent) => {
|
||||
res.results &&
|
||||
Array.isArray(res.results)
|
||||
) {
|
||||
[stdOut] = res.results;
|
||||
} else if (res) {
|
||||
stdOut = res.results.join('\n');
|
||||
} else if (res?.stdout) {
|
||||
stdOut = res.stdout;
|
||||
}
|
||||
return stdOut;
|
||||
@ -81,8 +78,8 @@ function HostEventModal({ onClose, hostEvent = {}, isOpen = false }) {
|
||||
};
|
||||
|
||||
const jsonObj = processCodeEditorValue(hostEvent?.event_data?.res);
|
||||
const stdErr = processCodeEditorValue(hostEvent?.event_data?.res?.stderr);
|
||||
const stdOut = processCodeEditorValue(processStdOutValue(hostEvent));
|
||||
const stdErr = hostEvent?.event_data?.res?.stderr;
|
||||
const stdOut = processCodeEditorValue(getStdOutValue(hostEvent));
|
||||
|
||||
return (
|
||||
<Modal
|
||||
@ -147,13 +144,13 @@ function HostEventModal({ onClose, hostEvent = {}, isOpen = false }) {
|
||||
<ContentEmpty title={t`No JSON Available`} />
|
||||
)}
|
||||
</Tab>
|
||||
<Tab
|
||||
eventKey={2}
|
||||
title={<TabTitleText>{t`Standard Out`}</TabTitleText>}
|
||||
aria-label={t`Standard out tab`}
|
||||
ouiaId="standard-out-tab"
|
||||
>
|
||||
{activeTabKey === 2 && stdOut ? (
|
||||
{stdOut?.length ? (
|
||||
<Tab
|
||||
eventKey={2}
|
||||
title={<TabTitleText>{t`Output`}</TabTitleText>}
|
||||
aria-label={t`Output tab`}
|
||||
ouiaId="standard-out-tab"
|
||||
>
|
||||
<CodeEditor
|
||||
mode="javascript"
|
||||
readOnly
|
||||
@ -162,17 +159,15 @@ function HostEventModal({ onClose, hostEvent = {}, isOpen = false }) {
|
||||
rows={20}
|
||||
hasErrors={false}
|
||||
/>
|
||||
) : (
|
||||
<ContentEmpty title={t`No Standard Out Available`} />
|
||||
)}
|
||||
</Tab>
|
||||
<Tab
|
||||
eventKey={3}
|
||||
title={<TabTitleText>{t`Standard Error`}</TabTitleText>}
|
||||
aria-label={t`Standard error tab`}
|
||||
ouiaId="standard-error-tab"
|
||||
>
|
||||
{activeTabKey === 3 && stdErr ? (
|
||||
</Tab>
|
||||
) : null}
|
||||
{stdErr?.length ? (
|
||||
<Tab
|
||||
eventKey={3}
|
||||
title={<TabTitleText>{t`Standard Error`}</TabTitleText>}
|
||||
aria-label={t`Standard error tab`}
|
||||
ouiaId="standard-error-tab"
|
||||
>
|
||||
<CodeEditor
|
||||
mode="javascript"
|
||||
readOnly
|
||||
@ -181,10 +176,8 @@ function HostEventModal({ onClose, hostEvent = {}, isOpen = false }) {
|
||||
hasErrors={false}
|
||||
rows={20}
|
||||
/>
|
||||
) : (
|
||||
<ContentEmpty title={t`No Standard Error Available`} />
|
||||
)}
|
||||
</Tab>
|
||||
</Tab>
|
||||
) : null}
|
||||
</Tabs>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
@ -17,6 +17,7 @@ const hostEvent = {
|
||||
msg: 'This is a debug message: 1',
|
||||
stdout:
|
||||
' total used free shared buff/cache available\nMem: 7973 3005 960 30 4007 4582\nSwap: 1023 0 1023',
|
||||
stderr: 'problems',
|
||||
cmd: ['free', '-m'],
|
||||
stderr_lines: [],
|
||||
stdout_lines: [
|
||||
@ -51,6 +52,7 @@ const jsonValue = `{
|
||||
\"item\": \"1\",
|
||||
\"msg\": \"This is a debug message: 1\",
|
||||
\"stdout\": \" total used free shared buff/cache available\\nMem: 7973 3005 960 30 4007 4582\\nSwap: 1023 0 1023\",
|
||||
\"stderr\": \"problems\",
|
||||
\"cmd\": [
|
||||
\"free\",
|
||||
\"-m\"
|
||||
@ -169,7 +171,7 @@ describe('HostEventModal', () => {
|
||||
handleTabClick(null, 1);
|
||||
wrapper.update();
|
||||
|
||||
const codeEditor = wrapper.find('CodeEditor');
|
||||
const codeEditor = wrapper.find('Tab[eventKey=1] CodeEditor');
|
||||
expect(codeEditor.prop('mode')).toBe('javascript');
|
||||
expect(codeEditor.prop('readOnly')).toBe(true);
|
||||
expect(codeEditor.prop('value')).toEqual(jsonValue);
|
||||
@ -184,7 +186,7 @@ describe('HostEventModal', () => {
|
||||
handleTabClick(null, 2);
|
||||
wrapper.update();
|
||||
|
||||
const codeEditor = wrapper.find('CodeEditor');
|
||||
const codeEditor = wrapper.find('Tab[eventKey=2] CodeEditor');
|
||||
expect(codeEditor.prop('mode')).toBe('javascript');
|
||||
expect(codeEditor.prop('readOnly')).toBe(true);
|
||||
expect(codeEditor.prop('value')).toEqual(hostEvent.event_data.res.stdout);
|
||||
@ -195,7 +197,7 @@ describe('HostEventModal', () => {
|
||||
...hostEvent,
|
||||
event_data: {
|
||||
res: {
|
||||
stderr: '',
|
||||
stderr: 'error content',
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -207,10 +209,10 @@ describe('HostEventModal', () => {
|
||||
handleTabClick(null, 3);
|
||||
wrapper.update();
|
||||
|
||||
const codeEditor = wrapper.find('CodeEditor');
|
||||
const codeEditor = wrapper.find('Tab[eventKey=3] CodeEditor');
|
||||
expect(codeEditor.prop('mode')).toBe('javascript');
|
||||
expect(codeEditor.prop('readOnly')).toBe(true);
|
||||
expect(codeEditor.prop('value')).toEqual(' ');
|
||||
expect(codeEditor.prop('value')).toEqual('error content');
|
||||
});
|
||||
|
||||
test('should pass onClose to Modal', () => {
|
||||
@ -226,7 +228,7 @@ describe('HostEventModal', () => {
|
||||
const debugTaskAction = {
|
||||
...hostEvent,
|
||||
event_data: {
|
||||
taskAction: 'debug',
|
||||
task_action: 'debug',
|
||||
res: {
|
||||
result: {
|
||||
stdout: 'foo bar',
|
||||
@ -242,7 +244,7 @@ describe('HostEventModal', () => {
|
||||
handleTabClick(null, 2);
|
||||
wrapper.update();
|
||||
|
||||
const codeEditor = wrapper.find('CodeEditor');
|
||||
const codeEditor = wrapper.find('Tab[eventKey=2] CodeEditor');
|
||||
expect(codeEditor.prop('mode')).toBe('javascript');
|
||||
expect(codeEditor.prop('readOnly')).toBe(true);
|
||||
expect(codeEditor.prop('value')).toEqual('foo bar');
|
||||
@ -252,7 +254,7 @@ describe('HostEventModal', () => {
|
||||
const yumTaskAction = {
|
||||
...hostEvent,
|
||||
event_data: {
|
||||
taskAction: 'yum',
|
||||
task_action: 'yum',
|
||||
res: {
|
||||
results: ['baz', 'bar'],
|
||||
},
|
||||
@ -266,9 +268,9 @@ describe('HostEventModal', () => {
|
||||
handleTabClick(null, 2);
|
||||
wrapper.update();
|
||||
|
||||
const codeEditor = wrapper.find('CodeEditor');
|
||||
const codeEditor = wrapper.find('Tab[eventKey=2] CodeEditor');
|
||||
expect(codeEditor.prop('mode')).toBe('javascript');
|
||||
expect(codeEditor.prop('readOnly')).toBe(true);
|
||||
expect(codeEditor.prop('value')).toEqual('baz');
|
||||
expect(codeEditor.prop('value')).toEqual('baz\nbar');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user