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 #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -4965,6 +4965,112 @@ describe('Process Tests', function () {
assert.deepEqual(context.data, submission.data);
});

it('Should properly validate comopnents inside Data Components with Advanced logic', async function () {
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', function () {
const nestedForm = {
key: 'form',
Expand Down
9 changes: 8 additions & 1 deletion src/utils/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { get, set, clone, isEqual, assign } from 'lodash';
import { evaluate, interpolate } from 'modules/jsonlogic';
import { setComponentScope } from 'utils/formUtil';
import { fastCloneDeep } from "./fastCloneDeep";

export const hasLogic = (context: LogicContext): boolean => {
const { component } = context;
Expand Down Expand Up @@ -73,7 +74,13 @@ export function setActionBooleanProperty(
const currentValue = get(component, property, false).toString();
const newValue = action.state.toString();
if (currentValue !== newValue) {
set(component, property, newValue === 'true');
if (property === 'hidden') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If the property is hidden and we don't clone, wouldn't the same issue affect subsequent rows of the component?
  2. We have a similar set of circumstances with conditionally hidden components, where we set an ephemeral "scope" on the component and then reset that scope each time we iterate rows. Is there an opportunity here for something similar so that we don't just willy nilly clone the component JSON?

set(component, 'hidden', newValue === 'true');
} else {
const newComponent = fastCloneDeep(component);
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 Down
Loading