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-9299: ensure eachComponent does not mutate a component's path #184

Merged
merged 2 commits into from
Nov 4, 2024
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
25 changes: 22 additions & 3 deletions src/process/processOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function dataValue(component: Component, row: any) {
}

export async function processOne<ProcessorScope>(context: ProcessorsContext<ProcessorScope>) {
const { processors, component } = context;
const { processors, component, path } = context;
// Create a getter for `value` that is always derived from the current data object
if (typeof context.value === 'undefined') {
Object.defineProperty(context, 'value', {
Expand All @@ -22,8 +22,18 @@ export async function processOne<ProcessorScope>(context: ProcessorsContext<Proc
},
});
}
// 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

// Define the component path
Object.defineProperty(component, 'path', {
enumerable: false,
writable: true,
value: path,
});

// 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
resetEphemeralState(component);

if (!context.row) {
return;
}
Expand All @@ -36,7 +46,7 @@ export async function processOne<ProcessorScope>(context: ProcessorsContext<Proc
}

export function processOneSync<ProcessorScope>(context: ProcessorsContext<ProcessorScope>) {
const { processors, component } = context;
const { processors, component, path } = context;
// Create a getter for `value` that is always derived from the current data object
if (typeof context.value === 'undefined') {
Object.defineProperty(context, 'value', {
Expand All @@ -49,8 +59,17 @@ export function processOneSync<ProcessorScope>(context: ProcessorsContext<Proces
},
});
}

// Define the component path
Object.defineProperty(component, 'path', {
enumerable: false,
writable: true,
value: path,
});

// 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
resetEphemeralState(component);

if (!context.row) {
return;
}
Expand Down
27 changes: 0 additions & 27 deletions src/utils/__tests__/fixtures/components5.json

This file was deleted.

Loading
Loading