From 808a0c7b1a4d57eb7b2561853c281e854bcac87d Mon Sep 17 00:00:00 2001 From: Gabe Esquivel Gaghi Date: Mon, 29 Jun 2026 11:59:54 -0300 Subject: [PATCH 1/4] update forms --- .../PublishRepositoryExistingForm.tsx | 6 +- .../PublishMirrorContentsBlock.tsx | 14 ++-- .../PublishMirrorExistingForm.tsx | 6 +- .../PublishMirrorNewForm.tsx | 66 +++++++++++++++++-- .../PublishMirrorNewForm/constants.ts | 7 ++ .../AddPublicationForm/AddPublicationForm.tsx | 59 +++++++++-------- .../AddPublicationForm/constants.ts | 1 - src/features/publications/index.ts | 2 +- .../publications/types/PublishValues.ts | 2 + src/tests/mocks/publications.ts | 42 ++++++++++++ 10 files changed, 156 insertions(+), 49 deletions(-) create mode 100644 src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorNewForm/constants.ts diff --git a/src/features/local-repositories/components/PublishLocalRepositorySidePanel/components/PublishRepositoryExistingForm/PublishRepositoryExistingForm.tsx b/src/features/local-repositories/components/PublishLocalRepositorySidePanel/components/PublishRepositoryExistingForm/PublishRepositoryExistingForm.tsx index 7b5b2f8a6b..c543c1ad1f 100644 --- a/src/features/local-repositories/components/PublishLocalRepositorySidePanel/components/PublishRepositoryExistingForm/PublishRepositoryExistingForm.tsx +++ b/src/features/local-repositories/components/PublishLocalRepositorySidePanel/components/PublishRepositoryExistingForm/PublishRepositoryExistingForm.tsx @@ -90,15 +90,13 @@ const PublishRepositoryExistingForm: FC = ({ diff --git a/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorContentsBlock/PublishMirrorContentsBlock.tsx b/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorContentsBlock/PublishMirrorContentsBlock.tsx index 9715a9c358..d3c48afa82 100644 --- a/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorContentsBlock/PublishMirrorContentsBlock.tsx +++ b/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorContentsBlock/PublishMirrorContentsBlock.tsx @@ -1,31 +1,33 @@ import Blocks from "@/components/layout/Blocks"; import type { FC } from "react"; import ReadOnlyField from "@/components/form/ReadOnlyField"; -import type { Mirror } from "@canonical/landscape-openapi"; +import type { Mirror, Publication } from "@canonical/landscape-openapi"; interface PublishMirrorContentsBlockProps { readonly mirror: Mirror; + readonly publication: Publication; } const PublishMirrorContentsBlock: FC = ({ mirror, + publication, }) => { return ( ); diff --git a/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorExistingForm/PublishMirrorExistingForm.tsx b/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorExistingForm/PublishMirrorExistingForm.tsx index 95c51b9c34..e5369118c8 100644 --- a/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorExistingForm/PublishMirrorExistingForm.tsx +++ b/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorExistingForm/PublishMirrorExistingForm.tsx @@ -38,7 +38,7 @@ const PublishMirrorExistingForm: FC = ({ onSubmit: async (values) => { try { - await publishPublication({ name: values.name ?? "" }); + await publishPublication({ name: values.name }); closeSidePanel(); @@ -79,7 +79,7 @@ const PublishMirrorExistingForm: FC = ({ + )} + + + formik.values.architectures?.includes(value), + )} + onItemsUpdate={handleArchitectureChange} + error={getFormikError(formik, "architectures")} + /> + diff --git a/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorNewForm/constants.ts b/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorNewForm/constants.ts new file mode 100644 index 0000000000..e25fe381ea --- /dev/null +++ b/src/features/mirrors/components/PublishMirrorForm/components/PublishMirrorNewForm/constants.ts @@ -0,0 +1,7 @@ +import { VALIDATION_SCHEMA_NEW, REQUIRED_FIELD_MESSAGE } from "@/features/publications"; +import * as Yup from "yup"; + +export const VALIDATION_SCHEMA_NEW_MIRROR = VALIDATION_SCHEMA_NEW.shape({ + distribution: Yup.string().required(REQUIRED_FIELD_MESSAGE), + architectures: Yup.array().of(Yup.string()).min(1, REQUIRED_FIELD_MESSAGE), +}); diff --git a/src/features/publications/components/AddPublicationForm/AddPublicationForm.tsx b/src/features/publications/components/AddPublicationForm/AddPublicationForm.tsx index d29f7216e2..81f1fdabca 100644 --- a/src/features/publications/components/AddPublicationForm/AddPublicationForm.tsx +++ b/src/features/publications/components/AddPublicationForm/AddPublicationForm.tsx @@ -48,7 +48,7 @@ const AddPublicationForm: FC = () => { const formik = useFormik({ initialValues: { ...getInitialValues(), - sourceType: "", + sourceType: SOURCE_TYPE_MIRROR, source: "", distribution: "", architectures: [], @@ -65,7 +65,7 @@ const AddPublicationForm: FC = () => { notify.success({ title: `You have successfully added ${values.name}`, message: - "The publication has been created and is now available to be published.", + "The publication has been created and marked to be published.", }); } catch (error) { debug(error); @@ -102,17 +102,16 @@ const AddPublicationForm: FC = () => { [locals], ); - const selectableSources = useMemo(() => { - if (formik.values.sourceType === SOURCE_TYPE_MIRROR) { - return mirrorSources; - } + const isLocalSourceType = + formik.values.sourceType === SOURCE_TYPE_LOCAL_REPOSITORY; - if (formik.values.sourceType === SOURCE_TYPE_LOCAL_REPOSITORY) { + const selectableSources = useMemo(() => { + if (isLocalSourceType) { return localSources; } - return []; - }, [formik.values.sourceType, localSources, mirrorSources]); + return mirrorSources; + }, [isLocalSourceType, localSources, mirrorSources]); const sourceOptions = useMemo( () => [ @@ -126,12 +125,7 @@ const AddPublicationForm: FC = () => { ({ value }) => value === formik.values.source, ); - const isLocalSourceType = - formik.values.sourceType === SOURCE_TYPE_LOCAL_REPOSITORY; - - const isGettingSources = - formik.values.sourceType === SOURCE_TYPE_LOCAL_REPOSITORY && - isGettingLocals; + const isGettingSources = isLocalSourceType && isGettingLocals; const publicationTargetOptions = useMemo( () => [ @@ -212,7 +206,7 @@ const AddPublicationForm: FC = () => {