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

fixing child components being displayed when they should be removed when clearOnHide is set #120

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
183 changes: 182 additions & 1 deletion src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2938,7 +2938,7 @@ describe('Process Tests', () => {
}
],

};
};
const submission = {
"data": {
"candidates": [
Expand Down Expand Up @@ -2977,7 +2977,188 @@ describe('Process Tests', () => {
submit: true

});

})
it('Should not return fields from conditionally hidden containers, clearOnHide = false', async () => {

const TestForm45588WithClearOnHideFalse = {
display: 'form',
"components": [
{
"title": "__information_on_the_appointee",
"theme": "primary",
"collapsible": false,
"key": "HeadingNestedFormCandidates",
"type": "panel",
"label": "Appointees",
"input": false,
"tableView": false,
"components": [
{
"label": "Appointees",
"hideLabel": true,
"tableView": false,

"addAnother": "__add_appointee",
"modal": true,
"saveRow": "Close",
"rowDrafts": true,
"key": "candidates",
"type": "editgrid",
"displayAsTable": false,
"input": true,
"components": [
{
"label": "Appointee",
"tableView": false,
"key": "candidate",
"type": "container",
"input": true,
"components": [
{
"label": "Data",
"tableView": false,
"key": "data",
"type": "container",
"input": true,
"components": [
{
"label": "Tabs",
"components": [
{
"label": "__6_time_commitment",
"key": "section6tab",
"components": [
{
"label": "Section 6",
"tableView": false,
"clearOnHide": false,
"validateWhenHidden": false,
"key": "section6",
"properties": {
"clearHiddenOnSave": "true"
},
"customConditional": "show = false;",
"type": "container",
"input": true,
"components": [
{
"title": "__6_dash_time_commitment",
"theme": "primary",
"collapsible": false,
"key": "heading6",
"type": "panel",
"label": "Time Commitment",
"input": false,
"tableView": false,
"components": [
{
"label": "__a_information_to_be_provided_by_the_supervised_entity_the",
"description": "__ul_li_see_the_report_on_declared_time_commitment_of",
"autoExpand": false,
"tableView": true,
"validate": {
"required": true
},
"key": "entityExpectedTimeCommit",
"type": "textarea",
"input": true
},
{
"label": "c",
"tableView": false,
"key": "c",
"type": "container",
"input": true,
"components": []
},
{
"label": "__d_list_of_executive_and_non_executive_directorships_and_other",
"description": "__for_each_directorship_or_other_activity_a_separate_row_needs",
"tableView": false,
"addAnother": "__add_another",
"validate": {
"required": true
},
"rowDrafts": false,
"key": "d",
"type": "editgrid",
"input": true,
"components": []
}
]
}
]
}
]
}
],
"key": "tabs1",
"type": "tabs",
"input": false,
"tableView": false
}
]
}
]
}
]
}
]
},
{
"label": "Submit",
"action": "saveState",
"showValidations": false,
"tableView": false,
"key": "submit",
"type": "button",
"input": true,
"state": "draft"
}
],

};

const submission = {
"data": {
"candidates": [
{
"candidate": {
"data": {
"section6": {
"c": {},
"d": []
}
}
}
}
],
"submit": true
}
};

const context = {
form: TestForm45588WithClearOnHideFalse,
submission,
data: submission.data,
components: TestForm45588WithClearOnHideFalse.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(JSON.stringify(context.data, null, 2))
expect(context.data).to.deep.equal({
candidates:[{candidate:{data:{section6:{}}}}],
submit: true

});
})

describe('For EditGrid:', () => {
const components = [
Expand Down
3 changes: 2 additions & 1 deletion src/process/clearHidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const clearHiddenProcess: ProcessorFnSync<ClearHiddenScope> = (context) =
if (!scope.clearHidden) {
scope.clearHidden = {};
}
//conditional path is a partial path, check to see if in the path
const conditionallyHidden = (scope as ConditionsScope).conditionals?.find((cond) => {
return cond.path === path;
return path.includes(cond.path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the path set in the conditionals is partial, relaxing the check from exact match to component path contains the conditional path

});
if (
conditionallyHidden?.conditionallyHidden &&
Expand Down
13 changes: 0 additions & 13 deletions src/process/conditions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ import {
isJSONConditional
} from 'utils/conditions';

const skipOnServer = (context: ConditionsContext): boolean => {
const { component, config } = context;
const clearOnHide = component.hasOwnProperty('clearOnHide') ? component.clearOnHide : true;
if (config?.server && !clearOnHide) {
// No need to run conditionals on server unless clearOnHide is set.
return true;
}
return false;
};
Comment on lines -15 to -23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used


const hasCustomConditions = (context: ConditionsContext): boolean => {
const { component } = context;
Expand Down Expand Up @@ -102,10 +93,6 @@ export const conditionalProcess = (context: ConditionsContext, isHidden: Conditi
scope.conditionals.push(conditionalComp);
}

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

conditionalComp.conditionallyHidden = conditionalComp.conditionallyHidden || isHidden(context);
if (conditionalComp.conditionallyHidden) {
const info = componentInfo(component);
Expand Down
Loading