Skip to content
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
8 changes: 0 additions & 8 deletions src/process/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export async function process<ProcessScope>(
components,
data,
async (component, compData, row, path, components, index, parent) => {
// Skip processing if row is null or undefined
if (!row) {
return;
}
await processOne<ProcessScope>({
...context,
data: compData,
Expand Down Expand Up @@ -74,10 +70,6 @@ export function processSync<ProcessScope>(context: ProcessContext<ProcessScope>)
components,
data,
(component, compData, row, path, components, index, parent) => {
// Skip processing if row is null or undefined
if (!row) {
return;
}
processOneSync<ProcessScope>({
...context,
data: compData,
Expand Down
8 changes: 0 additions & 8 deletions src/process/processOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ export async function processOne<ProcessorScope>(context: ProcessorsContext<Proc
// If the component has ephemeral state, then we need to reset it in case this is e.g. a data grid,
// in which each row needs to be validated independently
resetEphermalState(component);

if (!context.row) {
return;
}
context.processor = ProcessorType.Custom;
for (const processor of processors) {
if (processor?.process) {
Expand Down Expand Up @@ -69,10 +65,6 @@ export function processOneSync<ProcessorScope>(context: ProcessorsContext<Proces

// If the component has ephemeral state, then we need to reset the ephemeral state in case this is e.g. a data grid, in which each row needs to be validated independently
resetEphermalState(component);

if (!context.row) {
return;
}
context.processor = ProcessorType.Custom;
for (const processor of processors) {
if (processor?.processSync) {
Expand Down
42 changes: 26 additions & 16 deletions src/utils/formUtil/eachComponentData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,40 @@ export const eachComponentData = (
if (fn(component, data, row, compPath, componentComponents, index, compParent) === true) {
return true;
}
const modelType = getModelType(component);
if (isComponentNestedDataType(component)) {
const value = get(data, compPath, data) as DataObject;
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
const nestedComponentPath =
getModelType(component) === 'nestedDataArray'
? `${compPath}[${i}].data`
: `${compPath}[${i}]`;
const value = get(data, compPath) as DataObject;
if (modelType === 'nestedArray' || modelType === 'nestedDataArray') {
if (Array.isArray(value) && value.length) {
for (let i = 0; i < value.length; i++) {
const nestedComponentPath =
modelType === 'nestedDataArray' ? `${compPath}[${i}].data` : `${compPath}[${i}]`;
eachComponentData(
component.components,
data,
fn,
nestedComponentPath,
i,
component,
includeAll,
);
}
return true;
} else if (includeAll) {
eachComponentData(
component.components,
data,
fn,
nestedComponentPath,
i,
modelType === 'nestedDataArray' ? `${compPath}[0].data` : `${compPath}[0]`,
0,
component,
includeAll,
);
} else {
// This is an empty nested array, so we do not need to process the children.
return true;
}
return true;
} else if (isEmpty(row) && !includeAll) {
// Tree components may submit empty objects; since we've already evaluated the parent tree/layout component, we won't worry about constituent elements
return true;
}
if (getModelType(component) === 'dataObject') {
} else if (modelType === 'dataObject') {
const nestedFormValue: any = get(data, component.path);
const noReferenceAttached = nestedFormValue?._id
? isEmpty(nestedFormValue.data) && !has(nestedFormValue, 'form')
Expand Down Expand Up @@ -97,7 +107,7 @@ export const eachComponentData = (
);
}
return true;
} else if (getModelType(component) === 'none') {
} else if (modelType === 'none') {
const info = componentInfo(component);
if (info.hasColumns) {
const columnsComponent = component as HasColumns;
Expand Down
42 changes: 26 additions & 16 deletions src/utils/formUtil/eachComponentDataAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,40 @@ export const eachComponentDataAsync = async (
) {
return true;
}
const modelType = getModelType(component);
if (isComponentNestedDataType(component)) {
const value = get(data, compPath, data);
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
const nestedComponentPath =
getModelType(component) === 'nestedDataArray'
? `${compPath}[${i}].data`
: `${compPath}[${i}]`;
const value = get(data, compPath);
if (modelType === 'nestedArray' || modelType === 'nestedDataArray') {
if (Array.isArray(value) && value.length) {
for (let i = 0; i < value.length; i++) {
const nestedComponentPath =
modelType === 'nestedDataArray' ? `${compPath}[${i}].data` : `${compPath}[${i}]`;
await eachComponentDataAsync(
component.components,
data,
fn,
nestedComponentPath,
i,
component,
includeAll,
);
}
return true;
} else if (includeAll) {
await eachComponentDataAsync(
component.components,
data,
fn,
nestedComponentPath,
i,
modelType === 'nestedDataArray' ? `${compPath}[0].data` : `${compPath}[0]`,
0,
component,
includeAll,
);
} else {
// This is an empty nested array, so we do not need to process the children.
return true;
}
return true;
} else if (isEmpty(row) && !includeAll) {
// Tree components may submit empty objects; since we've already evaluated the parent tree/layout component, we won't worry about constituent elements
return true;
}
if (getModelType(component) === 'dataObject') {
} else if (modelType === 'dataObject') {
const nestedFormValue: any = get(data, component.path);
const noReferenceAttached = nestedFormValue?._id
? isEmpty(nestedFormValue.data) && !has(nestedFormValue, 'form')
Expand Down Expand Up @@ -100,7 +110,7 @@ export const eachComponentDataAsync = async (
);
}
return true;
} else if (getModelType(component) === 'none') {
} else if (modelType === 'none') {
const info = componentInfo(component);
if (info.hasColumns) {
const columnsComponent = component as HasColumns;
Expand Down
Loading