Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove depth validation logic from ux-editor #14303

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading