From e5c1bef8de6f9d57ee0f79fd01a5f9377cf619d0 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Wed, 13 Mar 2024 19:00:28 +0800 Subject: [PATCH] fix(client): size undefined in nanoid (#3708) * fix(data-source): foreignkey * fix: size undefined in nanoid --- .../schema-component/antd/nanoIDInput/NanoIDInput.tsx | 10 +++++----- .../component/CollectionsManager/components/index.tsx | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx b/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx index 648cb411e..48deba759 100644 --- a/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx +++ b/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx @@ -11,22 +11,22 @@ export const NanoIDInput = Object.assign( connect( AntdInput, mapProps((props: any, field: any) => { - const { size, customAlphabet } = useCollectionField(); + const { size, customAlphabet } = useCollectionField() || {}; const { t } = useTranslation(); const form = useForm(); function isValidNanoid(value) { - if (value.length !== size) { - return t('Field value size is') + ` ${size}`; + if (value?.length !== size) { + return t('Field value size is') + ` ${size || 21}`; } for (let i = 0; i < value.length; i++) { - if (customAlphabet.indexOf(value[i]) === -1) { + if (customAlphabet?.indexOf(value[i]) === -1) { return t(`Field value do not meet the requirements`); } } } useEffect(() => { - if (!field.initialValue) { + if (!field.initialValue && customAlphabet) { field.setInitialValue(Alphabet(customAlphabet, size)()); } form.setFieldState(field.props.name, (state) => { diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx index 84ca05760..24a8e578c 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx @@ -63,7 +63,7 @@ export const ForeignKey = observer( : ['belongsToMany'].includes(type) ? through : target; - const fields = getCollection(effectField || name, dataSourceKey)?.fields; + const fields = getCollection(effectField, dataSourceKey)?.fields; if (fields) { const sourceOptions = fields ?.filter((v) => { @@ -95,7 +95,7 @@ export const ForeignKey = observer( onDropdownVisibleChange={async (open) => { const { target, type, through } = form.values; const effectField = ['belongsTo'].includes(type) - ? collectionName + ? collectionName || name : ['belongsToMany'].includes(type) ? through : target;