Close} />
);
};
interface ISoftwareInstallDetailsProps {
details: IPackageInstallDetails;
hostSoftware?: IHostSoftware; // for software name when not Fleet installed (not present on activity feeds)
deviceAuthToken?: string; // My Device Page only
onCancel: () => void;
onRerun?: (id: number, isScriptPackage?: boolean) => void; // My Device Page only
contactUrl?: string; // My Device Page only
}
export const SoftwareScriptDetailsModal = ({
details: detailsFromProps,
onCancel,
hostSoftware,
deviceAuthToken,
onRerun,
contactUrl,
}: ISoftwareInstallDetailsProps) => {
// will always be present
const installUUID = detailsFromProps.install_uuid ?? "";
const [showInstallDetails, setShowInstallDetails] = useState(false);
const toggleInstallDetails = () => {
setShowInstallDetails((prev) => !prev);
};
const { data: swInstallResult, isLoading, isError, error } = useQuery<
ISoftwareInstallResults,
AxiosError,
ISoftwareScriptResult
>(
["softwareInstallResults", installUUID],
() => {
return deviceAuthToken
? deviceUserAPI.getSoftwareInstallResult(deviceAuthToken, installUUID)
: softwareAPI.getSoftwareInstallResult(installUUID);
},
{
...DEFAULT_USE_QUERY_OPTIONS,
staleTime: 3000,
select: (data) => data.results as ISoftwareScriptResult,
}
);
const renderScriptDetailsSection = () => {
// Only show details button if there's details to display
const showDetailsButton =
swInstallResult?.status !== "pending_install" && swInstallResult?.output;
return (
<>
{showDetailsButton && (
)}
{showInstallDetails && swInstallResult?.output && (
)}
>
);
};
const hostDisplayname =
swInstallResult?.host_display_name || detailsFromProps.host_display_name;
const installResultWithHostDisplayName = swInstallResult
? {
...swInstallResult,
host_display_name: hostDisplayname,
}
: undefined;
const renderContent = () => {
if (isLoading) {
return ;
}
if (isError) {
if (error?.status === 404) {
return deviceAuthToken ? (
) : (
);
}
if (error?.status === 401) {
return deviceAuthToken ? (
) : (
);
}
}
if (!installResultWithHostDisplayName) {
return deviceAuthToken ? (
) : (
);
}
if (
!["installed", "pending_install", "failed_install"].includes(
installResultWithHostDisplayName.status
)
) {
return (
);
}
return (
{renderScriptDetailsSection()}
);
};
return (
{renderContent()}
);
};
export default SoftwareScriptDetailsModal;