Skip to content
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
8 changes: 8 additions & 0 deletions libs/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"Alias devices using a custom template. Add a number using": "Alias devices using a custom template. Add a number using",
"All {{ resumedCount }} devices resumed successfully": "All {{ resumedCount }} devices resumed successfully",
"All application workloads are healthy": "All application workloads are healthy",
"All export formats from this image build are already included in this promotion": "All export formats from this image build are already included in this promotion",
"All good!": "All good!",
"All images are stored under the same repository path in this registry.": "All images are stored under the same repository path in this registry.",
"All levels": "All levels",
Expand Down Expand Up @@ -988,6 +989,7 @@
"Exporting...": "Exporting...",
"External organization name": "External organization name",
"Failed": "Failed",
"Failed image promotions cannot be edited. Create a new image promotion to retry.": "Failed image promotions cannot be edited. Create a new image promotion to retry.",
"Failed to cancel image build": "Failed to cancel image build",
"Failed to connect to device": "Failed to connect to device",
"Failed to connect to device terminal": "Failed to connect to device terminal",
Expand Down Expand Up @@ -1203,8 +1205,11 @@
"Image output reference URL": "Image output reference URL",
"Image output tag": "Image output tag",
"Image placement": "Image placement",
"Image promotion cannot be edited while publishing is in progress": "Image promotion cannot be edited while publishing is in progress",
"Image Promotion name": "Image Promotion name",
"Image promotions": "Image promotions",
"Image promotions for canceled image builds cannot be edited. Create a new image promotion to retry.": "Image promotions for canceled image builds cannot be edited. Create a new image promotion to retry.",
"Image promotions for failed image builds cannot be edited. Create a new image promotion to retry.": "Image promotions for failed image builds cannot be edited. Create a new image promotion to retry.",
"Image reference": "Image reference",
"Image reference is required for this volume type": "Image reference is required for this volume type",
"Image reference URL": "Image reference URL",
Expand Down Expand Up @@ -1465,6 +1470,7 @@
"No fleet eligible for catalog deployment is available": "No fleet eligible for catalog deployment is available",
"No fleets currently match the selected labels.": "No fleets currently match the selected labels.",
"No fleets yet": "No fleets yet",
"No formats selected": "No formats selected",
"No Git repositories found": "No Git repositories found",
"No GPUs found": "No GPUs found",
"No image promotions yet": "No image promotions yet",
Expand Down Expand Up @@ -2403,6 +2409,7 @@
"View fleet": "View fleet",
"View fleet configurations": "View fleet configurations",
"View fleet details": "View fleet details",
"View image promotion": "View image promotion",
"View in repository": "View in repository",
"View logs": "View logs",
"View more": "View more",
Expand Down Expand Up @@ -2506,6 +2513,7 @@
"You do not have permissions to list devices": "You do not have permissions to list devices",
"You do not have permissions to list fleets": "You do not have permissions to list fleets",
"You do not have permissions to promote builds to the catalog": "You do not have permissions to promote builds to the catalog",
"You do not have permissions to update image promotions": "You do not have permissions to update image promotions",
"You don't have access to this section.": "You don't have access to this section.",
"You don't have permissions to create catalogs": "You don't have permissions to create catalogs",
"You don't have permissions to create image builds": "You don't have permissions to create image builds",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import {
StackItem,
} from '@patternfly/react-core';
import { type TFunction, Trans } from 'react-i18next';
import { ActionsColumn, type IAction, Tbody, Td, Tr } from '@patternfly/react-table';
import { InfoCircleIcon } from '@patternfly/react-icons/dist/js/icons/info-circle-icon';

import { BindingType, type ImagePromotion } from '@flightctl/types/imagebuilder';
import ImagePromotionModal from '../../ImagePromotion/ImagePromotionModal';
import { getAvailableExportFormats, getPromotionEditDisabledReason } from '../../ImagePromotion/utils';
import { getDisabledTooltipProps } from '../../../utils/tooltip';
import ImagePromotionStatus from '../../ImagePromotion/ImagePromotionStatus';
import { getDateDisplay } from '../../../utils/dates';
import { getExportFormatLabel, getImageReference } from '../../../utils/imageBuilds';
Expand All @@ -37,7 +40,6 @@ import { ImageBuildStatusDisplay } from '../ImageBuildAndExportStatus';
import ImageUrl from '../ImageUrl';
import { getErrorMessage } from '../../../utils/error';
import Table from '../../Table/Table';
import { ActionsColumn, type IAction, Tbody, Td, Tr } from '@patternfly/react-table';
import TablePagination from '../../Table/TablePagination';
import { getResourceId } from '../../../utils/resource';
import DeleteImagePromotionModal from '../../ImagePromotion/DeleteImagePromotionModal';
Expand All @@ -52,38 +54,53 @@ const detailsPermissions = [
{ kind: RESOURCE.IMAGE_PROMOTION, verb: VERB.DELETE },
];

type PromotionAction = 'view' | 'edit' | 'delete';

type PromotionActionState = {
id: string;
action: PromotionAction;
};

const ImagePromotionRow = ({
imagePromotion,
onDeleteClick,
onEditClick,
editDisabledReason,
onActionClick,
canEditPromotions,
canDeletePromotions,
}: {
imagePromotion: ImagePromotion;
onDeleteClick: VoidFunction;
onEditClick: VoidFunction;
editDisabledReason?: string;
onActionClick: (action: PromotionAction) => void;
canEditPromotions: boolean;
canDeletePromotions: boolean;
}) => {
const { t } = useTranslation();

const regularActions: IAction[] = canEditPromotions
? [
{
title: t('Edit image promotion'),
onClick: onEditClick,
},
]
: [];
const dangerActions: IAction[] = canDeletePromotions
? [
{
title: t('Delete image promotion'),
onClick: onDeleteClick,
},
]
: [];
const actions = buildAllDropdownActions(regularActions, dangerActions);
const actions: IAction[] = [
{
title: t('View image promotion'),
onClick: () => onActionClick('view'),
},
];
if (canEditPromotions) {
actions.push({
title: t('Edit image promotion'),
onClick: () => onActionClick('edit'),
...getDisabledTooltipProps(editDisabledReason),
});
}

const allActions = buildAllDropdownActions(
actions,
canDeletePromotions
? [
{
title: t('Delete image promotion'),
onClick: () => onActionClick('delete'),
},
]
: [],
);

return (
<Tr>
Expand All @@ -94,11 +111,9 @@ const ImagePromotionRow = ({
<Td dataLabel={t('Status')}>
<ImagePromotionStatus promotion={imagePromotion} />
</Td>
{!!actions.length && (
<Td isActionCell>
<ActionsColumn items={actions} />
</Td>
)}
<Td isActionCell>
<ActionsColumn items={allActions} />
</Td>
</Tr>
);
};
Expand Down Expand Up @@ -131,8 +146,9 @@ const ImagePromotionsCard = ({

const { error, isLoading, isUpdating, pagination, imagePromotions, refetchPromotions } = useImagePromotionsContext();

const [promotionToDeleteId, setPromotionToDeleteId] = React.useState<string>();
const [promotionToEditId, setPromotionToEditId] = React.useState<string>();
const [promotionAction, setPromotionAction] = React.useState<PromotionActionState>();

const availableFormats = getAvailableExportFormats(imageBuild);

let content: React.ReactNode;
if (error) {
Expand All @@ -154,8 +170,8 @@ const ImagePromotionsCard = ({
<ImagePromotionRow
key={getResourceId(promotion)}
imagePromotion={promotion}
onEditClick={() => setPromotionToEditId(promotion.metadata.name)}
onDeleteClick={() => setPromotionToDeleteId(promotion.metadata.name)}
editDisabledReason={getPromotionEditDisabledReason(promotion, availableFormats, canEditPromotions, t)}
onActionClick={(action) => setPromotionAction({ id: promotion.metadata.name as string, action })}
canEditPromotions={canEditPromotions}
canDeletePromotions={canDeletePromotions}
/>
Expand All @@ -167,30 +183,41 @@ const ImagePromotionsCard = ({
);
}

const promotionToDelete = imagePromotions.find((p) => p.metadata.name === promotionToDeleteId);
const promotionToEdit = imagePromotions.find((p) => p.metadata.name === promotionToEditId);
const activePromotion = promotionAction
? imagePromotions.find((p) => p.metadata.name === promotionAction.id)
: undefined;

const closePromotionAction = () => setPromotionAction(undefined);

return (
<DetailsPageCard>
<CardTitle>{t('Image promotions')}</CardTitle>
<CardBody>{content}</CardBody>
{promotionToDelete && (
{activePromotion && promotionAction?.action === 'delete' && (
<DeleteImagePromotionModal
promotion={promotionToDelete}
promotion={activePromotion}
onClose={(hasDeleted?: boolean) => {
if (hasDeleted) {
refetchPromotions();
}
setPromotionToDeleteId(undefined);
closePromotionAction();
}}
/>
)}
{promotionToEdit && (
{activePromotion && promotionAction?.action === 'view' && (
<ImagePromotionModal
readOnly
imageBuild={imageBuild}
imagePromotion={activePromotion}
onClose={closePromotionAction}
Comment thread
celdrake marked this conversation as resolved.
Resolved
/>
)}
{activePromotion && promotionAction?.action === 'edit' && (
<ImagePromotionModal
imageBuild={imageBuild}
imagePromotion={promotionToEdit}
imagePromotion={activePromotion}
onClose={(updated) => {
setPromotionToEditId(undefined);
closePromotionAction();
if (updated) {
refetchPromotions();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Alert, Button, FormGroup, FormSection, Spinner, Stack, StackItem } from '@patternfly/react-core';
import { Alert, FormGroup, FormSection, Spinner } from '@patternfly/react-core';
import { useFormikContext } from 'formik';

import { type CatalogItem, type CatalogList } from '@flightctl/types/alpha';
Expand All @@ -15,8 +15,8 @@ import NameField from '../form/NameField';
import { getDnsSubdomainValidations } from '../form/validations';
import { useCatalogItems } from '../Catalog/useCatalogItems';
import { getErrorMessage } from '../../utils/error';
import { getExportFormatLabel } from '../../utils/imageBuilds';
import { type ImagePromotionFormValues } from './types';
import type { ImagePromotionFormValues } from './types';
import ImagePromotionFormatsField from './ImagePromotionFormatsField';

const NewItemForm = ({ isDisabled }: { isDisabled?: boolean }) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -114,16 +114,64 @@ const ExistingItemForm = ({ catalogItems, isDisabled }: { catalogItems: CatalogI
);
};

const ImagePromotionForm = ({
type ImagePromotionFormProps = {
isEdit?: boolean;
canAmendExportFormats?: boolean;
availableFormats?: ExportFormatType[];
};

// Content can be used when the catalog references cannot be resolved (e.g. user does not have permissions to view catalog/catalogItems)
export const ImagePromotionFormContent = ({
isEdit,
canAmendExportFormats = true,
availableFormats,
catalogs,
catalogItems,
}: {
isEdit?: boolean;
availableFormats?: ExportFormatType[];
}) => {
catalogs: Record<string, SelectItem>;
catalogItems: CatalogItem[];
} & ImagePromotionFormProps) => {
const { t } = useTranslation();
const { values } = useFormikContext<ImagePromotionFormValues>();

return (
<FlightCtlForm>
<NameField
resourceType="imagepromotions"
name="name"
aria-label={t('Image Promotion name')}
isRequired
isDisabled={isEdit}
validations={getDnsSubdomainValidations(t)}
/>
<ImagePromotionFormatsField
isEdit={isEdit}
canAmendExportFormats={canAmendExportFormats}
availableFormats={availableFormats}
/>
<FormGroup label={t('Catalog')} isRequired>
<FormSelect name="catalog" items={catalogs} isDisabled={isEdit} />
</FormGroup>
<FormGroup label={t('Add as')} isRequired>
<RadioField
id="existing-item"
name="type"
label={t('Existing catalog item')}
checkedValue="existing"
isDisabled={!catalogItems.length || isEdit}
/>
<RadioField id="new-item" name="type" label={t('New catalog item')} checkedValue="new" isDisabled={isEdit} />
</FormGroup>
{values.type === 'new' && <NewItemForm isDisabled={isEdit} />}
{values.type === 'existing' && <ExistingItemForm catalogItems={catalogItems} isDisabled={isEdit} />}
</FlightCtlForm>
);
};

const ImagePromotionForm = ({ isEdit, canAmendExportFormats = true, availableFormats }: ImagePromotionFormProps) => {
const { t } = useTranslation();

const { values, setFieldValue } = useFormikContext<ImagePromotionFormValues>();
const { values } = useFormikContext<ImagePromotionFormValues>();

const [catalogList, catalogsLoading, catalogsErr] = useFetchPeriodically<CatalogList>({
endpoint: 'catalogs',
Expand Down Expand Up @@ -179,67 +227,14 @@ const ImagePromotionForm = ({
);
}

const hasExports = availableFormats?.length || values.exportFormats.length;

const extraFormats = availableFormats?.filter((f) => !values.exportFormats.includes(f));

return (
<FlightCtlForm>
<NameField
resourceType="imagepromotions"
name="name"
aria-label={t('Image Promotion name')}
isRequired
isDisabled={isEdit}
validations={getDnsSubdomainValidations(t)}
/>
<FormGroup label={t('Formats')}>
{hasExports ? (
<Stack>
<StackItem>{values.exportFormats.map((format) => getExportFormatLabel(t, format)).join(', ')}</StackItem>
{extraFormats?.map((f) => {
const isIncluded = values.additionalExportFormats?.includes(f);
const exportLabel = getExportFormatLabel(t, f);
return (
<StackItem key={f}>
<Button
isInline
variant="link"
onClick={() => {
const newFormats = isIncluded
? values.additionalExportFormats?.filter((format) => format !== f)
: [...(values.additionalExportFormats || []), f];
setFieldValue('additionalExportFormats', newFormats);
}}
>
{isIncluded
? t('Remove {{ exportLabel }}', { exportLabel })
: t('Add {{ exportLabel }}', { exportLabel })}
</Button>
</StackItem>
);
})}
</Stack>
) : (
t('No additional formats')
)}
</FormGroup>
<FormGroup label={t('Catalog')} isRequired>
<FormSelect name="catalog" items={catalogs} isDisabled={isEdit} />
</FormGroup>
<FormGroup label={t('Add as')} isRequired>
<RadioField
id="existing-item"
name="type"
label={t('Existing catalog item')}
checkedValue="existing"
isDisabled={!catalogItems.length || isEdit}
/>
<RadioField id="new-item" name="type" label={t('New catalog item')} checkedValue="new" isDisabled={isEdit} />
</FormGroup>
{values.type === 'new' && <NewItemForm isDisabled={isEdit} />}
{values.type === 'existing' && <ExistingItemForm catalogItems={catalogItems} isDisabled={isEdit} />}
</FlightCtlForm>
<ImagePromotionFormContent
isEdit={isEdit}
catalogs={catalogs}
catalogItems={catalogItems}
canAmendExportFormats={canAmendExportFormats}
availableFormats={availableFormats}
/>
);
};

Expand Down
Loading
Loading