Skip to content

Commit

Permalink
Ensure we allow process call to include the parent and parentPaths so…
Browse files Browse the repository at this point in the history
… any component can be checked independently.
  • Loading branch information
travist committed Nov 15, 2024
1 parent 0aa0de3 commit f16636e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/process/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { hideChildrenProcessorInfo } from './hideChildren';
export async function process<ProcessScope>(
context: ProcessContext<ProcessScope>,
): Promise<ProcessScope> {
const { instances, components, data, scope, flat, processors } = context;
const { instances, components, data, scope, flat, processors, parent, parentPaths } = context;
await eachComponentDataAsync(
components,
data,
Expand Down Expand Up @@ -57,6 +57,9 @@ export async function process<ProcessScope>(
return true;
}
},
false,
parent,
parentPaths,
);
for (let i = 0; i < processors?.length; i++) {
const processor = processors[i];
Expand All @@ -68,7 +71,7 @@ export async function process<ProcessScope>(
}

export function processSync<ProcessScope>(context: ProcessContext<ProcessScope>): ProcessScope {
const { instances, components, data, scope, flat, processors } = context;
const { instances, components, data, scope, flat, processors, parent, parentPaths } = context;
eachComponentData(
components,
data,
Expand Down Expand Up @@ -97,6 +100,9 @@ export function processSync<ProcessScope>(context: ProcessContext<ProcessScope>)
return true;
}
},
false,
parent,
parentPaths,
);
for (let i = 0; i < processors?.length; i++) {
const processor = processors[i];
Expand Down
1 change: 0 additions & 1 deletion src/types/BaseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export type BaseComponent = {
validateOn?: string;
validateWhenHidden?: boolean;
modelType?: ReturnType<typeof getModelType>;
parentPath?: string;
validate?: {
required?: boolean;
custom?: string;
Expand Down
3 changes: 3 additions & 0 deletions src/types/process/ProcessContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ProcessorContext,
ProcessType,
ProcessorInfo,
ComponentPaths,
} from 'types';

export type ComponentInstances = {
Expand All @@ -21,6 +22,8 @@ export type BaseProcessContext<ProcessorScope> = {
form?: any;
submission?: any;
flat?: boolean;
parent?: Component;
parentPaths?: ComponentPaths;
evalContext?: (context: ProcessorContext<ProcessorScope>) => any;
};

Expand Down
16 changes: 14 additions & 2 deletions src/utils/formUtil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ export function componentMatches(
}
}

// Get the current model type.
const modelType = getModelType(component);
const dataModel = modelType !== 'none' && modelType !== 'content';

[
ComponentPath.path,
ComponentPath.fullPath,
Expand All @@ -387,8 +391,16 @@ export function componentMatches(
].forEach((type) => {
const dataPath = type === ComponentPath.dataPath || type === ComponentPath.localDataPath;
if (paths[type as ComponentPath] === path) {
// Only add a new match if it already doesn't exist OR if the dataIndex is the same (more direct match).
if (!matches[type as ComponentPath] || dataPath || dataIndex === paths.dataIndex) {
const currentMatch = matches[type as ComponentPath];
const currentModelType = currentMatch?.component
? getModelType(currentMatch.component)
: 'none';
const currentDataModel = currentModelType !== 'none' && currentModelType !== 'content';
if (
!currentMatch ||
(dataPath && dataModel && currentDataModel) || // Replace the current match if this is a dataPath and both are dataModels.
(!dataPath && dataIndex === paths.dataIndex) // Replace the current match if this is not a dataPath and the indexes are the same.
) {
if (dataPath) {
const dataPaths = {
dataPath: paths.dataPath || '',
Expand Down

0 comments on commit f16636e

Please sign in to comment.