From 6c9f335d33c7162c71e1406a42c757eed9cbac43 Mon Sep 17 00:00:00 2001 From: nick_lloyd Date: Tue, 13 Feb 2024 12:41:05 +0100 Subject: [PATCH 1/4] include filed type when persisting configurable resources --- src/components/ResourceForm.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ResourceForm.tsx b/src/components/ResourceForm.tsx index 3a18cd1..bbe0fca 100644 --- a/src/components/ResourceForm.tsx +++ b/src/components/ResourceForm.tsx @@ -81,13 +81,19 @@ const ResourceForm = ({ resource, closeForm }: Props) => { {} ); + const typeMap = sortedFormFields.reduce((acc: any, formField: FormField) => { + const { id, type } = formField; + acc[id] = type || undefined; + return acc; + }, {}); + const formik = useFormik({ initialValues, onSubmit: async (values) => { const defaults = Object.entries(values) .map(([k, v]) => { return v !== undefined - ? { id: k, value: v, target: targetMap[k] } + ? { id: k, value: v, target: targetMap[k], type: typeMap[k] } : v; }) .filter(Boolean); From ccbe9f0017166b9712b6c4e41e4503e3307733bd Mon Sep 17 00:00:00 2001 From: nick_lloyd Date: Tue, 13 Feb 2024 14:39:08 +0100 Subject: [PATCH 2/4] include type when sending form fields --- src/components/ConnectionDetails.tsx | 18 +++++++++++++++++- src/components/ConnectionForm.tsx | 1 + stories/Vault.stories.tsx | 6 ++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/components/ConnectionDetails.tsx b/src/components/ConnectionDetails.tsx index cc8c176..f8b7037 100644 --- a/src/components/ConnectionDetails.tsx +++ b/src/components/ConnectionDetails.tsx @@ -116,11 +116,27 @@ const ConnectionDetails = ({ return; } + if ( + selectedConnection.state === 'callable' && + selectedConnection.configurable_resources?.length > 0 && + currentView === null + ) { + setCurrentView(ConnectionViewType.ConfigurableResources); + return; + } + // On single connection mode, open settings by default if (currentView === null && singleConnectionMode) { setCurrentView(ConnectionViewType.Settings); } - }, [needsInput, initialView, resources, settings]); + }, [ + needsInput, + initialView, + resources, + settings, + selectedConnection, + currentView, + ]); useEffect(() => { let hasRequiredMappings = false; diff --git a/src/components/ConnectionForm.tsx b/src/components/ConnectionForm.tsx index a0e3523..4216d17 100644 --- a/src/components/ConnectionForm.tsx +++ b/src/components/ConnectionForm.tsx @@ -48,6 +48,7 @@ const ConnectionForm = ({ connection, setCurrentView, settings }: Props) => { const formik = useFormik({ initialValues, + enableReinitialize: true, onSubmit: async (values) => { if (connection.validation_support) { setValidationState('validating'); diff --git a/stories/Vault.stories.tsx b/stories/Vault.stories.tsx index 2dee132..59efe1d 100644 --- a/stories/Vault.stories.tsx +++ b/stories/Vault.stories.tsx @@ -48,7 +48,9 @@ Programaticly.args = { export const SingleConnection = Template.bind({}); SingleConnection.args = { trigger: ( - + ), unifiedApi: 'crm', serviceId: 'act', @@ -68,7 +70,7 @@ export const ConfigurableResourcesView = Template.bind({}); ConfigurableResourcesView.args = { trigger: ( ), unifiedApi: 'crm', From d4e54284a47ba1028b3be8cff8f91ef07733c694 Mon Sep 17 00:00:00 2001 From: nick_lloyd Date: Fri, 16 Feb 2024 08:40:03 +0100 Subject: [PATCH 3/4] remove circular dependency --- src/components/FieldMappingForm.tsx | 15 +-------------- src/components/FieldSelector.tsx | 2 +- src/utils/fieldMappingUtils.ts | 13 +++++++++++++ 3 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 src/utils/fieldMappingUtils.ts diff --git a/src/components/FieldMappingForm.tsx b/src/components/FieldMappingForm.tsx index 92ce8f6..5361ae1 100644 --- a/src/components/FieldMappingForm.tsx +++ b/src/components/FieldMappingForm.tsx @@ -4,24 +4,11 @@ import { useTranslation } from 'react-i18next'; import useSWR, { useSWRConfig } from 'swr'; import { Connection, CustomMapping } from '../types/Connection'; import { extractLastAttribute } from '../utils/extractLastAttribute'; +import { findByDescription } from '../utils/fieldMappingUtils'; import { useConnections } from '../utils/useConnections'; import { useSession } from '../utils/useSession'; import FieldSelector from './FieldSelector'; -export const findByDescription = (obj: any, description: string): any => { - for (const key in obj) { - if (obj[key] instanceof Object) { - const result = findByDescription(obj[key], description); - if (result) { - return result; - } - } else if (key === 'description' && obj[key] === description) { - return obj; - } - } - return null; -}; - const renderReadableJSONPath = ( jsonPath: string, responseDataPath?: string diff --git a/src/components/FieldSelector.tsx b/src/components/FieldSelector.tsx index 89a4a61..2794a5b 100644 --- a/src/components/FieldSelector.tsx +++ b/src/components/FieldSelector.tsx @@ -17,8 +17,8 @@ import React, { import { useTranslation } from 'react-i18next'; import useSWR from 'swr'; import { extractLastAttribute } from '../utils/extractLastAttribute'; +import { findByDescription } from '../utils/fieldMappingUtils'; import { useConnections } from '../utils/useConnections'; -import { findByDescription } from './FieldMappingForm'; interface Props { onSelect: (field: any) => void; diff --git a/src/utils/fieldMappingUtils.ts b/src/utils/fieldMappingUtils.ts new file mode 100644 index 0000000..339abfa --- /dev/null +++ b/src/utils/fieldMappingUtils.ts @@ -0,0 +1,13 @@ +export const findByDescription = (obj: any, description: string): any => { + for (const key in obj) { + if (obj[key] instanceof Object) { + const result = findByDescription(obj[key], description); + if (result) { + return result; + } + } else if (key === 'description' && obj[key] === description) { + return obj; + } + } + return null; +}; From df74b4e2d3fe6dec7b81e9262aa958921eba130a Mon Sep 17 00:00:00 2001 From: nick_lloyd Date: Fri, 16 Feb 2024 10:15:30 +0100 Subject: [PATCH 4/4] bump size limit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 421eaf4..ec8dea5 100644 --- a/package.json +++ b/package.json @@ -71,11 +71,11 @@ "size-limit": [ { "path": "dist/react-vault.cjs.production.min.js", - "limit": "200 KB" + "limit": "300 KB" }, { "path": "dist/react-vault.esm.js", - "limit": "200 KB" + "limit": "300 KB" } ], "resolutions": {