Skip to content

Commit

Permalink
Merge branch 'main' into visualize-code-list-usage-in-library
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren authored Jan 6, 2025
2 parents b59bd2b + 1545c2d commit 52bb156
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,5 @@ describe('useValidateComponent', () => {
});

const render = (component: FormComponent) => {
const queries = {
getOptionListIds: jest
.fn()
.mockImplementation(() => Promise.resolve<string[]>(optionListIdsMock)),
};
return renderHookWithProviders(() => useValidateComponent(component), { queries }).result.current;
return renderHookWithProviders(() => useValidateComponent(component)).result.current;
};
18 changes: 2 additions & 16 deletions frontend/packages/ux-editor/src/hooks/useValidateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type {
FormComponent,
FormRadioButtonsComponent,
} from '../types/FormComponent';
import { useOptionListIdsQuery } from './queries/useOptionListIdsQuery';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';

export enum ErrorCode {
NoOptions = 'NoOptions',
Expand All @@ -20,17 +18,8 @@ export type ComponentValidationResult = {

const validateOptionGroup = (
component: FormCheckboxesComponent | FormRadioButtonsComponent,
optionListIds: string[],
): ComponentValidationResult => {
if (component.optionsId) {
const isExistingOptionId = optionListIds?.includes(component.optionsId);
if (!isExistingOptionId) {
return {
isValid: false,
error: ErrorCode.NoOptions,
};
}
} else {
if (!component.optionsId) {
if (!component.options || component.options.length === 0) {
return {
isValid: false,
Expand All @@ -48,13 +37,10 @@ const validateOptionGroup = (
};

export const useValidateComponent = (component: FormComponent): ComponentValidationResult => {
const { org, app } = useStudioEnvironmentParams();
const { data: optionListIds } = useOptionListIdsQuery(org, app);

switch (component.type) {
case ComponentType.Checkboxes:
case ComponentType.RadioButtons:
return validateOptionGroup(component, optionListIds);
return validateOptionGroup(component);
default:
return { isValid: true };
}
Expand Down

0 comments on commit 52bb156

Please sign in to comment.