From 642c51ed30445639a8275c0e72f66bed4b378e25 Mon Sep 17 00:00:00 2001 From: alashchev17 Date: Mon, 9 Dec 2024 19:01:30 +0100 Subject: [PATCH] fix: using parseOrElse instead of regular JSON.parse --- src/components/IntegrationsView/IntegrationsView.tsx | 12 +++++++----- src/services/refact/integrations.ts | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/IntegrationsView/IntegrationsView.tsx b/src/components/IntegrationsView/IntegrationsView.tsx index ccaaf323..c7c00dc9 100644 --- a/src/components/IntegrationsView/IntegrationsView.tsx +++ b/src/components/IntegrationsView/IntegrationsView.tsx @@ -24,7 +24,6 @@ import { useSaveIntegrationData } from "../../hooks/useSaveIntegrationData"; import { dockerApi, Integration, - IntegrationPrimitive, integrationsApi, IntegrationWithIconRecord, IntegrationWithIconResponse, @@ -43,6 +42,7 @@ import styles from "./IntegrationsView.module.css"; import { iconMap } from "./icons/iconMap"; import { LeftRightPadding } from "../../features/Integrations/Integrations"; import { IntermediateIntegration } from "./IntermediateIntegration"; +import { parseOrElse } from "../../utils"; type IntegrationViewProps = { integrationsMap?: IntegrationWithIconResponse; @@ -288,15 +288,17 @@ export const IntegrationsView: FC = ({ break; case "tool": // TODO: adjust types for data, it's not IntegrationPrimitive - acc[key] = JSON.parse( + acc[key] = parseOrElse( rawFormValues[key] as string, - ) as IntegrationPrimitive; + {}, + ); break; case "output": // TODO: adjust types for data, it's not IntegrationPrimitive - acc[key] = JSON.parse( + acc[key] = parseOrElse( rawFormValues[key] as string, - ) as IntegrationPrimitive; + {}, + ); break; default: acc[key] = rawFormValues[key] as string; diff --git a/src/services/refact/integrations.ts b/src/services/refact/integrations.ts index fee7220f..fd4e7ea1 100644 --- a/src/services/refact/integrations.ts +++ b/src/services/refact/integrations.ts @@ -132,7 +132,10 @@ export type Integration = { integr_name: string; integr_config_path: string; integr_schema: IntegrationSchema; - integr_values: Record>; + integr_values: Record< + string, + IntegrationPrimitive | Record | Record + >; error_log: null | YamlError[]; };