diff --git a/packages/bruno-app/src/components/CollectionSettings/ProxySettings/index.js b/packages/bruno-app/src/components/CollectionSettings/ProxySettings/index.js index 8a433e73e..54be8669a 100644 --- a/packages/bruno-app/src/components/CollectionSettings/ProxySettings/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/ProxySettings/index.js @@ -6,14 +6,28 @@ import * as Yup from 'yup'; import toast from 'react-hot-toast'; import { IconEye, IconEyeOff } from '@tabler/icons'; import { useState } from 'react'; +import { useMemo } from 'react'; +import { cloneDeep } from 'lodash'; + +const ProxySettings = ({ proxyConfig: _proxyConfig, onUpdate }) => { + const proxyConfig = useMemo(() => { + const proxyConfigCopy = cloneDeep(_proxyConfig); + // backward compatibility check + if (proxyConfigCopy?.enabled == 'true') proxyConfigCopy.enabled = true; + if (proxyConfigCopy?.enabled == 'false') proxyConfigCopy.enabled = false; + + proxyConfigCopy.enabled = ['string', 'boolean'].includes(typeof proxyConfigCopy?.enabled) + ? proxyConfigCopy?.enabled + : 'global'; + return proxyConfigCopy; + }, [_proxyConfig]); -const ProxySettings = ({ proxyConfig, onUpdate }) => { const proxySchema = Yup.object({ - enabled: Yup.string().oneOf(['global', 'true', 'false']), + enabled: Yup.mixed().oneOf([false, true, 'global']), protocol: Yup.string().oneOf(['http', 'https', 'socks4', 'socks5']), hostname: Yup.string() .when('enabled', { - is: 'true', + is: true, then: (hostname) => hostname.required('Specify the hostname for your proxy.'), otherwise: (hostname) => hostname.nullable() }) @@ -26,7 +40,7 @@ const ProxySettings = ({ proxyConfig, onUpdate }) => { .transform((_, val) => (val ? Number(val) : null)), auth: Yup.object() .when('enabled', { - is: 'true', + is: true, then: Yup.object({ enabled: Yup.boolean(), username: Yup.string() @@ -49,7 +63,7 @@ const ProxySettings = ({ proxyConfig, onUpdate }) => { const formik = useFormik({ initialValues: { - enabled: proxyConfig.enabled || 'global', + enabled: proxyConfig.enabled, protocol: proxyConfig.protocol || 'http', hostname: proxyConfig.hostname || '', port: proxyConfig.port || '', @@ -65,13 +79,6 @@ const ProxySettings = ({ proxyConfig, onUpdate }) => { proxySchema .validate(values, { abortEarly: true }) .then((validatedProxy) => { - // serialize 'enabled' to boolean - if (validatedProxy.enabled === 'true') { - validatedProxy.enabled = true; - } else if (validatedProxy.enabled === 'false') { - validatedProxy.enabled = false; - } - onUpdate(validatedProxy); }) .catch((error) => { @@ -84,7 +91,7 @@ const ProxySettings = ({ proxyConfig, onUpdate }) => { useEffect(() => { formik.setValues({ - enabled: proxyConfig.enabled === true ? 'true' : proxyConfig.enabled === false ? 'false' : 'global', + enabled: proxyConfig.enabled, protocol: proxyConfig.protocol || 'http', hostname: proxyConfig.hostname || '', port: proxyConfig.port || '', @@ -118,214 +125,229 @@ const ProxySettings = ({ proxyConfig, onUpdate }) => { />
-
-
- -
-
-
- - - {formik.touched.hostname && formik.errors.hostname ? ( -
{formik.errors.hostname}
- ) : null} -
-
- - - {formik.touched.port && formik.errors.port ? ( -
{formik.errors.port}
- ) : null} -
-
- - -
-
-
- - - {formik.touched.auth?.username && formik.errors.auth?.username ? ( -
{formik.errors.auth.username}
- ) : null} -
-
- -
- + {formik.touched.hostname && formik.errors.hostname ? ( +
{formik.errors.hostname}
+ ) : null} +
+
+ + + {formik.touched.port && formik.errors.port ? ( +
{formik.errors.port}
+ ) : null} +
+
+ + -
- {formik.touched.auth?.password && formik.errors.auth?.password ? ( -
{formik.errors.auth.password}
- ) : null} -
-
-
- - - {formik.touched.bypassProxy && formik.errors.bypassProxy ? ( -
{formik.errors.bypassProxy}
- ) : null} -
+
+
+ + + {formik.touched.auth?.username && formik.errors.auth?.username ? ( +
{formik.errors.auth.username}
+ ) : null} +
+
+ +
+ + +
+ {formik.touched.auth?.password && formik.errors.auth?.password ? ( +
{formik.errors.auth.password}
+ ) : null} +
+
+
+ + + {formik.touched.bypassProxy && formik.errors.bypassProxy ? ( +
{formik.errors.bypassProxy}
+ ) : null} +
+ + ) : null}
- {formik.touched.auth?.password && formik.errors.auth?.password ? ( -
{formik.errors.auth.password}
- ) : null} -
- -
- - - {formik.touched.bypassProxy && formik.errors.bypassProxy ? ( -
{formik.errors.bypassProxy}
- ) : null} -
+
+
+ + + {formik.touched.auth?.username && formik.errors.auth?.username ? ( +
{formik.errors.auth.username}
+ ) : null} +
+
+ +
+ + +
+ {formik.touched.auth?.password && formik.errors.auth?.password ? ( +
{formik.errors.auth.password}
+ ) : null} +
+
+
+ + + {formik.touched.bypassProxy && formik.errors.bypassProxy ? ( +
{formik.errors.bypassProxy}
+ ) : null} +
+ + ) : null}