Skip to content

Commit

Permalink
fix: remove depth validation logic from ux-editor (#14303)
Browse files Browse the repository at this point in the history
Co-authored-by: JamalAlabdullah <90609090+JamalAlabdullah@users.noreply.github.com>
  • Loading branch information
Jondyr and JamalAlabdullah authored Dec 18, 2024
1 parent cef531f commit 5f64943
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 37 deletions.
10 changes: 0 additions & 10 deletions frontend/packages/ux-editor/src/containers/FormDesigner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
getItem,
isComponentTypeValidChild,
moveLayoutItem,
validateDepth,
} from '../utils/formLayoutUtils';
import { useAddItemToLayoutMutation } from '../hooks/mutations/useAddItemToLayoutMutation';
import { useFormLayoutMutation } from '../hooks/mutations/useFormLayoutMutation';
Expand Down Expand Up @@ -105,7 +104,6 @@ export const FormDesigner = (): JSX.Element => {
}

if (formLayoutIsReady) {
const triggerDepthAlert = () => alert(t('schema_editor.error_depth'));
const triggerInvalidChildAlert = () => alert(t('schema_editor.error_invalid_child'));
const layout = formLayouts[selectedFormLayoutName];

Expand All @@ -117,10 +115,6 @@ export const FormDesigner = (): JSX.Element => {
return;
}
const updatedLayout = addItemOfType(layout, type, newId, parentId, index);
if (!validateDepth(updatedLayout)) {
triggerDepthAlert();
return;
}
addItemToLayout(
{ componentType: type, newId, parentId, index },
{
Expand All @@ -138,10 +132,6 @@ export const FormDesigner = (): JSX.Element => {
return;
}
const updatedLayout = moveLayoutItem(layout, id, parentId, index);
if (!validateDepth(updatedLayout)) {
triggerDepthAlert();
return;
}
updateFormLayout(
{ internalLayout: updatedLayout },
{
Expand Down
18 changes: 0 additions & 18 deletions frontend/packages/ux-editor/src/utils/formLayoutUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
removeComponent,
removeComponentsByType,
updateContainer,
validateDepth,
findLayoutsContainingDuplicateComponents,
getAllDescendants,
getAllFormItemIds,
Expand Down Expand Up @@ -497,23 +496,6 @@ describe('formLayoutUtils', () => {
});
});

describe('validateDepth', () => {
it('Returns true if the depth is valid', () => {
expect(validateDepth(mockInternal)).toBe(true);
});

it('Returns false if the depth is invalid', () => {
let layout = ObjectUtils.deepCopy(mockInternal);
const container: FormContainer<ComponentType.Group> = {
id: groupInGroupId,
itemType: 'CONTAINER',
type: ComponentType.Group,
};
layout = addContainer(layout, container, 'groupingroupingroup', groupInGroupId);
expect(validateDepth(layout)).toBe(false);
});
});

describe('isComponentTypeValidChild', () => {
it.each([
ComponentType.ActionButton,
Expand Down
10 changes: 1 addition & 9 deletions frontend/packages/ux-editor/src/utils/formLayoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
InternalLayoutData,
IToolbarElement,
} from '../types/global';
import { BASE_CONTAINER_ID, MAX_NESTED_GROUP_LEVEL } from 'app-shared/constants';
import { BASE_CONTAINER_ID } from 'app-shared/constants';
import { ArrayUtils, ObjectUtils } from '@studio/pure-functions';
import { ComponentType, type CustomComponentType } from 'app-shared/types/ComponentType';
import type { FormComponent } from '../types/FormComponent';
Expand Down Expand Up @@ -362,14 +362,6 @@ export const getDepth = (layout: IInternalLayout): number => {
else return Math.max(...containers.map((id) => numberOfContainerLevels(layout, id)));
};

/**
* Checks if the depth of a layout is within the allowed range.
* @param layout The layout to check.
* @returns True if the depth is within the allowed range, false otherwise.
*/
export const validateDepth = (layout: IInternalLayout): boolean =>
getDepth(layout) <= MAX_NESTED_GROUP_LEVEL;

export const isComponentTypeValidChild = (
layout: IInternalLayout,
parentId: string,
Expand Down

0 comments on commit 5f64943

Please sign in to comment.