Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Apr 16, 2024
2 parents ac961eb + b9ebc0a commit 959a9ac
Show file tree
Hide file tree
Showing 31 changed files with 490 additions and 12,116 deletions.
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [Unreleased: 2.1.0-rc.1]
### Changed
- FIO-8177: fix unsetting empty array values
- FIO-8185: Fixing issues with EditGrid and DataGrid clearOnHide with Conditionally visible elements
- FIO-8178: correctly add "validator" param to interpolated error object
- FIO-8121: Fix json and custom validation errors response
- FIO-8128: allow export of dist minified js
- FIO-8143: update eachComponent to be able to return proper pathing


## 2.0.0-rc.24
### Changed
- FIO-8106: add default storeas value to tags
Expand Down
6 changes: 4 additions & 2 deletions src/error/FieldError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ type FieldErrorContext = ValidationContext & {
export class FieldError {
context: FieldErrorContext
errorKeyOrMessage: string;
ruleName: string;
level?: string;
constructor(errorKeyOrMessage: string, context: FieldErrorContext) {
constructor(errorKeyOrMessage: string, context: FieldErrorContext, ruleName: string = errorKeyOrMessage) {
const { component, hasLabel = true, field = getComponentErrorField(component, context), level = 'error' } = context;
this.ruleName = ruleName;
if (context.component.validate?.customMessage) {
this.errorKeyOrMessage = context.component.validate.customMessage;
this.context = { ...context, hasLabel: false, field, level };
Expand All @@ -40,4 +42,4 @@ export class FieldError {
}
}

export type InterpolateErrorFn = (text: string, context: FieldErrorContext) => string;
export type InterpolateErrorFn = (text: string, context: FieldErrorContext) => string;
104 changes: 104 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,110 @@ describe('Process Tests', () => {
processSync(context);
expect(context.data).to.deep.equal({ textField: '' });
});

it('Should allow conditionally hidden text fields within DataGrid and EditGrids', async () => {
const form = {
display: 'form',
components: [
{
"label": "Edit Grid",
"tableView": false,
"rowDrafts": false,
"key": "editGrid",
"type": "editgrid",
"displayAsTable": false,
"input": true,
"components": [
{
"label": "Select",
"widget": "choicesjs",
"tableView": true,
"data": {
"values": [
{
"label": "Action1",
"value": "action1"
},
{
"label": "Custom",
"value": "custom"
}
]
},
"key": "select",
"type": "select",
"input": true
},
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"key": "textField",
"conditional": {
"show": true,
"conjunction": "all",
"conditions": [
{
"component": "editGrid.select",
"operator": "isEqual",
"value": "custom"
}
]
},
"type": "textfield",
"input": true
}
]
},
{
"type": "button",
"label": "Submit",
"key": "submit",
"disableOnInvalid": true,
"input": true,
"tableView": false
}
]
};

const submission = {
data: {
editGrid: [
{
"select": "action1"
},
{
"select": "custom",
"textField": "TEST"
}
]
}
};

const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.evaluator,
scope: {},
config: {
server: true
}
};
processSync(context);
expect(context.data).to.deep.equal({
"editGrid": [
{
"select": "action1"
},
{
"select": "custom",
"textField": "TEST"
}
]
});
});
/*
it('Should not clearOnHide when set to false', async () => {
var components = [
Expand Down
12 changes: 10 additions & 2 deletions src/process/clearHidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
ProcessorScope,
ProcessorContext,
ProcessorInfo,
ProcessorFnSync
ProcessorFnSync,
ConditionsScope
} from "types";

type ClearHiddenScope = ProcessorScope & {
Expand All @@ -20,7 +21,14 @@ export const clearHiddenProcess: ProcessorFnSync<ClearHiddenScope> = (context) =
if (!scope.clearHidden) {
scope.clearHidden = {};
}
if (component.hidden && value !== undefined && (!component.hasOwnProperty('clearOnHide') || component.clearOnHide)) {
const conditionallyHidden = (scope as ConditionsScope).conditionals?.find((cond) => {
return cond.path === path;
});
if (
conditionallyHidden?.conditionallyHidden &&
(value !== undefined) &&
(!component.hasOwnProperty('clearOnHide') || component.clearOnHide)
) {
unset(data, path);
scope.clearHidden[path] = true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/process/conditions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,18 @@ export const conditionalProcess = (context: ConditionsContext, isHidden: Conditi
if (!scope.conditionals) {
scope.conditionals = [];
}
scope.conditionals.push({ path, conditionallyHidden: true });
const conditionalComp = scope.conditionals[scope.conditionals.length - 1];
let conditionalComp = scope.conditionals.find((cond) => (cond.path === path));
if (!conditionalComp) {
conditionalComp = {path, conditionallyHidden: false};
scope.conditionals.push(conditionalComp);
}

if (skipOnServer(context)) {
return false;
}

const conditionallyHidden = isHidden(context);
if (conditionallyHidden) {
conditionalComp.conditionallyHidden = conditionallyHidden;
conditionalComp.conditionallyHidden = conditionalComp.conditionallyHidden || isHidden(context);
if (conditionalComp.conditionallyHidden) {
const info = componentInfo(component);
if (info.hasColumns || info.hasComps || info.hasRows) {
// If this is a container component, we need to add all the child components as conditionally hidden as well.
Expand All @@ -119,8 +121,6 @@ export const conditionalProcess = (context: ConditionsContext, isHidden: Conditi
else {
set(component, 'hidden', true);
}
} else {
conditionalComp.conditionallyHidden = false;
}
};

Expand Down
73 changes: 73 additions & 0 deletions src/process/filter/__tests__/filter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { expect } from 'chai';

import { filterProcessSync } from '../';
import { generateProcessorContext } from '../../__tests__/fixtures/util';

it('Should not filter empty array value for dataGrid component', async () => {
const dataGridComp = {
type: 'datagrid',
key: 'dataGrid',
input: true,
path: 'dataGrid',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
dataGrid: []
};
const context: any = generateProcessorContext(dataGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true}});
});

it('Should not filter empty array value for editGrid component', async () => {
const editGridComp = {
type: 'editgrid',
key: 'editGrid',
input: true,
path: 'editGrid',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
editGrid: []
};
const context: any = generateProcessorContext(editGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': true}});
});

it('Should not filter empty array value for datTable component', async () => {
const dataTableComp = {
type: 'datatable',
key: 'dataTable',
input: true,
path: 'dataTable',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
dataTable: []
};
const context: any = generateProcessorContext(dataTableComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true}});
});
28 changes: 23 additions & 5 deletions src/process/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,31 @@ export const filterProcessSync: ProcessorFnSync<FilterScope> = (context: FilterC
const modelType = Utils.getModelType(component);
switch (modelType) {
case 'dataObject':
scope.filter[absolutePath] = {data: {}};
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
value: {data: {}}
};
break;
case 'array':
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
break;
case 'object':
if (component.type !== 'container') {
scope.filter[absolutePath] = true;
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
}
break;
default:
scope.filter[absolutePath] = true;
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
break;
}
}
Expand All @@ -36,10 +50,14 @@ export const filterPostProcess: ProcessorFnSync<FilterScope> = (context: FilterC
const { scope, submission } = context;
const filtered = {};
for (const path in scope.filter) {
if (scope.filter[path]) {
if (scope.filter[path].include) {
let value = get(submission?.data, path);
if (isObject(value) && isObject(scope.filter[path])) {
value = {...value, ...scope.filter[path]}
if (scope.filter[path].compModelType === 'dataObject') {
value = {...value, ...scope.filter[path].value, data: (value as any)?.data}
} else {
value = {...value, ...scope.filter[path].value}
}
}
set(filtered, path, value);
}
Expand Down
5 changes: 3 additions & 2 deletions src/process/validation/__tests__/Validator.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import get from 'lodash/get';
import { expect } from 'chai';
import { validateProcess } from '../index';
import { rules } from "../rules";
import { simpleForm } from './fixtures/forms';
import { ProcessorType, ValidationScope } from 'types';
import get from 'lodash/get';

it('Validator will throw the correct errors given a flat components array', async () => {
let errors: string[] = [];
const data = {
Expand All @@ -27,7 +28,7 @@ it('Validator will throw the correct errors given a flat components array', asyn
path,
value: get(data, component.key),
processor: ProcessorType.Validate,
rules: rules
rules
});
if (scope.errors) {
errors = [...errors, ...scope.errors.map((error) => error.errorKeyOrMessage)];
Expand Down
31 changes: 0 additions & 31 deletions src/process/validation/__tests__/fixtures/components.d.ts

This file was deleted.

Loading

0 comments on commit 959a9ac

Please sign in to comment.