Skip to content

Commit

Permalink
remove output/stderr tabs from host detail modals when not present
Browse files Browse the repository at this point in the history
  • Loading branch information
keithjgrant committed Apr 18, 2022
1 parent 2e99741 commit 9c2ba50
Showing 1 changed file with 26 additions and 33 deletions.
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

0 comments on commit 9c2ba50

Please sign in to comment.