From 49f4d1828df79cc3b106828943056464743057c1 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 12 Oct 2023 13:34:17 +0800 Subject: [PATCH] fix: data scope report error with invalid variables (#2811) * fix: data scope error with invalidate variables * fix: data scope error with invalidate variables --- .../antd/association-field/AssociationSelect.tsx | 2 +- packages/core/client/src/variables/VariablesProvider.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx index 4b7a0b51e..3ff4e8459 100644 --- a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx @@ -32,7 +32,7 @@ export const filterAnalyses = (filters): any[] => { return true; } const regex = /\{\{\$(?:[a-zA-Z_]\w*)\.([a-zA-Z_]\w*)(?:\.id)?\}\}/; - const fieldName = jsonlogic?.value.match(regex)?.[1]; + const fieldName = jsonlogic?.value.match?.(regex)?.[1]; if (fieldName) { results.push(fieldName); } diff --git a/packages/core/client/src/variables/VariablesProvider.tsx b/packages/core/client/src/variables/VariablesProvider.tsx index c72877384..3b7d51d25 100644 --- a/packages/core/client/src/variables/VariablesProvider.tsx +++ b/packages/core/client/src/variables/VariablesProvider.tsx @@ -71,7 +71,7 @@ const VariablesProvider = ({ children }) => { ); if (Array.isArray(current)) { const result = current.map((item) => { - if (shouldToRequest(item[key]) && item.id != null) { + if (shouldToRequest(item?.[key]) && item?.id != null) { if (associationField?.target) { const url = `/${collectionName}/${item.id}/${key}:${getAction(associationField.type)}`; if (hasRequested(url)) { @@ -90,7 +90,7 @@ const VariablesProvider = ({ children }) => { return result; } } - return item[key]; + return item?.[key]; }); current = _.flatten(await Promise.all(result)); } else if (shouldToRequest(current[key]) && current.id != null && associationField?.target) {