Skip to content

Commit

Permalink
fix: Added the designer id to the root property id in the Adaptive Fo…
Browse files Browse the repository at this point in the history
…rm (microsoft#4342)

Co-authored-by: Chris Whitten <[email protected]>
  • Loading branch information
tdurnford and cwhitten authored Oct 12, 2020
1 parent ee5c34f commit a4471e7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const AdaptiveForm: React.FC<AdaptiveFormProps> = function AdaptiveForm(p
<SchemaField
definitions={schema?.definitions}
depth={-1}
id="root"
id={formData.$designer?.id ? `root[${formData.$designer?.id}]` : 'root'}
name="root"
rawErrors={errors}
schema={schema}
Expand Down
16 changes: 1 addition & 15 deletions Composer/packages/adaptive-form/src/utils/arrayUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import { generateUniqueId } from '@bfc/shared';
import { ChangeHandler } from '@bfc/extension-client';
import { useEffect, useState } from 'react';
import isEqual from 'lodash/isEqual';
import { useState } from 'react';

type ArrayChangeHandler<ItemType> = (items: ArrayItem<ItemType>[]) => void;

Expand Down Expand Up @@ -79,19 +78,6 @@ export function useArrayItems<ItemType = unknown>(
): ArrayItemState<ItemType> {
const [cache, setCache] = useState(generateArrayItems(items));

useEffect(() => {
const newCache = generateArrayItems(items);

if (
!isEqual(
cache.map(({ value }) => value),
newCache.map(({ value }) => value)
)
) {
setCache(newCache);
}
}, [items]);

const handleChange = (newItems: ArrayItem<ItemType>[]) => {
setCache(newItems);
onChange(newItems.map(({ value }) => value));
Expand Down
16 changes: 1 addition & 15 deletions Composer/packages/adaptive-form/src/utils/objectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import { generateUniqueId } from '@bfc/shared';
import { ChangeHandler } from '@bfc/extension-client';
import { useEffect, useState } from 'react';
import isEqual from 'lodash/isEqual';
import { useState } from 'react';

type ItemType<ValueType = unknown> = { [key: string]: ValueType };
type ObjectChangeHandler<ValueType = unknown> = (items: ObjectItem<ValueType>[]) => void;
Expand Down Expand Up @@ -65,19 +64,6 @@ export function useObjectItems<ValueType = unknown>(
): ObjectItemState<ValueType> {
const [cache, setCache] = useState(generateObjectEntries(items));

useEffect(() => {
const newCache = generateObjectEntries(items);

if (
!isEqual(
newCache.map(({ id, ...rest }) => rest),
cache.map(({ id, ...rest }) => rest)
)
) {
setCache(generateObjectEntries(items));
}
}, [items]);

const handleChange = (items) => {
setCache(items);
onChange(items.reduce((acc, { propertyName, propertyValue }) => ({ ...acc, [propertyName]: propertyValue }), {}));
Expand Down

0 comments on commit a4471e7

Please sign in to comment.