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

FIO-8512: fixed an issue where conditionally visible data inside layout components inside editGrid/dataGrid is unset on server side #108

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
51 changes: 50 additions & 1 deletion src/utils/__tests__/formUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
findComponent,
findComponents,
getComponent,
flattenComponents
flattenComponents,
getComponentActualValue
} from "../formUtil";
import { fastCloneDeep } from 'utils/fastCloneDeep';

Expand Down Expand Up @@ -1747,3 +1748,51 @@ describe('eachComponentData', () => {
]);
});
});

describe('getComponentActualValue', () => {
it('Should return correct value for component inside inside panel inside editGrid', () => {
const component = {
label: 'Radio',
optionsLabelPosition: 'right',
inline: false,
tableView: false,
values: [
{ label: 'yes', value: 'yes', shortcut: '' },
{ label: 'no', value: 'no', shortcut: '' },
],
key: 'radio',
type: 'radio',
input: true,
path: 'editGrid.radio',
parent: {
collapsible: false,
key: 'panel',
type: 'panel',
label: 'Panel',
input: false,
tableView: false,
path: 'editGrid[0].panel',
parent: {
label: 'Edit Grid',
tableView: false,
rowDrafts: false,
key: 'editGrid',
type: 'editgrid',
path: 'editGrid',
displayAsTable: false,
input: true,
},
},
};
const compPath = 'editGrid.radio';
const data = {
editGrid: [{ radio: 'yes', textArea: 'test' }],
submit: true,
};
const row = { radio: 'yes', textArea: 'test' };

const value = getComponentActualValue(component, compPath, data, row);
expect(value).to.equal('yes');
});
});

9 changes: 6 additions & 3 deletions src/utils/conditions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConditionsContext, JSONConditional, LegacyConditional, SimpleConditional } from "types";
import { EvaluatorFn, evaluate, JSONLogicEvaluator } from 'modules/jsonlogic';
import { getComponentActualValue } from "./formUtil";
import { getComponent, getComponentActualValue } from "./formUtil";
import { has, isObject, map, every, some, find, filter } from 'lodash';
import ConditionOperators from './operators';

Expand Down Expand Up @@ -95,7 +95,7 @@ export function checkJsonConditional(conditional: JSONConditional, context: Cond
* @returns
*/
export function checkSimpleConditional(conditional: SimpleConditional, context: ConditionsContext): boolean | null {
const { component, data, row, instance } = context;
const { component, data, row, instance, form } = context;
if (!conditional || !isSimpleConditional(conditional)) {
return null;
}
Expand All @@ -110,7 +110,10 @@ export function checkSimpleConditional(conditional: SimpleConditional, context:
// Ignore conditions if there is no component path.
return null;
}
const value = getComponentActualValue(component, conditionComponentPath, data, row);

const conditionComp = getComponent(form?.components || [], conditionComponentPath, true);
const value = conditionComp ? getComponentActualValue(conditionComp, conditionComponentPath, data, row) : null;

const ConditionOperator = ConditionOperators[operator];
return ConditionOperator
? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath })
Expand Down
14 changes: 12 additions & 2 deletions src/utils/formUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,18 @@ export function getComponentActualValue(component: Component, compPath: string,
//
// a[0].b[2].c[3].d => a.b.c.d
//
if (component.parent?.path) {
const parentCompPath = component.parent?.path.replace(/\[[0-9]+\]/g, '');
let parentInputComponent: any = null;
let parent = component;

while (parent?.parent?.path && !parentInputComponent) {
parent = parent.parent;
if (parent.input) {
parentInputComponent = parent;
}
}

if (parentInputComponent) {
const parentCompPath = parentInputComponent.path.replace(/\[[0-9]+\]/g, '');
compPath = compPath.replace(parentCompPath, '');
compPath = trim(compPath, '. ');
}
Expand Down
Loading