From 136db0c82b06305e239480680eb700fac31b4da4 Mon Sep 17 00:00:00 2001 From: Jeremy Pople Date: Fri, 15 Dec 2023 16:34:41 -0500 Subject: [PATCH 1/6] fix issues with vendor selector behavior --- .../features/system/SystemInformationForm.tsx | 19 +- .../src/features/system/VendorSelector.tsx | 310 ++++++++++-------- clients/admin-ui/src/flags.json | 6 - 3 files changed, 178 insertions(+), 157 deletions(-) diff --git a/clients/admin-ui/src/features/system/SystemInformationForm.tsx b/clients/admin-ui/src/features/system/SystemInformationForm.tsx index daface9152..10d74c55d3 100644 --- a/clients/admin-ui/src/features/system/SystemInformationForm.tsx +++ b/clients/admin-ui/src/features/system/SystemInformationForm.tsx @@ -129,12 +129,17 @@ const SystemInformationForm = ({ name: Yup.string() .required() .label("System name") - .notOneOf( - systems + .test("is-unique", "", (value, context) => { + const takenSystemNames = systems .filter((s) => s.name !== initialValues.name) - .map((s) => s.name), - "System must have a unique name" - ), + .map((s) => s.name); + if (takenSystemNames.some((name) => name === value)) { + return context.createError({ + message: `You already have a system called "${value}". Please specify a unique name for this system.`, + }); + } + return true; + }), privacy_policy: Yup.string().min(1).url().nullable(), }), [systems, initialValues.name] @@ -300,10 +305,6 @@ const SystemInformationForm = ({ {features.dictionaryService ? ( { const isShowingSuggestions = useAppSelector(selectSuggestions); const [initialField, meta, { setValue }] = useField({ - name: fieldsSeparated ? "vendor_id" : "name", + name: "name", }); const isInvalid = !!(meta.touched && meta.error); const field = { ...initialField, value: initialField.value ?? "" }; @@ -109,166 +111,190 @@ const VendorSelector = ({ opt.label.toLowerCase().startsWith(searchParam.toLowerCase()) ); + const isTypeahead = !field.value && !values.vendor_id; + const showSelectMenu = !!searchParam && suggestions.length > 0; + + const handleClear = () => { + setValue(""); + setSearchParam(""); + setFieldValue("vendor_id", undefined); + onVendorSelected(undefined); + }; + const handleTabPressed = () => { + if (!searchParam) { + return; + } if (suggestions.length > 0 && searchParam !== suggestions[0].label) { setSearchParam(suggestions[0].label); setValue(suggestions[0].value); } }; - const handleChange = ( + const handleSelectChange = ( newValue: SingleValue