From d89d337b6ad9d1da828591a4c295e9f2373e7649 Mon Sep 17 00:00:00 2001 From: Travis Jenkins Date: Mon, 27 Nov 2023 19:43:12 -0500 Subject: [PATCH] Making the funtion super safe --- .../editor/Bindings/FieldSelection/index.tsx | 7 ++++--- src/utils/workflow-utils.ts | 13 +++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/editor/Bindings/FieldSelection/index.tsx b/src/components/editor/Bindings/FieldSelection/index.tsx index 035c03e97..ca8a6fc02 100644 --- a/src/components/editor/Bindings/FieldSelection/index.tsx +++ b/src/components/editor/Bindings/FieldSelection/index.tsx @@ -169,9 +169,10 @@ function FieldSelectionViewer({ collectionName }: Props) { draftSpecs[0].spec.bindings, collectionName ); - const selectedBinding: Schema | undefined = bindingIndex - ? draftSpecs[0].spec.bindings[bindingIndex] - : undefined; + const selectedBinding: Schema | undefined = + bindingIndex > -1 + ? draftSpecs[0].spec.bindings[bindingIndex] + : undefined; let evaluatedFieldMetadata: FieldMetadata | undefined; if ( diff --git a/src/utils/workflow-utils.ts b/src/utils/workflow-utils.ts index e24679b59..c50e1522b 100644 --- a/src/utils/workflow-utils.ts +++ b/src/utils/workflow-utils.ts @@ -44,10 +44,15 @@ export const getCollectionName = (binding: any) => { return getCollectionNameDirectly(scopedBinding); }; -export const getBindingIndex = (bindings: any[], collectionName: string) => { - return bindings.findIndex( - (binding: any) => getCollectionName(binding) === collectionName - ); +export const getBindingIndex = ( + bindings: any[] | null | undefined, + collectionName: string +) => { + return bindings?.findIndex + ? bindings.findIndex( + (binding: any) => getCollectionName(binding) === collectionName + ) + : -1; }; export const getDisableProps = (disable: boolean | undefined) => {