= (props) => {
[props.input.onChange, props.input.name],
);
- const parentOnUnmount = React.useCallback(
- (childName: string) =>
- props.input.onChange((currentValue) => currentValue, {[childName]: false}),
- [props.input.onChange],
- );
-
return (
= (props) => {
spec={specProperties[oneOfValue]}
name={`${props.name}.${oneOfValue}`}
parentOnChange={parentOnChange}
- parentOnUnmount={parentOnUnmount}
+ parentOnUnmount={props.input.parentOnUnmount}
key={`${props.name}.${oneOfValue}`}
/>
diff --git a/src/lib/kit/components/Inputs/OneOfCard/OneOfCard.tsx b/src/lib/kit/components/Inputs/OneOfCard/OneOfCard.tsx
index c28521b1..0b7d6d72 100644
--- a/src/lib/kit/components/Inputs/OneOfCard/OneOfCard.tsx
+++ b/src/lib/kit/components/Inputs/OneOfCard/OneOfCard.tsx
@@ -74,11 +74,6 @@ export const OneOfCard: ObjectIndependentInput = (props) => {
[input.onChange, input.name],
);
- const parentOnUnmount = React.useCallback(
- (childName: string) => input.onChange((currentValue) => currentValue, {[childName]: false}),
- [input.onChange],
- );
-
useErrorChecker({name, meta, open, setOpen});
return (
@@ -98,7 +93,7 @@ export const OneOfCard: ObjectIndependentInput = (props) => {
spec={specProperties[oneOfValue]}
name={`${name}.${oneOfValue}`}
parentOnChange={parentOnChange}
- parentOnUnmount={parentOnUnmount}
+ parentOnUnmount={input.parentOnUnmount}
key={`${name}.${oneOfValue}`}
/>
) : null}
diff --git a/src/lib/kit/components/Inputs/Secret/Secret.tsx b/src/lib/kit/components/Inputs/Secret/Secret.tsx
index 051d15c4..5b7c593e 100644
--- a/src/lib/kit/components/Inputs/Secret/Secret.tsx
+++ b/src/lib/kit/components/Inputs/Secret/Secret.tsx
@@ -35,11 +35,6 @@ export const Secret: ObjectIndependentInput = (props) => {
[input.onChange, input.name],
);
- const parentOnUnmount = React.useCallback(
- (childName: string) => input.onChange((currentValue) => currentValue, {[childName]: false}),
- [input.onChange],
- );
-
if (!childSpec) {
return null;
}
@@ -50,7 +45,7 @@ export const Secret: ObjectIndependentInput = (props) => {
spec={childSpec}
name={`${name}.${SECRET_PROPERTY_NAME}`}
parentOnChange={parentOnChange}
- parentOnUnmount={parentOnUnmount}
+ parentOnUnmount={input.parentOnUnmount}
key={`${name}.${SECRET_PROPERTY_NAME}`}
/>
);
diff --git a/src/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.tsx b/src/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.tsx
index 4ea508f2..c2d96459 100644
--- a/src/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.tsx
+++ b/src/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.tsx
@@ -13,7 +13,6 @@ import {
FieldValue,
OBJECT_ARRAY_CNT,
OBJECT_ARRAY_FLAG,
- REMOVED_ITEM,
ValidateError,
isArraySpec,
isBooleanSpec,
@@ -33,12 +32,7 @@ export const TableArrayInput: ArrayInput = ({spec, name, arrayInput, input}) =>
const keys = React.useMemo(
() =>
Object.keys(arrayInput.value || {})
- .filter(
- (k) =>
- k !== OBJECT_ARRAY_FLAG &&
- k !== OBJECT_ARRAY_CNT &&
- arrayInput.value[k] !== REMOVED_ITEM,
- )
+ .filter((k) => k !== OBJECT_ARRAY_FLAG && k !== OBJECT_ARRAY_CNT)
.map((k) => k.split('<').join('').split('>').join(''))
.sort((a, b) => Number(a) - Number(b))
.map((key) => ({
@@ -72,11 +66,6 @@ export const TableArrayInput: ArrayInput = ({spec, name, arrayInput, input}) =>
[input.onChange, input.name],
);
- const parentOnUnmount = React.useCallback(
- (childName: string) => input.onChange((currentValue) => currentValue, {[childName]: false}),
- [input.onChange],
- );
-
const columns = React.useMemo(() => {
const {
items,
@@ -154,7 +143,7 @@ export const TableArrayInput: ArrayInput = ({spec, name, arrayInput, input}) =>
spec={preparedEntitySpec}
name={`${name}.<${key}>.${property}`}
parentOnChange={parentOnChange}
- parentOnUnmount={parentOnUnmount}
+ parentOnUnmount={_.noop}
/>
);
@@ -162,7 +151,7 @@ export const TableArrayInput: ArrayInput = ({spec, name, arrayInput, input}) =>
}));
return [idxColumn, ...columns, removeColumn];
- }, [name, spec, onItemRemove, parentOnChange, parentOnUnmount, input.value]);
+ }, [name, spec, onItemRemove, parentOnChange, input.parentOnUnmount, input.value]);
const getRowClassNames = React.useCallback(
({key}: {key: string}) => {
diff --git a/src/lib/kit/components/Inputs/TextLink/TextLink.tsx b/src/lib/kit/components/Inputs/TextLink/TextLink.tsx
index ef9019ef..37580081 100644
--- a/src/lib/kit/components/Inputs/TextLink/TextLink.tsx
+++ b/src/lib/kit/components/Inputs/TextLink/TextLink.tsx
@@ -25,11 +25,6 @@ export const TextLink: ObjectIndependentInput = (props) => {
[input.onChange, input.name],
);
- const parentOnUnmount = React.useCallback(
- (childName: string) => input.onChange((currentValue) => currentValue, {[childName]: false}),
- [input.onChange],
- );
-
const childSpec = React.useMemo(() => {
if (
spec.properties?.[TEXT_LINK_PROPERTY_NAME] &&
@@ -56,7 +51,7 @@ export const TextLink: ObjectIndependentInput = (props) => {
name={`${name}.${TEXT_LINK_PROPERTY_NAME}`}
key={`${name}.${TEXT_LINK_PROPERTY_NAME}`}
parentOnChange={parentOnChange}
- parentOnUnmount={parentOnUnmount}
+ parentOnUnmount={input.parentOnUnmount}
/>
);
diff --git a/src/stories/Editor.stories.tsx b/src/stories/Editor.stories.tsx
index 45ddce0c..3455c1da 100644
--- a/src/stories/Editor.stories.tsx
+++ b/src/stories/Editor.stories.tsx
@@ -12,6 +12,21 @@ export default {
};
const spec: ObjectSpec = {
+ defaultValue: {
+ id: 12345,
+ name: 'Foo',
+ description:
+ 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla quod error voluptatibus odio minima assumenda voluptatum harum quidem maxime iste exercitationem, quam numquam, necessitatibus saepe praesentium, commodi beatae. Vitae, odit. Assumenda nobis similique voluptatibus? Sint itaque qui laudantium iste? In doloribus nam vitae quasi suscipit dolores maiores culpa amet quo. Distinctio mollitia ad expedita tempore sit? Nemo odit quae impedit?',
+ labels: ['foo', 'bar', 'rab', 'oof'],
+ settings: true,
+ autor: {
+ external: {
+ name: 'Bar',
+ age: 12345,
+ license: true,
+ },
+ },
+ },
required: true,
type: SpecTypes.Object,
properties: {
@@ -105,25 +120,9 @@ const spec: ObjectSpec = {
},
};
-const value = {
- id: 12345,
- name: 'Foo',
- description:
- 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla quod error voluptatibus odio minima assumenda voluptatum harum quidem maxime iste exercitationem, quam numquam, necessitatibus saepe praesentium, commodi beatae. Vitae, odit. Assumenda nobis similique voluptatibus? Sint itaque qui laudantium iste? In doloribus nam vitae quasi suscipit dolores maiores culpa amet quo. Distinctio mollitia ad expedita tempore sit? Nemo odit quae impedit?',
- labels: ['foo', 'bar', 'rab', 'oof'],
- settings: true,
- autor: {
- external: {
- name: 'Bar',
- age: 12345,
- license: true,
- },
- },
-};
-
const template = () => {
const Template: ComponentStory = (__, {viewMode}) => (
-
+
);
return Template;
diff --git a/src/stories/components/DynamicField/DynamicField.tsx b/src/stories/components/DynamicField/DynamicField.tsx
index ab7f22b0..67f083dd 100644
--- a/src/stories/components/DynamicField/DynamicField.tsx
+++ b/src/stories/components/DynamicField/DynamicField.tsx
@@ -16,9 +16,15 @@ export interface DynamicFieldProps {
name: string;
spec: Spec;
search?: string | ((spec: Spec, input: FieldValue, name: string) => boolean);
+ parseJsonDefaultValue?: boolean;
}
-export const DynamicField: React.FC = ({name, spec, search}) => {
+export const DynamicField: React.FC = ({
+ name,
+ spec,
+ search,
+ parseJsonDefaultValue = true,
+}) => {
const config = React.useMemo(() => {
const cfg = _.cloneDeep(dynamicConfig);
@@ -30,7 +36,7 @@ export const DynamicField: React.FC = ({name, spec, search})
return (
= ({spec: externalSpec, value, viewMode}) => {
const [spec, setSpec] = React.useState(externalSpec);
+ const [ready, setReady] = React.useState(true);
const [toggler, setToggler] = React.useState<'form' | 'view' | 'json'>('form');
const togglerItems = React.useMemo(
@@ -45,6 +46,14 @@ export const Editor: React.FC = ({spec: externalSpec, value, viewMo
[setToggler],
);
+ const handleSetSpec = React.useCallback(
+ (value: Spec) => {
+ setReady(false);
+ setSpec(value);
+ },
+ [setSpec, setReady],
+ );
+
const specEditorProps = React.useMemo(
() =>
({
@@ -52,7 +61,9 @@ export const Editor: React.FC = ({spec: externalSpec, value, viewMo
value: JSON.stringify(spec, null, 2),
onChange: (value) => {
try {
- setSpec(JSON.parse(value as string));
+ const spec = JSON.parse(value as string);
+
+ handleSetSpec(spec);
} catch (_) {}
},
},
@@ -93,6 +104,12 @@ export const Editor: React.FC = ({spec: externalSpec, value, viewMo
[],
);
+ React.useEffect(() => {
+ if (!ready) {
+ setReady(true);
+ }
+ }, [ready]);
+
return (
@@ -115,9 +132,15 @@ export const Editor: React.FC
= ({spec: externalSpec, value, viewMo