From b48b95ac4812b45f7121062109cc7be94a0b21ff Mon Sep 17 00:00:00 2001
From: Tyler Ohlsen <ohltyler@amazon.com>
Date: Mon, 3 Feb 2025 09:42:53 -0800
Subject: [PATCH] Add NPE checks on object.values() calls

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
---
 .../components/edit_workflow_metadata_modal.tsx             | 2 +-
 .../tools/resources/resource_list_with_flyout.tsx           | 2 +-
 .../workflow_inputs/ingest_inputs/advanced_settings.tsx     | 6 +++---
 .../workflow_inputs/ingest_inputs/source_data_modal.tsx     | 2 +-
 .../search_inputs/configure_search_request.tsx              | 2 +-
 .../workflows/import_workflow/import_workflow_modal.tsx     | 2 +-
 .../pages/workflows/new_workflow/quick_configure_inputs.tsx | 2 +-
 .../pages/workflows/new_workflow/quick_configure_modal.tsx  | 2 +-
 public/pages/workflows/workflow_list/resource_list.tsx      | 2 +-
 public/utils/config_to_schema_utils.ts                      | 2 +-
 10 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/public/pages/workflow_detail/components/edit_workflow_metadata_modal.tsx b/public/pages/workflow_detail/components/edit_workflow_metadata_modal.tsx
index e9409cab..6dbba509 100644
--- a/public/pages/workflow_detail/components/edit_workflow_metadata_modal.tsx
+++ b/public/pages/workflow_detail/components/edit_workflow_metadata_modal.tsx
@@ -78,7 +78,7 @@ export function EditWorkflowMetadataModal(
         'This workflow name is already in use. Use a different name',
         (name) => {
           return !(
-            Object.values(workflows)
+            Object.values(workflows || {})
               .map((workflow) => workflow.name)
               .includes(name || '') && name !== props.workflow?.name
           );
diff --git a/public/pages/workflow_detail/tools/resources/resource_list_with_flyout.tsx b/public/pages/workflow_detail/tools/resources/resource_list_with_flyout.tsx
index 494bf2e8..fecbead9 100644
--- a/public/pages/workflow_detail/tools/resources/resource_list_with_flyout.tsx
+++ b/public/pages/workflow_detail/tools/resources/resource_list_with_flyout.tsx
@@ -71,7 +71,7 @@ export function ResourceListWithFlyout(props: ResourceListFlyoutProps) {
       props.workflow.resourcesCreated.forEach((resource) => {
         resourcesMap[resource.id] = resource;
       });
-      setAllResources(Object.values(resourcesMap));
+      setAllResources(Object.values(resourcesMap || {}));
     }
   }, [props.workflow?.resourcesCreated]);
 
diff --git a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/advanced_settings.tsx b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/advanced_settings.tsx
index 16a345c0..54e7fad3 100644
--- a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/advanced_settings.tsx
+++ b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/advanced_settings.tsx
@@ -37,7 +37,7 @@ export function AdvancedSettings(props: AdvancedSettingsProps) {
   const { values, setFieldValue } = useFormikContext<WorkflowFormValues>();
   const { models, connectors } = useSelector((state: AppState) => state.ml);
   const ingestMLProcessors = (Object.values(
-    values?.ingest?.enrich
+    values?.ingest?.enrich || {}
   ) as any[]).filter((ingestProcessor) => ingestProcessor?.model !== undefined);
   const ingestProcessorModelIds = ingestMLProcessors
     .map((ingestProcessor) => ingestProcessor?.model?.id as string | undefined)
@@ -52,7 +52,7 @@ export function AdvancedSettings(props: AdvancedSettingsProps) {
   useEffect(() => {
     if (ingestProcessorModelIds.length > 0) {
       ingestProcessorModelIds.forEach((ingestProcessorModelId) => {
-        const processorModel = Object.values(models).find(
+        const processorModel = Object.values(models || {}).find(
           (model) => model.id === ingestProcessorModelId
         );
         if (processorModel?.connectorId !== undefined) {
@@ -91,7 +91,7 @@ export function AdvancedSettings(props: AdvancedSettingsProps) {
   useEffect(() => {
     if (ingestMLProcessors.length > 0) {
       ingestMLProcessors.forEach((ingestMLProcessor) => {
-        const processorModel = Object.values(models).find(
+        const processorModel = Object.values(models || {}).find(
           (model) => model.id === ingestMLProcessor?.model?.id
         );
         if (processorModel?.connectorId !== undefined) {
diff --git a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data_modal.tsx b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data_modal.tsx
index 978a8e03..cb443dfd 100644
--- a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data_modal.tsx
+++ b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data_modal.tsx
@@ -266,7 +266,7 @@ export function SourceDataModal(props: SourceDataProps) {
                     <EuiCompressedComboBox
                       placeholder="Select an index"
                       singleSelection={{ asPlainText: true }}
-                      options={Object.values(indices).map((option) => {
+                      options={Object.values(indices || {}).map((option) => {
                         return { label: option.name };
                       })}
                       onChange={(options) => {
diff --git a/public/pages/workflow_detail/workflow_inputs/search_inputs/configure_search_request.tsx b/public/pages/workflow_detail/workflow_inputs/search_inputs/configure_search_request.tsx
index c92c39aa..0bc8fe63 100644
--- a/public/pages/workflow_detail/workflow_inputs/search_inputs/configure_search_request.tsx
+++ b/public/pages/workflow_detail/workflow_inputs/search_inputs/configure_search_request.tsx
@@ -75,7 +75,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
               />
             ) : (
               <EuiCompressedSuperSelect
-                options={Object.values(indices).map(
+                options={Object.values(indices || {}).map(
                   (option) =>
                     ({
                       value: option.name,
diff --git a/public/pages/workflows/import_workflow/import_workflow_modal.tsx b/public/pages/workflows/import_workflow/import_workflow_modal.tsx
index 1fa9c2dc..e913b058 100644
--- a/public/pages/workflows/import_workflow/import_workflow_modal.tsx
+++ b/public/pages/workflows/import_workflow/import_workflow_modal.tsx
@@ -76,7 +76,7 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
       workflowNameExists
     );
   }
-  const workflowNameExists = Object.values(workflows)
+  const workflowNameExists = Object.values(workflows || {})
     .map((workflow) => workflow.name)
     .includes(workflowName);
 
diff --git a/public/pages/workflows/new_workflow/quick_configure_inputs.tsx b/public/pages/workflows/new_workflow/quick_configure_inputs.tsx
index 4ee280cd..1c4f521b 100644
--- a/public/pages/workflows/new_workflow/quick_configure_inputs.tsx
+++ b/public/pages/workflows/new_workflow/quick_configure_inputs.tsx
@@ -57,7 +57,7 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
   useEffect(() => {
     if (models) {
       setDeployedModels(
-        Object.values(models).filter(
+        Object.values(models || {}).filter(
           (model) => model.state === MODEL_STATE.DEPLOYED
         )
       );
diff --git a/public/pages/workflows/new_workflow/quick_configure_modal.tsx b/public/pages/workflows/new_workflow/quick_configure_modal.tsx
index 0c7fd491..603eee3e 100644
--- a/public/pages/workflows/new_workflow/quick_configure_modal.tsx
+++ b/public/pages/workflows/new_workflow/quick_configure_modal.tsx
@@ -87,7 +87,7 @@ export function QuickConfigureModal(props: QuickConfigureModalProps) {
   const [workflowNameTouched, setWorkflowNameTouched] = useState<boolean>(
     false
   );
-  const workflowNameExists = Object.values(workflows)
+  const workflowNameExists = Object.values(workflows || {})
     .map((workflow) => workflow.name)
     .includes(workflowName);
 
diff --git a/public/pages/workflows/workflow_list/resource_list.tsx b/public/pages/workflows/workflow_list/resource_list.tsx
index 48421258..7c86612d 100644
--- a/public/pages/workflows/workflow_list/resource_list.tsx
+++ b/public/pages/workflows/workflow_list/resource_list.tsx
@@ -73,7 +73,7 @@ export function ResourceList(props: ResourceListProps) {
       props.workflow.resourcesCreated.forEach((resource) => {
         resourcesMap[resource.id] = resource;
       });
-      setAllResources(Object.values(resourcesMap));
+      setAllResources(Object.values(resourcesMap || {}));
     }
   }, [props.workflow?.resourcesCreated]);
 
diff --git a/public/utils/config_to_schema_utils.ts b/public/utils/config_to_schema_utils.ts
index 9316fc2d..96ca938c 100644
--- a/public/utils/config_to_schema_utils.ts
+++ b/public/utils/config_to_schema_utils.ts
@@ -77,7 +77,7 @@ function indexConfigToSchema(
       'name',
       'This index name is already in use. Use a different name',
       (name) => {
-        return !Object.values(indices)
+        return !Object.values(indices || {})
           .map((index) => index.name)
           .includes(name || '');
       }