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-8273 fixed advanced logic for data components #125

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
106 changes: 106 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2780,6 +2780,112 @@ describe('Process Tests', () => {
});
});

it('Should properly validate comopnents inside Data Components with Advanced logic', async () => {
const form = {
display: 'form',
components: [
{
label: 'Data Grid',
reorder: false,
addAnotherPosition: 'bottom',
layoutFixed: false,
enableRowGroups: false,
initEmpty: false,
tableView: false,
key: 'dataGrid',
type: 'datagrid',
input: true,
components: [
{
label: 'Text Field1',
tableView: true,
key: 'textField1',
logic: [
{
name: 'logic1',
trigger: {
type: 'javascript',
javascript: 'result = !row.textField2;'
},
actions: [
{
name: 'action1',
type: 'property',
property: {
label: 'Required',
value: 'validate.required',
type: 'boolean'
},
state: true
}
]
}
],
type: 'textfield',
input: true
},
{
label: 'Text Field2',
tableView: true,
key: 'textField2',
logic: [
{
name: 'logic2',
trigger: {
type: 'javascript',
javascript: 'result = !row.textField1;'
},
actions: [
{
name: 'action2',
type: 'property',
property: {
label: 'Required',
value: 'validate.required',
type: 'boolean'
},
state: true
}
]
}
],
type: 'textfield',
input: true
}
]
}
]
};
const submission ={
data: {
dataGrid: [
{
textField1: 'test',
textField2: ''
},
{
textField1: '',
textField2: 'test'
}
]
}
}
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.evaluator,
scope: {},
config: {
server: true,
},
};
processSync(context);
expect(context.components[0].components).to.deep.equal(form.components[0].components);
expect((context.scope as ValidationScope).errors).to.have.length(0);
})

describe('Required component validation in nested form in DataGrid/EditGrid', () => {
const nestedForm = {
key: 'form',
Expand Down
10 changes: 7 additions & 3 deletions src/utils/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { checkCustomConditional, checkJsonConditional, checkLegacyConditional, c
import { LogicActionCustomAction, LogicActionMergeComponentSchema, LogicActionProperty, LogicActionPropertyBoolean, LogicActionPropertyString, LogicActionValue } from "types/AdvancedLogic";
import { get, set, clone, isEqual, assign } from 'lodash';
import { evaluate, interpolate } from 'modules/jsonlogic';
import { fastCloneDeep } from "./fastCloneDeep";

export const hasLogic = (context: LogicContext): boolean => {
const { component } = context;
Expand Down Expand Up @@ -46,7 +47,10 @@ export function setActionBooleanProperty(context: LogicContext, action: LogicAct
const currentValue = get(component, property, false).toString();
const newValue = action.state.toString();
if (currentValue !== newValue) {
set(component, property, newValue === 'true');
const newComponent = fastCloneDeep(component);
brendanbond marked this conversation as resolved.
Show resolved Hide resolved
set(newComponent, property, newValue === 'true');
set(context, 'component', newComponent);


// If this is "logic" forcing a component to set hidden property, then we will set the "conditionallyHidden"
// flag which will trigger the clearOnHide functionality.
Expand All @@ -61,12 +65,12 @@ export function setActionBooleanProperty(context: LogicContext, action: LogicAct
return cond.path === path
});
if (conditionalyHidden) {
conditionalyHidden.conditionallyHidden = component.hidden;
conditionalyHidden.conditionallyHidden = newComponent.hidden;
}
else {
(scope as any).conditionals.push({
path,
conditionallyHidden: component.hidden,
conditionallyHidden: newComponent.hidden,
});
}
}
Expand Down
Loading