Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove output/stderr tabs from host detail modals when not present #12064

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 26 additions & 33 deletions awx/ui/src/screens/Job/JobOutput/HostEventModal.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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>
);
Expand Down
22 changes: 12 additions & 10 deletions awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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\"
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -195,7 +197,7 @@ describe('HostEventModal', () => {
...hostEvent,
event_data: {
res: {
stderr: '',
stderr: 'error content',
},
},
};
Expand All @@ -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', () => {
Expand All @@ -226,7 +228,7 @@ describe('HostEventModal', () => {
const debugTaskAction = {
...hostEvent,
event_data: {
taskAction: 'debug',
task_action: 'debug',
res: {
result: {
stdout: 'foo bar',
Expand All @@ -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');
Expand All @@ -252,7 +254,7 @@ describe('HostEventModal', () => {
const yumTaskAction = {
...hostEvent,
event_data: {
taskAction: 'yum',
task_action: 'yum',
res: {
results: ['baz', 'bar'],
},
Expand All @@ -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');
});
});