From 69ba06ed2a02b866d97c9290d370822a467a1475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Mon, 16 Sep 2024 14:20:20 +0100 Subject: [PATCH] feat: Add Editor warning UI --- .../src/@planx/components/List/Editor.tsx | 54 ++++++++++--------- .../src/@planx/components/List/model.ts | 7 +++ 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/List/Editor.tsx b/editor.planx.uk/src/@planx/components/List/Editor.tsx index 1771b8b36a..52aeef7bf9 100644 --- a/editor.planx.uk/src/@planx/components/List/Editor.tsx +++ b/editor.planx.uk/src/@planx/components/List/Editor.tsx @@ -1,19 +1,19 @@ import MenuItem from "@mui/material/MenuItem"; import { ComponentType as TYPES } from "@opensystemslab/planx-core/types"; import { useFormik } from "formik"; -import { hasFeatureFlag } from "lib/featureFlags"; import React from "react"; import ModalSection from "ui/editor/ModalSection"; import ModalSectionContent from "ui/editor/ModalSectionContent"; import RichTextInput from "ui/editor/RichTextInput"; import SelectInput from "ui/editor/SelectInput"; +import ErrorWrapper from "ui/shared/ErrorWrapper"; import Input from "ui/shared/Input"; import InputRow from "ui/shared/InputRow"; import InputRowItem from "ui/shared/InputRowItem"; import InputRowLabel from "ui/shared/InputRowLabel"; import { EditorProps, ICONS, InternalNotes, MoreInformation } from "../ui"; -import { List, parseContent } from "./model"; +import { List, parseContent, validationSchema } from "./model"; import { ProposedAdvertisements } from "./schemas/Adverts"; import { NonResidentialFloorspace } from "./schemas/Floorspace"; import { BuildingDetailsGLA } from "./schemas/GLA/BuildingDetails"; @@ -90,6 +90,8 @@ function ListComponent(props: Props) { data: newValues, }); }, + validationSchema, + validateOnChange: false, }); return ( @@ -124,29 +126,31 @@ function ListComponent(props: Props) { required /> - - Schema - - { - formik.setFieldValue("schemaName", e.target.value); - formik.setFieldValue( - "schema", - SCHEMAS.find( - ({ name }) => name === (e.target.value as string), - )?.schema, - ); - }} - > - {SCHEMAS.map(({ name }) => ( - - {name} - - ))} - - - + + + Schema + + { + formik.setFieldValue("schemaName", e.target.value); + formik.setFieldValue( + "schema", + SCHEMAS.find( + ({ name }) => name === (e.target.value as string), + )?.schema, + ); + }} + > + {SCHEMAS.map(({ name }) => ( + + {name} + + ))} + + + + | undefined): List => ({ schema: cloneDeep(data?.schema) || SCHEMAS[0].schema, ...parseMoreInformation(data), }); + +export const validationSchema = object({ + schema: object({ + max: number().optional().min(2, "Please use a Page component - the maximum must be greater than 1 item"), + }), +}); \ No newline at end of file