From 07757c7e7bc387b191d2bd1d4f0d62d59021eae2 Mon Sep 17 00:00:00 2001 From: ashit-rath Date: Fri, 22 Apr 2022 14:15:45 +0530 Subject: [PATCH] fix: Replace "klona/full" -> "klona" in JSONForm to avoid cloning of non-enumerable properties (#13193) - non-enumerable like `writable`, `configurable`, `enumerable` were getting cloned with `klona/full` and it wasn't needed. --- .../propertyControls/FieldConfigurationControl.tsx | 5 ++--- app/client/src/widgets/JSONFormWidget/component/Field.tsx | 3 +-- app/client/src/widgets/JSONFormWidget/component/Form.tsx | 3 +-- app/client/src/widgets/JSONFormWidget/fields/ArrayField.tsx | 3 +-- .../JSONFormWidget/fields/useRegisterFieldValidity.ts | 3 +-- .../JSONFormWidget/fields/useUpdateInternalMetaState.ts | 3 +-- app/client/src/widgets/JSONFormWidget/schemaParser.test.ts | 3 +-- app/client/src/widgets/JSONFormWidget/schemaParser.ts | 4 ++-- .../JSONFormWidget/widget/propertyConfig/helper.test.ts | 3 +-- 9 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/client/src/components/propertyControls/FieldConfigurationControl.tsx b/app/client/src/components/propertyControls/FieldConfigurationControl.tsx index 0e1f768a34..1d0cbfed4f 100644 --- a/app/client/src/components/propertyControls/FieldConfigurationControl.tsx +++ b/app/client/src/components/propertyControls/FieldConfigurationControl.tsx @@ -1,6 +1,7 @@ import React from "react"; -import { isEmpty, isString, maxBy, set, sortBy } from "lodash"; import log from "loglevel"; +import { klona } from "klona"; +import { isEmpty, isString, maxBy, set, sortBy } from "lodash"; import BaseControl, { ControlProps } from "./BaseControl"; import EmptyDataState from "components/utils/EmptyDataState"; @@ -19,8 +20,6 @@ import { StyledPropertyPaneButton } from "./StyledControls"; import { getNextEntityName } from "utils/AppsmithUtils"; import { InputText } from "./InputTextControl"; -import { klona } from "klona/full"; - type DroppableItem = BaseItemProps & { index: number; isCustomField: boolean; diff --git a/app/client/src/widgets/JSONFormWidget/component/Field.tsx b/app/client/src/widgets/JSONFormWidget/component/Field.tsx index e9f03a6919..9b86696e19 100644 --- a/app/client/src/widgets/JSONFormWidget/component/Field.tsx +++ b/app/client/src/widgets/JSONFormWidget/component/Field.tsx @@ -2,13 +2,12 @@ import equal from "fast-deep-equal/es6"; import React, { useEffect, useRef } from "react"; import styled from "styled-components"; import { ControllerProps, useFormContext } from "react-hook-form"; +import { klona } from "klona"; import FieldLabel, { FieldLabelProps } from "./FieldLabel"; import useUpdateAccessor from "../fields/useObserveAccessor"; import { FIELD_MARGIN_BOTTOM } from "./styleConstants"; -import { klona } from "klona/full"; - type FieldProps = React.PropsWithChildren< { accessor: string; diff --git a/app/client/src/widgets/JSONFormWidget/component/Form.tsx b/app/client/src/widgets/JSONFormWidget/component/Form.tsx index 5191aef041..5f664a75bd 100644 --- a/app/client/src/widgets/JSONFormWidget/component/Form.tsx +++ b/app/client/src/widgets/JSONFormWidget/component/Form.tsx @@ -4,6 +4,7 @@ import styled from "styled-components"; import { debounce, isEmpty } from "lodash"; import { FormProvider, useForm } from "react-hook-form"; import { Text } from "@blueprintjs/core"; +import { klona } from "klona"; import useFixedFooter from "./useFixedFooter"; import { @@ -16,8 +17,6 @@ import { ROOT_SCHEMA_KEY, Schema } from "../constants"; import { convertSchemaItemToFormData, schemaItemDefaultValue } from "../helper"; import { TEXT_SIZES } from "constants/WidgetConstants"; -import { klona } from "klona/full"; - export type FormProps = PropsWithChildren<{ backgroundColor?: string; disabledWhenInvalid?: boolean; diff --git a/app/client/src/widgets/JSONFormWidget/fields/ArrayField.tsx b/app/client/src/widgets/JSONFormWidget/fields/ArrayField.tsx index bb2d637bb2..ee65d30934 100644 --- a/app/client/src/widgets/JSONFormWidget/fields/ArrayField.tsx +++ b/app/client/src/widgets/JSONFormWidget/fields/ArrayField.tsx @@ -9,6 +9,7 @@ import styled from "styled-components"; import { ControllerRenderProps, useFormContext } from "react-hook-form"; import { get, set } from "lodash"; import { Icon } from "@blueprintjs/core"; +import { klona } from "klona"; import Accordion from "../component/Accordion"; import FieldLabel from "../component/FieldLabel"; @@ -30,8 +31,6 @@ import { FIELD_MARGIN_BOTTOM } from "../component/styleConstants"; import { generateReactKey } from "utils/generators"; import { schemaItemDefaultValue } from "../helper"; -import { klona } from "klona/full"; - type ArrayComponentProps = FieldComponentBaseProps & { backgroundColor?: string; cellBackgroundColor?: string; diff --git a/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts b/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts index 3aa4ee5618..59ccdf6517 100644 --- a/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts +++ b/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts @@ -2,12 +2,11 @@ import * as Sentry from "@sentry/react"; import { set } from "lodash"; import { ControllerProps, useFormContext } from "react-hook-form"; import { useContext, useEffect } from "react"; +import { klona } from "klona"; import FormContext from "../FormContext"; import { FieldType } from "../constants"; -import { klona } from "klona/full"; - export type UseRegisterFieldValidityProps = { isValid: boolean; fieldName: ControllerProps["name"]; diff --git a/app/client/src/widgets/JSONFormWidget/fields/useUpdateInternalMetaState.ts b/app/client/src/widgets/JSONFormWidget/fields/useUpdateInternalMetaState.ts index 855d3eb678..ecd9f4a365 100644 --- a/app/client/src/widgets/JSONFormWidget/fields/useUpdateInternalMetaState.ts +++ b/app/client/src/widgets/JSONFormWidget/fields/useUpdateInternalMetaState.ts @@ -1,11 +1,10 @@ import { debounce, set } from "lodash"; import { useMemo, useContext, useCallback } from "react"; +import { klona } from "klona"; import { DebouncedExecuteActionPayload } from "widgets/MetaHOC"; import FormContext from "../FormContext"; -import { klona } from "klona/full"; - export type UseUpdateInternalMetaStateProps = { propertyName?: string; }; diff --git a/app/client/src/widgets/JSONFormWidget/schemaParser.test.ts b/app/client/src/widgets/JSONFormWidget/schemaParser.test.ts index 2fa5ebec55..eb7d34e9ed 100644 --- a/app/client/src/widgets/JSONFormWidget/schemaParser.test.ts +++ b/app/client/src/widgets/JSONFormWidget/schemaParser.test.ts @@ -1,4 +1,5 @@ import { get, set } from "lodash"; +import { klona } from "klona"; import SchemaParser, { applyPositions, @@ -22,8 +23,6 @@ import { SchemaItem, } from "./constants"; -import { klona } from "klona/full"; - const widgetName = "JSONForm1"; describe("#parse", () => { diff --git a/app/client/src/widgets/JSONFormWidget/schemaParser.ts b/app/client/src/widgets/JSONFormWidget/schemaParser.ts index 80c8a56533..32d08bd454 100644 --- a/app/client/src/widgets/JSONFormWidget/schemaParser.ts +++ b/app/client/src/widgets/JSONFormWidget/schemaParser.ts @@ -7,6 +7,8 @@ import { sortBy, startCase, } from "lodash"; +import { klona } from "klona"; + import { sanitizeKey } from "widgets/WidgetUtils"; import { ARRAY_ITEM_KEY, @@ -23,8 +25,6 @@ import { SchemaItem, } from "./constants"; -import { klona } from "klona/full"; - type Obj = Record; type JSON = Obj | Obj[]; diff --git a/app/client/src/widgets/JSONFormWidget/widget/propertyConfig/helper.test.ts b/app/client/src/widgets/JSONFormWidget/widget/propertyConfig/helper.test.ts index 0a2fb354cd..2c6906984f 100644 --- a/app/client/src/widgets/JSONFormWidget/widget/propertyConfig/helper.test.ts +++ b/app/client/src/widgets/JSONFormWidget/widget/propertyConfig/helper.test.ts @@ -1,4 +1,5 @@ import { get, set } from "lodash"; +import { klona } from "klona"; import schemaTestData from "widgets/JSONFormWidget/schemaTestData"; import { @@ -16,8 +17,6 @@ import { updateChildrenDisabledStateHook, } from "./helper"; -import { klona } from "klona/full"; - const widgetName = "JSONForm1"; describe(".fieldTypeUpdateHook", () => {