Fleet UI: Hide install modals' details button if no details to display (#34954)

This commit is contained in:
RachelElysia 2025-10-29 16:04:44 -04:00 committed by GitHub
parent b04ba96929
commit 03ddd18758
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 52 additions and 34 deletions

View file

@ -247,10 +247,10 @@ describe("SoftwareInstallDetailsModal", () => {
expect(screen.getByText("Post-install success")).toBeInTheDocument();
});
it("does not render output textareas if script outputs are empty", async () => {
it("does not render details button if details (script outputs) are empty", async () => {
mockServer.use(getSoftwareInstallHandlerNoOutputs);
const renderWithServer = createCustomRenderer({ withBackendMock: true });
const { user } = renderWithServer(
renderWithServer(
<SoftwareInstallDetailsModal
details={baseDetails}
hostSoftware={baseHostSoftware}
@ -258,16 +258,10 @@ describe("SoftwareInstallDetailsModal", () => {
/>
);
const detailsBtn = await screen.findByRole("button", {
name: /Details/i,
});
await user.click(detailsBtn);
expect(
screen.queryByText(/Install script output:/i)
).not.toBeInTheDocument();
expect(
screen.queryByText(/Post-install script output:/i)
screen.queryByRole("button", {
name: /Details/i,
})
).not.toBeInTheDocument();
});

View file

@ -270,15 +270,23 @@ export const SoftwareInstallDetailsModal = ({
},
];
// Only show details button if there's details to display
const showDetailsButton =
(!!swInstallResult?.post_install_script_output ||
!!swInstallResult?.output) &&
swInstallResult?.status !== "pending_install";
return (
<>
<RevealButton
isShowing={showInstallDetails}
showText="Details"
hideText="Details"
caretPosition="after"
onClick={toggleInstallDetails}
/>
{showDetailsButton && (
<RevealButton
isShowing={showInstallDetails}
showText="Details"
hideText="Details"
caretPosition="after"
onClick={toggleInstallDetails}
/>
)}
{showInstallDetails &&
outputs.map(
({ label, value }) =>
@ -364,10 +372,7 @@ export const SoftwareInstallDetailsModal = ({
/>
{hostSoftware && !excludeVersions && renderInventoryVersionsSection()}
{swInstallResult?.status !== "pending_install" &&
isInstalledByFleet &&
renderInstallDetailsSection()}
{isInstalledByFleet && renderInstallDetailsSection()}
</div>
);
};

View file

@ -317,6 +317,11 @@ export const SoftwareIpaInstallDetailsModal = ({
};
const renderInstallDetailsSection = () => {
// Hide section if there's no details to display
if (!swInstallResult?.result && !swInstallResult?.payload) {
return null;
}
return (
<>
<RevealButton

View file

@ -228,9 +228,13 @@ export const SoftwareInstallDetailsModal = ({
);
const renderScriptDetailsSection = () => {
if (swInstallResult?.status !== "pending_install") {
return (
<>
// Only show details button if there's details to display
const showDetailsButton =
swInstallResult?.status !== "pending_install" && swInstallResult?.output;
return (
<>
{showDetailsButton && (
<RevealButton
isShowing={showInstallDetails}
showText="Details"
@ -238,14 +242,14 @@ export const SoftwareInstallDetailsModal = ({
caretPosition="after"
onClick={toggleInstallDetails}
/>
{showInstallDetails && swInstallResult?.output && (
<Textarea label="Script output:" variant="code">
{swInstallResult.output}
</Textarea>
)}
</>
);
}
)}
{showInstallDetails && swInstallResult?.output && (
<Textarea label="Script output:" variant="code">
{swInstallResult.output}
</Textarea>
)}
</>
);
};
const hostDisplayname =

View file

@ -223,6 +223,11 @@ const SoftwareUninstallDetailsModal = ({
return <DataError description="No data returned." />;
}
// Only show details button if there's details to display
const showDetailsButton =
(!!uninstallResult?.script_contents || !!uninstallResult?.output) &&
uninstallStatus !== "pending_uninstall";
return (
<div className={`${baseClass}__modal-content`}>
<StatusMessage
@ -236,7 +241,7 @@ const SoftwareUninstallDetailsModal = ({
isMyDevicePage={!!deviceAuthToken}
contactUrl={contactUrl}
/>
{uninstallStatus !== "pending_uninstall" && (
{showDetailsButton && (
<RevealButton
isShowing={showDetails}
showText="Details"

View file

@ -323,6 +323,11 @@ export const VppInstallDetailsModal = ({
};
const renderInstallDetailsSection = () => {
// Hide section if there's no details to display
if (!vppCommandResult?.result && !vppCommandResult?.payload) {
return null;
}
return (
<>
<RevealButton