ImagesTable: remove else after return

This commit is contained in:
Anna Vítová 2025-05-05 14:55:35 +02:00 committed by Klara Simickova
parent 1715d395c2
commit 5e4f94ccbe
3 changed files with 191 additions and 188 deletions

View file

@ -91,9 +91,9 @@ const AzureSourceName = ({ id }: AzureSourceNamePropTypes) => {
const sourcename = sources?.find((source) => source.id === id);
if (sourcename) {
return <p>{sourcename.name}</p>;
} else {
return <SourceNotFoundPopover />;
}
return <SourceNotFoundPopover />;
};
type AwsSourceNamePropTypes = {
@ -114,9 +114,9 @@ const AwsSourceName = ({ id }: AwsSourceNamePropTypes) => {
const sourcename = sources?.find((source) => source.id === id);
if (sourcename) {
return <p>{sourcename.name}</p>;
} else {
return <SourceNotFoundPopover />;
}
return <SourceNotFoundPopover />;
};
const parseGcpSharedWith = (

View file

@ -73,9 +73,9 @@ export const CloudInstance = ({ compose }: CloudInstancePropTypes) => {
if (hasProvisioning) {
return <ProvisioningLink compose={compose} composeStatus={data} />;
} else {
return <DisabledProvisioningLink />;
}
return <DisabledProvisioningLink />;
};
const DisabledProvisioningLink = () => {
@ -142,97 +142,95 @@ const ProvisioningLink = ({
composeStatus?.image_status.status !== 'success'
) {
return <DisabledProvisioningLink />;
} else {
const ProvisioningWizard = exposedScalprumModule.default;
const provider = getImageProvider(compose);
const options = compose.request.image_requests[0].upload_request.options;
let sourceIds = undefined;
let accountIds = undefined;
if (isGcpUploadRequestOptions(options)) {
accountIds = options.share_with_accounts;
}
if (isAwsUploadRequestOptions(options)) {
accountIds = options.share_with_accounts;
sourceIds = options.share_with_sources;
}
const btn = (
<Button
spinnerAriaLabel="Loading launch"
isLoading={isLoadingPermission}
variant="link"
isInline
onClick={() => {
analytics.track(`${AMPLITUDE_MODULE_NAME} - Link Clicked`, {
module: AMPLITUDE_MODULE_NAME,
image_name: compose.image_name,
current_path: window.location.pathname,
account_id: userData?.identity.internal?.account_id || 'Not found',
});
setWizardOpen(true);
}}
>
Launch
</Button>
);
const buttonWithTooltip = (
<Popover
triggerAction="hover"
position={PopoverPosition.left}
aria-label="Outdated image tooltip"
headerContent={<div>A newer version is available</div>}
bodyContent={
<div>
This image can be launched, but it is not the latest version.
</div>
}
>
{btn}
</Popover>
);
return (
<>
<Suspense fallback="loading...">
{selectedBlueprintVersion &&
compose.blueprint_version !== selectedBlueprintVersion
? buttonWithTooltip
: btn}
{wizardOpen && (
<Modal
isOpen
hasNoBodyWrapper
appendTo={appendTo}
showClose={false}
variant={ModalVariant.large}
aria-label="Open launch wizard"
>
<ProvisioningWizard
hasAccess={permissions[provider]}
onClose={() => setWizardOpen(false)}
image={{
name: compose.image_name || compose.id,
id: compose.id,
architecture: compose.request.image_requests[0].architecture,
provider: provider,
sourceIDs: sourceIds,
accountIDs: accountIds,
uploadOptions:
compose.request.image_requests[0].upload_request.options,
uploadStatus: composeStatus.image_status.upload_status,
}}
/>
</Modal>
)}
</Suspense>
</>
);
}
const ProvisioningWizard = exposedScalprumModule.default;
const provider = getImageProvider(compose);
const options = compose.request.image_requests[0].upload_request.options;
let sourceIds = undefined;
let accountIds = undefined;
if (isGcpUploadRequestOptions(options)) {
accountIds = options.share_with_accounts;
}
if (isAwsUploadRequestOptions(options)) {
accountIds = options.share_with_accounts;
sourceIds = options.share_with_sources;
}
const btn = (
<Button
spinnerAriaLabel="Loading launch"
isLoading={isLoadingPermission}
variant="link"
isInline
onClick={() => {
analytics.track(`${AMPLITUDE_MODULE_NAME} - Link Clicked`, {
module: AMPLITUDE_MODULE_NAME,
image_name: compose.image_name,
current_path: window.location.pathname,
account_id: userData?.identity.internal?.account_id || 'Not found',
});
setWizardOpen(true);
}}
>
Launch
</Button>
);
const buttonWithTooltip = (
<Popover
triggerAction="hover"
position={PopoverPosition.left}
aria-label="Outdated image tooltip"
headerContent={<div>A newer version is available</div>}
bodyContent={
<div>This image can be launched, but it is not the latest version.</div>
}
>
{btn}
</Popover>
);
return (
<>
<Suspense fallback="loading...">
{selectedBlueprintVersion &&
compose.blueprint_version !== selectedBlueprintVersion
? buttonWithTooltip
: btn}
{wizardOpen && (
<Modal
isOpen
hasNoBodyWrapper
appendTo={appendTo}
showClose={false}
variant={ModalVariant.large}
aria-label="Open launch wizard"
>
<ProvisioningWizard
hasAccess={permissions[provider]}
onClose={() => setWizardOpen(false)}
image={{
name: compose.image_name || compose.id,
id: compose.id,
architecture: compose.request.image_requests[0].architecture,
provider: provider,
sourceIDs: sourceIds,
accountIDs: accountIds,
uploadOptions:
compose.request.image_requests[0].upload_request.options,
uploadStatus: composeStatus.image_status.upload_status,
}}
/>
</Modal>
)}
</Suspense>
</>
);
};
const getImageProvider = (compose: ComposesResponseItem) => {
@ -283,80 +281,80 @@ export const OciInstance = ({ compose, isExpired }: OciInstancePropTypes) => {
Recreate image
</Button>
);
} else {
return (
<Popover
position="bottom"
headerContent={<div>Launch an OCI image</div>}
minWidth="30rem"
bodyContent={
<>
<p>
To run the image copy the link below and follow the steps below:
</p>
<List component={ListComponent.ol} type={OrderType.number}>
<ListItem>
Go to &quot;Compute&quot; in Oracle Cloud and choose &quot;
Custom Images&quot;.
</ListItem>
<ListItem>
Click on &quot;Import image&quot;, choose &quot;Import from an
object storage URL&quot;.
</ListItem>
<ListItem>
Choose &quot;Import from an object storage URL&quot; and paste
the URL in the &quot;Object Storage URL&quot; field. The image
type has to be set to QCOW2 and the launch mode should be
paravirtualized.
</ListItem>
</List>
<br />
{isSuccess && (
<ClipboardCopy
hoverTip="Copy"
clickTip="Copied"
variant="inline-compact"
isBlock
>
{options?.url || ''}
</ClipboardCopy>
)}
{isFetching && <Skeleton />}
{isError && (
<Alert
title="The link to launch the image could not be loaded. Please refresh
the page and try again."
variant="danger"
isPlain
isInline
/>
)}
<br />
<Button
component="a"
target="_blank"
variant="link"
icon={<ExternalLinkAltIcon />}
iconPosition="right"
// TO DO update the link after documentation is up
href={FILE_SYSTEM_CUSTOMIZATION_URL}
className="pf-v5-u-pl-0"
>
Read more about launching OCI images
</Button>
</>
}
>
<Button
variant="link"
className="pf-v5-u-p-0 pf-v5-u-font-size-sm"
isDisabled={data?.image_status.status === 'success' ? false : true}
>
Image link
</Button>
</Popover>
);
}
return (
<Popover
position="bottom"
headerContent={<div>Launch an OCI image</div>}
minWidth="30rem"
bodyContent={
<>
<p>
To run the image copy the link below and follow the steps below:
</p>
<List component={ListComponent.ol} type={OrderType.number}>
<ListItem>
Go to &quot;Compute&quot; in Oracle Cloud and choose &quot; Custom
Images&quot;.
</ListItem>
<ListItem>
Click on &quot;Import image&quot;, choose &quot;Import from an
object storage URL&quot;.
</ListItem>
<ListItem>
Choose &quot;Import from an object storage URL&quot; and paste the
URL in the &quot;Object Storage URL&quot; field. The image type
has to be set to QCOW2 and the launch mode should be
paravirtualized.
</ListItem>
</List>
<br />
{isSuccess && (
<ClipboardCopy
hoverTip="Copy"
clickTip="Copied"
variant="inline-compact"
isBlock
>
{options?.url || ''}
</ClipboardCopy>
)}
{isFetching && <Skeleton />}
{isError && (
<Alert
title="The link to launch the image could not be loaded. Please refresh
the page and try again."
variant="danger"
isPlain
isInline
/>
)}
<br />
<Button
component="a"
target="_blank"
variant="link"
icon={<ExternalLinkAltIcon />}
iconPosition="right"
// TO DO update the link after documentation is up
href={FILE_SYSTEM_CUSTOMIZATION_URL}
className="pf-v5-u-pl-0"
>
Read more about launching OCI images
</Button>
</>
}
>
<Button
variant="link"
className="pf-v5-u-p-0 pf-v5-u-font-size-sm"
isDisabled={data?.image_status.status === 'success' ? false : true}
>
Image link
</Button>
</Popover>
);
};
type AwsS3InstancePropTypes = {
@ -410,21 +408,20 @@ export const AwsS3Instance = ({
)
</Button>
);
} else {
return (
<Button
component="a"
target="_blank"
variant="link"
isInline
href={options?.url}
isDisabled={isExpired}
>
Download ({fileExtensions[compose.request.image_requests[0].image_type]}
)
</Button>
);
}
return (
<Button
component="a"
target="_blank"
variant="link"
isInline
href={options?.url}
isDisabled={isExpired}
>
Download ({fileExtensions[compose.request.image_requests[0].image_type]})
</Button>
);
};
type LocalInstancePropTypes = {

View file

@ -222,7 +222,9 @@ export const ExpiringStatus = ({
return (
<Status icon={statuses['expired'].icon} text={statuses['expired'].text} />
);
} else if (imageType === 'aws.s3' && status === 'success') {
}
if (imageType === 'aws.s3' && status === 'success') {
const text = `Expires in ${remainingHours} ${
remainingHours > 1 ? 'hours' : 'hour'
}`;
@ -236,7 +238,9 @@ export const ExpiringStatus = ({
}
/>
);
} else if (imageType === 'oci.objectstorage' && status === 'success') {
}
if (imageType === 'oci.objectstorage' && status === 'success') {
const text = `Expires in ${remainingDays} ${
remainingDays > 1 ? 'days' : 'day'
}`;
@ -250,7 +254,9 @@ export const ExpiringStatus = ({
}
/>
);
} else if (status === 'failure') {
}
if (status === 'failure') {
return (
<ErrorStatus
icon={statuses[status].icon}
@ -258,9 +264,9 @@ export const ExpiringStatus = ({
error={composeStatus?.image_status.error || ''}
/>
);
} else {
return <Status icon={statuses[status].icon} text={statuses[status].text} />;
}
return <Status icon={statuses[status].icon} text={statuses[status].text} />;
};
type LocalStatusPropTypes = {