Skip to content

Commit

Permalink
FIO-8690: Add small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekotikov committed Oct 30, 2024
1 parent 78114ae commit b3387fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/utils/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { flattenComponents, getComponent, getComponentActualValue } from './form
import { has, isObject, map, every, some, find, filter, isBoolean, split } from 'lodash';
import ConditionOperators from './operators';
import _ from 'lodash';
import { checkComponentType } from './utils';

export const isJSONConditional = (conditional: any): conditional is JSONConditional => {
return conditional && conditional.json && isObject(conditional.json);
Expand Down Expand Up @@ -118,7 +119,7 @@ function isConditionPotentiallyBasedOnValuePath(condition: any = {}) {
);
}

function getConditionalPathsRecursive(conditionPaths: any, data: any): any {
function getConditionalPathsRecursive(conditionPaths: string[], data: any): any {
let currentGlobalIndex = 0;
const conditionalPathsArray: string[] = [];
const getConditionalPaths = (data: any, currentPath = '', localIndex = 0) => {
Expand Down Expand Up @@ -225,12 +226,12 @@ export function checkSimpleConditional(
const isParentGrid = (component?.parent?.type || instance?.parent?.type) === 'datagrid' || (component?.parent?.type || instance?.parent?.type) === 'editgrid'
const conditionalPaths = isParentGrid ? [] : getConditionalPathsRecursive(splittedConditionPath, data);

if (conditionComponent?.component?.type === "checkbox") {
if (checkComponentType(conditionComponent, "checkbox")) {
if (typeof comparedValue === 'string') {
comparedValue = comparedValue === 'true'
}
}
if (conditionComponent?.type === 'select') {
if (checkComponentType(conditionComponent, "select")) {
conditionComponent = conditionComponent?.component || conditionComponent;
}
if (conditionalPaths.length > 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/formUtil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { eachComponent } from './eachComponent';
import { eachComponentData } from './eachComponentData';
import { eachComponentAsync } from './eachComponentAsync';
import { eachComponentDataAsync } from './eachComponentDataAsync';
import { checkComponentType } from 'utils/utils';

/**
* Flatten the form components for data manipulation.
Expand Down Expand Up @@ -360,7 +361,7 @@ export function getComponentActualValue(
let value = null;
if (data) {
value = get(data, compPath);
if(component?.type === 'address') {
if(checkComponentType(component, "address")) {
const addressIgnoreProperties = ['mode', 'address'];
const result = Object.values(omit(value, addressIgnoreProperties)).some(Boolean);
if(!result) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ export function resetEphemeralState(component: Component) {
delete component.ephemeralState;
}
}

export function checkComponentType(component: Component | undefined, type:string) {
return component?.type === type;
}

0 comments on commit b3387fc

Please sign in to comment.