Skip to content

Commit

Permalink
fix: proper key change handling and repeatable filtering
Browse files Browse the repository at this point in the history
Related to #808
  • Loading branch information
Skaiir committed Dec 11, 2023
1 parent ec819b2 commit 0c4f873
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class UpdateKeyClaimHandler {
const valuePath = this._pathRegistry.getValuePath(formField, options);

if (claiming) {
this._pathRegistry.claimPath(valuePath, { isClosed: true });
this._pathRegistry.claimPath(valuePath, { isClosed: true, claimerId: formField.id });
} else {
this._pathRegistry.unclaimPath(valuePath);
}
Expand All @@ -36,13 +36,14 @@ export default class UpdateKeyClaimHandler {
revert(context) {
const {
claiming,
formField,
valuePath
} = context;

if (claiming) {
this._pathRegistry.unclaimPath(valuePath);
} else {
this._pathRegistry.claimPath(valuePath, { isClosed: true });
this._pathRegistry.claimPath(valuePath, { isClosed: true, claimerId: formField.id });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function Key(props) {
// unclaim temporarily to avoid self-conflicts
pathRegistry.unclaimPath(oldPath);
const canClaim = pathRegistry.canClaimPath(newPath, { isClosed: true, claimerId: field.id });
pathRegistry.claimPath(oldPath, { isClosed: true });
pathRegistry.claimPath(oldPath, { isClosed: true, claimerId: field.id });

return canClaim ? null : 'Must not conflict with other key/path assignments.';
};
Expand Down
7 changes: 6 additions & 1 deletion packages/form-js-viewer/src/core/PathRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,17 @@ export default class PathRegistry {
result = result && callResult;
}

// stop executing if false is specifically returned
if (result === false) {
return result;
}

if (Array.isArray(field.components)) {
for (const child of field.components) {
const callResult = this.executeRecursivelyOnFields(child, fn, clone(context));
result = result && callResult;

// only stop executing if false is specifically returned, not if undefined
// stop executing if false is specifically returned
if (result === false) {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export default class ConditionChecker {
throw new Error('form field registry has no form');
}

this._pathRegistry.executeRecursivelyOnFields(form, ({ field, isClosed, context }) => {
this._pathRegistry.executeRecursivelyOnFields(form, ({ field, isClosed, isRepeatable, context }) => {
const { conditional: condition } = field;

context.isHidden = context.isHidden || (condition && this._checkHideCondition(condition, data));

// only clear the leaf nodes, as groups may both point to the same path
if (context.isHidden && isClosed) {
// if a field is a leaf node (or repeatable, as they behave similarly), and hidden, we need to clear the value from the data from each index
if (context.isHidden && (isClosed || isRepeatable)) {
this._clearObjectValueRecursively(getFilterPath(field), newProperties);
}
});
Expand Down

0 comments on commit 0c4f873

Please sign in to comment.